ASM this library is major p.i.t.a cause releases aren't backwards compatible, and is done for the performance improvements. Spring doesn't plan to upgrade as from this post and this post but instead will reference a packaged version of asm, due to release with Spring 3.0 M3 . This is all part of the cost of working with milestones.
Google app engine / java uses Data Nucleus to enhance class files for persistence and relies on asm 3.1. Currently I am using the maven-datanucleus-plugin to enhance my class files. With maven I couldn't figure out how to include both libraries. The solution was to define the asm 2.3.2 libraries with scope runtime, and change ant-macros.xml file to not failonerror to false. I haven't tested on gae/j itself and just hosted mode, and this seemed to work. Also I had to define the datanucleus-core dependency as runtime scope as well, because the plugin requires 1.1.2, and gae only works with 1.1.1 now.
Wednesday, April 29, 2009
Tuesday, April 28, 2009
GWT, Spring 3.0 MVC, and REST on Google App Engine / Java - Part 2
From Part 1 of GWT, Spring 3.0 MVC and REST on Gae/J posting, you should now have a spring application with REST up and running and should be deployable on google app engine.
Integrating GWT with your backend now is pretty straight forward for the most part. Restlet is a REST framework, they released a module called Restlet-GWT module. For more understanding about it and why use rest with GWT, here is a link to blog posting on release Restlet ported to GWT. I'll be referring to the Greeting demo when you create a new application with the Google eclipse plugin. In what ever you named your Entry point class, look for the function
private void sendNameToServer()
your going to replace everything from greetService.greetServer(textToServer, with this..
final Client client = new Client(Protocol.HTTP);
client.get("http://localhost:/greet.json", new Callback() {
public void onEvent(Request request, Response response) {
dialogBox.setText("Remote Procedure Call");
serverResponseLabel.removeStyleName("serverResponseLabelError");
JSONValue json;
json = JSONParser.parse(response.getEntity().getText());
JSONValue value = json.isObject().get("hello");
serverResponseLabel.setHTML(value.toString());
dialogBox.center();
closeButton.setFocus(true);
}
});
Sorry for formatting, but you can see
client.get("http://localhost:/greet.json", new Callback() {
here is where I'm calling the rest url to retrieve the json string returned from the backend and GWT already provides functionality to parse JSON. For more information on Restlet-GWT. Restlet Maven Repository.
I found an issue with running Spring MVC 3.0 on google app engine ( could be only hosted mode). GWT compiles and generates a bunch of css, and javascript files. To get the nice REST style url's all requests need to be mapped to context
( / )
The servlet mapping will match the longest matching map first. So when something like
is given .. this should go directly to the mapping default servlet (above example), and not the main spring dispatcher. The issue is with jetty vs tomcat and how they handle paths. From the posting I found on stackoverflow (servlet for serving static content) "The problem is that Tomcat's default servlet does not take the ServletPath into account (so it looks for the static files in the main folder), while Jetty does (so it looks in the static folder)." Luckily the user provides the file of a servlet. In the servlet I made one change in the servlet class provided.
In the function protected String getPath(HttpServletRequest req).. I changed it to return pathInfo; and not return servletPath + pathInfo; . This changes makes the behavior like Tomcat, and so you won't have to move all your files inside of a folder called static. This basically ignores the /static/ and looks for path after that. Now in your web.xml just define new servlet, and define for static mapping.
Thats it.. You should now have your GWT front end talking to your Spring 3.0 MVC application running in hosted mode, and GAE/J. The cool thing is now you can switch between regular spring mvc application functionality (exmaple: submitting forms) using html, css and GWT. Coming up - Nightmare dependencies with Spring 3.0 M2 and Data nucleus GAE/J, GenericDao with Spring and JDO, and Spring Security.
Integrating GWT with your backend now is pretty straight forward for the most part. Restlet is a REST framework, they released a module called Restlet-GWT module. For more understanding about it and why use rest with GWT, here is a link to blog posting on release Restlet ported to GWT. I'll be referring to the Greeting demo when you create a new application with the Google eclipse plugin. In what ever you named your Entry point class, look for the function
private void sendNameToServer()
your going to replace everything from greetService.greetServer(textToServer, with this..
final Client client = new Client(Protocol.HTTP);
client.get("http://localhost:
public void onEvent(Request request, Response response) {
dialogBox.setText("Remote Procedure Call");
serverResponseLabel.removeStyleName("serverResponseLabelError");
JSONValue json;
json = JSONParser.parse(response.getEntity().getText());
JSONValue value = json.isObject().get("hello");
serverResponseLabel.setHTML(value.toString());
dialogBox.center();
closeButton.setFocus(true);
}
});
Sorry for formatting, but you can see
client.get("http://localhost:
here is where I'm calling the rest url to retrieve the json string returned from the backend and GWT already provides functionality to parse JSON. For more information on Restlet-GWT. Restlet Maven Repository.
I found an issue with running Spring MVC 3.0 on google app engine ( could be only hosted mode). GWT compiles and generates a bunch of css, and javascript files. To get the nice REST style url's all requests need to be mapped to context
( / )
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/static/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>app</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
The servlet mapping will match the longest matching map first. So when something like
<script type="text/javascript" language="javascript" src="/static/app/app.nocache.js"></script>
is given .. this should go directly to the mapping default servlet (above example), and not the main spring dispatcher. The issue is with jetty vs tomcat and how they handle paths. From the posting I found on stackoverflow (servlet for serving static content) "The problem is that Tomcat's default servlet does not take the ServletPath into account (so it looks for the static files in the main folder), while Jetty does (so it looks in the static folder)." Luckily the user provides the file of a servlet. In the servlet I made one change in the servlet class provided.
In the function protected String getPath(HttpServletRequest req).. I changed it to return pathInfo; and not return servletPath + pathInfo; . This changes makes the behavior like Tomcat, and so you won't have to move all your files inside of a folder called static. This basically ignores the /static/ and looks for path after that. Now in your web.xml just define new servlet, and define for static mapping.
Thats it.. You should now have your GWT front end talking to your Spring 3.0 MVC application running in hosted mode, and GAE/J. The cool thing is now you can switch between regular spring mvc application functionality (exmaple: submitting forms) using html, css and GWT. Coming up - Nightmare dependencies with Spring 3.0 M2 and Data nucleus GAE/J, GenericDao with Spring and JDO, and Spring Security.
Labels:
gae/j,
google app engine,
google webtoolkit,
gwt,
json,
REST,
spring,
spring 3.0,
spring mvc
Tuesday, April 21, 2009
GWT, Spring 3.0 MVC, and REST on Google App Engine / Java - Part 1
When googleing how to integrate GWT and Spring/Spring mvc, the most popular answer is to use the GWT- Widget/Server Library. The solutions are wrapping pojos as an RPC service or for better performance taking a spring controller and adding RPC functionality by extension.
With the intoduction of REST features in Spring MVC 3.0, this should make integration between GWT and Spring more natural. This is how to get it all working together on Google App Engine / Java.
First use Spring 3.0 M2. To include this in maven
Add the milestone repository
SpringSource Enterprise Bundle Repository - External Bundle Milestones
http://repository.springsource.com/maven/bundles/milestone
Note: ensure your using asm 2.2.3
Now in the web application you need to create the REST support with MVC. The most important feature added is the ContentNegotiatingViewResolver, this will determine which view to present from Accept header or extension, and from media type can resolve appropriate view. Probably the more important type will be for JSON support. In the blog post from Spring about REST in Spring 3 they hint at the JacksonJsonView and its inclusion in WebFlow or Spring Js, and at the time of this posting, unavailable. Anyways.. I really don't care to add web flow, or spring js to my project when using GWT. The project json-lib-ext-spring : details provides a json view that works seamlessly. Ensure that you exclude all spring libraries in your maven dependency.
In you spring configuration , it will look like this now..
In the GreetJsonView just :
import net.sf.json.spring.web.servlet.view.JsonView;
public class GreetJsonView extends JsonView {
}
In the future it should be as easy and changing the class that you extend when spring releases a proper JSON view.
@Controller
@RequestMapping("/greet")
public class GreetController {
@RequestMapping(value = "greet", method = RequestMethod.GET)
public String list(ModelMap modelMap) {
modelMap.put("hello","REST rocks");
return "greet";
}
}
Now when you go to /path/greet it will display the jsp or if you go to /path/greet.json it will return the json string.
For additional details on how to get Spring MVC started and configured -
The most helpful is the pet clinic demo for Spring 3 M2 found in the subversion repository.
AtomView and REST Support
Example program called Spring Finance
Thats it for part 1, in my next post, I will show how to get GWT working with your spring mvc back end through REST calls, and putting it all together to get it working nicely on GAE/J
With the intoduction of REST features in Spring MVC 3.0, this should make integration between GWT and Spring more natural. This is how to get it all working together on Google App Engine / Java.
First use Spring 3.0 M2. To include this in maven
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.spring-library</artifactId>
<type>libd</type>
<version>3.0.0.M2</version>
</dependency>
Add the milestone repository
SpringSource Enterprise Bundle Repository - External Bundle Milestones
http://repository.springsource.com/maven/bundles/milestone
Note: ensure your using asm 2.2.3
Now in the web application you need to create the REST support with MVC. The most important feature added is the ContentNegotiatingViewResolver, this will determine which view to present from Accept header or extension, and from media type can resolve appropriate view. Probably the more important type will be for JSON support. In the blog post from Spring about REST in Spring 3 they hint at the JacksonJsonView and its inclusion in WebFlow or Spring Js, and at the time of this posting, unavailable. Anyways.. I really don't care to add web flow, or spring js to my project when using GWT. The project json-lib-ext-spring : details provides a json view that works seamlessly. Ensure that you exclude all spring libraries in your maven dependency.
In you spring configuration , it will look like this now..
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="mediaTypes">
<map>
<entry key="html" value="text/html"/>
<entry key="json" value="application/json"/>
</map>
</property>
<property name="viewResolvers">
<list>
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</list>
</property>
</bean>
<bean id="greet" class="path.to.GreetJsonView"/>
In the GreetJsonView just :
import net.sf.json.spring.web.servlet.view.JsonView;
public class GreetJsonView extends JsonView {
}
In the future it should be as easy and changing the class that you extend when spring releases a proper JSON view.
@Controller
@RequestMapping("/greet")
public class GreetController {
@RequestMapping(value = "greet", method = RequestMethod.GET)
public String list(ModelMap modelMap) {
modelMap.put("hello","REST rocks");
return "greet";
}
}
Now when you go to /path/greet it will display the jsp or if you go to /path/greet.json it will return the json string.
For additional details on how to get Spring MVC started and configured -
The most helpful is the pet clinic demo for Spring 3 M2 found in the subversion repository.
AtomView and REST Support
Example program called Spring Finance
Thats it for part 1, in my next post, I will show how to get GWT working with your spring mvc back end through REST calls, and putting it all together to get it working nicely on GAE/J
Labels:
gae/j,
google app engine,
gwt,
maven,
REST,
spring,
spring 3.0,
spring mvc
Monday, April 13, 2009
Google App Engine / Java and Maven
When first creating a project with the elipse google plugin, your presented with a project with gwt and gae/j ( google app engine / java) support. The first question I asked is how to get this all working with maven. The best archetype I have found is here gae-mvn-archetype. Instructions as followed:
1 create GAE/J project from maven archetype, artifactId is the app id.
> mvn archetype:generate -DarchetypeCatalog=http://www.mvnsearch.org/maven2
maven2
2 Build project
> mvn package
3 Test
> dev_appserver target\app-name
4 Deploy
> appcfg update target\app-name
But better to go here for specific details Maven for Google Appengine
Two things I've found from first use. First I was receiving ResourceDoesNotExistException: Unable to locate resource in repository. To get around this, in your settings.xml, usually found in /Users/.m2 .. there's a node called interactiveMode. Just comment this line out. As to the exact details I haven't looked into it yet. Second the META-INF directory is created in the resources directory. I would move this to the webapps, directory so the files jdoconfig.xml and persistence.xml are included in final build. Now in the google groups in the posting found here GAE/J Maven Support there's an alternative that doesn't rely on ant or google app engine SDK. I've tried this one out as well but found it to be not as easy to follow or use. I guess its a matter of what happens in the future on support and features, as to which one will be the better choice.
GWT support:
There were two maven plugins I found for this found here : gwt-maven google code and here : Google Web toolkit plugin. Long story short, the contributors from the google code hosted project will now be contributing to the Gwt plugin found on codehaus.org. So using this plugin Google Web toolkit plugin, should be good. The issues I've found is most of the documentation found on the site, refer to version 1.1. Using their plugin repository there was no 1.1 at the time of this post only 1.0 is found on there plugin repository So the solution is to use there sandbox repository found here Sandbox repository. Here you will be able to find the 1.1 release of GWT maven plugin.
1 create GAE/J project from maven archetype, artifactId is the app id.
> mvn archetype:generate -DarchetypeCatalog=http://www.mvnsearch.org/maven2
maven2
2 Build project
> mvn package
3 Test
> dev_appserver target\app-name
4 Deploy
> appcfg update target\app-name
But better to go here for specific details Maven for Google Appengine
Two things I've found from first use. First I was receiving ResourceDoesNotExistException: Unable to locate resource in repository. To get around this, in your settings.xml, usually found in /Users/.m2 .. there's a node called interactiveMode. Just comment this line out. As to the exact details I haven't looked into it yet. Second the META-INF directory is created in the resources directory. I would move this to the webapps, directory so the files jdoconfig.xml and persistence.xml are included in final build. Now in the google groups in the posting found here GAE/J Maven Support there's an alternative that doesn't rely on ant or google app engine SDK. I've tried this one out as well but found it to be not as easy to follow or use. I guess its a matter of what happens in the future on support and features, as to which one will be the better choice.
GWT support:
There were two maven plugins I found for this found here : gwt-maven google code and here : Google Web toolkit plugin. Long story short, the contributors from the google code hosted project will now be contributing to the Gwt plugin found on codehaus.org. So using this plugin Google Web toolkit plugin, should be good. The issues I've found is most of the documentation found on the site, refer to version 1.1. Using their plugin repository there was no 1.1 at the time of this post only 1.0 is found on there plugin repository So the solution is to use there sandbox repository found here Sandbox repository. Here you will be able to find the 1.1 release of GWT maven plugin.
Labels:
gae/j,
google app engine,
google webtoolkit,
gwt,
java,
maven
Subscribe to:
Posts (Atom)