Sunday, October 4, 2015

SharePoint API Research

Seeing whether SharePoint 2013 supports creating related entries by doing the following from the OData 2 spec:
Alternatively a client can create and Link an Entry to a related Entry by leveraging the addressing scheme if the server supports addressing related items. For example, if a server implements the OData URI conventions described in [OData-URI], the address …/Categories(10)/Products points at all the products in the specified category. When a POST request is issued against that products collection (instead of the top-level products collection) the server will create the new product Entry and automatically Link it to the parent category. Clients may combine this method and the previous one to create an Entry that is related to another one implicitly through the relationship implied in the URL, and related to other Entries by explicitly-specified Links in the request body.
http://www.odata.org/documentation/odata-version-2-0/operations/

Thursday, June 25, 2015

Tomcat on OpenShift

Basically needed a testing/learning environment for Spring because doing Spring on JBoss is too cumbersome for me.

Followed a combination of:
https://blog.openshift.com/free-apache-tomcat-hosting-in-the-cloud-for-java-applications-its-called-openshift/
https://blog.openshift.com/how-to-run-apache-tomcat-8-on-openshift/
Did for Tomcat 7. The latter describes the correct env var to use: OPENSHIFT_DIY_IP

Added a user to tomcat-users.xml per the first link so that I could access the manager app. Uploaded a test war (taken from http://www.michael-thomas.com/tech/apache/tomcat/tutorial_firststeps_tomcat/) and verified the application loads.

Friday, March 13, 2015

Grizzly scanning JAX-RS Providers?

Spent half a day troubleshooting issue where Jersey serialization was not working; evidently my RuntimeTypeAdapterFactory that was supposed to be registered as a GSON adapter -- through the following registration path: RuntimeTypeAdapterFactory --> javax.ws.rs.ext.MessageBodyWriter<Object> --> org.glassfish.jersey.client.ClientConfig --> org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory -- wasn't evidently since breakpoints in the MessageBodyWriter weren't getting hit. I was working in Eclipse and had set the project as a higher order dependency via both the project "Order and Export" and the run configuration classpath. Still SOME MessageBodyWriter was registered since I saw its log4j debug output. The funny thing is that the breakpoint in my development MessageBodyWriter was getting hit in the constructor, but not the writeTo method. So that tells me both classes -- the old one and the new one (in a different package) were getting loaded into the classpath and mine was definitely getting created and registered per the above registration path. Could the issue be due to caching? No. Tried clean project, restart Eclipse, etc. Then I started fiddling with the registration path, inserting a test writer from another package. This time that test writer produced writeTo output. But switching back to my desired dev version did not "reset" any cache whether Grizzly or Jersey if there is such a thing. I did not see my dev version getting hit. Then I deleted the test version AND moved the dev version of the MessageBodyWriter to the same project as the Grizzly server and that did the trick. This was inherited code and I started looking at it for clues as to the explanation. Being new to Jersey and JAX-RS I hadn't noticed that one of the annotations on the MessageBodyWriter was @javax.ws.rs.ext.Provider. A quick google search for GSON Jersey integration took me to the following blog http://eclipsesource.com/blogs/2012/11/02/integrating-gson-into-a-jax-rs-based-application/ where it explains that the server scans for @Providers to use. Sure enough, removing the @Provider annotation on the test MessageBodyWriter caused it to not replace my target MessageBodyWriter. So evidently Grizzly tries to behave like a JEE container and scans like one or perhaps it's just following spec (but if it were, then it should have at least produced a warning I believe). Either way, moral of the story is, if you are registring a provider with Grizzly manually via some programmatic registration path such as the one above, DO NOT annotate the providers with @Provider or else you won't know which one is actually being used to do the serialization at runtime!

Monday, October 27, 2014

Eclipse Cougaar Windows

Got "Hello World Demo" working on Win.

Following tutorial: http://cougaar.org/wp/documentation/tutorials/helloworlddemo/
Source: http://cougaar.org/build/ and http://sourceforge.net/projects/cougaar/

In run configuration set Main class to:
org.cougaar.bootstrap.Bootstrapper

Gotchas are: command line is: C:\Work\hello\run>cougaar -v %COUGAAR_SOCIETY_PATH%/configs/HelloWorldSociety.xml SingleNodeRuntime.xml
Note, misnamed 'hello' xml file.
To get running in Eclipse (without using the mentioned cougaar IDE) use the following Run configuration arguments: -Dorg.cougaar.society.xsl.param.template=single_node -Dorg.cougaar.core.logging.config.filename=logging.props -Dorg.cougaar.bootstrap.application=org.cougaar.core.node.Node -Dorg.cougaar.society.file=C:\Work\hello/configs/HelloWorldSociety.xml -Dorg.cougaar.runtime.file=SingleNodeRuntime.xml -Dorg.cougaar.node.name=Node1 -Dorg.cougaar.runtime.path=${env_var:COUGAAR_RUNTIME_PATH} -Dorg.cougaar.society.path=${env_var:COUGAAR_SOCIETY_PATH} -Dorg.cougaar.install.path=${env_var:COUGAAR_INSTALL_PATH} -Xbootclasspath/p:${env_var:COUGAAR_INSTALL_PATH}/lib/javaiopatch.jar -Dorg.cougaar.core.node.InitializationComponent=XML -Djava.class.path=${env_var:COUGAAR_INSTALL_PATH}/lib/bootstrap.jar

Note use of "env_var" -- these are OS environment variables not to be confused with those set in Eclipse Environment tab (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=170789)

Working directory per instructions is set to ${workspace_loc:hello/run}

Monday, September 22, 2014

FactoryBean Woes

Be careful with org.springframework.beans.factory.FactoryBean. I created a couple of them and used them with something like <bean id="mybean" class="pkg.myfactory" />
Everything seemed to work fine. Then as soon as I added a third and fourth, everything went haywire and started getting no end to circular dependency errors. So I had to switch to plain vanilla "factory-bean" beans in xml and everything was fine then!

Friday, August 29, 2014

Researching Hibernate for Queries

How to perform unions and/or one-to-one joins with multiple intermediate tables? Looks like there are no easy solutions. Best may be using SQL or creating numerous hibernate mappings for a legacy database.

Read:
http://hibernate-samples.blogspot.com/2011/10/one-to-one-association-using-join-table.html
 https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Web_Server/1.0/html/Hibernate_Core_Reference_Guide/assoc-bidirectional-join-121.html
 example of multiple intermediate join tables?
 named query: http://stackoverflow.com/questions/8399379/hibernate-named-query-join-3-tables
 with sql: http://jumpingbean.co.za/blogs/mark/hibernate
 http://stackoverflow.com/questions/18257757/how-to-execute-query-with-union-in-hibernate

Wednesday, July 9, 2014

Bit shift operators

Experimentation in Java Snippet Runner to learn about bit shift operator and binary operators based on http://stackoverflow.com/questions/2534116/how-to-convert-get-rgbx-y-integer-pixel-to-colorr-g-b-a-in-java. >>> shifts all bits to the right with the bits falling off the right and zero filling from the left (as opposed to >> which fills from left based on sign (in this case 1 ... 0xAABBCCDD = -1430532899).


int argb = 0xAABBCCDD;
int r = (argb)&0xFF;
int g = (argb>>8)&0xFF;
int b = (argb>>16)&0xFF;
int a = (argb>>24)&0xFF;
int r_ = (argb)&0xFF;
int g_ = (argb>>8)&0xFF;
int b_ = (argb>>16)&0xFF;
int a_ = (argb>>24)&0xFF;
int r_1 = (argb)&0xFFFFFFFF;
int g_1 = (argb>>8)&0xFFFFFFFF;
int b_1 = (argb>>16)&0xFFFFFFFF;
int a_1 = (argb>>24)&0xFFFFFFFF;
System.out.println(Integer.toBinaryString(argb));
System.out.println(r + " red " + Integer.toBinaryString(r_) + "\n" + Integer.toBinaryString(r_1));
System.out.println(g + " green " + Integer.toBinaryString(g_) + "\n" + Integer.toBinaryString(g_1));
System.out.println(b + " blue " + Integer.toBinaryString(b_) + "\n" + Integer.toBinaryString(b_1));
System.out.println(a + " alpha " + Integer.toBinaryString(a_) + "\n" + Integer.toBinaryString(a_1));
System.out.println("righters");
System.out.println((argb>>8));
System.out.println((argb>>16));
System.out.println((argb>>24));

System.out.println(argb +"color methods");
   java.awt.Color c = new java.awt.Color(argb, true);
    System.out.println("red " + c.getRed());
    System.out.println("green " + c.getGreen());
    System.out.println("blue " + c.getBlue());
    System.out.println("alpha "  + c.getAlpha());

10101010101110111100110011011101
221 red 11011101
10101010101110111100110011011101
204 green 11001100
11111111101010101011101111001100
187 blue 10111011
11111111111111111010101010111011
170 alpha 10101010
11111111111111111111111110101010
righters
-5588020
-21829
-86
-1430532899color methods
red 187
green 204
blue 221
alpha 170

OK