<?xml version="1.0" encoding='utf-8'?>
<?xml-stylesheet type="text/xsl" href="https://raibledesigns.com/roller-ui/styles/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom">
    <title type="html">Raible Designs</title>
    <subtitle type="html">Raible Designs is an Enterprise Open Source Consulting company. We specialize in UI and Full Stack Architectures using HTML5, CSS, JavaScript and Java. We love HTML5, Angular, Bootstrap, Spring Boot, and especially JHipster.</subtitle>
    <id>https://raibledesigns.com/rd/feed/entries/atom</id>
            <link rel="self" type="application/atom+xml" href="https://raibledesigns.com/rd/feed/entries/atom?tags=rest" />
        <link rel="alternate" type="text/html" href="https://raibledesigns.com/rd/" />
        <updated>2026-05-25T13:53:18-06:00</updated>
    <generator uri="http://roller.apache.org" version="5.0.3 (1388864191739:dave)">Apache Roller (incubating)</generator>
        <entry>
        <id>https://raibledesigns.com/rd/entry/building_a_rest_api_with</id>
        <title type="html">Building a REST API with JAXB, Spring Boot and Spring Data</title>
        <author><name>Matt Raible</name></author>
        <link rel="alternate" type="text/html" href="https://raibledesigns.com/rd/entry/building_a_rest_api_with"/>
        <published>2014-10-29T05:52:37-06:00</published>
        <updated>2014-10-29T20:25:55-06:00</updated> 
        <category term="/Java" label="Java" />
        <category term="jaxb" scheme="http://roller.apache.org/ns/tags/" />
        <category term="rest" scheme="http://roller.apache.org/ns/tags/" />
        <category term="spring-boot" scheme="http://roller.apache.org/ns/tags/" />
        <category term="spring" scheme="http://roller.apache.org/ns/tags/" />
        <category term="api" scheme="http://roller.apache.org/ns/tags/" />
        <category term="spring-data" scheme="http://roller.apache.org/ns/tags/" />
        <summary type="html">&lt;p&gt;
&lt;a href=&quot;https://jaxb.java.net/&quot;&gt;&lt;img src=&quot;//raibledesigns.com/repository/images/javaxml-duke.gif&quot; alt=&quot;Project JAXB&quot; width=&quot;100&quot; class=&quot;picture&quot; style=&quot;margin-top: -20px&quot;&gt;&lt;/a&gt;
    If someone asked you to develop a REST API on the JVM, which frameworks would you use? I was recently tasked with such a project.
    My client asked me to implement a REST API to ingest requests from a 3rd party. The project entailed consuming XML
    requests, storing the data in a database, then exposing the data to internal application with a JSON endpoint.
    Finally, it would allow taking in a JSON request and turning it into an XML request back to the 3rd party.
&lt;/p&gt;
&lt;p&gt;
    With the recent &lt;a href=&quot;http://www.infoq.com/news/2014/10/apache-camel-2.14&quot;&gt;release of Apache Camel 2.14&lt;/a&gt; and
    &lt;a href=&quot;http://raibledesigns.com/rd/entry/developing_services_with_apache_camel2&quot;&gt;my success using it&lt;/a&gt;, I started by
    copying my Apache Camel / CXF / Spring Boot project and trimming it down to the bare essentials. I whipped together
    a simple &lt;em&gt;Hello World&lt;/em&gt; service using Camel and Spring MVC. I also integrated Swagger into both. Both
    implementations were pretty easy to create (&lt;a href=&quot;http://camel.465427.n5.nabble.com/Camel-s-Swagger-vs-Spring-MVC-Swagger-td5757023.html&quot;&gt;sample code&lt;/a&gt;),
    but I decided to use Spring MVC. My reasons were simple: its REST support was more mature, I knew it well, and
    &lt;a href=&quot;http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/testing.html#spring-mvc-test-framework&quot;&gt;Spring MVC Test&lt;/a&gt; makes it easy to test APIs.
&lt;/p&gt;
&lt;p class=&quot;alert alert-info&quot;&gt;&lt;strong&gt;Camel&apos;s Swagger support without web.xml&lt;/strong&gt;&lt;br/&gt;
    As part of the aforementioned spike, I learned out how to configure Camel&apos;s REST and Swagger support using Spring&apos;s
    JavaConfig and no web.xml. I made this into a sample project and put it on GitHub as
    &lt;a href=&quot;https://github.com/mraible/camel-rest-swagger&quot;&gt;camel-rest-swagger&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
    This article shows how I built a REST API with Java 8, Spring Boot/MVC, JAXB and Spring Data (JPA and REST
    components).
    I stumbled a few times while developing this project, but figured out how to get over all the hurdles. I hope this
    helps the team that&apos;s now maintaining this project (my last day was Friday) and those that are trying to do
    something similar.
&lt;/p&gt;</summary>
        <content type="html">&lt;p&gt;
&lt;a href=&quot;https://jaxb.java.net/&quot;&gt;&lt;img src=&quot;//raibledesigns.com/repository/images/javaxml-duke.gif&quot; alt=&quot;Project JAXB&quot; width=&quot;100&quot; class=&quot;picture&quot; style=&quot;margin-top: -20px&quot;&gt;&lt;/a&gt;
    If someone asked you to develop a REST API on the JVM, which frameworks would you use? I was recently tasked with such a project.
    My client asked me to implement a REST API to ingest requests from a 3rd party. The project entailed consuming XML
    requests, storing the data in a database, then exposing the data to internal application with a JSON endpoint.
    Finally, it would allow taking in a JSON request and turning it into an XML request back to the 3rd party.
&lt;/p&gt;
&lt;p&gt;
    With the recent &lt;a href=&quot;http://www.infoq.com/news/2014/10/apache-camel-2.14&quot;&gt;release of Apache Camel 2.14&lt;/a&gt; and
    &lt;a href=&quot;http://raibledesigns.com/rd/entry/developing_services_with_apache_camel2&quot;&gt;my success using it&lt;/a&gt;, I started by
    copying my Apache Camel / CXF / Spring Boot project and trimming it down to the bare essentials. I whipped together
    a simple &lt;em&gt;Hello World&lt;/em&gt; service using Camel and Spring MVC. I also integrated Swagger into both. Both
    implementations were pretty easy to create (&lt;a href=&quot;http://camel.465427.n5.nabble.com/Camel-s-Swagger-vs-Spring-MVC-Swagger-td5757023.html&quot;&gt;sample code&lt;/a&gt;),
    but I decided to use Spring MVC. My reasons were simple: its REST support was more mature, I knew it well, and
    &lt;a href=&quot;http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/testing.html#spring-mvc-test-framework&quot;&gt;Spring MVC Test&lt;/a&gt; makes it easy to test APIs.
&lt;/p&gt;
&lt;p class=&quot;alert alert-info&quot;&gt;&lt;strong&gt;Camel&apos;s Swagger support without web.xml&lt;/strong&gt;&lt;br/&gt;
    As part of the aforementioned spike, I learned out how to configure Camel&apos;s REST and Swagger support using Spring&apos;s
    JavaConfig and no web.xml. I made this into a sample project and put it on GitHub as
    &lt;a href=&quot;https://github.com/mraible/camel-rest-swagger&quot;&gt;camel-rest-swagger&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
    This article shows how I built a REST API with Java 8, Spring Boot/MVC, JAXB and Spring Data (JPA and REST
    components).
    I stumbled a few times while developing this project, but figured out how to get over all the hurdles. I hope this
    helps the team that&apos;s now maintaining this project (my last day was Friday) and those that are trying to do
    something similar.
&lt;/p&gt;
&lt;h3 id=&quot;jaxb&quot;&gt;XML to Java with JAXB&lt;/h3&gt;
&lt;p&gt;
    The data we needed to ingest from a 3rd party was based on the &lt;a href=&quot;http://ncpdp.org/&quot;&gt;NCPDP&lt;/a&gt; Standards. As a member,
    we were able to download a number of XSD files, put them in our project and generate Java classes to handle the
    incoming/outgoing requests. I used the &lt;a href=&quot;https://java.net/projects/maven-jaxb2-plugin/pages/Home&quot;&gt;maven-jaxb2-plugin&lt;/a&gt;
    to generate the Java classes.
&lt;/p&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;plugin&amp;gt;
    &amp;lt;groupId&amp;gt;org.jvnet.jaxb2.maven2&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;maven-jaxb2-plugin&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;0.8.3&amp;lt;/version&amp;gt;
    &amp;lt;executions&amp;gt;
        &amp;lt;execution&amp;gt;
            &amp;lt;goals&amp;gt;
                &amp;lt;goal&amp;gt;generate&amp;lt;/goal&amp;gt;
            &amp;lt;/goals&amp;gt;
            &amp;lt;configuration&amp;gt;
                &amp;lt;args&amp;gt;
                    &amp;lt;arg&amp;gt;-XtoString&amp;lt;/arg&amp;gt;
                    &amp;lt;arg&amp;gt;-Xequals&amp;lt;/arg&amp;gt;
                    &amp;lt;arg&amp;gt;-XhashCode&amp;lt;/arg&amp;gt;
                    &amp;lt;arg&amp;gt;-Xcopyable&amp;lt;/arg&amp;gt;
                &amp;lt;/args&amp;gt;
                &amp;lt;plugins&amp;gt;
                    &amp;lt;plugin&amp;gt;
                        &amp;lt;groupId&amp;gt;org.jvnet.jaxb2_commons&amp;lt;/groupId&amp;gt;
                        &amp;lt;artifactId&amp;gt;jaxb2-basics&amp;lt;/artifactId&amp;gt;
                        &amp;lt;version&amp;gt;0.6.4&amp;lt;/version&amp;gt;
                    &amp;lt;/plugin&amp;gt;
                &amp;lt;/plugins&amp;gt;
                &amp;lt;schemaDirectory&amp;gt;src/main/resources/schemas/ncpdp&amp;lt;/schemaDirectory&amp;gt;
            &amp;lt;/configuration&amp;gt;
        &amp;lt;/execution&amp;gt;
    &amp;lt;/executions&amp;gt;
&amp;lt;/plugin&amp;gt;
&lt;/pre&gt;
&lt;p&gt;The first error I ran into was about a property already being defined.
&lt;/p&gt;
&lt;pre class=&quot;brush: shell&quot;&gt;
[INFO] --- maven-jaxb2-plugin:0.8.3:generate (default) @ spring-app ---
[ERROR] Error while parsing schema(s).Location [ file:/Users/mraible/dev/spring-app/src/main/resources/schemas/ncpdp/structures.xsd{1811,48}].
com.sun.istack.SAXParseException2; systemId: file:/Users/mraible/dev/spring-app/src/main/resources/schemas/ncpdp/structures.xsd;
    lineNumber: 1811; columnNumber: 48; Property &quot;MultipleTimingModifierAndTimingAndDuration&quot; is already defined.
    Use &amp;lt;jaxb:property&gt; to resolve this conflict.
at com.sun.tools.xjc.ErrorReceiver.error(ErrorReceiver.java:86)
&lt;/pre&gt;
&lt;p&gt;
    I was able to workaround this by upgrading to maven-jaxb2-plugin version 0.9.1. I created a controller and stubbed
    out a response with hard-coded data. I confirmed the incoming XML-to-Java marshalling worked by testing with a
    sample request provided by our 3rd party customer. I started with a &lt;code&gt;curl&lt;/code&gt;
    command, because it was easy to use and could be run by anyone with the file and curl installed.
&lt;/p&gt;
&lt;pre class=&quot;brush: shell&quot;&gt;
curl -X POST -H &apos;Accept: application/xml&apos; -H &apos;Content-type: application/xml&apos; \
--data-binary @sample-request.xml http://localhost:8080/api/message -v
&lt;/pre&gt;
&lt;p&gt;
    This is when I ran into another stumbling block: the response wasn&apos;t getting marshalled back to XML correctly.
    After some research, I found out this was caused by the lack of &lt;code&gt;@XmlRootElement&lt;/code&gt; annotations on my
    generated classes.
    I
    posted a question to Stack Overflow titled &lt;a
        href=&quot;http://stackoverflow.com/questions/26070566/returning-jaxb-generated-elements-from-spring-boot-controller&quot;&gt;
    Returning JAXB-generated elements from Spring Boot Controller&lt;/a&gt;. After banging my head against the wall for a
    couple days, I figured out &lt;a href=&quot;http://stackoverflow.com/a/26124104/65681&quot;&gt;the solution&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
    I created a bindings.xjb file in the same directory as my schemas. This causes JAXB to generate &lt;code&gt;@XmlRootElement&lt;/code&gt;
    on
    classes.
&lt;/p&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot;?&amp;gt;
&amp;lt;jxb:bindings version=&quot;1.0&quot;
              xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;
              xmlns:jxb=&quot;http://java.sun.com/xml/ns/jaxb&quot;
              xmlns:xjc=&quot;http://java.sun.com/xml/ns/jaxb/xjc&quot;
              xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
              xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd&quot;&amp;gt;

    &amp;lt;jxb:bindings schemaLocation=&quot;transport.xsd&quot; node=&quot;/xsd:schema&quot;&amp;gt;
        &amp;lt;jxb:globalBindings&amp;gt;
            &amp;lt;xjc:simple/&amp;gt;
        &amp;lt;/jxb:globalBindings&amp;gt;
    &amp;lt;/jxb:bindings&amp;gt;
&amp;lt;/jxb:bindings&amp;gt;
&lt;/pre&gt;
&lt;p&gt;To add namespaces prefixes to the returned XML, I had to modify the maven-jaxb2-plugin to add a couple arguments.
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;arg&amp;gt;-extension&amp;lt;/arg&amp;gt;
&amp;lt;arg&amp;gt;-Xnamespace-prefix&amp;lt;/arg&amp;gt;
&lt;/pre&gt;
&lt;p&gt;And add a dependency:&lt;/p&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;dependencies&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;org.jvnet.jaxb2_commons&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;jaxb2-namespace-prefix&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;1.1&amp;lt;/version&amp;gt;
    &amp;lt;/dependency&amp;gt;
&amp;lt;/dependencies&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Then I modified &lt;code&gt;bindings.xjb&lt;/code&gt; to include the package and prefix settings. I also moved
    &lt;code&gt;&amp;lt;xjc:simple/&amp;gt;&lt;/code&gt; into a global setting. I eventually had to add prefixes for all schemas and their
    packages. &lt;/p&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot;?&amp;gt;
&amp;lt;bindings version=&quot;2.0&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns=&quot;http://java.sun.com/xml/ns/jaxb&quot;
          xmlns:xjc=&quot;http://java.sun.com/xml/ns/jaxb/xjc&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
          xmlns:namespace=&quot;http://jaxb2-commons.dev.java.net/namespace-prefix&quot;
          xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd
              http://jaxb2-commons.dev.java.net/namespace-prefix http://java.net/projects/jaxb2-commons/sources/svn/content/namespace-prefix/trunk/src/main/resources/prefix-namespace-schema.xsd&quot;&amp;gt;

    &amp;lt;globalBindings&amp;gt;
        &amp;lt;xjc:simple/&amp;gt;
    &amp;lt;/globalBindings&amp;gt;

    &amp;lt;bindings schemaLocation=&quot;transport.xsd&quot; node=&quot;/xsd:schema&quot;&amp;gt;
        &amp;lt;schemaBindings&amp;gt;
            &amp;lt;package name=&quot;org.ncpdp.schema.transport&quot;/&amp;gt;
        &amp;lt;/schemaBindings&amp;gt;
        &amp;lt;bindings&amp;gt;
            &amp;lt;namespace:prefix name=&quot;transport&quot;/&amp;gt;
        &amp;lt;/bindings&amp;gt;
    &amp;lt;/bindings&amp;gt;
&amp;lt;/bindings&amp;gt;
&lt;/pre&gt;
&lt;p&gt;
    I learned how to add prefixes from the &lt;a href=&quot;https://java.net/projects/jaxb2-commons/pages/Namespace-prefix&quot;&gt;namespace-prefix
    plugins page&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;Finally, I customized the code-generation process to generate Joda Time&apos;s
    &lt;a href=&quot;http://joda-time.sourceforge.net/apidocs/org/joda/time/DateTime.html&quot;&gt;DateTime&lt;/a&gt; instead of the
    default &lt;code&gt;XMLGregorianCalendar&lt;/code&gt;. This involved a couple custom XmlAdapters and a couple
    additional lines in &lt;code&gt;bindings.xjb&lt;/code&gt;. You can see the adapters and &lt;code&gt;bindings.xjb&lt;/code&gt; with all
    necessary prefixes
    in &lt;a href=&quot;https://gist.github.com/mraible/abad8d78c1f053ec686b&quot;&gt;this gist&lt;/a&gt;.
    Nicolas Fr&#228;nkel&apos;s &lt;a href=&quot;http://blog.frankel.ch/customize-your-jaxb-bindings&quot;&gt;Customize your JAXB bindings&lt;/a&gt;
    was a great resource for making all this work.
&lt;/p&gt;
&lt;p&gt;I wrote a test to prove that the ingest API worked as desired.&lt;/p&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public class InitiateRequestControllerTest {

    @Inject
    private InitiateRequestController controller;

    private MockMvc mockMvc;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
    }

    @Test
    public void testGetNotAllowedOnMessagesAPI() throws Exception {
        mockMvc.perform(get(&quot;/api/initiate&quot;)
                .accept(MediaType.APPLICATION_XML))
                .andExpect(status().isMethodNotAllowed());
    }

    @Test
    public void testPostPaInitiationRequest() throws Exception {
        String request = new Scanner(new ClassPathResource(&quot;sample-request.xml&quot;).getFile()).useDelimiter(&quot;\\Z&quot;).next();

        mockMvc.perform(post(&quot;/api/initiate&quot;)
                .accept(MediaType.APPLICATION_XML)
                .contentType(MediaType.APPLICATION_XML)
                .content(request))
                .andExpect(status().isOk())
                .andExpect(content().contentType(MediaType.APPLICATION_XML))
                .andExpect(xpath(&quot;/Message/Header/To&quot;).string(&quot;3rdParty&quot;))
                .andExpect(xpath(&quot;/Message/Header/SenderSoftware/SenderSoftwareDeveloper&quot;).string(&quot;HID&quot;))
                .andExpect(xpath(&quot;/Message/Body/Status/Code&quot;).string(&quot;010&quot;));
    }
}
&lt;/pre&gt;
&lt;h3 id=&quot;spring-data&quot;&gt;Spring Data for JPA and REST&lt;/h3&gt;
&lt;p&gt;
    With JAXB out of the way, I turned to creating an internal API that could be used by another application. Spring
    Data was fresh in my mind after &lt;a href=&quot;http://shop.oreilly.com/product/0636920024767.do&quot;&gt;reading about it&lt;/a&gt; last
    summer. I created classes for entities I wanted to persist, using &lt;a href=&quot;http://projectlombok.org/&quot;&gt;Lombok&apos;s&lt;/a&gt;
    @Data to reduce boilerplate.
&lt;/p&gt;
&lt;p&gt;
    I read the &lt;a href=&quot;https://spring.io/guides/gs/accessing-data-jpa/&quot;&gt;Accessing Data with JPA&lt;/a&gt; guide, created
    a couple repositories and wrote some tests to prove they worked. I ran into an issue trying to persist
    Joda&apos;s DateTime and found &lt;a href=&quot;http://jadira.sourceforge.net/usertype-userguide.html&quot;&gt;Jadira&lt;/a&gt; provided a
    solution.
&lt;/p&gt;
&lt;p&gt;
    I added its usertype.core as a dependency to my pom.xml:
&lt;/p&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;org.jadira.usertype&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;usertype.core&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;3.2.0.GA&amp;lt;/version&amp;gt;
&amp;lt;/dependency&amp;gt;
&lt;/pre&gt;
&lt;p&gt;... and annotated DateTime variables accordingly.&lt;/p&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
@Column(name = &quot;last_modified&quot;, nullable = false)
@Type(type=&quot;org.jadira.usertype.dateandtime.joda.PersistentDateTime&quot;)
private DateTime lastModified;
&lt;/pre&gt;
&lt;p&gt;With JPA working, I turned to exposing REST endpoints. I used &lt;a
        href=&quot;https://spring.io/guides/gs/accessing-data-rest/&quot;&gt;Accessing JPA Data with REST&lt;/a&gt;
    as a guide and was looking at JSON in my browser in a matter of minutes. I was surprised to see a &quot;profile&quot; service
    listed next to mine, and posted &lt;a href=&quot;https://github.com/spring-projects/spring-boot/issues/1718&quot;&gt;a question&lt;/a&gt;
    to the Spring Boot team. Oliver Gierke &lt;a
            href=&quot;https://github.com/spring-projects/spring-boot/issues/1718#issuecomment-59329942&quot;&gt;provided an
        excellent answer&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;swagger&quot;&gt;Swagger&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/martypitt/swagger-springmvc&quot;&gt;Spring MVC&apos;s integration for Swagger&lt;/a&gt; has greatly
    improved
    since I &lt;a href=&quot;http://raibledesigns.com/rd/entry/documenting_your_spring_api_with&quot;&gt;last wrote about it&lt;/a&gt;.
    Now you can enable it with a &lt;code&gt;@EnableSwagger&lt;/code&gt; annotation. Below
    is the &lt;code&gt;SwaggerConfig&lt;/code&gt; class I used to configure Swagger and read properties from
    &lt;code&gt;application.yml&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
@Configuration
@EnableSwagger
public class SwaggerConfig implements EnvironmentAware {
	public static final String DEFAULT_INCLUDE_PATTERN = &quot;/api/.*&quot;;

	private RelaxedPropertyResolver propertyResolver;

	@Override
	public void setEnvironment(Environment environment) {
		this.propertyResolver = new RelaxedPropertyResolver(environment, &quot;swagger.&quot;);
	}

	/**
	 * Swagger Spring MVC configuration
	 */
	@Bean
	public SwaggerSpringMvcPlugin swaggerSpringMvcPlugin(SpringSwaggerConfig springSwaggerConfig) {
		return new SwaggerSpringMvcPlugin(springSwaggerConfig)
				.apiInfo(apiInfo())
				.genericModelSubstitutes(ResponseEntity.class)
				.includePatterns(DEFAULT_INCLUDE_PATTERN);
	}

	/**
	 * API Info as it appears on the swagger-ui page
	 */
	private ApiInfo apiInfo() {
		return new ApiInfo(
				propertyResolver.getProperty(&quot;title&quot;),
				propertyResolver.getProperty(&quot;description&quot;),
				propertyResolver.getProperty(&quot;termsOfServiceUrl&quot;),
				propertyResolver.getProperty(&quot;contact&quot;),
				propertyResolver.getProperty(&quot;license&quot;),
				propertyResolver.getProperty(&quot;licenseUrl&quot;));
	}
}
&lt;/pre&gt;
&lt;p&gt;After getting Swagger to work, I discovered that endpoints published with &lt;code&gt;@RepositoryRestResource&lt;/code&gt; aren&apos;t
    picked up by Swagger. There is an &lt;a href=&quot;https://github.com/martypitt/swagger-springmvc/issues/238&quot;&gt;open issue&lt;/a&gt;
    for Spring Data support in the swagger-springmvc project.&lt;/p&gt;

&lt;h3 id=&quot;liquibase&quot;&gt;Liquibase Integration&lt;/h3&gt;
&lt;p&gt;
    I configured this project to use H2 in development and PostgreSQL in production. I used Spring profiles to do this
    and copied XML/YAML (for Maven and application*.yml files) from a previously created &lt;a href=&quot;https://jhipster.github.io&quot;&gt;JHipster&lt;/a&gt;
    project.
&lt;/p&gt;
&lt;p&gt;Next, I needed to create a database. I decided to use &lt;a href=&quot;http://www.liquibase.org/&quot;&gt;Liquibase&lt;/a&gt; to
    create tables, rather than Hibernate&apos;s schema-export. I chose Liquibase
    over &lt;a href=&quot;http://flywaydb.org/&quot;&gt;Flyway&lt;/a&gt; based of discussions in the &lt;a
            href=&quot;https://github.com/jhipster/generator-jhipster/issues/588&quot;&gt;JHipster project&lt;/a&gt;. To use Liquibase with
    Spring Boot is dead simple: add the following dependency to pom.xml, then place changelog files in
    &lt;code&gt;src/main/resources/db/changelog&lt;/code&gt;.
&lt;/p&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;org.liquibase&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;liquibase-core&amp;lt;/artifactId&amp;gt;
&amp;lt;/dependency&amp;gt;
&lt;/pre&gt;&lt;p&gt;
    I started by using Hibernate&apos;s schema-export and changing &lt;code&gt;hibernate.ddl-auto&lt;/code&gt; to &quot;create-drop&quot; in
    &lt;code&gt;application-dev.yml&lt;/code&gt;. I also commented out the liquibase-core dependency.
    Then I setup a PostgreSQL database and started the app with &quot;mvn spring-boot:run -Pprod&quot;.
&lt;/p&gt;
&lt;p&gt;I generated the liquibase changelog from an existing schema using the following command (after
    &lt;a href=&quot;http://www.liquibase.org/download/&quot;&gt;downloading&lt;/a&gt; and installing Liquibase). &lt;/p&gt;
&lt;pre&gt;
liquibase --driver=org.postgresql.Driver --classpath=&quot;/Users/mraible/.m2/repository/org/postgresql/postgresql/9.3-1102-jdbc41/postgresql-9.3-1102-jdbc41.jar:/Users/mraible/snakeyaml-1.11.jar&quot; --changeLogFile=/Users/mraible/dev/spring-app/src/main/resources/db/changelog/db.changelog-02.yaml --url=&quot;jdbc:postgresql://localhost:5432/mydb&quot; --username=user --password=pass generateChangeLog
&lt;/pre&gt;

&lt;p&gt;I did find one bug - the generateChangeLog command &lt;a href=&quot;https://liquibase.jira.com/browse/CORE-2056&quot;&gt;generates
    too many constraints in version 3.2.2&lt;/a&gt;. I was able to fix this by manually editing the generated YAML file.
&lt;/p&gt;
&lt;div class=&quot;alert alert-success&quot;&gt;&lt;p style=&quot;margin-top: 5px&quot;&gt;&lt;strong&gt;Tip:&lt;/strong&gt; If you want to drop all tables in your database to verify
    Liquibase creation is working in PostgeSQL, run the following commands:&lt;/p&gt;
&lt;pre style=&quot;margin-bottom: 5px&quot;&gt;psql -d mydb
drop schema public cascade;
create schema public;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;After writing minimal code for Spring Data and configuring Liquibase to create tables/relationships, I relaxed
    a bit, documented how everything worked and added a &lt;a href=&quot;https://github.com/isrsal/spring-mvc-logger&quot;&gt;LoggingFilter&lt;/a&gt;.
    The LoggingFilter was handy for viewing API requests and responses.
&lt;/p&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
@Bean
public FilterRegistrationBean loggingFilter() {
    LoggingFilter filter = new LoggingFilter();
    FilterRegistrationBean registrationBean = new FilterRegistrationBean();
    registrationBean.setFilter(filter);
    registrationBean.setUrlPatterns(Arrays.asList(&quot;/api/*&quot;));
    return registrationBean;
}
&lt;/pre&gt;
&lt;h3 id=&quot;resttemplate&quot;&gt;Accessing API with RestTemplate&lt;/h3&gt;
&lt;p&gt;The final step I needed to do was figure out how to access my new and fancy API with
    &lt;a href=&quot;http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/client/RestTemplate.html&quot;&gt;RestTemplate&lt;/a&gt;.
    At first, I thought it would be easy. Then I realized that Spring Data produces a
    &lt;a href=&quot;http://stateless.co/hal_specification.html&quot;&gt;HAL&lt;/a&gt;-compliant API, so its content is embedded inside an
    &quot;_embedded&quot; JSON key.
&lt;/p&gt;
&lt;p&gt;After much trial and error, I discovered I needed to create a &lt;code&gt;RestTemplate&lt;/code&gt; with HAL and Joda-Time
    awareness.
&lt;/p&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
@Bean
public RestTemplate restTemplate() {
	ObjectMapper mapper = new ObjectMapper();
	mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	mapper.registerModule(new Jackson2HalModule());
	mapper.registerModule(new JodaModule());

	MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
	converter.setSupportedMediaTypes(MediaType.parseMediaTypes(&quot;application/hal+json&quot;));
	converter.setObjectMapper(mapper);
	StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
	stringConverter.setSupportedMediaTypes(MediaType.parseMediaTypes(&quot;application/xml&quot;));

	List&amp;lt;HttpMessageConverter&amp;lt;?&amp;gt;&amp;gt; converters = new ArrayList&amp;lt;&amp;gt;();
	converters.add(converter);
	converters.add(stringConverter);

	return new RestTemplate(converters);
}
&lt;/pre&gt;
&lt;p&gt;
    The &lt;code&gt;JodaModule&lt;/code&gt; was provided by the following dependency:
&lt;/p&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;com.fasterxml.jackson.datatype&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;jackson-datatype-joda&amp;lt;/artifactId&amp;gt;
&amp;lt;/dependency&amp;gt;
&lt;/pre&gt;
&lt;p&gt;With the configuration complete, I was able to write a &lt;code&gt;MessagesApiITest&lt;/code&gt; integration test that posts a
    request
    and retrieves it using the API. The API was secured using basic authentication, so it took me a bit to figure out
    how
    to make that work with RestTemplate. Willie Wheeler&apos;s
    &lt;a href=&quot;http://springinpractice.com/2013/10/02/quick-tip-basic-authentication-with-spring-resttemplate&quot;&gt;Basic
        Authentication With Spring RestTemplate&lt;/a&gt; was a big help.&lt;/p&gt;

&lt;pre class=&quot;brush: java&quot;&gt;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = IntegrationTestConfig.class)
public class MessagesApiITest {
    private final static Log log = LogFactory.getLog(MessagesApiITest.class);
    @Value(&quot;http://${app.host}/api/initiate&quot;)
    private String initiateAPI;
    @Value(&quot;http://${app.host}/api/messages&quot;)
    private String messagesAPI;
    @Value(&quot;${app.host}&quot;)
    private String host;
    @Inject
    private RestTemplate restTemplate;

    @Before
    public void setup() throws Exception {
        String request = new Scanner(new ClassPathResource(&quot;sample-request.xml&quot;).getFile()).useDelimiter(&quot;\\Z&quot;).next();

        ResponseEntity&amp;lt;org.ncpdp.schema.transport.Message&amp;gt; response = restTemplate.exchange(getTestUrl(initiateAPI),
                HttpMethod.POST, getBasicAuthHeaders(request), org.ncpdp.schema.transport.Message.class,
                Collections.emptyMap());
        assertEquals(HttpStatus.OK, response.getStatusCode());
    }

    @Test
    public void testGetMessages() {
        HttpEntity&amp;lt;String&amp;gt; request = getBasicAuthHeaders(null);

        ResponseEntity&amp;lt;PagedResources&amp;lt;Message&amp;gt;&amp;gt; result = restTemplate.exchange(getTestUrl(messagesAPI), HttpMethod.GET,
                request, new ParameterizedTypeReference&amp;lt;PagedResources&amp;lt;Message&amp;gt;&amp;gt;() {});
        HttpStatus status = result.getStatusCode();
        Collection&amp;lt;Message&amp;gt; messages = result.getBody().getContent();

        log.debug(&quot;messages found: &quot; + messages.size());
        assertEquals(HttpStatus.OK, status);
        for (Message message : messages) {
            log.debug(&quot;message.id: &quot; + message.getId());
            log.debug(&quot;message.dateCreated: &quot; + message.getDateCreated());
        }
    }

    private HttpEntity&amp;lt;String&amp;gt; getBasicAuthHeaders(String body) {
        String plainCreds = &quot;user:pass&quot;;
        byte&amp;#91;&amp;#93; plainCredsBytes = plainCreds.getBytes();
        byte&amp;#91;&amp;#93; base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
        String base64Creds = new String(base64CredsBytes);

        HttpHeaders headers = new HttpHeaders();
        headers.add(&quot;Authorization&quot;, &quot;Basic &quot; + base64Creds);
        headers.add(&quot;Content-type&quot;, &quot;application/xml&quot;);

        if (body == null) {
            return new HttpEntity&amp;lt;&amp;gt;(headers);
        } else {
            return new HttpEntity&amp;lt;&amp;gt;(body, headers);
        }
    }
}
&lt;/pre&gt;
&lt;p&gt;To get Spring Data to populate the message id, I created a custom &lt;code&gt;RestConfig&lt;/code&gt; class to expose it. I learned how to do this from &lt;a href=&quot;http://tommyziegler.com/how-to-expose-the-resourceid-with-spring-data-rest/&quot;&gt;Tommy Ziegler&lt;/a&gt;.&lt;/p&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
/**
 * Used to expose ids for resources.
 */
@Configuration
public class RestConfig extends RepositoryRestMvcConfiguration {

    @Override
    protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
        config.exposeIdsFor(Message.class);
        config.setBaseUri(&quot;/api&quot;);
    }
}

&lt;/pre&gt;
&lt;h3 id=&quot;summary&quot;&gt;Summary&lt;/h3&gt;
&lt;p&gt;
    This article explains how I built a REST API using JAXB, Spring Boot, Spring Data and Liquibase.
    It was relatively easy to build, but required some tricks to access it with Spring&apos;s RestTemplate. Figuring out
    how to customize JAXB&apos;s code generation was also essential to make things work.
&lt;/p&gt;&lt;p&gt;
    I started developing the project with Spring Boot 1.1.7, but upgraded to 1.2.0.M2 after I found it supported
    Log4j2 and configuring Spring Data REST&apos;s base URI in application.yml. When I handed the project off to my client
    last week, it was using 1.2.0.BUILD-SNAPSHOT because of a
    &lt;a href=&quot;https://github.com/spring-projects/spring-boot/issues/1719&quot;&gt;bug when running in Tomcat&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;This was an enjoyable project to work on. I especially liked how easy Spring Data makes it to expose JPA
    entities in an API. Spring Boot made things easy to configure once again and Liquibase seems like a nice
    tool for database migrations.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;If someone asked me to develop a REST API on the JVM, which frameworks would I use?&lt;/em&gt; Spring Boot, Spring Data, Jackson, Joda-Time, Lombok and Liquibase. These frameworks worked really well for me on this particular project.&lt;/p&gt;</content>
    </entry>
    <entry>
        <id>https://raibledesigns.com/rd/entry/developing_with_angularjs_part_iii</id>
        <title type="html">Developing with AngularJS - Part III: Services</title>
        <author><name>Matt Raible</name></author>
        <link rel="alternate" type="text/html" href="https://raibledesigns.com/rd/entry/developing_with_angularjs_part_iii"/>
        <published>2013-06-25T07:03:26-06:00</published>
        <updated>2014-05-08T19:47:19-06:00</updated> 
        <category term="/The Web" label="The Web" />
        <category term="rest" scheme="http://roller.apache.org/ns/tags/" />
        <category term="angularjs" scheme="http://roller.apache.org/ns/tags/" />
        <category term="taleo" scheme="http://roller.apache.org/ns/tags/" />
        <category term="javascript" scheme="http://roller.apache.org/ns/tags/" />
        <category term="dwr" scheme="http://roller.apache.org/ns/tags/" />
        <summary type="html">&lt;p&gt;This is the 3rd article in a series on my experience developing with &lt;a href=&quot;http://angularjs.org/&quot;&gt;AngularJS&lt;/a&gt;. I used AngularJS for several months to create a &quot;My Dashboard&quot; feature for a client and learned a whole bunch of Angular goodness along the way. For previous articles, please see &lt;a href=&quot;http://raibledesigns.com/rd/entry/developing_with_angularjs_part_i&quot;&gt;Part I: The Basics&lt;/a&gt; and &lt;a href=&quot;http://raibledesigns.com/rd/entry/developing_with_angularjs_part_ii&quot;&gt;Part II: Dialogs and Data&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Angular offers several ways to interact with data from the server. The easiest way is to use the &lt;a href=&quot;http://docs.angularjs.org/api/ngResource.$resource&quot;&gt;$resource factory&lt;/a&gt;, which lets you interact with &lt;a href=&quot;http://en.wikipedia.org/wiki/Representational_State_Transfer&quot;&gt;RESTful&lt;/a&gt; server-side data sources. When we started the My Dashboard project, we were hoping to interact with a REST API, but soon found out that it didn&apos;t have all the data we needed. Rather than loading the page and then making another request to get its data, we decided to embed the JSON in the page. For communication back to the server, we used our tried-and-true Ajax solution: &lt;a href=&quot;http://directwebremoting.org/&quot;&gt;DWR&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In Angular-speak, &lt;em&gt;services&lt;/em&gt; are &lt;a href=&quot;http://docs.angularjs.org/guide/dev_guide.services.understanding_services&quot;&gt;singletons that carry out specific tasks common to web apps&lt;/a&gt;. In other words, they&apos;re any &lt;em&gt;$name&lt;/em&gt; object that can be injected into a controller or directive. However, as a Java Developer, I tend to think of services as objects that communicate with the server. Angular&apos;s documentation on &lt;a href=&quot;http://docs.angularjs.org/guide/dev_guide.services.creating_services&quot;&gt;Creating Services&lt;/a&gt; shows you various options for registering services. I used the angular.Module api method.&lt;/p&gt;</summary>
        <content type="html">&lt;p&gt;
&lt;a href=&quot;http://angularjs.org/&quot; title=&quot;AngularJS&quot;&gt;&lt;img src=&quot;//farm8.staticflickr.com/7445/9137074888_9d3bb13d32_s.jpg&quot; width=&quot;75&quot; height=&quot;75&quot; alt=&quot;AngularJS&quot; class=&quot;picture&quot;&gt;&lt;/a&gt;
This is the 3rd article in a series on my experience developing with &lt;a href=&quot;http://angularjs.org/&quot;&gt;AngularJS&lt;/a&gt;. I used AngularJS for several months to create a &quot;My Dashboard&quot; feature for a client and learned a whole bunch of Angular goodness along the way. For previous articles, please see &lt;a href=&quot;http://raibledesigns.com/rd/entry/developing_with_angularjs_part_i&quot;&gt;Part I: The Basics&lt;/a&gt; and &lt;a href=&quot;http://raibledesigns.com/rd/entry/developing_with_angularjs_part_ii&quot;&gt;Part II: Dialogs and Data&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Angular offers several ways to interact with data from the server. The easiest way is to use the &lt;a href=&quot;http://docs.angularjs.org/api/ngResource.$resource&quot;&gt;$resource factory&lt;/a&gt;, which lets you interact with &lt;a href=&quot;http://en.wikipedia.org/wiki/Representational_State_Transfer&quot;&gt;RESTful&lt;/a&gt; server-side data sources. When we started the My Dashboard project, we were hoping to interact with a REST API, but soon found out that it didn&apos;t have all the data we needed. Rather than loading the page and then making another request to get its data, we decided to embed the JSON in the page. For communication back to the server, we used our tried-and-true Ajax solution: &lt;a href=&quot;http://directwebremoting.org/&quot;&gt;DWR&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In Angular-speak, &lt;em&gt;services&lt;/em&gt; are &lt;a href=&quot;http://docs.angularjs.org/guide/dev_guide.services.understanding_services&quot;&gt;singletons that carry out specific tasks common to web apps&lt;/a&gt;. In other words, they&apos;re any &lt;em&gt;$name&lt;/em&gt; object that can be injected into a controller or directive. However, as a Java Developer, I tend to think of services as objects that communicate with the server. Angular&apos;s documentation on &lt;a href=&quot;http://docs.angularjs.org/guide/dev_guide.services.creating_services&quot;&gt;Creating Services&lt;/a&gt; shows you various options for registering services. I used the angular.Module api method.&lt;/p&gt;

&lt;p&gt;When I last worked on the project, there were only two services in My Dashboard: Widget and Preferences.&lt;/p&gt;

&lt;h3 id=&quot;widget&quot;&gt;Widget Service&lt;/h3&gt;
&lt;p&gt;The Widget service is used to retrieve the visible widgets for the user. It has two functions that are exposed to controllers: &lt;code&gt;getUserWidgets(type)&lt;/code&gt; and &lt;code&gt;getHiddenWidgets(type)&lt;/code&gt;. The former function is used at the top of &lt;code&gt;WidgetController&lt;/code&gt;, while the latter is used for the configuration dialog mentioned in the &lt;a href=&quot;http://raibledesigns.com/rd/entry/developing_with_angularjs_part_ii&quot;&gt;previous article&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The code for this service is in &lt;em&gt;services.js&lt;/em&gt;. The bulk of the logic is in its &lt;code&gt;filterData()&lt;/code&gt; function, where it goes through a 4-step process:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;Get all the widgets by type, ensuring they&apos;re unique.&lt;/li&gt;&lt;li&gt;Remove the widgets that are &lt;em&gt;hidden&lt;/em&gt; by the user&apos;s preferences.&lt;/li&gt;&lt;li&gt;Build an array that&apos;s &lt;em&gt;ordered&lt;/em&gt; by user&apos;s preferences.&lt;/li&gt;&lt;li&gt;Add any new widgets that aren&apos;t &lt;em&gt;hidden&lt;/em&gt; or &lt;em&gt;ordered&lt;/em&gt;.&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;The code for the Widget object is as follows:&lt;/p&gt;
&lt;pre class=&quot;brush: js&quot;&gt;
angular.module(&apos;dashboard.services&apos;, &amp;#91;&amp;#93;).
    factory(&apos;Widget&apos;,function ($filter, Preferences) {
        var filter = $filter(&apos;filter&apos;);
        var unique = $filter(&apos;unique&apos;);

        function filterData(array, query) {
            // get all possible widgets for a particular type
            var data = filter(array, query);
            data = unique(data);

            // remove widgets that are hidden by users preference
            var hidden = Preferences.getHiddenWidgets(query.type);
            for (var i = 0; i &amp;lt; hidden.length; i++) {
                var w = filter(data, {id: hidden&amp;#91;i&amp;#93;});
                $.each(w, function (index, item) {
                    var itemId = item.id;
                    if (hidden.indexOf(itemId) &amp;gt; -1) {
                        data.splice(data.indexOf(item), 1);
                    }
                });
            }

            // build an array that&apos;s ordered by users preference
            var ordered = &amp;#91;&amp;#93;;
            var visible = Preferences.getUserWidgets(query.type);
            for (var j = 0; j &amp;lt; visible.length; j++) {
                var v = filter(data, {id: visible&amp;#91;j&amp;#93;});
                $.each(v, function (index, item) {
                    var itemId = item.id;
                    if (visible.indexOf(itemId) &amp;gt; -1) {
                        ordered.push(item)
                    }
                });
            }

            // loop through data again and add any new widgets not in ordered
            $.each(data, function (index, item) {
                if (ordered.indexOf(item) === -1) {
                    ordered.push(item);
                }
            });

            return ordered;
        }

        return {
            getUserWidgets: function (type) {
                return filterData(widgetData, {type: type})
            },

            getHiddenWidgets: function (type) {
                var hidden = Preferences.getHiddenWidgets(type);
                var widgetsForType = filter(widgetData, {type: type});
                widgetsForType = unique(widgetsForType);
                var widgets = &amp;#91;&amp;#93;;
                for (var j = 0; j &amp;lt; hidden.length; j++) {
                    var v = filter(widgetsForType, {id: hidden&amp;#91;j&amp;#93;});
                    $.each(v, function (index, item) {
                        if (widgetsForType.indexOf(item) &amp;gt; -1) {
                            widgets.push(item)
                        }
                    });
                }
                return widgets;
            }
        }
    })
&lt;/pre&gt;
&lt;p&gt;Once you have a service configured like this, you can inject it by name. For example, &lt;code&gt;WidgetController&lt;/code&gt; has &lt;code&gt;Widget&lt;/code&gt; injected into its constructor:&lt;/p&gt;
&lt;pre class=&quot;brush: js&quot;&gt;
function WidgetController($dialog, $scope, Widget, Preferences) {
&lt;/pre&gt;
&lt;h3 id=&quot;preferences&quot;&gt;Preferences Service&lt;/h3&gt;
&lt;p&gt;The Preferences service is used to get and save user preferences. It&apos;s pretty straightforward and the bulk of its code is interacting with DWR. This service has 5 methods:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;getHiddenWidgets(type) - used by Widget service&lt;/li&gt;&lt;li&gt;getUserWidgets(type) - used by Widget service&lt;/li&gt;&lt;li&gt;saveBarOrder(bars) - called from WidgetController&lt;/li&gt;&lt;li&gt;saveWidgetOrder(type, widgets) - called from WidgetController&lt;/li&gt;&lt;li&gt;saveWidgetPreferences(type, widgets) - called from WidgetController&lt;/li&gt;&lt;/ol&gt;

&lt;p&gt;First, let&apos;s take a look at the &lt;code&gt;save*Order()&lt;/code&gt; functions. There are two parts of the page that use the &lt;em&gt;ui-sortable&lt;/em&gt; directive to initialize drag-and-drop functionality. The first is on the main &amp;lt;ul&amp;gt; that holds the 3 bars on the left.&lt;/p&gt;
&lt;pre class=&quot;brush: js&quot;&gt;
&amp;lt;ul class=&quot;widgets&quot; ui-sortable=&quot;{handle:&apos;.heading&apos;, update: updateBars}&quot;&amp;gt;
&lt;/pre&gt;
&lt;p&gt;The &quot;update&quot; property in the configuration JSON indicates which method to call in the controller. Similarly, the tasks and summary items call an &lt;code&gt;updateOrder&lt;/code&gt; function.&lt;/p&gt;
&lt;pre class=&quot;brush: js&quot;&gt;
&amp;lt;ul class=&quot;summary-items&quot; ng-model=&quot;summaryWidgets&quot; ui-sortable=&quot;{update: updateOrder}&quot;&amp;gt;
...
&amp;lt;ul class=&quot;task-items&quot; ng-model=&quot;taskWidgets&quot; ui-sortable=&quot;{update: updateOrder}&quot;&amp;gt;
&lt;/pre&gt;
&lt;p&gt;These functions are in &lt;code&gt;WidgetController&lt;/code&gt; and build an array of widget ids to pass to the Preferences service.&lt;/p&gt;
&lt;pre class=&quot;brush: js&quot;&gt;
$scope.updateBars = function(event, ui) {
    var bars = &amp;#91;&amp;#93;;
    $.each($(ui.item).parent().children(), function (index, item) {
        bars.push(item.id.substring(0, item.id.indexOf(&apos;-&apos;)))
    });
    Preferences.saveBarOrder(bars);
};

$scope.updateOrder = function(event, ui) {
    var parentId = $(ui.item).parent().parent().attr(&apos;id&apos;);
    var type = parentId.substring(0, parentId.indexOf(&apos;-&apos;));
    var items = &amp;#91;&amp;#93;;
    $.each($(ui.item).parent().children(), function (index, item) {
        items.push(item.id.substring(item.id.indexOf(&apos;-&apos;) + 1))
    });
    Preferences.saveWidgetOrder(type, {items: items});
};
&lt;/pre&gt;
&lt;p&gt;The bar order is used when the page is loaded. The following scriptlet code exists at the bottom of the app&apos;s page, in its $(document).ready:&lt;/p&gt;
&lt;pre class=&quot;brush: js&quot;&gt;
&amp;lt;%  String barOrder = user.getDashboardBarSortOrder();
    if (barOrder != null) { %&amp;gt;
    sortBars(&amp;#91;&apos;&amp;lt;%= barOrder %&amp;gt;&apos;&amp;#93;);
&amp;lt;% } %&amp;gt;
&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;sortBars()&lt;/code&gt; function is in a &lt;em&gt;dashboard.js&lt;/em&gt; file (where we put all non-Angular functions):&lt;/p&gt;
&lt;pre class=&quot;brush: js&quot;&gt;
function sortBars(barOrder) {
    // Sort bars according to user preferences
    $.each(barOrder, function(index, item) {
        var bar = $(&apos;#&apos; + item + &apos;-bar&apos;);
        if (bar.index() !== index) {
            if (index === 0) {
                bar.insertBefore($(&apos;.widgets&amp;gt;li:first-child&apos;));
            } else if (index === (barOrder.length - 1)) {
                bar.insertAfter($(&apos;.widgets&amp;gt;li:last-child&apos;));
            } else {
                bar.insertBefore($(&apos;.widgets&amp;gt;li:eq(&apos; + index + &apos;)&apos;));
            }
        }
    });
}
&lt;/pre&gt;
&lt;p&gt;Now that you&apos;ve seen where Preferences is called from, let&apos;s take a look at the code for the service.&lt;/p&gt;
&lt;div class=&quot;alert alert-info&quot;&gt;
The checks for undefined and uniqueness in the code below shouldn&apos;t be necessary, but I prefer defensive coding.
&lt;/div&gt;
&lt;pre class=&quot;brush: js&quot;&gt;
factory(&apos;Preferences&apos;, function ($filter) {
    var unique = $filter(&apos;unique&apos;);

    return {
        // Get in-page variable: hiddenWidgets
        getHiddenWidgets: function (type) {
            var items = hiddenWidgets&amp;#91;type&amp;#93;;
            return (angular.isUndefined(items) ? &amp;#91;&amp;#93; : unique(items));
        },

        // Get in-page variable: userWidgets
        getUserWidgets: function (type) {
            var items = userWidgets&amp;#91;type&amp;#93;;
            return (angular.isUndefined(items) ? &amp;#91;&amp;#93; : unique(items));
        },

        // Save main bar (task, summary, chart) order
        saveBarOrder: function (bars) {
            DWRFacade.saveDashboardBarSortOrder(bars, {
                errorHandler: function (errorString) {
                    alert(errorString);
                }
            })
        },

        // Save order of widgets from sortable
        saveWidgetOrder: function (type, widgets) {
            userWidgets&amp;#91;type&amp;#93; = widgets.items;
            DWRFacade.saveDashboardWidgetPreference(type, widgets, {
                errorHandler: function (errorString) {
                    alert(errorString);
                }
            });
        },

        // Save hidden and visible (and order) widgets from config dialog
        saveWidgetPreferences: function (type, widgets) {
            // widgets is a map of hidden and visible
            var hiddenIds = &amp;#91;&amp;#93;;
            $.each(widgets.hidden, function (index, item) {
                hiddenIds.push(item.id);
            });
            var visibleIds = &amp;#91;&amp;#93;;
            $.each(widgets.items, function (index, item) {
                visibleIds.push(item.id);
            });
            var preferences = {
                hidden: hiddenIds,
                items: visibleIds
            };
            // reset local variables in page
            hiddenWidgets&amp;#91;type&amp;#93; = hiddenIds;
            userWidgets&amp;#91;type&amp;#93; = visibleIds;
            DWRFacade.saveDashboardWidgetPreference(type, preferences, {
                errorHandler: function (errorString) {
                    alert(errorString);
                }
            });
        }
    }
})
&lt;/pre&gt;
&lt;h3 id=&quot;http&quot;&gt;Using $http and Receiving Data&lt;/h3&gt;
&lt;p&gt;In this particular application, we didn&apos;t do any reading from the server with Angular. We simply wrote preferences to the server, and updated embedded variables when data changed. Real-time functionality of the app wouldn&apos;t be noticeable if a write failed. 
&lt;/p&gt;
&lt;p&gt;
In my current Angular project, it&apos;s more of a full-blown application that does as much reading as writing. For this, I&apos;ve found it useful to either 1) pass in callbacks to services or 2) use Angular&apos;s event system to publish/subscribe to events.
&lt;/p&gt;
&lt;p&gt;The first method is the easiest, and likely the most familiar to JavaScript developers. For example, here&apos;s the controller code to remove a profile picture:
&lt;/p&gt;

&lt;pre class=&quot;brush: js&quot;&gt;
Profile.removePhoto($scope.user, function (data) {
    // close the dialog
    $scope.close(&apos;avatar&apos;);
    // success message using toastr: http://bit.ly/14Uisgm
    Flash.pop({type: &apos;success&apos;, body: &apos;Your profile picture was removed.&apos;});
})
&lt;/pre&gt;
&lt;p&gt;And the &lt;code&gt;Profile.removePhoto()&lt;/code&gt; method:
&lt;/p&gt;
&lt;pre class=&quot;brush: js&quot;&gt;
removePhoto: function (user, callback) {
    $http.post(&apos;/profile/removePhoto&apos;, user).success(function (response) {
        return callback(response);
    });
}
&lt;/pre&gt;
&lt;p&gt;The second, event-driven method works equally as well, but can easily suffer from typos in event names.&lt;/p&gt;
&lt;pre class=&quot;brush: js&quot;&gt;
// controller calling code
Profile.getUser();

// service code
getUser: function () {
    $http.get(&apos;/profile&apos;).success(function (data) {
        if (data.username) {
            $log.info(&apos;Profile for &apos; + data.username + &apos; retrieved!&apos;);
            $rootScope.$broadcast(&apos;event:profile&apos;, data);
        }
    });
}

// controller receiving code
$rootScope.$on(&apos;event:profile&apos;, function (event, data) {
    $scope.user = data;
});
&lt;/pre&gt;
&lt;p&gt;I like both methods, but the event-driven one seems like it could offer more extensibility in the future.&lt;/p&gt;

&lt;h3 id=&quot;summary&quot;&gt;Summary&lt;/h3&gt;
&lt;p&gt;Using in-page variables and DWR doesn&apos;t seem to be recommended by the Angular Team. However, it worked well for us and seems like a good way to construct Angular services. Even if a REST API becomes available to get all the data, I think using in-page variables to minimize requests is a good idea. &lt;/p&gt;
&lt;p&gt;When retrieving data, you can use callbacks or Angular&apos;s pub/sub event system ($broadcast and $on) to get data in your controllers. If you want to learn more about this technique, see Eric Terpstra&apos;s &lt;a href=&quot;http://ericterpstra.com/2012/09/angular-cats-part-3-communicating-with-broadcast/&quot;&gt;Communicating with $broadcast&lt;/a&gt;. In his article, Eric mentions &lt;a href=&quot;https://groups.google.com/d/msg/angular/M0SHItdgBqg/R1t_17cR0pYJ&quot;&gt;Thomas Burleson&apos;s pub/sub module&lt;/a&gt; that acts as a message queue. If you&apos;ve used Thomas&apos;s MessageQueue (or something similar) with Angular, I&apos;d love to hear about your experience. 
&lt;/p&gt;
&lt;p&gt;In the &lt;a href=&quot;http://raibledesigns.com/rd/entry/developing_with_angularjs_part_iv&quot;&gt;next article&lt;/a&gt;, I&apos;ll talk about how we redesigned My Dashboard and used CSS3 and JavaScript to implement new ideas.&lt;/p&gt;</content>
    </entry>
    <entry>
        <id>https://raibledesigns.com/rd/entry/secure_json_services_with_play</id>
        <title type="html">Secure JSON Services with Play Scala and SecureSocial</title>
        <author><name>Matt Raible</name></author>
        <link rel="alternate" type="text/html" href="https://raibledesigns.com/rd/entry/secure_json_services_with_play"/>
        <published>2012-02-12T16:02:43-07:00</published>
        <updated>2014-05-08T19:47:19-06:00</updated> 
        <category term="/Java" label="Java" />
        <category term="securesocial" scheme="http://roller.apache.org/ns/tags/" />
        <category term="json" scheme="http://roller.apache.org/ns/tags/" />
        <category term="jfokus" scheme="http://roller.apache.org/ns/tags/" />
        <category term="scala" scheme="http://roller.apache.org/ns/tags/" />
        <category term="playframework" scheme="http://roller.apache.org/ns/tags/" />
        <category term="rest" scheme="http://roller.apache.org/ns/tags/" />
        <category term="play-more" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">&lt;a href=&quot;http://www.flickr.com/photos/mcginityphoto/6716294395/&quot; title=&quot;AntwerpTownSquare by McGinityPhoto, on Flickr&quot;&gt;&lt;img src=&quot;//farm8.staticflickr.com/7002/6716294395_28ce2c5f5b_t.jpg&quot; width=&quot;100&quot; height=&quot;66&quot; alt=&quot;AntwerpTownSquare&quot; class=&quot;picture&quot;&gt;&lt;/a&gt;
Last November, I &lt;a href=&quot;http://raibledesigns.com/rd/entry/my_html5_with_play_scala&quot;&gt;traveled to Antwerp to speak at Devoxx&lt;/a&gt;. After my talk on HTML5 with Play Scala, &lt;a href=&quot;http://twitter.com/matkar&quot;&gt;Mattias Karlsson&lt;/a&gt; approached me and we had a chat about doing the same talk at &lt;a href=&quot;http://www.jfokus.se/&quot;&gt;Jfokus&lt;/a&gt; in Stockholm. I agreed and we began talking details after Trish and I returned to the US. 
&lt;p style=&quot;text-align: center&quot;&gt;
&lt;a href=&quot;http://jfokus.se&quot;&gt;
&lt;img width=&quot;450&quot; style=&quot;border-radius: 10px&quot; height=&quot;200&quot; src=&quot;//static.raibledesigns.com/repository/images/Jfokus2012_450x200.jpg&quot; alt=&quot;Jfokus&quot;&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;I wrote this article on a plane between Denver and Seattle and will be hopping over the North Pole to Stockholm via Iceland tonight. For the past couple of weeks, I&apos;ve been updating my &lt;em&gt;Play More!&lt;/em&gt; HTML5/mobile app to add some new features. Most notably, I wanted to upgrade to Play 2.0, create JSON services and add authentication. 
&lt;/p&gt;
&lt;p id=&quot;play2&quot;&gt;&lt;strong&gt;Upgrading to Play 2.0&lt;/strong&gt;&lt;br/&gt;
My attempt to upgrade to Play 2.0 involved &lt;a href=&quot;https://github.com/playframework/play20&quot;&gt;checking out the source from GitHub&lt;/a&gt;, building and installing the RC1 snapshot. As I tried to upgrade my app and started getting failed imports, I turned to the internet (specifically StackOverflow) to &lt;a href=&quot;http://stackoverflow.com/questions/8264010/todays-options-for-an-easier-migration-path-to-play-2&quot;&gt;see if it was a good idea&lt;/a&gt;. The first answer for that question suggested I stay with 1.x.
  &lt;/p&gt;
&lt;p class=&quot;quote&quot;&gt;
If it&apos;s a critical project, to be finished before next March 2012, I would go with Play 1.x. If it&apos;s a less important project, which could be delayed, and that in any case won&apos;t be released before March 2012, try Play 2.0.&lt;/p&gt;
&lt;p&gt;While I didn&apos;t plan on releasing &lt;em&gt;Play More!&lt;/em&gt; before Jfokus, I decided upgrading didn&apos;t add a whole lot to the talk. Also, I couldn&apos;t find a Play Scala 0.9.1 to Play 2.0 upgrade guide and I didn&apos;t have enough time to create one. So I decided to stick with Play 1.2.4 and add some JSON services for my iPhone client. 
&lt;/p&gt;
&lt;p id=&quot;play-json&quot;&gt;&lt;strong&gt;JSON Servers&lt;/strong&gt;&lt;br/&gt;
I found Manuel Bernhardt&apos;s &lt;a href=&quot;http://logician.free.fr/index.php/2011/09/16/play-scala-and-json/&quot;&gt;Play! Scala and JSON&lt;/a&gt;. This led me to &lt;a href=&quot;https://github.com/codahale/jerkson&quot;&gt;Jerkson&lt;/a&gt;, built by the &lt;a href=&quot;http://codahale.com/the-rest-of-the-story/&quot;&gt;now infamous&lt;/a&gt; &lt;a href=&quot;https://twitter.com/coda&quot;&gt;@coda&lt;/a&gt;.  
I was able to easily get things working fairly quickly and wrote the following WorkoutService.scala:
&lt;/p&gt;
&lt;pre class=&quot;brush: scala&quot;&gt;
package controllers.api

import play.mvc.Controller
import models._
import com.codahale.jerkson.Json._

object WorkoutService extends Controller {

  def workouts = {
    response.setContentTypeIfNotSet(&quot;application/json&quot;)
    generate(Workout.find().list())
  }
  def edit(id: Long) = {
    generate(Workout.byIdWithAthleteAndComments(id))
  }

  def create() = {
    var workout = params.get(&quot;workout&quot;, classOf[Workout])
    Workout.create(workout)
  }

  def save(id: Option[Long]) = {
    var workout = params.get(&quot;workout&quot;, classOf[Workout])
    Workout.update(workout)
  }

  def delete(id: Long) = {
    Workout.delete(&quot;id={id}&quot;).on(&quot;id&quot; -&gt; id).executeUpdate()
  }
}
&lt;/pre&gt;
&lt;p&gt;Next, I added routes for my new API to &lt;em&gt;conf/routes&lt;/em&gt;:
&lt;/p&gt;
&lt;pre&gt;
GET     /api/workouts               api.WorkoutService.workouts
GET     /api/workout/{id}           api.WorkoutService.edit
POST    /api/workout                api.WorkoutService.create
PUT     /api/workout/{id}           api.WorkoutService.save
DELETE  /api/workout/{id}           api.WorkoutService.delete
&lt;/pre&gt;
&lt;p&gt;
Then I created an ApiTest.scala class that verifies the first method works as expected.&lt;/p&gt;
&lt;pre class=&quot;brush: scala&quot;&gt;
import play.test.FunctionalTest
import play.test.FunctionalTest._
import org.junit._

class ApiTests extends FunctionalTest {
  
    @Test
    def testGetWorkouts() {
        var response = GET(&quot;/api/workouts&quot;);
        assertStatus(200, response);
        assertContentType(&quot;application/json&quot;, response)
        println(response.out)
    }
}
&lt;/pre&gt;
&lt;p&gt;
I ran &quot;play test&quot;, opened my browser to http://localhost:9000/@tests and clicked ApiTests -&gt; Start to verify it worked. All the green made me happy.
&lt;/p&gt;
&lt;p style=&quot;text-align: center&quot;&gt;
&lt;a href=&quot;http://farm8.staticflickr.com/7180/6869080391_5a163cb28e.jpg&quot; title=&quot;Play More API Tests&quot; rel=&quot;lightbox[playmore-json]&quot;&gt;&lt;img src=&quot;//farm8.staticflickr.com/7180/6869080391_5a163cb28e_m.jpg&quot; width=&quot;240&quot; height=&quot;184&quot; alt=&quot;Play More API Tests&quot;&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;Finally, I wrote some CoffeeScript and jQuery to allow users to delete workouts and make sure delete functionality worked.&lt;/p&gt;
&lt;pre class=&quot;brush: js&quot;&gt;
$(&apos;#delete&apos;).click -&gt;
  $.ajax
    type: &apos;POST&apos;
    url: $(this).attr(&apos;rel&apos;)
    error: -&gt;
      alert(&apos;Delete failed, please try again.&apos;)
    success: (data) -&gt;
      location.href = &quot;/more&quot;
&lt;/pre&gt;
&lt;p&gt;I was very impressed with how easy Play made it to create JSON services and I smiled as my CoffeeScript skills got a refresher.&lt;/p&gt;
&lt;p&gt;The Friday before we left for Devoxx, I saw the &lt;a href=&quot;http://groups.google.com/group/play-framework/browse_thread/thread/1cdebc6f54ec3e6f&quot;&gt;module registration request for SecureSocial&lt;/a&gt;.
&lt;p id=&quot;securesocial&quot;&gt;&lt;strong&gt;SecureSocial with Play Scala&lt;/strong&gt;&lt;br/&gt;
From SecureSocial&apos;s &lt;a href=&quot;https://github.com/jaliss/securesocial&quot;&gt;README&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&quot;quote&quot; style=&quot;margin-left: 0; margin-bottom: 10px&quot;&gt;
&lt;p&gt;SecureSocial allows you to add an authentication UI to your app that works with services based on OAuth1, OAuth2, OpenID and OpenID+OAuth hybrid protocols.
&lt;/p&gt;
&lt;p&gt;
It also provides a Username and Password mechanism for users that do not wish to use existing accounts in other networks.
&lt;/p&gt;
&lt;p&gt;
The following services are supported in this release:
&lt;/p&gt;
&lt;ul style=&quot;margin-bottom: 0&quot;&gt;
&lt;li&gt;Twitter (OAuth1)&lt;/li&gt;
	&lt;li&gt;Facebook (OAuth2)&lt;/li&gt;
	&lt;li&gt;Google (OpenID + OAuth Hybrid)&lt;/li&gt;
	&lt;li&gt;Yahoo (OpenID + OAuth Hybrid)&lt;/li&gt;
	&lt;li&gt;LinkedIn (OAuth1)&lt;/li&gt;
	&lt;li&gt;Foursquare (OAuth2)&lt;/li&gt;
	&lt;li&gt;MyOpenID (OpenID)&lt;/li&gt;
	&lt;li&gt;Wordpress (OpenID)&lt;/li&gt;
	&lt;li&gt;Username and Password&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;p&gt;In other words, it sounded like a dream come true and I resolved to try it once I found the time. That time found me last Monday evening and I sent a direct message to &lt;a href=&quot;http://twitter.com/jaliss&quot;&gt;@jaliss&lt;/a&gt; (the module&apos;s author) via Twitter.
&lt;/p&gt;
&lt;p class=&quot;quote&quot;&gt;
Does Secure Social work with Play Scala? I&apos;d like to use it in my Play More! project.
&lt;/p&gt;
&lt;p&gt;Jorge responded 16 minutes later saying that he hadn&apos;t used Play Scala and he&apos;d need to do some research. At 8 o&apos;clock that night (1.5 hours after my original DM), Jorge had a sample working and emailed it to me. 10 minutes later I was adding a Secure trait to my project.
&lt;/p&gt;
&lt;pre class=&quot;brush: scala&quot;&gt;
package controllers

import play.mvc._
import controllers.securesocial.SecureSocial

/*
 * @author Jorge Aliss &amp;lt;jaliss@gmail.com&gt; of Secure Social fame.
 */
trait Secure {
  self: Controller =&gt;

  @Before def checkAccess() {
    SecureSocial.DeadboltHelper.beforeRoleCheck()
  }

  def currentUser = {
    SecureSocial.getCurrentUser
  }
}
&lt;/pre&gt;
&lt;p&gt;I configured Twitter and Username + Password as my providers by adding the following to &lt;em&gt;conf/application.conf&lt;/em&gt;.
&lt;/p&gt;
&lt;pre&gt;
securesocial.providers=twitter,userpass
&lt;/pre&gt;
&lt;p&gt;I also had to configure a number of securesocial.twitter.* properties. Next, I made sure my routes were aware of SecureSocial by adding the following to the top of &lt;em&gt;conf/routes&lt;/em&gt;:
&lt;pre&gt;
  *       /auth               module:securesocial
&lt;/pre&gt;
&lt;p&gt;Then I specified it as a dependency in &lt;em&gt;conf/dependencies.yml&lt;/em&gt; and ran &quot;play deps&quot;.
&lt;/p&gt;
&lt;pre&gt;
    - play -&gt; securesocial 0.2.4
&lt;/pre&gt;
&lt;p&gt;After adding &quot;with Secure&quot; to my Profile.scala controller, I tried to access its route and was prompted to login. Right off the bat, I was shown an error about a missing jQuery 1.5.2 file in my &quot;javascripts&quot; folder, so I added it and rejoiced when I was presented with a login screen. I had to add the app on Twitter to use its OAuth servers, but I was pumped when both username/password authentication worked (complete with signup!) as well as Twitter. 
&lt;/p&gt;
&lt;p&gt;
The only issue I ran into with SecureSocial was that it didn&apos;t find the default implementation of SecureSocial&apos;s UserService.Service when running in prod mode. I was able to workaround this by adding a SecureService.scala implementation to my project and coding it to talk to my Athlete model. I didn&apos;t bother to hook in creating a new user when they logged in from Twitter, but that&apos;s something I&apos;ll want to do in the future. I was also pleased to find out customizing SecureSocial&apos;s views was a breeze. I simply copied them from the module into my app&apos;s views and &lt;em&gt;voila!&lt;/em&gt;
&lt;/p&gt;
&lt;pre class=&quot;brush: scala&quot;&gt;
package services

import play.db.anorm.NotAssigned
import play.libs.Codec
import collection.mutable.{SynchronizedMap, HashMap}
import models.Athlete
import securesocial.provider.{ProviderType, UserService, SocialUser, UserId}

class SecureService extends UserService.Service {
  val activations = new HashMap[String, SocialUser] with SynchronizedMap[String, SocialUser]

  def find(userId: UserId): SocialUser = {
    val user = Athlete.find(&quot;email={email}&quot;).on(&quot;email&quot; -&gt; userId.id).first()

    user match {
      case Some(user) =&gt; {
        val socialUser = new SocialUser
        socialUser.id = userId
        socialUser.displayName = user.firstName
        socialUser.email = user.email
        socialUser.isEmailVerified = true
        socialUser.password = user.password
        socialUser
      }
      case None =&gt; {
        if (!userId.provider.eq(ProviderType.userpass)) {
          var socialUser = new SocialUser
          socialUser.id = userId
          socialUser
        } else {
          null
        }
      }
    }
  }

  def save(user: SocialUser) {
    if (find(user.id) == null) {
      val firstName = user.displayName
      val lastName = user.displayName
      Athlete.create(Athlete(NotAssigned, user.email, user.password, firstName, lastName))
    }
  }

  def createActivation(user: SocialUser): String = {
    val uuid: String = Codec.UUID()
    activations.put(uuid, user)
    uuid
  }

  def activate(uuid: String): Boolean = {
    val user: SocialUser = activations.get(uuid).asInstanceOf[SocialUser]
    var result = false

    if (user != null) {
      user.isEmailVerified = true
      save(user)
      activations.remove(uuid)
      result = true
    }

    result
  }

  def deletePendingActivations() {
    activations.clear()
  }
}
&lt;/pre&gt;
&lt;p&gt;Jorge was a great help in getting my authentication needs met and he even wrote a BasicAuth.scala trait to implement Basic Authentication on my JSON services.
&lt;/p&gt;
&lt;pre class=&quot;brush: scala&quot;&gt;
package controllers

import _root_.securesocial.provider.{UserService, ProviderType, UserId}
import play._
import play.mvc._
import play.libs.Crypto

import controllers.securesocial.SecureSocial

/*
 * @author Jorge Aliss &amp;lt;jaliss@gmail.com&gt; of Secure Social fame.
 */
trait BasicAuth {
  self: Controller =&gt;

  @Before def checkAccess = {
    if (currentUser != null) {
      // this allows SecureSocial.getCurrentUser() to work.
      renderArgs.put(&quot;user&quot;, currentUser)
      Continue
    }

    val realm =
      Play.configuration.getProperty(&quot;securesocial.basicAuth.realm&quot;, &quot;Unauthorized&quot;)

    if (request.user == null || request.password == null) {
      Unauthorized(realm)
    } else {
      val userId = new UserId
      userId.id = request.user
      userId.provider = ProviderType.userpass
      val user = UserService.find(userId)

      if (user == null ||
        !Crypto.passwordHash(request.password).equals(user.password)) {
        Unauthorized(realm)
      } else {
        // this allows SecureSocial.getCurrentUser() to work.
        renderArgs.put(&quot;user&quot;, user)
        Continue
      }
    }
  }

  def currentUser = {
    SecureSocial.getCurrentUser()
  }
}
&lt;/pre&gt;
&lt;p id=&quot;summary&quot;&gt;
&lt;strong&gt;Summary&lt;/strong&gt;&lt;br/&gt;
My latest pass at developing with Scala and leveraging Play to build my app was a lot of fun. While there were issues with class reloading every-so-often and &lt;a href=&quot;http://groups.google.com/group/scalate/browse_thread/thread/ddf455ec8676abf1&quot;&gt;Scala versions with Scalate&lt;/a&gt;, I was able to add the features I wanted. I wasn&apos;t able to upgrade to Play 2.0, but I didn&apos;t try that hard and figured it&apos;s best to wait until its upgrade guide has been published. 
&lt;/p&gt;
&lt;p&gt;
I&apos;m excited to describe my latest experience to the developers at Jfokus this week. In addition, the conference has talks on &lt;a href=&quot;http://www.jfokus.se/jfokus/talks.jsp#Play%20Framework%202.0&quot;&gt;Play 2.0&lt;/a&gt;, &lt;a href=&quot;http://www.jfokus.se/jfokus/talks.jsp#CoffeeScript%3A%20JavaScript%20without%20the%20Fail&quot;&gt;CoffeeScript&lt;/a&gt;, &lt;a href=&quot;http://www.jfokus.se/jfokus/talks.jsp#Client-side%20Storage%3A%20When%20%26%20How&quot;&gt;HTML5&lt;/a&gt;, &lt;a href=&quot;http://www.jfokus.se/jfokus/talks.jsp#Scala%20in%20Action&quot;&gt;Scala&lt;/a&gt; and &lt;a href=&quot;http://www.jfokus.se/jfokus/talks.jsp#Introducing%20Scalate%2C%20the%20Scala%20Template%20Engine&quot;&gt;Scalate&lt;/a&gt;. I hope to attend many of these and learn some new tricks to improve my skills and my app. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; The Delving developers have written an article on &lt;a href=&quot;http://delving.eu/node/27&quot;&gt;Migration to Play 2&lt;/a&gt;. While it doesn&apos;t provide specific details on what they needed to change, it does have good information on how long it took and things to watch for.</content>
    </entry>
    <entry>
        <id>https://raibledesigns.com/rd/entry/integrating_oauth_with_appfuse_and</id>
        <title type="html">Integrating OAuth with AppFuse and its REST API</title>
        <author><name>Matt Raible</name></author>
        <link rel="alternate" type="text/html" href="https://raibledesigns.com/rd/entry/integrating_oauth_with_appfuse_and"/>
        <published>2011-07-05T10:56:48-06:00</published>
        <updated>2014-05-08T19:47:19-06:00</updated> 
        <category term="/Java" label="Java" />
        <category term="appfuse" scheme="http://roller.apache.org/ns/tags/" />
        <category term="springsecurity" scheme="http://roller.apache.org/ns/tags/" />
        <category term="rest" scheme="http://roller.apache.org/ns/tags/" />
        <category term="oauth" scheme="http://roller.apache.org/ns/tags/" />
        <category term="enunciate" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">One of the new features in &lt;a href=&quot;http://raibledesigns.com/rd/entry/appfuse_2_1_released&quot;&gt;AppFuse 2.1&lt;/a&gt; is an &lt;a href=&quot;http://issues.appfuse.org/browse/APF-897&quot;&gt;appfuse-ws&lt;/a&gt; archetype. This archetype leverages &lt;a href=&quot;http://enunciate.codehaus.org/&quot;&gt;Enunciate&lt;/a&gt; and &lt;a href=&quot;http://cxf.apache.org/&quot;&gt;CXF&lt;/a&gt; to create a project with a REST API and generated HTML documentation. Enunciate is a very useful tool, allowing you to develop web services with JAX-RS and JAX-WS annotations and have all types of client libraries generated. For me, it seems very useful for developing the backend of &lt;abbr title=&quot;Service Oriented Front End Applications&quot;&gt;SOFEA&lt;/abbr&gt; (a.k.a. modern) applications. &lt;/p&gt;
&lt;p&gt;Back in March, &lt;a href=&quot;http://www.java.net/blogs/stoicflame/&quot;&gt;Ryan Heaton&lt;/a&gt; published a nice article on &lt;a href=&quot;http://docs.codehaus.org/display/ENUNCIATE/Securing+Web+Services&quot;&gt;Securing Web Services&lt;/a&gt; in an Enunciate application. I decided to take his tutorial a step further and not only secure my web services, but also to integrate with  OAuth 2. In this tutorial, I&apos;ll show you how to create a new application with AppFuse WS, secure it, add OAuth support, and then use a client app to authenticate and retrieve data.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;#create-appfuse-ws&quot;&gt;Create a New AppFuse WS Project&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#integrate-oauth&quot;&gt;Integrate Spring Security and OAuth&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#oauth-client&quot;&gt;Authenticate and Retrieve Data with Client&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p id=&quot;create-appfuse-ws&quot;&gt;
&lt;strong&gt;Create a New AppFuse WS Project&lt;/strong&gt;&lt;br/&gt;
To begin, I visited the &lt;a href=&quot;http://static.appfuse.org/archetypes.html&quot;&gt;Create AppFuse Archetypes&lt;/a&gt; page and created a new application using the &quot;Web Services Only&quot; option in the &lt;em&gt;Web Framework&lt;/em&gt; dropdown. Below is the command I used to create the &quot;appfuse-oauth&quot; project.
&lt;/p&gt;
&lt;pre&gt;
mvn archetype:generate -B -DarchetypeGroupId=org.appfuse.archetypes \
-DarchetypeArtifactId=appfuse-ws-archetype -DarchetypeVersion=2.1.0 \
-DgroupId=org.appfuse.example -DartifactId=appfuse-oauth 
&lt;/pre&gt;
&lt;p&gt;After doing this, I started the app using &lt;strong&gt;mvn jetty:run&lt;/strong&gt; and confirmed it started OK. At this point, I was able to view the generated documentation for the application at &lt;a href=&quot;http://localhost:8080&quot;&gt;http://localhost:8080&lt;/a&gt;. The screenshot below shows what the app looks like at this point.
&lt;/p&gt;
&lt;p style=&quot;text-align: center&quot;&gt;
&lt;a href=&quot;http://farm7.static.flickr.com/6004/5891597325_7f9829e158.jpg&quot; title=&quot;AppFuse WS Homepage&quot; rel=&quot;lightbox[appfuse-oauth]&quot;&gt;&lt;img src=&quot;//farm7.static.flickr.com/6004/5891597325_7f9829e158_m.jpg&quot; width=&quot;240&quot; height=&quot;198&quot; alt=&quot;AppFuse WS Homepage&quot;&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p style=&quot;font-weight: italic; color: #666; margin-left: 10px&quot;&gt;
NOTE: You might notice the REST endpoint of /{username}. This is &lt;a href=&quot;http://issues.appfuse.org/browse/APF-1246&quot; style=&quot;color: #666&quot;&gt;a bug&lt;/a&gt; in AppFuse 2.1.0 and has been fixed in SVN. It does not affect this tutorial.&lt;/p&gt;
&lt;p id=&quot;integrate-oauth&quot;&gt;
&lt;strong&gt;Integrate Spring Security and OAuth&lt;/strong&gt;&lt;br/&gt;
I originally tried to integrate Spring Security with Enunciate&apos;s &lt;a href=&quot;http://docs.codehaus.org/display/ENUNCIATE/Securing+Web+Services&quot;&gt;Securing Web Services Tutorial&lt;/a&gt;. However, it only secures endpoints and doesn&apos;t do enough filtering for OAuth support, so I ended up using a custom web.xml. I put this file in &lt;em&gt;src/main/resources&lt;/em&gt; and loaded it in my &lt;em&gt;enunciate.xml&lt;/em&gt; file. I also upgraded Spring Security and imported my security.xml file.
&lt;/p&gt;
&lt;pre class=&quot;brush: xml; auto-links: false&quot;&gt;
  &amp;lt;?xml version=&quot;1.0&quot;?&amp;gt;
  &amp;lt;enunciate xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
             xsi:noNamespaceSchemaLocation=&quot;http://enunciate.codehaus.org/schemas/enunciate-1.22.xsd&quot;&amp;gt;
      ...
      &amp;lt;webapp mergeWebXML=&quot;src/main/resources/web.xml&quot;/&amp;gt;
      &amp;lt;modules&amp;gt;
      ...
          &amp;lt;spring-app disabled=&quot;false&quot; springVersion=&quot;3.0.5.RELEASE&quot;&amp;gt;
              &amp;lt;springImport uri=&quot;classpath:/applicationContext-resources.xml&quot;/&amp;gt;
              &amp;lt;springImport uri=&quot;classpath:/applicationContext-dao.xml&quot;/&amp;gt;
              &amp;lt;springImport uri=&quot;classpath:/applicationContext-service.xml&quot;/&amp;gt;
              &amp;lt;springImport uri=&quot;classpath:/applicationContext.xml&quot;/&amp;gt;
              &amp;lt;springImport uri=&quot;classpath:/security.xml&quot;/&amp;gt;
          &amp;lt;/spring-app&amp;gt;
      &amp;lt;/modules&amp;gt;
  &amp;lt;/enunciate&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Then I created &lt;em&gt;src/main/resources/web.xml&lt;/em&gt; with a filter for Spring Security and a DispatcherServlet for OAuth support.
&lt;/p&gt;
&lt;pre class=&quot;brush: xml; auto-links: false&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;
&amp;lt;web-app xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot;
         xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
         xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd&quot;
         version=&quot;3.0&quot;&amp;gt;

    &amp;lt;filter&amp;gt;
        &amp;lt;filter-name&amp;gt;securityFilter&amp;lt;/filter-name&amp;gt;
        &amp;lt;filter-class&amp;gt;org.springframework.web.filter.DelegatingFilterProxy&amp;lt;/filter-class&amp;gt;
        &amp;lt;init-param&amp;gt;
            &amp;lt;param-name&amp;gt;targetBeanName&amp;lt;/param-name&amp;gt;
            &amp;lt;param-value&amp;gt;springSecurityFilterChain&amp;lt;/param-value&amp;gt;
        &amp;lt;/init-param&amp;gt;
    &amp;lt;/filter&amp;gt;

    &amp;lt;filter-mapping&amp;gt;
        &amp;lt;filter-name&amp;gt;securityFilter&amp;lt;/filter-name&amp;gt;
        &amp;lt;url-pattern&amp;gt;/*&amp;lt;/url-pattern&amp;gt;
    &amp;lt;/filter-mapping&amp;gt;

    &amp;lt;servlet&amp;gt;
        &amp;lt;servlet-name&amp;gt;appfuse-oauth&amp;lt;/servlet-name&amp;gt;
        &amp;lt;servlet-class&amp;gt;org.springframework.web.servlet.DispatcherServlet&amp;lt;/servlet-class&amp;gt;
        &amp;lt;load-on-startup&amp;gt;1&amp;lt;/load-on-startup&amp;gt;
    &amp;lt;/servlet&amp;gt;

    &amp;lt;servlet-mapping&amp;gt;
        &amp;lt;servlet-name&amp;gt;appfuse-oauth&amp;lt;/servlet-name&amp;gt;
        &amp;lt;url-pattern&amp;gt;/oauth/*&amp;lt;/url-pattern&amp;gt;
    &amp;lt;/servlet-mapping&amp;gt;
&amp;lt;/web-app&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Next, I created a &lt;em&gt;src/main/resources/security.xml&lt;/em&gt; and used it to secure my API, specify a login page, supply the users and integrate OAuth (see the last 4 beans below). &lt;/p&gt;
&lt;pre class=&quot;brush: xml; auto-links: false&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;
&amp;lt;beans:beans xmlns=&quot;http://www.springframework.org/schema/security&quot;
             xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
             xmlns:beans=&quot;http://www.springframework.org/schema/beans&quot;
             xmlns:oauth=&quot;http://www.springframework.org/schema/security/oauth2&quot;
             xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd
                           http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2.xsd&quot;&amp;gt;

    &amp;lt;http auto-config=&quot;true&quot;&amp;gt;
        &amp;lt;intercept-url pattern=&quot;/api/**&quot; access=&quot;ROLE_USER&quot;/&amp;gt;
        &amp;lt;intercept-url pattern=&quot;/oauth/**&quot; access=&quot;ROLE_USER&quot;/&amp;gt;
        &amp;lt;intercept-url pattern=&quot;/**&quot; access=&quot;IS_AUTHENTICATED_ANONYMOUSLY&quot;/&amp;gt;
        &amp;lt;form-login login-page=&quot;/login.jsp&quot; authentication-failure-url=&quot;/login.jsp?error=true&quot;
                    login-processing-url=&quot;/j_security_check&quot;/&amp;gt;
    &amp;lt;/http&amp;gt;

    &amp;lt;authentication-manager&amp;gt;
        &amp;lt;authentication-provider&amp;gt;
            &amp;lt;user-service&amp;gt;
                &amp;lt;user name=&quot;admin&quot; password=&quot;admin&quot; authorities=&quot;ROLE_USER,ROLE_ADMIN&quot;/&amp;gt;
                &amp;lt;user name=&quot;user&quot; password=&quot;user&quot; authorities=&quot;ROLE_USER&quot;/&amp;gt;
            &amp;lt;/user-service&amp;gt;
        &amp;lt;/authentication-provider&amp;gt;
    &amp;lt;/authentication-manager&amp;gt;

    &amp;lt;!--hook up the spring security filter chain--&amp;gt;
    &amp;lt;beans:alias name=&quot;springSecurityFilterChain&quot; alias=&quot;securityFilter&quot;/&amp;gt;

    &amp;lt;beans:bean id=&quot;tokenServices&quot;
                class=&quot;org.springframework.security.oauth2.provider.token.InMemoryOAuth2ProviderTokenServices&quot;&amp;gt;
        &amp;lt;beans:property name=&quot;supportRefreshToken&quot; value=&quot;true&quot;/&amp;gt;
    &amp;lt;/beans:bean&amp;gt;

    &amp;lt;oauth:provider client-details-service-ref=&quot;clientDetails&quot; token-services-ref=&quot;tokenServices&quot;&amp;gt;
        &amp;lt;oauth:verification-code user-approval-page=&quot;/oauth/confirm_access&quot;/&amp;gt;
    &amp;lt;/oauth:provider&amp;gt;

    &amp;lt;oauth:client-details-service id=&quot;clientDetails&quot;&amp;gt;
        &amp;lt;!--&amp;lt;oauth:client clientId=&quot;my-trusted-client&quot; authorizedGrantTypes=&quot;password,authorization_code,refresh_token&quot;/&amp;gt;
        &amp;lt;oauth:client clientId=&quot;my-trusted-client-with-secret&quot;
                      authorizedGrantTypes=&quot;password,authorization_code,refresh_token&quot; secret=&quot;somesecret&quot;/&amp;gt;
        &amp;lt;oauth:client clientId=&quot;my-less-trusted-client&quot; authorizedGrantTypes=&quot;authorization_code&quot;/&amp;gt;--&amp;gt;
        &amp;lt;oauth:client clientId=&quot;ajax-login&quot; authorizedGrantTypes=&quot;authorization_code&quot;/&amp;gt;
    &amp;lt;/oauth:client-details-service&amp;gt;
&amp;lt;/beans:beans&amp;gt;
&lt;/pre&gt;
&lt;p&gt;I used the &lt;a href=&quot;http://static.springsource.org/spring-security/oauth/tutorial.html&quot;&gt;OAuth for Spring Security sample apps&lt;/a&gt; to figure this out. In this example, I used authorizedGrantTypes=&quot;authorization_code&quot;, but you can see from the commented &amp;lt;oauth:client&gt; elements above that there&apos;s a few different options. You should also note that the clientId is hard-coded to &quot;ajax-login&quot;, signifying I only want to allow a single application to authenticate.
&lt;/p&gt;
&lt;p class=&quot;quote&quot;&gt;At this point, I&apos;d like to give a shoutout to Ryan Heaton for creating &lt;em&gt;both&lt;/em&gt; Enunciate and Spring Security&apos;s OAuth support. Nice work Ryan!&lt;/p&gt;
&lt;p&gt;At this point, I needed to do a number of additional tasks to finish integrating oauth. The first was to modify the Jetty Plugin&apos;s configuration to 1) run on port 9000, 2) load my custom files and 3) allow jetty:run to recognize Enunciate&apos;s generated files. Below is the final configuration in my pom.xml.
&lt;/p&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;plugin&amp;gt;
    &amp;lt;groupId&amp;gt;org.mortbay.jetty&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;maven-jetty-plugin&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;6.1.26&amp;lt;/version&amp;gt;
    &amp;lt;configuration&amp;gt;
        &amp;lt;connectors&amp;gt;
            &amp;lt;connector implementation=&quot;org.mortbay.jetty.nio.SelectChannelConnector&quot;&amp;gt;
                &amp;lt;port&amp;gt;9000&amp;lt;/port&amp;gt;
                &amp;lt;maxIdleTime&amp;gt;60000&amp;lt;/maxIdleTime&amp;gt;
            &amp;lt;/connector&amp;gt;
        &amp;lt;/connectors&amp;gt;
        &amp;lt;webAppConfig&amp;gt;
            &amp;lt;baseResource implementation=&quot;org.mortbay.resource.ResourceCollection&quot;&amp;gt;
                &amp;lt;resourcesAsCSV&amp;gt;
                    ${basedir}/src/main/webapp,
                    ${project.build.directory}/${project.build.finalName}
                &amp;lt;/resourcesAsCSV&amp;gt;
            &amp;lt;/baseResource&amp;gt;
            &amp;lt;contextPath&amp;gt;/appfuse-oauth&amp;lt;/contextPath&amp;gt;
        &amp;lt;/webAppConfig&amp;gt;
        &amp;lt;webXml&amp;gt;${project.build.directory}/${project.build.finalName}/WEB-INF/web.xml&amp;lt;/webXml&amp;gt;
    &amp;lt;/configuration&amp;gt;
&amp;lt;/plugin&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Next, I added the necessary OAuth dependencies for Spring Security to my pom.xml. Since the latest release is a milestone release, I had to add Spring&apos;s milestone repo too. 
&lt;/p&gt;
&lt;pre class=&quot;brush: xml; auto-links: false&quot;&gt;
&amp;lt;repository&amp;gt;
    &amp;lt;id&amp;gt;spring-milestone&amp;lt;/id&amp;gt;
    &amp;lt;url&amp;gt;http://s3.amazonaws.com/maven.springframework.org/milestone&amp;lt;/url&amp;gt;
&amp;lt;/repository&amp;gt;
...
&amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;org.springframework.security&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;spring-security-taglibs&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;${spring.version}&amp;lt;/version&amp;gt;
    &amp;lt;exclusions&amp;gt;
        &amp;lt;exclusion&amp;gt;
            &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;spring-web&amp;lt;/artifactId&amp;gt;
        &amp;lt;/exclusion&amp;gt;
        &amp;lt;exclusion&amp;gt;
            &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;spring-support&amp;lt;/artifactId&amp;gt;
        &amp;lt;/exclusion&amp;gt;
    &amp;lt;/exclusions&amp;gt;
&amp;lt;/dependency&amp;gt;
&amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;org.springframework.security.oauth&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;spring-security-oauth&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;1.0.0.M3&amp;lt;/version&amp;gt;
    &amp;lt;exclusions&amp;gt;
        &amp;lt;exclusion&amp;gt;
            &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;spring-beans&amp;lt;/artifactId&amp;gt;
        &amp;lt;/exclusion&amp;gt;
        &amp;lt;exclusion&amp;gt;
            &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;spring-context&amp;lt;/artifactId&amp;gt;
        &amp;lt;/exclusion&amp;gt;
        &amp;lt;exclusion&amp;gt;
            &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;spring-core&amp;lt;/artifactId&amp;gt;
        &amp;lt;/exclusion&amp;gt;
    &amp;lt;/exclusions&amp;gt;
&amp;lt;/dependency&amp;gt;
&amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;spring-webmvc&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;${spring.version}&amp;lt;/version&amp;gt;
&amp;lt;/dependency&amp;gt;
&amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;javax.servlet&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;servlet-api&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;2.5&amp;lt;/version&amp;gt;
    &amp;lt;scope&amp;gt;provided&amp;lt;/scope&amp;gt;
&amp;lt;/dependency&amp;gt;
&amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;javax.servlet&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;jstl&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;1.1.2&amp;lt;/version&amp;gt;
&amp;lt;/dependency&amp;gt;
&amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;taglibs&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;standard&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;1.1.2&amp;lt;/version&amp;gt;
&amp;lt;/dependency&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Since I named my DispatcherServlet &quot;appfuse-oauth&quot; in web.xml, I created a &lt;em&gt;src/main/webapp/WEB-INF/appfuse-oauth-servlet.xml&lt;/em&gt; to configure Spring MVC. I had to create the &lt;em&gt;src/main/webapp/WEB-INF&lt;/em&gt; directory. &lt;/p&gt;
&lt;pre class=&quot;brush: xml; auto-links: false&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;
&amp;lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
       xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
       xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
       xmlns:mvc=&quot;http://www.springframework.org/schema/mvc&quot;
       xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
                http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd&quot;&amp;gt;

    &amp;lt;!-- Scans the classpath of this application for @Components to deploy as beans --&amp;gt;
    &amp;lt;context:component-scan base-package=&quot;org.appfuse.examples.webapp&quot;/&amp;gt;

    &amp;lt;!-- Configures the @Controller programming model --&amp;gt;
    &amp;lt;mvc:annotation-driven/&amp;gt;

    &amp;lt;!-- Resolves view names to protected .jsp resources within the /WEB-INF/views directory --&amp;gt;
    &amp;lt;bean class=&quot;org.springframework.web.servlet.view.InternalResourceViewResolver&quot;&amp;gt;
        &amp;lt;property name=&quot;viewClass&quot; value=&quot;org.springframework.web.servlet.view.JstlView&quot;/&amp;gt;
        &amp;lt;property name=&quot;prefix&quot; value=&quot;/&quot;/&amp;gt;
        &amp;lt;property name=&quot;suffix&quot; value=&quot;.jsp&quot;/&amp;gt;
    &amp;lt;/bean&amp;gt;
&amp;lt;/beans&amp;gt;
&lt;/pre&gt;
&lt;p&gt;In order to show the OAuth confirmation page, I needed to create &lt;em&gt;src/main/java/org/appfuse/examples/webapp/AccessConfirmationController.java&lt;/em&gt; and map it to /oauth/confirm_access. I copied this from one of the sample projects and modified to use Spring&apos;s annotations.
&lt;/p&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
package org.appfuse.examples.webapp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.ClientAuthenticationToken;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.verification.ClientAuthenticationCache;
import org.springframework.security.oauth2.provider.verification.DefaultClientAuthenticationCache;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.TreeMap;

/**
 * Controller for retrieving the model for and displaying the confirmation page
 * for access to a protected resource.
 *
 * @author Ryan Heaton
 */
@Controller
@RequestMapping(&quot;/confirm_access&quot;)
public class AccessConfirmationController {

    private ClientAuthenticationCache authenticationCache = new DefaultClientAuthenticationCache();
    @Autowired
    private ClientDetailsService clientDetailsService;

    @RequestMapping(method = RequestMethod.GET)
    protected ModelAndView confirm(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ClientAuthenticationToken clientAuth = authenticationCache.getAuthentication(request, response);
        if (clientAuth == null) {
            throw new IllegalStateException(&quot;No client authentication request to authorize.&quot;);
        }

        TreeMap&amp;lt;String, Object&amp;gt; model = new TreeMap&amp;lt;String, Object&amp;gt;();
        ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId());
        model.put(&quot;auth_request&quot;, clientAuth);
        model.put(&quot;client&quot;, client);

        return new ModelAndView(&quot;access_confirmation&quot;, model);
    }
}
&lt;/pre&gt;
&lt;p&gt;This controller delegates to &lt;em&gt;src/main/webapp/access_confirmation.jsp&lt;/em&gt;. I created this file and filled it with code to display Accept and Deny buttons.
&lt;/p&gt;
&lt;pre class=&quot;brush: xml; auto-links: false&quot;&gt;
&amp;lt;%@ page import=&quot;org.springframework.security.core.AuthenticationException&quot; %&amp;gt;
&amp;lt;%@ page import=&quot;org.springframework.security.oauth2.common.exceptions.UnapprovedClientAuthenticationException&quot; %&amp;gt;
&amp;lt;%@ page import=&quot;org.springframework.security.oauth2.provider.verification.BasicUserApprovalFilter&quot; %&amp;gt;
&amp;lt;%@ page import=&quot;org.springframework.security.oauth2.provider.verification.VerificationCodeFilter&quot; %&amp;gt;
&amp;lt;%@ page import=&quot;org.springframework.security.web.WebAttributes&quot; %&amp;gt;
&amp;lt;%@ taglib prefix=&quot;authz&quot; uri=&quot;http://www.springframework.org/security/tags&quot; %&amp;gt;
&amp;lt;%@ taglib uri=&quot;http://java.sun.com/jsp/jstl/core&quot; prefix=&quot;c&quot; %&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Confirm Access&amp;lt;/title&amp;gt;
    &amp;lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;all&quot;
          href=&quot;http://demo.appfuse.org/appfuse-struts/styles/simplicity/theme.css&quot;/&amp;gt;
    &amp;lt;style type=&quot;text/css&quot;&amp;gt;
        h1 {
            margin-left: -300px;
            margin-top: 50px
        }
    &amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;

&amp;lt;h1&amp;gt;Confirm Access&amp;lt;/h1&amp;gt;

&amp;lt;div id=&quot;content&quot;&amp;gt;

    &amp;lt;% if (session.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION) != null &amp;amp;&amp;amp; 
                 !(session.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION) instanceof UnapprovedClientAuthenticationException)) { %&amp;gt;
    &amp;lt;div class=&quot;error&quot;&amp;gt;
        &amp;lt;h2&amp;gt;Woops!&amp;lt;/h2&amp;gt;

        &amp;lt;p&amp;gt;Access could not be granted.
            (&amp;lt;%= ((AuthenticationException) session.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION)).getMessage() %&amp;gt;)&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;% } %&amp;gt;
    &amp;lt;c:remove scope=&quot;session&quot; var=&quot;SPRING_SECURITY_LAST_EXCEPTION&quot;/&amp;gt;

    &amp;lt;authz:authorize ifAnyGranted=&quot;ROLE_USER,ROLE_ADMIN&quot;&amp;gt;
        &amp;lt;h2&amp;gt;Please Confirm&amp;lt;/h2&amp;gt;

        &amp;lt;p&amp;gt;You hereby authorize &quot;&amp;lt;c:out value=&quot;${client.clientId}&quot; escapeXml=&quot;true&quot;/&amp;gt;&quot; to access your protected resources.&amp;lt;/p&amp;gt;

        &amp;lt;form id=&quot;confirmationForm&quot; name=&quot;confirmationForm&quot;
              action=&quot;&amp;lt;%=request.getContextPath() + VerificationCodeFilter.DEFAULT_PROCESSING_URL%&amp;gt;&quot; method=&quot;POST&quot;&amp;gt;
            &amp;lt;input name=&quot;&amp;lt;%=BasicUserApprovalFilter.DEFAULT_APPROVAL_REQUEST_PARAMETER%&amp;gt;&quot;
                   value=&quot;&amp;lt;%=BasicUserApprovalFilter.DEFAULT_APPROVAL_PARAMETER_VALUE%&amp;gt;&quot; type=&quot;hidden&quot;/&amp;gt;
            &amp;lt;label&amp;gt;&amp;lt;input name=&quot;authorize&quot; value=&quot;Authorize&quot; type=&quot;submit&quot;&amp;gt;&amp;lt;/label&amp;gt;
        &amp;lt;/form&amp;gt;
        &amp;lt;form id=&quot;denialForm&quot; name=&quot;denialForm&quot;
              action=&quot;&amp;lt;%=request.getContextPath() + VerificationCodeFilter.DEFAULT_PROCESSING_URL%&amp;gt;&quot; method=&quot;POST&quot;&amp;gt;
            &amp;lt;input name=&quot;&amp;lt;%=BasicUserApprovalFilter.DEFAULT_APPROVAL_REQUEST_PARAMETER%&amp;gt;&quot;
                   value=&quot;not_&amp;lt;%=BasicUserApprovalFilter.DEFAULT_APPROVAL_PARAMETER_VALUE%&amp;gt;&quot; type=&quot;hidden&quot;/&amp;gt;
            &amp;lt;label&amp;gt;&amp;lt;input name=&quot;deny&quot; value=&quot;Deny&quot; type=&quot;submit&quot;&amp;gt;&amp;lt;/label&amp;gt;
        &amp;lt;/form&amp;gt;
    &amp;lt;/authz:authorize&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Finally, I needed to create &lt;em&gt;src/main/webapp/login.jsp&lt;/em&gt; to allow users to login.&lt;/p&gt;
&lt;pre class=&quot;brush: xml; auto-links: false&quot;&gt;
&amp;lt;%@ page language=&quot;java&quot; pageEncoding=&quot;UTF-8&quot; contentType=&quot;text/html;charset=utf-8&quot; %&amp;gt;
&amp;lt;%@ taglib uri=&quot;http://java.sun.com/jsp/jstl/core&quot; prefix=&quot;c&quot; %&amp;gt;
&amp;lt;%@ taglib uri=&quot;http://java.sun.com/jsp/jstl/fmt&quot; prefix=&quot;fmt&quot; %&amp;gt;
&amp;lt;%@ taglib uri=&quot;http://java.sun.com/jsp/jstl/core&quot; prefix=&quot;c&quot; %&amp;gt;

&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Login&amp;lt;/title&amp;gt;
    &amp;lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;all&quot;
          href=&quot;http://demo.appfuse.org/appfuse-struts/styles/simplicity/theme.css&quot;/&amp;gt;
    &amp;lt;style type=&quot;text/css&quot;&amp;gt;
        h1 {
            margin-left: -300px;
            margin-top: 50px
        }
    &amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;h1&amp;gt;Login&amp;lt;/h1&amp;gt;

&amp;lt;form method=&quot;post&quot; id=&quot;loginForm&quot; action=&quot;&amp;lt;c:url value=&apos;/j_security_check&apos;/&amp;gt;&quot;&amp;gt;
    &amp;lt;fieldset style=&quot;padding-bottom: 0&quot;&amp;gt;
        &amp;lt;ul&amp;gt;
            &amp;lt;c:if test=&quot;${param.error != null}&quot;&amp;gt;
                &amp;lt;li class=&quot;error&quot;&amp;gt;
                    ${sessionScope.SPRING_SECURITY_LAST_EXCEPTION.message}
                &amp;lt;/li&amp;gt;
            &amp;lt;/c:if&amp;gt;
            &amp;lt;li&amp;gt;
                &amp;lt;label for=&quot;j_username&quot; class=&quot;required desc&quot;&amp;gt;
                    Username &amp;lt;span class=&quot;req&quot;&amp;gt;*&amp;lt;/span&amp;gt;
                &amp;lt;/label&amp;gt;
                &amp;lt;input type=&quot;text&quot; class=&quot;text medium&quot; name=&quot;j_username&quot;
                       id=&quot;j_username&quot; tabindex=&quot;1&quot;/&amp;gt;
            &amp;lt;/li&amp;gt;

            &amp;lt;li&amp;gt;
                &amp;lt;label for=&quot;j_password&quot; class=&quot;required desc&quot;&amp;gt;
                    Password &amp;lt;span class=&quot;req&quot;&amp;gt;*&amp;lt;/span&amp;gt;
                &amp;lt;/label&amp;gt;
                &amp;lt;input type=&quot;password&quot; class=&quot;text medium&quot; name=&quot;j_password&quot;
                       id=&quot;j_password&quot; tabindex=&quot;2&quot;/&amp;gt;
            &amp;lt;/li&amp;gt;
            &amp;lt;li&amp;gt;
                &amp;lt;input type=&quot;submit&quot; class=&quot;button&quot; name=&quot;login&quot; value=&quot;Login&quot;
                       tabindex=&quot;3&quot;/&amp;gt;
            &amp;lt;/li&amp;gt;
        &amp;lt;/ul&amp;gt;
    &amp;lt;/fieldset&amp;gt;
&amp;lt;/form&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;
&lt;p&gt;All the changes described in the above section are necessary to implement OAuth if you create a project with AppFuse WS 2.1. It may seem like a lot of code, but I was able to copy/paste and get it all working in an app in under 5 minutes. Hopefully you can do the same. I&apos;m also considering adding it by default to the next version of AppFuse. Now let&apos;s look at integrating OAuth into a client to authenticate and retrieve data from this application.
&lt;/p&gt;
&lt;p id=&quot;oauth-client&quot;&gt;&lt;strong&gt;Authenticate and Retrieve Data with Client&lt;/strong&gt;&lt;br/&gt;
I originally thought my &lt;a href=&quot;http://raibledesigns.com/rd/entry/implementing_oauth_with_gwt&quot;&gt;GWT OAuth&lt;/a&gt; application would provide a nice client. However, after 30 minutes of trying to get GWT 1.7.1 and the GWT Maven plugin (1.1) working with my 64-bit Java 6 JDK on OS X, I gave up. So I opted to use the &lt;a href=&quot;https://github.com/mraible/ajax-login&quot;&gt;Ajax Login&lt;/a&gt; application I&apos;ve been using in my recent security tutorials.
&lt;/p&gt;
&lt;p&gt;In this example, I used OAuth2RestTemplate from Spring Security OAuth. While this works, and works well, I&apos;d still like to get things working with GWT (or jQuery) to demonstrate how to do it from a pure client-side perspective.
&lt;/p&gt;
&lt;p&gt;To begin, I got the latest source of Ajax Login from GitHub (as of this morning) and made some changes. First of all, I added the Spring Security OAuth dependencies to pom.xml:
&lt;/p&gt;
&lt;pre class=&quot;brush: xml; auto-links: false&quot;&gt;
&amp;lt;repository&amp;gt;
    &amp;lt;id&amp;gt;spring-milestone&amp;lt;/id&amp;gt;
    &amp;lt;url&amp;gt;http://s3.amazonaws.com/maven.springframework.org/milestone&amp;lt;/url&amp;gt;
&amp;lt;/repository&amp;gt;
...
&amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;org.springframework.security.oauth&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;spring-security-oauth&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;1.0.0.M3&amp;lt;/version&amp;gt;
    &amp;lt;exclusions&amp;gt;
        &amp;lt;exclusion&amp;gt;
            &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;spring-beans&amp;lt;/artifactId&amp;gt;
        &amp;lt;/exclusion&amp;gt;
        &amp;lt;exclusion&amp;gt;
            &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;spring-context&amp;lt;/artifactId&amp;gt;
        &amp;lt;/exclusion&amp;gt;
        &amp;lt;exclusion&amp;gt;
            &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;spring-core&amp;lt;/artifactId&amp;gt;
        &amp;lt;/exclusion&amp;gt;
    &amp;lt;/exclusions&amp;gt;
&amp;lt;/dependency&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Then I modified &lt;em&gt;src/main/webapp/WEB-INF/security.xml&lt;/em&gt; and added an OAuth Token Service and defined the location of the OAuth server.&lt;/p&gt; 
&lt;pre class=&quot;brush: xml; auto-links: false&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;
&amp;lt;beans:beans xmlns=&quot;http://www.springframework.org/schema/security&quot;
             xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
             xmlns:beans=&quot;http://www.springframework.org/schema/beans&quot;
             xmlns:oauth=&quot;http://www.springframework.org/schema/security/oauth2&quot;
             xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
              http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
              http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2.xsd&quot;&amp;gt;

...
    &amp;lt;oauth:client token-services-ref=&quot;oauth2TokenServices&quot;/&amp;gt;

    &amp;lt;beans:bean id=&quot;oauth2TokenServices&quot;
                class=&quot;org.springframework.security.oauth2.consumer.token.InMemoryOAuth2ClientTokenServices&quot;/&amp;gt;

    &amp;lt;oauth:resource id=&quot;appfuse&quot; type=&quot;authorization_code&quot; clientId=&quot;ajax-login&quot;
                    accessTokenUri=&quot;http://localhost:9000/appfuse-oauth/oauth/authorize&quot;
                    userAuthorizationUri=&quot;http://localhost:9000/appfuse-oauth/oauth/user/authorize&quot;/&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Next, I created a Controller that uses OAuth2RestTemplate to make the request and get the data from the AppFuse OAuth application&apos;s API. I created &lt;em&gt;src/main/java/org/appfuse/examples/webapp/oauth/UsersApiController.java&lt;/em&gt; and filled it with the following code:&lt;/p&gt;
&lt;pre class=&quot;brush: java; auto-links: false&quot;&gt;
package org.appfuse.examples.webapp.oauth;

import org.appfuse.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.common.exceptions.InvalidTokenException;
import org.springframework.security.oauth2.consumer.*;
import org.springframework.security.oauth2.consumer.token.OAuth2ClientTokenServices;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@RequestMapping(&quot;/appfuse/users&quot;)
@Controller
public class UsersApiController {

    private OAuth2RestTemplate apiRestTemplate;
    @Autowired
    private OAuth2ClientTokenServices tokenServices;

    private static final String REMOTE_DATA_URL = &quot;http://localhost:9000/appfuse-oauth/api/users&quot;;

    @Autowired
    public UsersApiController(OAuth2ProtectedResourceDetails resourceDetails) {
        this.apiRestTemplate = new OAuth2RestTemplate(resourceDetails);
    }

    @RequestMapping(method = RequestMethod.GET)
    @ResponseBody
    public List&amp;lt;User&amp;gt; getUsers() {
        try {
            List users = apiRestTemplate.getForObject(REMOTE_DATA_URL, List.class);
            return new ArrayList&amp;lt;User&amp;gt;(users);
        } catch (InvalidTokenException badToken) {
            //we&apos;ve got a bad token, probably because it&apos;s expired.
            OAuth2ProtectedResourceDetails resource = apiRestTemplate.getResource();
            OAuth2SecurityContext context = OAuth2SecurityContextHolder.getContext();
            if (context != null) {
                // this one is kind of a hack for this application
                // the problem is that the sparklr photos page doesn&apos;t remove the &apos;code=&apos; request parameter.
                ((OAuth2SecurityContextImpl) context).setVerificationCode(null);
            }
            //clear any stored access tokens...
            tokenServices.removeToken(SecurityContextHolder.getContext().getAuthentication(), resource);
            //go get a new access token...
            throw new OAuth2AccessTokenRequiredException(resource);
        }
    }
}
&lt;/pre&gt;
&lt;p&gt;At this point, I thought everything would work and I spent quite some time banging my head against the wall when it didn&apos;t. As I was composing an email to the Enunciate users mailing list, I realized the issue. It appeared to be working, but from the server side, and the redirect back to the client was not happening. The Ajax Login app uses UrlRewriteFilter (for pretty URLs) to redirect from /app/* to /$1 and this redirect was losing the code parameter in the URL. 
&lt;/p&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;rule&amp;gt;
    &amp;lt;from&amp;gt;/app/**&amp;lt;/from&amp;gt;
    &amp;lt;to last=&quot;true&quot; type=&quot;redirect&quot;&amp;gt;%{context-path}/$1&amp;lt;/to&amp;gt;
&amp;lt;/rule&amp;gt;
&lt;/pre&gt;
&lt;p&gt;To fix this, I added use-query-string=&quot;true&quot; to the root element in &lt;em&gt;src/main/webapp/WEB-INF/urlrewrite.xml&lt;/em&gt;:
&lt;pre class=&quot;brush: xml; toolbar: false&quot;&gt;
&amp;lt;urlrewrite default-match-type=&quot;wildcard&quot; use-query-string=&quot;true&quot;&gt;
&lt;/pre&gt;
&lt;p&gt;After making all these changes, I ran &lt;strong&gt;mvn jetty:run&lt;/strong&gt; on both apps and opened &lt;a href=&quot;http://localhost:8080/appfuse/users&quot;&gt;http://localhost:8080/appfuse/users&lt;/a&gt; in my browser. It all worked and a smile crept across my face. I&apos;ve checked in the client changes into &lt;a href=&quot;https://github.com/mraible/ajax-login&quot;&gt;ajax-login on GitHub&lt;/a&gt; and the appfuse-oauth example into &lt;a href=&quot;http://code.google.com/p/appfuse-demos/&quot;&gt;AppFuse Demos on Google Code&lt;/a&gt;. If you&apos;d like to see this example in action, I&apos;d encourage you to checkout both projects and let me know if you find any issues.</content>
    </entry>
    <entry>
        <id>https://raibledesigns.com/rd/entry/how_s_the_ol_team</id>
        <title type="html">How&apos;s the ol&apos; Team Doing?</title>
        <author><name>Matt Raible</name></author>
        <link rel="alternate" type="text/html" href="https://raibledesigns.com/rd/entry/how_s_the_ol_team"/>
        <published>2010-10-21T09:00:41-06:00</published>
        <updated>2012-11-11T02:00:40-07:00</updated> 
        <category term="/Java" label="Java" />
        <category term="recruiting" scheme="http://roller.apache.org/ns/tags/" />
        <category term="video" scheme="http://roller.apache.org/ns/tags/" />
        <category term="java" scheme="http://roller.apache.org/ns/tags/" />
        <category term="ipad" scheme="http://roller.apache.org/ns/tags/" />
        <category term="hiring" scheme="http://roller.apache.org/ns/tags/" />
        <category term="team" scheme="http://roller.apache.org/ns/tags/" />
        <category term="rest" scheme="http://roller.apache.org/ns/tags/" />
        <category term="android" scheme="http://roller.apache.org/ns/tags/" />
        <category term="developers" scheme="http://roller.apache.org/ns/tags/" />
        <category term="html5" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">Back in March, I wrote about &lt;a href=&quot;http://raibledesigns.com/rd/entry/how_we_hired_a_team&quot;&gt;How We Hired a Team of 10 in 2 Months&lt;/a&gt;: &lt;/p&gt;
&lt;p class=&quot;quote&quot;&gt;
This week, we on-boarded 3 of our final 4 developers. I breathed a big sigh of relief that the hiring was over and we could get back to slinging code and making things happen. As luck would have it, I received an e-mail from my boss on Tuesday that the hiring engine is starting up again and we need to hire 6 more developers. While I&apos;m not anxious to start the Hiring Engine again, I am glad to know it works well and it &lt;em&gt;has&lt;/em&gt; helped us build a great team.
&lt;/p&gt;
&lt;p&gt;We never ended up hiring those additional 6 developers, but we&apos;ve had quite a ride since March. One of the first commenters on my original post wrote:&lt;/p&gt;
&lt;p class=&quot;quote&quot;&gt;I hope that whirlwind of hiring works out for you Matt. But, don&apos;t you think it&apos;s a bit early to be declaring success? 
&lt;/p&gt;
&lt;p&gt;At that time, we still had a lot of work to do to become a successful team. However, by the end of March, we&apos;d finished our first deliverable - converting a somewhat slow ColdFusion/jQuery/Video webapp into a fast Java/jQuery/Video webapp. The slowness wasn&apos;t due to ColdFusion, but mostly performance, caching and YSlow-type optimizations. At that time, we surprised the folks that were in charge of our app. They didn&apos;t think we&apos;d finish so fast and it took them awhile to decide what to do with our work. 
&lt;/p&gt;
&lt;p&gt;
While we were waiting for the product folks to launch our app in April/May, we decided to experiment with developing some new clients. So we wrote an iPhone app, an Android App, an iPhone/Android/iPad/HTML5 version of our webapp and a Blu-ray client. All of these applications used our webapp&apos;s backend RESTful services and we were able to learn the SDKs and implement all the apps in a matter of weeks. In May, we demoed all our clients and got rave reviews from executives. We celebrated that afternoon with a big sigh of relief.
&lt;/p&gt;
&lt;p&gt;The glowing from our many-clients demo was short-lived. A week later, we were asked to enhance our iPad app to include TV-Remote type features, namely channel-changing and DVR functionality. After freaking out and trying to figure out how to deliver such an app in a week, the demo was rescheduled and we were afforded 2 weeks to build the app.
After much frantic development, we were able to complete the app in time and the &lt;a href=&quot;http://gizmodo.com/5611578/time-warner-cable-ipad-app-to-deliver-on+demand-tv-streaming&quot;&gt;demo was published to YouTube&lt;/a&gt; a couple months later. 
&lt;/p&gt;
&lt;p&gt;In June, if you asked me if we were a successful team, I would&apos;ve definitely said &quot;Yes!&quot; We&apos;d been asked to develop apps for 3 different demos and we delivered on-time. 
&lt;/p&gt;
&lt;p&gt;
The remainder of June and July we slipped into a bit of limbo where we weren&apos;t asked to develop anything, but simply maintain and enhance the stuff we&apos;d already developed. After a few weeks of doing this, several of us began to wonder if the apps we&apos;d developed would ever see the light of day. We expressed this concern to our VP and a new idea was hatched: The 60-Day Push.
&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;60-Day Push&lt;/em&gt; was designed to eliminate politics and meetings and allow us to develop a 3-screen (PC, iPad, TV) experience for our video content. We decided to aim high and try to complete most of the work in 30-days, so we could do executive demos of our progress. We started all our applications from scratch, split into Services, Portal, TV and iPad teams and worked with &lt;a href=&quot;http://method.com/&quot;&gt;Method&lt;/a&gt; to implement a slick design for all our apps. I&apos;m proud to say we delivered yet again and there were many proud moments as we demoed to the top executives of the company.
&lt;/p&gt;
&lt;p&gt;In early September, after doing several demos, we were approved to launch and we&apos;ve been working towards that goal ever since. We feel we have several weeks of work to coax our DemoWare into RealWorldWare, but the momentum is there and the end of the tunnel is in sight. &lt;/p&gt;
&lt;p&gt;As a further sign of our success, we&apos;re moving into a new office in LoDo next week. This also means the End of an Era, where the Raible Designs&apos; office across from Forest Room 5 will cease to exist. We (Goodwill, Scotty, Country Bry and I) first moved into this office while working for Evite in April 2009. It&apos;s been a fantastic location, a facilitator of extensive collaboration and host to many dart games, FACs, bird-dog spottings and way too many Mom Jokes.&lt;/p&gt;
&lt;p&gt;As part of our transition, I&apos;ll be looking for renters to fill out the rest of my lease (through March 2010). If you&apos;re looking for a sweet location for 5-6 people in &lt;a href=&quot;http://maps.google.com/maps?q=2525+15th+Street,+Denver&quot;&gt;Denver&apos;s Highlands&lt;/a&gt; (near the REI store downtown), please &lt;a href=&quot;http://raibledesigns.com/contact.jsp&quot;&gt;let me know&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Also, there&apos;s a good chance my team will continue to grow as we move our apps into production and start ramping up for millions of users. If you&apos;re a strong Web or Java developer with social skills and a &lt;a href=&quot;http://www.jroller.com/wj/entry/a_tale_of_two_programmers&quot;&gt;Ditchdigger&lt;/a&gt; attitude, I&apos;d love to hear from you. We probably won&apos;t be hiring until January, but that doesn&apos;t mean we can&apos;t start talking now.</content>
    </entry>
    <entry>
        <id>https://raibledesigns.com/rd/entry/developing_rich_web_service_apis</id>
        <title type="html">Developing Rich Web Service APIs with Java</title>
        <author><name>Matt Raible</name></author>
        <link rel="alternate" type="text/html" href="https://raibledesigns.com/rd/entry/developing_rich_web_service_apis"/>
        <published>2010-03-18T17:51:00-06:00</published>
        <updated>2010-03-19T00:03:34-06:00</updated> 
        <category term="/Java" label="Java" />
        <category term="jax-ws" scheme="http://roller.apache.org/ns/tags/" />
        <category term="api" scheme="http://roller.apache.org/ns/tags/" />
        <category term="xml" scheme="http://roller.apache.org/ns/tags/" />
        <category term="json" scheme="http://roller.apache.org/ns/tags/" />
        <category term="enunciate" scheme="http://roller.apache.org/ns/tags/" />
        <category term="webservices" scheme="http://roller.apache.org/ns/tags/" />
        <category term="soap" scheme="http://roller.apache.org/ns/tags/" />
        <category term="ryanheaton" scheme="http://roller.apache.org/ns/tags/" />
        <category term="jax-rs" scheme="http://roller.apache.org/ns/tags/" />
        <category term="rest" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">This afternoon, I attended &lt;a href=&quot;http://www.java.net/blog/stoicflame/&quot;&gt;Ryan Heaton&apos;s&lt;/a&gt; talk on &lt;a href=&quot;http://javasymposium.techtarget.com/html/tools_tech.html%23RHeatonTech&quot;&gt;Developing Rich Web Service APIs with Java&lt;/a&gt;. I&apos;ve always admired Ryan&apos;s work and what he&apos;s done with &lt;a href=&quot;http://enunciate.codehaus.org&quot;&gt;Enunciate&lt;/a&gt;. Below are my notes from his talk.
&lt;/p&gt;
&lt;p style=&quot;border-top: 1px dotted silver; padding-top: 10px&quot;&gt;
We&apos;ve come a long way from the WS (SOAP) &amp;lt;-&gt; EJB days. There are many tools that you can use to develop web services today. A Web Service is an API that&apos;s accessible over a network via platform-independent protocol. Historical examples of web services (in chronological order):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;CORBA&lt;/li&gt;
&lt;li&gt;DCOM&lt;/li&gt;
&lt;li&gt;RMI&lt;/li&gt;
&lt;li&gt;SOAP&lt;/li&gt;
&lt;li&gt;REST&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A Web Service is composed of &lt;em&gt;code&lt;/em&gt; wrapped with a &lt;em&gt;container&lt;/em&gt; and it&apos;s bound to a &lt;em&gt;contract&lt;/em&gt;. The table below shows the types of web services and their equivalent Java standard.&lt;/p&gt;
&lt;p&gt;
&lt;style type=&quot;text/css&quot;&gt;
table.comparison { width: 200px }
table.comparison th, table.comparison td { padding-left: 7px }
&lt;/style&gt;
&lt;table class=&quot;comparison&quot;&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Standard&lt;/th&gt;&lt;th&gt;Technology&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;
SOAP&lt;/td&gt; &lt;td&gt;JAX-WS&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;REST&lt;/td&gt;&lt;td&gt;JAX-RS&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;XML&lt;/td&gt;&lt;td&gt;JAXB&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;JSON&lt;/td&gt;&lt;td&gt;???&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;JAXB is the standard technology used to marshal XML &amp;lt;-&gt; Java. It&apos;s annotation-driven, using @XmlRootElement, @XmlElement and @XmlAttribute to translate Java properties to XML.&lt;/p&gt;
&lt;p&gt;JAX-WS is a Java standard, outputs classes as SOAP endpoints and it&apos;s annotation-driven. @WebService and @WebMethod are the main annotations. @WebMethod is only needed if you&apos;re trying to expose a non-public method.
&lt;/p&gt;
&lt;p&gt;
JAX-RS is a Java standard used to expose REST services. Not surprisingly, it&apos;s annotation-driven. The class itself needs to be annotated with @Path. Methods are annotated with @GET, @PUT, @POST or @DELETE. If you need to pass in a parameter to a method, you can add a path parameter like the following:
&lt;/p&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
@Path(&quot;/{id}&quot;)
@GET
public Person readPerson(@PathParam(&quot;id&quot;) String id);
&lt;/pre&gt;
&lt;p&gt;To specify the possible mime-type outputs of a method, you can use the @Produces annotation. For example:
&lt;pre class=&quot;brush: java&quot;&gt;
@Produces({&quot;application/xml&quot;, &quot;application/json&quot;})
&lt;/pre&gt;
&lt;p&gt;
You can also do this for input methods with the @Consumes annotation. &lt;/p&gt;
&lt;p&gt;For JSON, there&apos;s no Java standard. However, there&apos;s a number of libraries available, including &lt;a href=&quot;http://jackson.codehaus.org&quot;&gt;Jackson&lt;/a&gt;, Jettison, GSON, XStream. Personally, I&apos;ve used Jackson and highly recommend it.&lt;/p&gt;
&lt;p&gt;
The major players in exposing Java code as JAX-WS and JAX-RS services are Oracle, Spring and JBoss. Oracle (formerly Sun) has implemented the JAX-WS reference implementation and it&apos;s called Metro (a.k.a. JAX-WS RI). For JAX-RS, Oracle has the Jersey project. For Spring, the JAX-WS and JAX-RS implementation is Apache CXF. JBoss has JBoss-WS and RESTEasy. 
&lt;/p&gt;
&lt;p&gt;There&apos;s also a number of custom containers for exposing web services. For example, AMF (implementations: BlazeDS, GraniteDS), GWT-RPC (GWT),  JSON-PRC (DWR), Atom (Abdera), OpenSocial (Shindig).
&lt;/p&gt;
&lt;p&gt;
The contract is a very important part of a web service API. It&apos;s composed of an Interface Definition Language (WSDL, WADL JSON Schema), Developer Docs (text, context, preconditions, restrictions), example code and client libraries.
&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://enunciate.codehaus.org&quot;&gt;Enunciate&lt;/a&gt; allows you to create your contract for your web services. It&apos;s a build-time WS Development tool. It generates developer documentation and client-side libraries (for Java, C/C++, Objective C, ActionScript and Ruby). It leverages existing specs (JAX-*) and fails fast at compile time.
&lt;/p&gt;
&lt;p&gt;From there, Ryan gave us a demo of Enunciate and how it could easily create an API website based on JAX-RS annotations.
&lt;/p&gt;
&lt;p style=&quot;border-top: 1px dotted silver; padding-top: 10px&quot;&gt;I liked Ryan&apos;s talk and I&apos;m definitely a fan of Enunciate. While I didn&apos;t learn anything new, I think there&apos;s a lot of Java developers that don&apos;t know about the various standards and how easy it is to develop web services. Hopefully by taking notes from Ryan&apos;s talk, I&apos;ll get the word out a bit more and make more folks aware of Enunciate. On a related note, Sonatype has a good post on how they &lt;a href=&quot;http://www.sonatype.com/people/2010/02/documenting-the-nexus-rest-api-with-enunciate/&quot;&gt;documented the Nexus API with Enunciate&lt;/a&gt;.</content>
    </entry>
    <entry>
        <id>https://raibledesigns.com/rd/entry/the_cloud_computing_continuum_with</id>
        <title type="html">The Cloud Computing Continuum with Bob McWhirter</title>
        <author><name>Matt Raible</name></author>
        <link rel="alternate" type="text/html" href="https://raibledesigns.com/rd/entry/the_cloud_computing_continuum_with"/>
        <published>2010-03-17T16:20:26-06:00</published>
        <updated>2010-03-18T23:55:04-06:00</updated> 
        <category term="/Java" label="Java" />
        <category term="virtualization" scheme="http://roller.apache.org/ns/tags/" />
        <category term="bobmcwhirter" scheme="http://roller.apache.org/ns/tags/" />
        <category term="nosql" scheme="http://roller.apache.org/ns/tags/" />
        <category term="rest" scheme="http://roller.apache.org/ns/tags/" />
        <category term="caching" scheme="http://roller.apache.org/ns/tags/" />
        <category term="paas" scheme="http://roller.apache.org/ns/tags/" />
        <category term="tssjs" scheme="http://roller.apache.org/ns/tags/" />
        <category term="cloud" scheme="http://roller.apache.org/ns/tags/" />
        <category term="jboss" scheme="http://roller.apache.org/ns/tags/" />
        <category term="saas" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">This afternoon, I sat in a Keynote by Bob McWhirter at TSSJS 2010. Bob is the Chief Architect of Cloud Computing at Red Hat. Bob is &quot;The Despot&quot; at &lt;a href=&quot;http://codehaus.org&quot;&gt;Codehaus&lt;/a&gt;, helped start Groovy and founded &lt;a href=&quot;http://www.jboss.org/drools&quot;&gt;Drools&lt;/a&gt;. Below are my notes from his talk.
&lt;/p&gt;
&lt;p style=&quot;border-top: 1px dotted silver; padding-top: 10px&quot;&gt;The cloud is not an either/or question. A scorched Earth strategy is not necessary to be in the cloud. The cloud is a continuum of technologies, many of those that you&apos;re already familiar with. You&apos;re used to web, messaging and storage. You can add just a little bot of cloud to your application at a time. 
&lt;/p&gt;
&lt;p&gt;
So what is the cloud?
&lt;/p&gt;
&lt;p&gt;
It&apos;s the next logical step in application delivery.
&lt;/p&gt;
&lt;p&gt;
How did we get to the cloud? First, we jammed a lot of servers into a closet (back in the .com days). That&apos;s a lot of stuff to deal with if all you want to do is deliver an internet-based service. Then we did some colo. The problem with colo was that it was still &lt;em&gt;our&lt;/em&gt; stuff. Then we leased managed servers. With the cloud, we lease what &lt;em&gt;appears&lt;/em&gt; to be servers (or services). This is a path we&apos;ve all been taking to abstract the annoying bits away from hosting an internet-based service.
&lt;/p&gt;
&lt;p&gt;
The typical diagram of a cloud has IaaS, PaaS and PaaS. IaaS abstracts away hardware. PaaS abstracts away services. SaaS abstracts away software.
&lt;/p&gt;
&lt;p&gt;
Tenants of the cloud:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The illusion of infinite resources.&lt;/li&gt;
&lt;li&gt;On-demand acquisition and provision.&lt;/li&gt;
&lt;li&gt;Someone else&apos;s responsibility.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Magicians provide the illusion of pulling a card out of your ear, but they don&apos;t &lt;em&gt;actually&lt;/em&gt; do it. Because there &lt;em&gt;are&lt;/em&gt; limits of what we can do. With on-demand requisitioning, there&apos;s no more purchase orders. There&apos;s no more waiting for delivery. No waiting for IT to rack it. Or install it. By having someone else manage your hardware, it&apos;s not your problem. There&apos;s clear lines of responsibility. This intentionally limits visibility into the implementation. Hopefully it&apos;s best-of-breed.
&lt;/p&gt;
&lt;p&gt;
The Cloud is really just a mindset. Virtualization makes it affordable to make mistakes. Repeatedly. Each service is managed as an autonomous entity. Services are &lt;em&gt;designed&lt;/em&gt; for scalability.
&lt;/p&gt;
&lt;p&gt;
Architecture 101 give us a presentation layer, a business logic layer and a persistence layer. You can scale it by putting many instances on many servers. However, the truth is that most apps are a big ball of mud. You need to get your application in order, then figure out which parts really needs to scale. Is the web tier really where we have trouble? Painting HTML isn&apos;t all that hard.
&lt;/p&gt;
&lt;p&gt;
You don&apos;t have to put &lt;em&gt;everything&lt;/em&gt; in the cloud. The cloud is &lt;em&gt;not&lt;/em&gt; a revolution. We still need containers for web things, messaging things, storage of things and other &lt;em&gt;things&lt;/em&gt;. Containers still exist, they&apos;re just in the cloud.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;From container to cloud&lt;/strong&gt;&lt;br/&gt;
When you have an application and a database, there&apos;s not much to abstract away into the cloud. However, as soon as you notice your DB is slow, you&apos;ll add caching. Once you hit your machine&apos;s memory limit, you discover distributed caching systems. Once you&apos;ve done this, you&apos;ll discover that the network isn&apos;t all that slow, especially compared to spinning disks. Then you realize that you don&apos;t even need the storage and you can keep everything in cache. From there, you move to a RESTful caching service. Then you call it a NoSQL Service so you can be buzzword-compliant. 
&lt;/p&gt;
&lt;p&gt;
As far as caching services, there&apos;s many available, but a lot of them are startups. However, the cloud does &lt;em&gt;not&lt;/em&gt; have to mean external 3rd-party providers. Remember DBAs? It was their job to view the database as a service and to protect it. There&apos;s a good chance that we&apos;ll end up with DBAs for services. By turning caching into an independent service, it becomes subject to &lt;a href=&quot;http://en.wikipedia.org/wiki/Economy_of_scale&quot;&gt;economies of scale&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
The cloud is a mindset. It&apos;s an SOA approach that allows groups to specialize and optimize for scale.
&lt;/p&gt;
&lt;p&gt;
So how do you implementing a local cloud? We already have great caching technologies. Bob, with his JBoss hat on, recommends &lt;a href=&quot;http://www.jboss.org/infinispan&quot;&gt;Infinispan&lt;/a&gt; and its REST API. To get around network latency, you can still run your cloud on your LAN. You&apos;re essentially trading disk traffic for network traffic. You can use many hands (e.g. MapReduce) to make things happen quickly.
&lt;/p&gt;
&lt;p&gt;
Besides caching, there&apos;s a number of other services that can be put in the cloud. For example:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Messaging (REST-MQ&lt;/li&gt;
&lt;li&gt;Scheduling&lt;/li&gt;
&lt;li&gt;Security &amp;amp; Identity (OASIS, etc)&lt;/li&gt;
&lt;li&gt;Computation (query &amp; otherwise)&lt;/li&gt;
&lt;li&gt;Transactions (REST-TX)&lt;/li&gt;
&lt;li&gt;Business Process Management&lt;/li&gt;
&lt;li&gt;Telephony (VOIP, SMS)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Your application becomes a &lt;strong&gt;stack of services&lt;/strong&gt;, instead of a stack of software.
&lt;/p&gt;
&lt;p&gt;
Higher-order business-logic services are also subject to cloudification. Ultimately, going into the cloud is not rocket science. The cloud does &lt;em&gt;not&lt;/em&gt; turn everything on its head. We don&apos;t have to wait for new companies to develop new technologies. Startups may be the best consumers of the cloud, but might not be the best providers. We&apos;ll let the startups assume the risks for now. Until the 3rd party services have been proven, it&apos;s probably best to build your own cloud of services. 
&lt;/p&gt;
&lt;p&gt;
More than anything, the cloud has caused a return to fundamentals. Once your app is a collection of services, you can easily pick and choose what pieces you want to put in the cloud. This is where we&apos;re headed, whether you like it or not. As more apps become global-scape, you&apos;re going to run into these issues. By adopting a cloud mindset and architecture, your app can be prepared for scalability issues.
&lt;/p&gt;
&lt;p&gt;For more communication with Bob and his Cloud Evangelism, checkout &lt;a href=&quot;http://cloudpress.org/&quot;&gt;StormGrind&lt;/a&gt; or &lt;a href=&quot;http://twitter.com/bobmcwhirter&quot;&gt;follow him on Twitter&lt;/a&gt;.
&lt;/p&gt;
&lt;p style=&quot;border-top: 1px dotted silver; padding-top: 10px&quot;&gt;Personally, I really enjoyed Bob&apos;s talk. It was by far the best keynote today, mostly because he told a story and did it elegantly with a nice-looking presentation. Not only that, but he provided the audience with a practical view of the cloud and ways that we can start using it in our applications today.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; You can find the slides from this session &lt;a href=&quot;http://www.slideshare.net/javasymposium/the-cloud-computing-continuum-final&quot;&gt;on SlideShare&lt;/a&gt;.</content>
    </entry>
    <entry>
        <id>https://raibledesigns.com/rd/entry/developing_and_testing_gwt_client</id>
        <title type="html">Developing and Testing GWT Client Services</title>
        <author><name>Matt Raible</name></author>
        <link rel="alternate" type="text/html" href="https://raibledesigns.com/rd/entry/developing_and_testing_gwt_client"/>
        <published>2009-10-21T06:55:17-06:00</published>
        <updated>2010-02-22T22:47:19-07:00</updated> 
        <category term="/Java" label="Java" />
        <category term="gwt" scheme="http://roller.apache.org/ns/tags/" />
        <category term="requestbuilder" scheme="http://roller.apache.org/ns/tags/" />
        <category term="junit" scheme="http://roller.apache.org/ns/tags/" />
        <category term="gwtinpractice" scheme="http://roller.apache.org/ns/tags/" />
        <category term="testing" scheme="http://roller.apache.org/ns/tags/" />
        <category term="gwttestcase" scheme="http://roller.apache.org/ns/tags/" />
        <category term="rest" scheme="http://roller.apache.org/ns/tags/" />
        <category term="restygwt" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">Earlier this week, Hiram Chirino released &lt;a href=&quot;http://github.com/chirino/resty-gwt&quot;&gt;RestyGWT&lt;/a&gt;, a GWT generator for REST services and JSON encoded data transfer objects. You can read more about it in Hiram&apos;s post &lt;a href=&quot;http://hiramchirino.com/blog/2009/10/restygwt-a-better-gwt-rpc/&quot;&gt;RestyGWT, a Better GWT RPC??&lt;/a&gt;. First of all, I&apos;m impressed with RestyGWT because provides something I&apos;ve always wanted with GWT: the ability to call RESTful services and get a populated POJO in your callback, much like &lt;a href=&quot;http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/gwt/user/client/rpc/AsyncCallback.html&quot;&gt;AsyncCallback&lt;/a&gt; provides for RPC services. &lt;/p&gt;
&lt;p&gt;RestyGWT also allows you to easily create services using only interfaces and JAX-RS annotations. For example:
&lt;/p&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
import javax.ws.rs.POST;
...
public interface PizzaService extends RestService {
    @POST
    public void order(PizzaOrder request, MethodCallback&amp;lt;OrderConfirmation&amp;gt; callback);
}
&lt;/pre&gt;
&lt;p&gt;
After taking a brief look at RestyGWT, I thought it&apos;d be interesting to share how I develop and test GWT client services.
&lt;/p&gt;
&lt;p id=&quot;developing&quot;&gt;&lt;strong&gt;Developing GWT Client Services&lt;/strong&gt;&lt;br/&gt;
Writing services in a GWT application can be helpful when you&apos;re using MVP, especially since you can &lt;a href=&quot;http://googletesting.blogspot.com/2009/08/tott-testing-gwt-without-gwttest.html&quot;&gt;EasyMock them in a test&lt;/a&gt;. On my GWT projects, I&apos;ve often used &lt;a href=&quot;http://raibledesigns.com/rd/entry/json_parsing_with_javascript_overlay&quot;&gt;overlay types&lt;/a&gt; because they allow me to write less code and they make parsing JSON super simple. 
I&apos;ve &lt;a href=&quot;http://raibledesigns.com/rd/entry/building_gwt_applications_with_mvp&quot;&gt;had issues&lt;/a&gt; testing my presenters when using overlay types. The good news is I think I&apos;ve figured out a reasonable solution, but it does require using GWTTestCase. If RestyGWT supported overlay types, there&apos;s a good chance I&apos;d use it, especially since its  &lt;a href=&quot;http://github.com/chirino/resty-gwt/tree/master/src/it/resty-gwt-example/src/test/java/com/hiramchirino/restygwt/examples/client/&quot;&gt;integration tests&lt;/a&gt; seem to require GWTTestCase too.
&lt;/p&gt;
&lt;p&gt;Rather than using callbacks in my presenters, I try to only use them in my service implementations. That way, my presenters don&apos;t have to worry about overlay types and can be tested in a JUnit-only fashion. The callbacks in my services handle JSON parsing/object population and fire events with the populated objects. 
&lt;/p&gt;
&lt;p&gt;
GWT&apos;s &lt;a href=&quot;http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/gwt/http/client/RequestBuilder.html&quot;&gt;RequestBuilder&lt;/a&gt; is one option for communicating with RESTful services. The &lt;a href=&quot;http://code.google.com/p/google-web-toolkit-doc-1-5/wiki/DevGuideHttpRequests&quot;&gt;Development Guide for HTTP Requests&lt;/a&gt; explains how to use this class. To simplify REST requests and allow multiple callbacks, I&apos;m using a &lt;strong&gt;RestRequest&lt;/strong&gt; class, and a number of other utility classes that make up a small GWT REST framework (created by a former colleague). &lt;!--good friend of mine, Dan Mesh. Unfortunately, Dan doesn&apos;t have a blog to link to; you&apos;ll have to trust me that he&apos;s a smart guy and a lot of fun to work with.--&gt; RestRequest wraps RequestBuilder and provides a &lt;a href=&quot;http://martinfowler.com/bliki/FluentInterface.html&quot;&gt;Fluent API&lt;/a&gt; for executing HTTP requests. Another class, &lt;strong&gt;Deferred&lt;/strong&gt;, is a GWT implementation of &lt;a href=&quot;http://twistedmatrix.com/projects/core/documentation/howto/defer.html&quot;&gt;Twisted&apos;s Deferred&lt;/a&gt;. 
&lt;/p&gt;
&lt;p&gt;As part of my service implementation, I inject an EventBus (with &lt;a href=&quot;http://code.google.com/p/google-gin/&quot;&gt;GIN&lt;/a&gt;) into the constructor and then proceed to implement callbacks that fire Events to indicate loading, saving and deleting has succeeded. Here&apos;s an example service:
&lt;/p&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
public class ConversationServiceImpl implements ConversationService {
    private EventBus eventBus;

    @Inject
    public ConversationServiceImpl(EventBus eventBus) {
        this.eventBus = eventBus;
    }

    public void getConversation(String name) {
        Deferred&amp;lt;Representation&amp;gt; d =
                RestRequest.get(URLs.CONVERSATION + &quot;/&quot; + URL.encode(name)).build();

        d.addCallback(new Callback&amp;lt;Representation&amp;gt;() {
            public void onSuccess(Representation result) {
                Conversation conversation = convertResultToConversation(result);
                eventBus.fireEvent(new ResourceLoadedEvent&amp;lt;Conversation&amp;gt;(conversation));
            }
        });

        d.run();
    }

    public void saveConversation(Conversation conversation) {
        Deferred&amp;lt;Representation&amp;gt; d = RestRequest.post(URLs.CONVERSATION)
                .setRequestData(conversation.toJson()).build();
        
        d.addCallback(new Callback&amp;lt;Representation&amp;gt;() {
            public void onSuccess(Representation result) {
                Conversation conversation = convertResultToConversation(result);
                eventBus.fireEvent(new ResourceSavedEvent&amp;lt;Conversation&amp;gt;(conversation));
            }
        });

        d.run();
    }

    public void deleteConversation(Long id) {
        Deferred&amp;lt;Representation&amp;gt; d =
                RestRequest.post(URLs.CONVERSATION + &quot;/&quot; + id).build();

        d.addCallback(new Callback&amp;lt;Representation&amp;gt;() {
            public void onSuccess(Representation result) {
                eventBus.fireEvent(new ResourceDeletedEvent());
            }
        });

        d.run();
    }

    /**
     * Convenience method to populate object in one location
     *
     * @param result the result of a resource request.
     * @return the populated object.
     */
    private Conversation convertResultToConversation(Representation result) {
        JSOModel model = JSOModel.fromJson(result.getData());
        return new Conversation(model);
    }
}
&lt;/pre&gt;
&lt;p&gt;In the &lt;em&gt;saveConversation()&lt;/em&gt; method you&apos;ll notice the &lt;em&gt;conversation.toJson()&lt;/em&gt; method call. This method uses a JSON class that loops through an objects properties and constructs a JSON String.
&lt;/p&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
public JSON toJson() {
    return new JSON(getMap());
}
&lt;/pre&gt;
&lt;p id=&quot;testing&quot;&gt;&lt;strong&gt;Testing Services&lt;/strong&gt;&lt;br/&gt;
In my experience, the hardest part about using overlay types is writing your objects so they get populated correctly. I&apos;ve found that writing tests which read JSON from a file can be a great productivity boost. However, because of overlay types, you have to write a test that extends GWTTestCase. When using GWTTestCase, you can&apos;t simply read from the filesystem. The good news is there is a workaround where you can subclass GWTShellServlet and overwrite GWT&apos;s web.xml to have your own servlet that &lt;em&gt;can&lt;/em&gt; read from the filesystem. A detailed explanation of how to do this was written by Alex Moffat in &lt;a href=&quot;http://development.lombardi.com/?p=15&quot;&gt;Implementing a -noserver flag for GWTTestCase&lt;/a&gt;. 
&lt;/p&gt;
&lt;p&gt;Once this class is in place, I&apos;ve found you can easily write services using TDD and the server doesn&apos;t even have to exist. When constructing services, I&apos;ve found the following workflow to be the most productive:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create a file with the expected JSON in src/test/resources/&lt;em&gt;resource&lt;/em&gt;.json where &lt;em&gt;resource&lt;/em&gt; matches the last part of the URL for your service.&lt;/li&gt;
&lt;li&gt;Create a *ServiceGwtTest.java and write tests.&lt;/li&gt;
&lt;li&gt;Run tests to make sure they fail.&lt;/li&gt;
&lt;li&gt;Implement the service and run tests to ensure JSON is getting consumed/produced properly to/from model objects.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Below is the code for my JsonReaderServlet.java:&lt;/p&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
public class JsonReaderServlet extends GWTShellServlet {

    public void service(ServletRequest servletRequest, ServletResponse servletResponse)
            throws ServletException, IOException {

        HttpServletRequest req = (HttpServletRequest) servletRequest;
        HttpServletResponse resp = (HttpServletResponse) servletResponse;

        String uri = req.getRequestURI();
        if (req.getQueryString() != null) {
            uri += &quot;?&quot; + req.getQueryString();
        }

        if (uri.contains(&quot;/services&quot;)) {
            String method = req.getMethod();
            String output;

            if (method.equalsIgnoreCase(&quot;get&quot;)) {
                // use the part after the last slash as the filename
                String filename = uri.substring(uri.lastIndexOf(&quot;/&quot;) + 1, uri.length()) + &quot;.json&quot;;
                System.out.println(&quot;loading: &quot; + filename);
                String json = readFileAsString(&quot;/&quot; + filename);
                System.out.println(&quot;loaded json: &quot; + json);
                output = json;
            } else {
                // for posts, return the same body content
                output = getBody(req);
            }

            PrintWriter out = resp.getWriter();
            out.write(output);
            out.close();

            resp.setStatus(HttpServletResponse.SC_OK);
        } else {
            super.service(servletRequest, servletResponse);
        }
    }

    private String readFileAsString(String filePath) throws IOException {
        filePath = getClass().getResource(filePath).getFile();
        BufferedReader reader = new BufferedReader(new FileReader(filePath));
        return getStringFromReader(reader);
    }

    private String getBody(ServletRequest request) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
        return getStringFromReader(reader);
    }

    private String getStringFromReader(Reader reader) throws IOException {
        StringBuilder sb = new StringBuilder();
        char[] buf = new char[1024];
        int numRead;
        while ((numRead = reader.read(buf)) != -1) {
            sb.append(buf, 0, numRead);
        }
        reader.close();
        return sb.toString();
    }
}
&lt;/pre&gt;
&lt;p&gt;This servlet is mapped to &lt;code&gt;&amp;lt;url-pattern&amp;gt;/*&amp;lt;/url-pattern&amp;gt;&lt;/code&gt; in a web.xml file in src/test/resources/com/google/gwt/dev/etc/tomcat/webapps/ROOT/WEB-INF.&lt;/p&gt;
&lt;p&gt;My Service Test starts by getting an EventBus from GIN and registering itself to handle the fired events.&lt;/p&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
public class ConversationServiceGwtTest extends AbstractGwtTestCase
        implements ResourceLoadedEvent.Handler, ResourceSavedEvent.Handler, ResourceDeletedEvent.Handler {
    ConversationService service;
    ResourceLoadedEvent&amp;lt;Conversation&amp;gt; loadedEvent;
    ResourceSavedEvent&amp;lt;Conversation&amp;gt; savedEvent;
    ResourceDeletedEvent deletedEvent;

    @Override
    public void gwtSetUp() throws Exception {
        super.gwtSetUp();
        DesigntimeGinjector injector = GWT.create(MyGinjector.class);
        EventBus eventBus = injector.getEventBus();
        service = new ConversationServiceImpl(eventBus);
        eventBus.addHandler(ResourceLoadedEvent.ENGINE, this);
        eventBus.addHandler(ResourceSavedEvent.ENGINE, this);
        eventBus.addHandler(ResourceDeletedEvent.ENGINE, this);
    }

    @SuppressWarnings(&quot;unchecked&quot;)
    public void onLoad(ResourceLoadedEvent event) {
        this.loadedEvent = event;
    }

    @SuppressWarnings(&quot;unchecked&quot;)
    public void onSave(ResourceSavedEvent event) {
        this.savedEvent = event;
    }

    public void onDelete(ResourceDeletedEvent event) {
        this.deletedEvent = event;
    }
}
&lt;/pre&gt;
&lt;p&gt;After this groundwork has been done, a test can be written that loads up the JSON file and verifies the objects are populated correctly.
&lt;/p&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
public void testGetConversation() {

    service.getConversation(&quot;test-conversation&quot;);

    Timer t = new Timer() {
        public void run() {
            assertNotNull(&quot;ResourceLoadedEvent not received&quot;, loadedEvent);
            Conversation conversation = loadedEvent.getResource();
            assertEquals(&quot;Conversation name is incorrect&quot;,&quot;Test Conversation&quot;, conversation.getName());

            assertNotNull(&quot;Conversation has no channel&quot;, conversation.getChannel());
            assertEquals(&quot;Conversation has incorrect task size&quot;, 3, conversation.getTasks().size());

            convertToAndFromJson(conversation);
            finishTest();
        }
    };

    delayTestFinish(3000);
    t.schedule(100);
}

private void convertToAndFromJson(Conversation fromJsonModel) {
    Representation json = fromJsonModel.toJson();
    assertNotNull(&quot;Cannot convert empty JSON&quot;, json.getData());

    // change back into model
    JSOModel data = JSOModel.fromJson(json.getData());
    Conversation toJsonModel = new Conversation(data);
    verifyModelBuiltCorrectly(toJsonModel);
}

private void verifyModelBuiltCorrectly(Conversation model) {
    assertEquals(&quot;Conversation name is incorrect&quot;, &quot;Test Conversation&quot;, model.getString(&quot;name&quot;));
    assertEquals(&quot;Conversation has incorrect task size&quot;, 3, model.getTasks().size());
    assertEquals(&quot;Conversation channel is incorrect&quot;, &quot;Web&quot;, model.getChannel().getString(&quot;type&quot;));
}
&lt;/pre&gt;
&lt;p&gt;For more information on the usage of the Timer, &lt;em&gt;finishTest()&lt;/em&gt; and &lt;em&gt;delayTestFinish()&lt;/em&gt;, see &lt;a href=&quot;http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/junit/client/GWTTestCase.html#delayTestFinish%28int%29&quot;&gt;GWTTestCase&apos;s javadoc&lt;/a&gt;. 
&lt;/p&gt;
&lt;p&gt;
The tests for saving and deleting a resource look as follows:&lt;/p&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
public void testSaveConversation() {
    Conversation conversation = new Conversation().setName(&quot;Test&quot;).setId(&quot;1&quot;);

    List&amp;lt;Task&amp;gt; tasks = new ArrayList&amp;lt;Task&amp;gt;();
    for (int i = 1; i &amp;lt; 4; i++) {
        tasks.add(new Task().setName(&quot;Task &quot; + i));
    }
    conversation.setTasks(tasks);

    System.out.println(&quot;conversation.toJson(): &quot; + conversation.toJson());

    assertTrue(conversation.toJson().toString().contains(&quot;Task 1&quot;));

    service.saveConversation(conversation);

    Timer t = new Timer() {
        public void run() {
            assertNotNull(&quot;ResourceSavedEvent not received&quot;, savedEvent);
            finishTest();
        }
    };

    delayTestFinish(3000);
    t.schedule(100);
}
  
public void testDeleteConversation() {
    service.deleteConversation(1L);

    Timer t = new Timer() {
        public void run() {
            assertNotNull(&quot;ResourceDeletedEvent not received&quot;, deletedEvent);
            finishTest();
        }
    };

    delayTestFinish(3000);
    t.schedule(100);
}
&lt;/pre&gt;
&lt;p id=&quot;summary&quot;&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;br/&gt;This article has shown you how I develop and test GWT Client Services. If RestyGWT supported overlay types, there&apos;s a good chance I could change my service implementation to use it and I wouldn&apos;t have to change my test. &lt;a href=&quot;http://www.screaming-penguin.com/&quot;&gt;Robert Cooper&lt;/a&gt;, author of &lt;a href=&quot;http://www.manning.com/cooper/&quot;&gt;GWT in Practice&lt;/a&gt;, claims he &lt;a href=&quot;http://twitter.com/kebernet/status/4997144279&quot;&gt;has a framework that does this&lt;/a&gt;. Here&apos;s to hoping this article stimulates the GWT ecosystem and we get a GWT REST framework that&apos;s as easy to use as GWT RPC.
&lt;/p&gt;
&lt;p id=&quot;update&quot;&gt;&lt;strong&gt;Update:&lt;/strong&gt; Today I enhanced this code to use Generics-based classes (inspired by &lt;a href=&quot;http://www.ibm.com/developerworks/java/library/j-genericdao.html&quot;&gt;Don&apos;t repeat the DAO!&lt;/a&gt;) for the boiler-plate CRUD code in a service. In a nutshell, a service interface can now be written as:
&lt;/p&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
public interface FooService extends GenericService&amp;lt;Foo, String&amp;gt; {
 
}
&lt;/pre&gt;
&lt;p&gt;The implementation class is responsible for the URL and converting the JSON result to an object:&lt;/p&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
public class FooServiceImpl extends GenericServiceImpl&amp;lt;Foo, String&amp;gt; implements FooService {

    @Inject
    public FooServiceImpl(EventBus eventBus) {
        super(eventBus, &quot;/services/foo&quot;);
    }

    @Override
    protected Foo convertResultToModel(Representation result) {
        return new Foo(JSOModel.fromJson(result.getData()));
    }
}
&lt;/pre&gt;
&lt;p&gt;I&apos;m sure this can be further enhanced to get rid of the need to create classes altogether, possibly leveraging &lt;a href=&quot;http://code.google.com/p/google-gin/&quot;&gt;GIN&lt;/a&gt; or some sort of factory. The parent classes referenced in this code can be viewed at the following URLs:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://gist.github.com/216495&quot;&gt;GenericService.java&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://gist.github.com/216496&quot;&gt;GenericServiceImpl.java&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There&apos;s also a &lt;a href=&quot;http://gist.github.com/216497&quot;&gt;GenericServiceGwtTest.java&lt;/a&gt; that proves it all works as expected.</content>
    </entry>
    <entry>
        <id>https://raibledesigns.com/rd/entry/my_experience_with_java_rest</id>
        <title type="html">My Experience with Java REST Frameworks (specifically Jersey and CXF)</title>
        <author><name>Matt Raible</name></author>
        <link rel="alternate" type="text/html" href="https://raibledesigns.com/rd/entry/my_experience_with_java_rest"/>
        <published>2009-08-27T14:20:51-06:00</published>
        <updated>2012-11-11T02:00:40-07:00</updated> 
        <category term="/Java" label="Java" />
        <category term="jersey" scheme="http://roller.apache.org/ns/tags/" />
        <category term="cxf" scheme="http://roller.apache.org/ns/tags/" />
        <category term="json" scheme="http://roller.apache.org/ns/tags/" />
        <category term="gwt" scheme="http://roller.apache.org/ns/tags/" />
        <category term="soap" scheme="http://roller.apache.org/ns/tags/" />
        <category term="rpc" scheme="http://roller.apache.org/ns/tags/" />
        <category term="rest" scheme="http://roller.apache.org/ns/tags/" />
        <category term="webservices" scheme="http://roller.apache.org/ns/tags/" />
        <category term="enunciate" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">Recently I was tasked with developing a server-side REST strategy for a client. When I started working with them, they were using GWT RPC for exposing services. They wanted to move to RESTful services to allow for a more open platform, that multiple types of clients could talk to. There were interested in supporting SOAP and GWT RPC as well, but it wasn&apos;t required. They are using Spring, a &lt;a href=&quot;http://blog.springsource.com/2006/08/28/creating-a-spring-20-namespace-use-springs-abstractbeandefintionparser-hierarchy/&quot;&gt;custom namespace&lt;/a&gt; (for easily creating remote services) and an HTML documentation generator to expose their API in human readable form.
&lt;/p&gt;
&lt;p&gt;When I first starting developing, I chose to try &lt;a href=&quot;http://enunciate.codehaus.org/&quot;&gt;Enunciate&lt;/a&gt;. From Enunciate&apos;s homepage:&lt;/p&gt;
&lt;p class=&quot;quote&quot;&gt;
Enunciate is an engine for creating, maintaining, and deploying your rich Web service API on the Java platform.
If that sounds complicated, it&apos;s not. All you have to do is define your service interfaces in Java source code. ... 
Then invoke Enunciate.
&lt;/p&gt;
&lt;p&gt;Sounds pretty sweet, eh? At first glance, the things I liked about Enunciate were:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The ability to generate multiple endpoints (and clients).&lt;/li&gt;
&lt;li&gt;Generates nice-looking documentation.&lt;/li&gt;
&lt;li&gt;Allows selecting different frameworks (for example, &lt;a href=&quot;http://docs.codehaus.org/display/ENUNCIATE/Using+CXF+or+XFire&quot;&gt;CXF instead of JAX-WS RI&lt;/a&gt;).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Initially, the hardest part of using Enunciate was integrating it into my project. This was somewhat related to having a &lt;a href=&quot;http://docs.codehaus.org/display/ENUNCIATE/Multi-Module+Projects&quot;&gt;multi-module project&lt;/a&gt;, but moreso related to getting the settings right in my &lt;em&gt;enunciate.xml&lt;/em&gt; file. After getting everything working, I encountered &lt;a href=&quot;http://markmail.org/thread/g3wj2gyvtqq5v3f4&quot;&gt;a few Spring wiring issues&lt;/a&gt; with the GWT Endpoints and with Jersey&apos;s Spring support. 
&lt;/p&gt;
&lt;p&gt;
The good news is I believe most of these issues were related to my project and how it proxies Spring beans that Jersey couldn&apos;t find. Jersey&apos;s &lt;a href=&quot;http://blogs.sun.com/enterprisetechtips/entry/jersey_and_spring&quot;&gt;Spring support&lt;/a&gt; only supports annotations at this time, so I was unable to tell it the proxied bean names via XML (or even its own annotations). I&apos;m sure this problem is solvable, but after struggling with it for a day or two, I decided to give up on Enunciate. I had to get something working, and fast.
&lt;/p&gt;
&lt;p&gt;At this point, I was back to the drawing board. I knew there were plenty of good Java REST frameworks available, but Spring and CXF (for SOAP) were already available dependencies in my project, so I chose that route. I was able to get something up and running fairly quickly with &lt;a href=&quot;http://raulraja.com/2009/06/25/spring-exposing-a-bean-as-rest-xml-json-and-soap-webservice/&quot;&gt;this tutorial&lt;/a&gt; and CXF&apos;s &lt;a href=&quot;http://cwiki.apache.org/CXF20DOC/jax-rs.html&quot;&gt;JAX-RS documentation&lt;/a&gt;. I ran into an &lt;a href=&quot;http://twitter.com/mraible/statuses/3407586205&quot;&gt;Invalid JSON Namespace issue&lt;/a&gt;, but was able to solve it by &lt;a href=&quot;https://issues.apache.org/jira/browse/CXF-1671&quot;&gt;adding a custom namespace&lt;/a&gt;. 
&lt;/p&gt;
&lt;p&gt;It&apos;s not all rosy though, there are still a couple CXF issues I haven&apos;t solved:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I&apos;d like to remove the namespace prefixes on returned JSON. I&apos;ve never seen JSON with &quot;prefix.&quot; notation before and it doesn&apos;t seem right.&lt;/li&gt;
&lt;li&gt;I&apos;m &lt;a href=&quot;http://www.nabble.com/No-message-body-writer-found-for-response-class-%3A-String---tt25070046.html#a25070046&quot;&gt;unable to return String[] from services&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While CXF does take a bit of XML for each service, it&apos;s kinda slick in that it only requires you to annotate your service interfaces. It also generates documentation for your services (WSDL and WADL), but it&apos;s not as pretty as Enunciate&apos;s. To solve this, I &lt;a href=&quot;http://docs.codehaus.org/display/ENUNCIATE/Documentation+Only&quot;&gt;added Enunciate for documentation only&lt;/a&gt;. To make Enunciate work, I did have to add some annotations to my service implementation classes and &lt;a href=&quot;http://markmail.org/thread/r6i4rv45lkaknzv7&quot;&gt;parse the generated HTML&lt;/a&gt; to fix some links to CXF&apos;s services, but ultimately it works pretty well. 
&lt;/p&gt;
&lt;p&gt;In the end, I recommended my client not use Enunciate for generating endpoints. This was primarily related to their unique Spring configuration, but also because I was able to easily use the same classes for REST, SOAP and GWT Endpoints. However, I will continue to keep my eye on Enunciate. It could be very useful for the upcoming &lt;a href=&quot;http://jira.codehaus.org/browse/ENUNCIATE-290&quot;&gt;appfuse-ws&lt;/a&gt; archetype. I&apos;m also eager to see &lt;a href=&quot;http://jira.codehaus.org/browse/ENUNCIATE-319&quot;&gt;better GWT support&lt;/a&gt; and the ability to &lt;a href=&quot;http://jira.codehaus.org/browse/ENUNCIATE-290&quot;&gt;generate Overlay types&lt;/a&gt; in future releases. </content>
    </entry>
    <entry>
        <id>https://raibledesigns.com/rd/entry/enhancing_evite_com_with_gwt</id>
        <title type="html">Enhancing Evite.com with GWT and Grails</title>
        <author><name>Matt Raible</name></author>
        <link rel="alternate" type="text/html" href="https://raibledesigns.com/rd/entry/enhancing_evite_com_with_gwt"/>
        <published>2009-06-15T07:41:37-06:00</published>
        <updated>2014-05-08T19:47:19-06:00</updated> 
        <category term="/Java" label="Java" />
        <category term="sofea" scheme="http://roller.apache.org/ns/tags/" />
        <category term="grails" scheme="http://roller.apache.org/ns/tags/" />
        <category term="memcached" scheme="http://roller.apache.org/ns/tags/" />
        <category term="gxt" scheme="http://roller.apache.org/ns/tags/" />
        <category term="java" scheme="http://roller.apache.org/ns/tags/" />
        <category term="rest" scheme="http://roller.apache.org/ns/tags/" />
        <category term="gwt" scheme="http://roller.apache.org/ns/tags/" />
        <category term="evite" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">&lt;a href=&quot;http://www.evite.com&quot;&gt;&lt;img src=&quot;//static.raibledesigns.com/repository/images/evite-logo.png&quot; width=&quot;144&quot; height=&quot;93&quot; alt=&quot;Evite.com&quot; class=&quot;picture&quot; style=&quot;border: 1px solid silver&quot; /&gt;&lt;/a&gt;
On my &lt;a href=&quot;http://www.linkedin.com/in/mraible&quot;&gt;LinkedIn Profile&lt;/a&gt;, it says my current gig is a SOFEA consultant at a stealth-mode startup. &lt;/p&gt;
&lt;p class=&quot;quote&quot;&gt;
SOFEA Consultant, Stealth Mode Startup, Los Angeles, CA. December 2008 -- Present.
&lt;/p&gt;
&lt;p&gt;
OK, I lied. It&apos;s not a startup, it&apos;s a well-known company that helps you plan parties.
For the last 5+ months, my &lt;a href=&quot;http://raibledesigns.com/rd/entry/what_s_next&quot;&gt;UI team from LinkedIn&lt;/a&gt; has been working with &lt;a href=&quot;http://www.evite.com&quot;&gt;Evite.com&lt;/a&gt; to enhance portions of their site with a &lt;a href=&quot;http://raibledesigns.com/rd/entry/re_life_above_the_service&quot;&gt;SOFEA architecture&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;In January, we started &lt;a href=&quot;http://raibledesigns.com/rd/entry/choosing_an_ajax_framework&quot;&gt;evaluating Ajax Frameworks&lt;/a&gt; and came to the conclusion that &lt;a href=&quot;http://raibledesigns.com/rd/entry/ajax_framework_analysis_results&quot;&gt;GWT was right for us&lt;/a&gt;. After we chose the UI framework, other team members chose &lt;a href=&quot;http://grails.org&quot;&gt;Grails&lt;/a&gt; and &lt;a href=&quot;http://www.danga.com/memcached/&quot;&gt;memcached&lt;/a&gt; to develop scalable RESTful services. The architecture we implemented involves using GWT&apos;s &lt;a href=&quot;http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/gwt/http/client/RequestBuilder.html&quot;&gt;RequestBuilder&lt;/a&gt; to talk to Grails&apos; services, which cache almost all their JSON output in memcached.
&lt;/p&gt;
&lt;p&gt;To see an example of a feature we developed with GWT, see Evite&apos;s &lt;a href=&quot;http://www.evite.com/party/invitations&quot;&gt;Design Gallery&lt;/a&gt;. I personally worked on this feature and very much enjoyed becoming a GWT aficionado in the process. GWT&apos;s zero-turnaround feature made doing pure client-side work a lot of fun. It&apos;s definitely something I&apos;d like to continuing doing at my next gig. &lt;/p&gt;
&lt;p&gt;Everyone from Evite is very happy with what we&apos;ve been able to do with GWT and Grails. We have a stateless architecture and are quickly able to develop both client-side and server-side features. We&apos;ve learned to scale the client by using out-of-the-box GWT components. We&apos;ve scaled Grails by caching as much as possible. We serve up Ads and Analytics using the same JavaScript mechanisms that traditional server-side frameworks use. 
&lt;/p&gt;
&lt;p&gt;At the end of this month, my gig with Evite comes to an end. I&apos;ll be spending a few weeks at my family&apos;s cabin in Montana and then it&apos;s on to the next big thing. What&apos;s the next big thing? I&apos;m not sure yet, hence the reason for writing this. If you&apos;re looking to develop a GWT application, introduce a SOFEA architecture at your company, or simply adopt some open source frameworks, I&apos;d love to help out. &lt;a href=&quot;http://raibledesigns.com/contact.jsp&quot;&gt;Drop me a line&lt;/a&gt; and let&apos;s start a conversation. </content>
    </entry>
    <entry>
        <id>https://raibledesigns.com/rd/entry/gwt_and_appfuse</id>
        <title type="html">GWT and AppFuse</title>
        <author><name>Matt Raible</name></author>
        <link rel="alternate" type="text/html" href="https://raibledesigns.com/rd/entry/gwt_and_appfuse"/>
        <published>2009-03-04T22:50:26-07:00</published>
        <updated>2012-11-08T14:32:54-07:00</updated> 
        <category term="/Java" label="Java" />
        <category term="rest" scheme="http://roller.apache.org/ns/tags/" />
        <category term="appfuse" scheme="http://roller.apache.org/ns/tags/" />
        <category term="gwt" scheme="http://roller.apache.org/ns/tags/" />
        <category term="java" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">Someone recently sent me the following e-mail asking about GWT integration in &lt;a href=&quot;http://appfuse.org&quot;&gt;AppFuse&lt;/a&gt;.&lt;/p&gt;
&lt;p class=&quot;quote&quot;&gt;
I see from your blog that you&apos;re spending some time with GWT at the moment. What&apos;s your plan, are you going to integrate GWT as another UI Option for AppFuse?
&lt;br/&gt;&lt;br/&gt;
The reason I&apos;m asking is that I actually checked out all of the AppFuse code from the svn repository yesterday, with the intention of starting off adding some GWT stuff in there. My intention was to start by getting a basic Maven archetype together for GWT as an AppFuse UI.
&lt;br/&gt;&lt;br/&gt;
However, if you&apos;re planning on doing this yourself in the near future, then there&apos;s no point in me starting doing it, I&apos;d have to learn how to write archetype&apos;s for a start (not that it looks too difficult) but you&apos;d obviously do it much quicker.
&lt;/p&gt;
&lt;p&gt;Being a good open-source developer, I moved the discussion to the developer mailing list and &lt;a href=&quot;http://www.nabble.com/Re%3A-GWT---Appfuse-to22184159s2369.html&quot;&gt;replied there&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&quot;quote&quot; style=&quot;margin-left: 0; margin-bottom: 10px&quot;&gt;
&lt;p&gt;It&apos;s likely I&apos;ll create a version of AppFuse Light with GWT, but I 
doubt I&apos;ll do it in the near future. I hope to release AppFuse 2.1 
first (which will include &quot;light&quot; archetypes). I wouldn&apos;t get your 
hopes up in waiting for me to do the work. However, I&apos;d be happy to 
assist you in doing it. AppFuse Light is now modular and uses the 
AppFuse backend. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href=&quot;http://raibledesigns.com/rd/entry/appfuse_light_converted_to_maven&quot;&gt;http://raibledesigns.com/rd/entry/appfuse_light_converted_to_maven&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Here&apos;s how I believe GWT should be integrated: 
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create an appfuse-ws archetype that serves up RESTful services 
(&lt;a href=&quot;http://issues.appfuse.org/browse/APF-897&quot;&gt;http://issues.appfuse.org/browse/APF-897&lt;/a&gt;). &lt;/li&gt;
&lt;li&gt; Create an appfuse-gwt archetype that consumes those services. This 
archetype would contain a proxy servlet that allows #1 to be on a 
separate host/port. &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
In addition to #1, I hope to convert the Struts 2 and Spring MVC 
archetypes to use those frameworks&apos; REST support. 
&lt;/p&gt;
&lt;p style=&quot;margin-bottom: 0&quot;&gt;
For #2, we could use SmartGWT or GXT. SmartGWT might be better since 
Sanjiv is a committer on this project. &lt;img src=&quot;https://raibledesigns.com/images/smileys/wink.gif&quot; class=&quot;smiley&quot; alt=&quot;;-)&quot; title=&quot;;-)&quot; /&gt;&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;I know I&apos;ve been slacking on AppFuse development, but it &lt;em&gt;is&lt;/em&gt; ski season and running to work seems to drain my late-night coding ambitions. With that being said, I&apos;m committed to getting AppFuse 2.1 released by JavaOne (hopefully sooner). I figure it&apos;s a good week&apos;s worth of work and I&apos;ll probably have to do it late at night to find the time. That&apos;s OK though, I usually really start to enjoy it once I get into it.</content>
    </entry>
    <entry>
        <id>https://raibledesigns.com/rd/entry/colorado_software_summit_2008_wrapup</id>
        <title type="html">Colorado Software Summit 2008 Wrapup</title>
        <author><name>Matt Raible</name></author>
        <link rel="alternate" type="text/html" href="https://raibledesigns.com/rd/entry/colorado_software_summit_2008_wrapup"/>
        <published>2008-10-28T23:03:23-06:00</published>
        <updated>2014-05-08T19:47:19-06:00</updated> 
        <category term="/Java" label="Java" />
        <category term="ajax" scheme="http://roller.apache.org/ns/tags/" />
        <category term="maven" scheme="http://roller.apache.org/ns/tags/" />
        <category term="softwaresummit" scheme="http://roller.apache.org/ns/tags/" />
        <category term="spring" scheme="http://roller.apache.org/ns/tags/" />
        <category term="rest" scheme="http://roller.apache.org/ns/tags/" />
        <category term="java" scheme="http://roller.apache.org/ns/tags/" />
        <category term="appcelerator" scheme="http://roller.apache.org/ns/tags/" />
        <category term="camel" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">&lt;a title=&quot;Snowman in Keystone&quot; href=&quot;http://blog.linkedin.com/blog/2008/10/colorado-softwa.html&quot;&gt;&lt;img alt=&quot;Snowman in Keystone&quot; src=&quot;//farm4.static.flickr.com/3057/2980923121_f44dd0dc42_t.jpg&quot; class=&quot;picture&quot; height=&quot;75&quot; width=&quot;100&quot;&gt;&lt;/a&gt;

Last week, I attended the Colorado Software Summit in Keystone and had a great time. Not only was the weather beautiful and the food delicious, the sessions I attended were awesome. If you ever get a chance to go to this conference, I highly recommend it. It&apos;s like being on vacation and learning with a bunch of old friends.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.linkedin.com/in/yan&quot;&gt;Yan Pujante&lt;/a&gt; also attended this conference and documents his experience, photography and presentations in &lt;a href=&quot;http://blog.linkedin.com/blog/2008/10/colorado-softwa.html&quot;&gt;Colorado Software Summit 2008&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;Below is a list of my entries for all the sessions I attended.&lt;/p&gt;
&lt;ul class=&quot;glassList&quot;&gt;
&lt;li&gt;&lt;a href=&quot;http://raibledesigns.com/rd/entry/building_linkedin_s_next_generation&quot;&gt;Building LinkedIn&apos;s Next Generation Architecture with OSGi by Yan Pujante&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://raibledesigns.com/rd/entry/comprehensive_project_intelligence_with_jason&quot;&gt;Comprehensive Project Intelligence with Jason van Zyl&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://raibledesigns.com/rd/entry/what_s_coming_in_spring&quot;&gt;What&apos;s Coming in Spring 3.0&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://raibledesigns.com/rd/entry/applying_flash_to_java_flex&quot;&gt;Applying Flash to Java: Flex and OpenLaszlo with Dustin Marx&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://raibledesigns.com/rd/entry/building_rich_applications_with_appcelerator&quot;&gt;Building Rich Applications with Appcelerator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://raibledesigns.com/rd/entry/taking_apache_camel_for_a&quot;&gt;Taking Apache Camel for a Ride with Bruce Snyder&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://raibledesigns.com/rd/entry/core_animation_with_bill_dudney&quot;&gt;Core Animation with Bill Dudney&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://raibledesigns.com/rd/entry/restful_web_applications_with_subbu&quot;&gt;RESTful Web Applications with Subbu Allamaraju&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;p&gt;For next year, I think the conference should shorten its sessions (from 90 to 60 minutes), invite more speakers and cut the price in half (to $999 per person). How do you think the Software Summit could be improved?</content>
    </entry>
    <entry>
        <id>https://raibledesigns.com/rd/entry/restful_web_applications_with_subbu</id>
        <title type="html">RESTful Web Applications with Subbu Allamaraju</title>
        <author><name>Matt Raible</name></author>
        <link rel="alternate" type="text/html" href="https://raibledesigns.com/rd/entry/restful_web_applications_with_subbu"/>
        <published>2008-10-24T09:52:02-06:00</published>
        <updated>2009-06-04T20:04:17-06:00</updated> 
        <category term="/Java" label="Java" />
        <category term="jsf" scheme="http://roller.apache.org/ns/tags/" />
        <category term="webframeworks" scheme="http://roller.apache.org/ns/tags/" />
        <category term="sofea" scheme="http://roller.apache.org/ns/tags/" />
        <category term="appcelerator" scheme="http://roller.apache.org/ns/tags/" />
        <category term="softwaresummit" scheme="http://roller.apache.org/ns/tags/" />
        <category term="gwt" scheme="http://roller.apache.org/ns/tags/" />
        <category term="java" scheme="http://roller.apache.org/ns/tags/" />
        <category term="rest" scheme="http://roller.apache.org/ns/tags/" />
        <category term="servlets" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">Subbu works at Yahoo! developing standards, patterns and practices for HTTP web languages. In the past, he was a web service and Java developer. He was also a standards contributor at BEA and an author of books on Java EE. His current passion is HTTP and REST. Subbu confesses that he&apos;s not a web developer, has no interest in the internals of programming models used for web frameworks and he&apos;s only interested in the visible aspects of the architecture.
&lt;/p&gt;
&lt;p&gt;&quot;The Web is Mostly Restful&quot;&lt;/p&gt;
&lt;p&gt;Being RESTful in an abstract sense means:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Resources are named by URIs&lt;/li&gt;
&lt;li&gt;Resources have representations (Atom, HTML, JSON, XML)&lt;/li&gt;
&lt;li&gt;Resources contain contextual links to allow navigation of state&lt;/li&gt;
&lt;li&gt;There&apos;s a Uniform Interface&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
In the web today, some resources and URIs are personalized, but most are not. Some depend on sessions, but most do not. The consequence of a personalized UI with a non-unique URI is you cannot rely on browser caching. &lt;/p&gt;
&lt;p&gt;The web is full of different representations (HTML, XML, JS, PDF, CSS, Flash). The problem with HTML is you can&apos;t tell links that you want a particular representation based of a link. The links are hard-coded to be a particular content-type. However, some media types on responses are ignored. This is often a problem with browsers and whether the user has plugins installed.&lt;/p&gt;
&lt;p&gt;The Uniform Interface for the web is HTML and primarily links and forms (GET and POST). There&apos;s still some misconceptions (e.g. POST is secure). However, it&apos;s not about security, it&apos;s about idempotency and safety. You need to make sure you only use POST when you&apos;re changing data. POSTs are not repeatable. GET URIs are not always refreshable, which is quite unfortunate. Users shouldn&apos;t have to fight the back button.&lt;/p&gt;
&lt;p&gt;Caching is a fundamental aspect of the web. Even in a personalized site, most of the content can be cached. The web is read-only for the most part. However, many enterprise web applications don&apos;t take advantage of caching. This is fine when there&apos;s not that many users, but it&apos;s bad when you want to scale to thousands of users. There&apos;s several frameworks that use cache-busting and prefer backend caching over HTTP caching. These frameworks are not using the web like they should.&lt;/p&gt;
&lt;p&gt;Backend caching (e.g. Memcached) uses a non-uniform interface and you need to explicitly program to it. Frontend/HTTP caching has a uniform interface that&apos;s pluggable. Backend caching is generally more expensive to develop and deploy. There are cases where data should be cached on the backend, but you shouldn&apos;t focus all on backend caching w/o doing some frontend caching.
&lt;/p&gt;
&lt;p&gt;With Ajax, you get more opportunities to be RESTful. XMLHttpRequest is another HTTP client that can be programmed to. It has full support for the uniform interface, which allows content negotiation, optimistic concurrency and caching. Cross-domain hacks can be done with &amp;lt;script&gt; and &amp;lt;iframe&gt; to tunnel requests over GET. The W3C has been working for the last two years on how to do cross-domain Ajax w/o using hacks. The problem with current cross-domain implementations is they often use GET for everything, which isn&apos;t very RESTful. Subbu recommends using a proxy on the same domain if you do need to talk to other domains. This will allow your Ajax code to remain RESTful.
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Web Frameworks&lt;/strong&gt;&lt;br/&gt;
Web development is hard because of all the moving pieces that exist. Because of this, many web frameworks have been created to solve the various problems. In 1997, there were servlets. They provided basic plumbing and closely reflected HTTP/1.1. Servlets provided a poor programming model, but it allowed a lot of frameworks to be built on top of it. We don&apos;t use servlets to write applications, only to write application frameworks. The second era came about in 2001 when Action-oriented frameworks became popular. In 2004, JSF and friends came to play. JSF is a component-based framework with known limitations (complex, slow, uses POST for almost everything, Ajax is difficult). These limitations have resulted in a number of third-party patches being developed to solve these issues.&lt;/p&gt;
&lt;p&gt;JSF was designed to use the request to create a component tree that maintains state. Unfortunately, the state is not something the developer has control over. It&apos;s not the state of the application, it&apos;s the state of the components. The client&apos;s knowledge of the state is mentioned with a cookie and the server keeps the state in the session. The problem with JSF is you don&apos;t have a choice of state in your application - you can&apos;t write stateless applications like you can with servlets.
&lt;/p&gt;
&lt;p&gt;JSF uses overloaded URIs for its resources. When you have one URI with multiple representations, there&apos;s no way to tell how a representation was chosen. JSF&apos;s compromise is to allow client-side state saving. However, they do this by putting hidden field in the form and requiring POST for navigation. 
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;JSF vs. REST&lt;/strong&gt;&lt;br/&gt;
Basically, these two are at opposite extremes. JSF is focused heavily on a UI component model. The people that developed it misinterpreted how the web works and made some fundamental questionable choices. You can patch it, but you can not fix it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Web 2.0 Frameworks&lt;/strong&gt;&lt;br/&gt;
GWT is a cross-compilation based framework. You write Java to generate JavaScript (b/c everyone hates writing JavaScript). It mashes client and server code into a single source. These layers communicate using GWT-RPC. Typical RPC concerns do not apply since code generation handles coupling and the client is downloaded from the same application. GWT-PRC does POSTs to the server and uses HTTP like a transport layer. To be fair, GWT does allow you to use a RequestBuilder to use the web like it should be used.
This class allows more control over HTTP requests, it supports GET and POST and it allows so-called RESTful layers (GWT-REST and GET-Restlet). GWT is focused heavily on ease-of-use, which is good. It&apos;s modeled after RPC and breaks the uniform interface and focuses on backend caching. Unlike JSF, GWT is fixable, but the community tends to use RPC instead of RequestBuilder.
&lt;/p&gt;
&lt;p&gt;SOFEA has a central promise of SOA. Business logic is a reusable service that changes less often. The presentation application calls those services and changes more often. The nice thing about this type of architecture is it allows a separation of concerns and loose coupling. However, it doesn&apos;t embrace REST like it should. Appcelerator is an implementation of SOFEA that has a Ruby on Rails-like usability. However, it uses a SOAP/HTTP style with messaging and POSTs to a single URI. Appcelerator is interesting, but it introduces a different style of coupling. It breaks URI opacity and client deals with POX instead of links. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br/&gt;
Don&apos;t fight the architecture of the web. Innovate and enhance instead of breaking. If nothing else, break judiciously. As developers, we should demand more from our frameworks and make sure they use the web and HTTP like it should be used.</content>
    </entry>
    <entry>
        <id>https://raibledesigns.com/rd/entry/what_s_coming_in_spring</id>
        <title type="html">What&apos;s Coming in Spring 3.0</title>
        <author><name>Matt Raible</name></author>
        <link rel="alternate" type="text/html" href="https://raibledesigns.com/rd/entry/what_s_coming_in_spring"/>
        <published>2008-10-22T11:51:12-06:00</published>
        <updated>2014-05-08T19:47:19-06:00</updated> 
        <category term="/Java" label="Java" />
        <category term="spring" scheme="http://roller.apache.org/ns/tags/" />
        <category term="springframework" scheme="http://roller.apache.org/ns/tags/" />
        <category term="rest" scheme="http://roller.apache.org/ns/tags/" />
        <category term="presentation" scheme="http://roller.apache.org/ns/tags/" />
        <category term="annotations" scheme="http://roller.apache.org/ns/tags/" />
        <category term="webframeworks" scheme="http://roller.apache.org/ns/tags/" />
        <category term="softwaresummit" scheme="http://roller.apache.org/ns/tags/" />
        <category term="springexpressionlanguage" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">This morning, I delivered my &lt;a href=&quot;http://softwaresummit.com/2008/speakers/raible.htm&quot;&gt;What&apos;s Coming in Spring 3.0&lt;/a&gt; talk for the 2nd time at Colorado Software Summit. Since there is no Spring 3.0 source code to speak of, I was unable to do the &quot;Choose Your Own Adventure&quot; demo at the end. &lt;img src=&quot;https://raibledesigns.com/images/smileys/sad.gif&quot; class=&quot;smiley&quot; alt=&quot;:(&quot; title=&quot;:(&quot; /&gt;
&lt;/p&gt;
&lt;p&gt;
The good news is I was able to easily upgrade the &lt;a href=&quot;http://spring-kickstart.googlecode.com&quot;&gt;Spring Kickstart&lt;/a&gt; application from Spring 2.0 to Spring 2.5.5 (using annotations). When 3.0 is released, I hope to update this project to use 3.0 as well as show what I needed to change. If I get ambitious, I might even change the UI to use Flex or Ext JS to show a RESTful client. Below is my presentation - hope you enjoy.
&lt;/p&gt;
&lt;div style=&quot;text-align:center&quot;&gt;&lt;object style=&quot;margin:0px&quot; width=&quot;425&quot; height=&quot;355&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://static.slideshare.net/swf/ssplayer2.swf?doc=whats-coming-in-spring-30-18636&amp;stripped_title=whats-coming-in-spring-30&quot; /&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot;/&gt;&lt;param name=&quot;allowScriptAccess&quot; value=&quot;always&quot;/&gt;&lt;embed src=&quot;//static.slideshare.net/swf/ssplayer2.swf?doc=whats-coming-in-spring-30-18636&amp;stripped_title=whats-coming-in-spring-30&quot; type=&quot;application/x-shockwave-flash&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; width=&quot;425&quot; height=&quot;355&quot;&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div style=&quot;font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;&quot;&gt;&lt;a style=&quot;text-decoration:underline;&quot; href=&quot;http://www.slideshare.net/mraible/whats-coming-in-spring-30?type=powerpoint&quot; title=&quot;View What&amp;#39;s Coming in Spring 3.0 on SlideShare&quot;&gt;View on Slideshare&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;</content>
    </entry>
    <entry>
        <id>https://raibledesigns.com/rd/entry/presenting_web_frameworks_of_the</id>
        <title type="html">Presenting Web Frameworks of the Future Tomorrow in Denver</title>
        <author><name>Matt Raible</name></author>
        <link rel="alternate" type="text/html" href="https://raibledesigns.com/rd/entry/presenting_web_frameworks_of_the"/>
        <published>2008-07-30T21:56:17-06:00</published>
        <updated>2008-07-31T04:01:12-06:00</updated> 
        <category term="/Open Source" label="Open Source" />
        <category term="opensource" scheme="http://roller.apache.org/ns/tags/" />
        <category term="rest" scheme="http://roller.apache.org/ns/tags/" />
        <category term="webframeworks" scheme="http://roller.apache.org/ns/tags/" />
        <category term="grails" scheme="http://roller.apache.org/ns/tags/" />
        <category term="rails" scheme="http://roller.apache.org/ns/tags/" />
        <category term="oscon" scheme="http://roller.apache.org/ns/tags/" />
        <category term="flex" scheme="http://roller.apache.org/ns/tags/" />
        <category term="gwt" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">Tomorrow (Thursday) night, I&apos;ll be doing an encore presentation of my &lt;a href=&quot;http://raibledesigns.com/rd/entry/oscon_2008_web_frameworks_of&quot;&gt;Web Frameworks of the Future&lt;/a&gt; at &lt;a href=&quot;http://groups.google.com/group/derailed&quot;&gt;DeRailed&lt;/a&gt;. If you&apos;re in Denver and would like to hear me ramble while drinking a beer, join us at &lt;a href=&quot;http://www.forestroom5.com/&quot;&gt;Forestroom 5&lt;/a&gt; at 6:30.&lt;/p&gt;
&lt;p&gt;After the &lt;a href=&quot;http://raibledesigns.com/rd/entry/the_oscon_aftermath&quot;&gt;last few days&lt;/a&gt;, I&apos;m happy to report I should be in good enough condition to pull this off. If you&apos;re curious to learn more about my experience at OSCON and this presentation, please see &lt;a href=&quot;http://blog.linkedin.com/blog/2008/07/oscon-2008-and.html&quot;&gt;my writeup on the LinkedIn Blog&lt;/a&gt;.</content>
    </entry>
    <entry>
        <id>https://raibledesigns.com/rd/entry/oscon_2008_web_frameworks_of</id>
        <title type="html">[OSCON 2008] Web Frameworks of the Future: Flex, GWT, Grails and Rails</title>
        <author><name>Matt Raible</name></author>
        <link rel="alternate" type="text/html" href="https://raibledesigns.com/rd/entry/oscon_2008_web_frameworks_of"/>
        <published>2008-07-23T16:25:23-06:00</published>
        <updated>2014-05-08T19:47:19-06:00</updated> 
        <category term="/Open Source" label="Open Source" />
        <category term="rails" scheme="http://roller.apache.org/ns/tags/" />
        <category term="oscon" scheme="http://roller.apache.org/ns/tags/" />
        <category term="rest" scheme="http://roller.apache.org/ns/tags/" />
        <category term="gwt" scheme="http://roller.apache.org/ns/tags/" />
        <category term="oscon08" scheme="http://roller.apache.org/ns/tags/" />
        <category term="flex" scheme="http://roller.apache.org/ns/tags/" />
        <category term="grails" scheme="http://roller.apache.org/ns/tags/" />
        <category term="opensource" scheme="http://roller.apache.org/ns/tags/" />
        <category term="webframeworks" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">Below is the presentation I&apos;m &lt;a href=&quot;http://en.oreilly.com/oscon2008/public/schedule/speaker/6444&quot;&gt;delivering at OSCON&lt;/a&gt; today. Unfortunately, I had to remove slides on GWT and Flex to fit w/in the 45 minute time limit. I hope to expand this presentation in the future, as well as continue to develop the side project I&apos;m working on using these technologies.
&lt;/p&gt;
&lt;p style=&quot;text-align: center&quot;&gt;
&lt;object style=&quot;margin:0px&quot; width=&quot;425&quot; height=&quot;355&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://static.slideshare.net/swf/ssplayer2.swf?doc=webframeworksofthefutureflexgwtrailsandgrails-1216842992390310-9&quot;/&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot;/&gt;&lt;param name=&quot;allowScriptAccess&quot; value=&quot;always&quot;/&gt;&lt;embed src=&quot;//static.slideshare.net/swf/ssplayer2.swf?doc=webframeworksofthefutureflexgwtrailsandgrails-1216842992390310-9&quot; type=&quot;application/x-shockwave-flash&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; width=&quot;425&quot; height=&quot;355&quot;&gt;&lt;/embed&gt;&lt;/object&gt;
&lt;div style=&quot;font-size: .9em; text-align: center&quot;&gt;
&lt;a href=&quot;http://www.slideshare.net/mraible/web-frameworks-of-the-future-flex-gwt-grail-and-rails-525747?src=embed&quot; title=&quot;View Web Frameworks of the Future: Flex, GWT, Grail, and Rails on SlideShare&quot;&gt;view on slideshare&lt;/a&gt; | 
&lt;a href=&quot;http://www.slideshare.net/mraible/web-frameworks-of-the-future-flex-gwt-grail-and-rails-525747/download&quot;&gt;download&lt;/a&gt;&lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;</content>
    </entry>
    <entry>
        <id>https://raibledesigns.com/rd/entry/gwt_and_rest</id>
        <title type="html">GWT and REST</title>
        <author><name>Matt Raible</name></author>
        <link rel="alternate" type="text/html" href="https://raibledesigns.com/rd/entry/gwt_and_rest"/>
        <published>2008-07-21T10:31:58-06:00</published>
        <updated>2008-07-21T16:36:42-06:00</updated> 
        <category term="/Java" label="Java" />
        <category term="gwt" scheme="http://roller.apache.org/ns/tags/" />
        <category term="rest" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">I&apos;ve posted two message to the &lt;a href=&quot;http://groups.google.com/group/Google-Web-Toolkit&quot;&gt;GWT Google Group&lt;/a&gt; in the last couple of days. However, &lt;a href=&quot;http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/0dbb7f08915229e5&quot;&gt;new member messages are moderated&lt;/a&gt; and neither has shown up yet. I&apos;m reposting my questions here in hopes of getting some answers.
&lt;/p&gt;
&lt;div class=&quot;smokey&quot; style=&quot;margin-bottom: 10px&quot;&gt;
&lt;p&gt;
Is there a way to easily use a REST backend with GWT? I tried &lt;a href=&quot;http://code.google.com/p/gwt-rest/&quot;&gt;GWT-REST&lt;/a&gt;. It works, but it seems to be centered towards Rails (I&apos;m using Grails) and it suffers from the &lt;a href=&quot;http://code.google.com/p/google-web-toolkit-doc-1-5/wiki/FAQ_SOP&quot;&gt;SOP issue&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
&lt;a href=&quot;http://www.gwtsite.com/how-to-access-web-services-with-gwt/&quot;&gt;JSONRequest&lt;/a&gt; looks promising for cross-domain support, but I can&apos;t
get it to work either. The provided examples work, but not my simple
hello world that returns:
&lt;/p&gt;
&lt;pre&gt;
{&quot;response&quot;:&quot;Hello World!&quot;}
&lt;/pre&gt;
&lt;p&gt;
Also, the example implementation only has GET support, not PUT, DELETE
or POST. I can post my REST backend on the public internet if anyone
is interested in seeing the issues I&apos;m having.
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Thanks in advance for any advice.</content>
    </entry>
    <entry>
        <id>https://raibledesigns.com/rd/entry/should_we_retool_appfuse_to</id>
        <title type="html">Should we change AppFuse to be Struts 2-specific?</title>
        <author><name>Matt Raible</name></author>
        <link rel="alternate" type="text/html" href="https://raibledesigns.com/rd/entry/should_we_retool_appfuse_to"/>
        <published>2008-05-29T08:29:44-06:00</published>
        <updated>2012-11-08T14:34:30-07:00</updated> 
        <category term="/Java" label="Java" />
        <category term="struts2" scheme="http://roller.apache.org/ns/tags/" />
        <category term="appfuse" scheme="http://roller.apache.org/ns/tags/" />
        <category term="rest" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">Dusty recently &lt;a href=&quot;http://www.nabble.com/Re%3A-RE%3A-Getting-ready-for-Struts-2.1.1-p17461105s2369.html&quot;&gt;posted&lt;/a&gt; an interesting idea to the AppFuse developers mailing list:&lt;/p&gt;
&lt;p class=&quot;quote&quot;&gt;
After thinking/coding/reading for a while I think the more interesting  
task is:  Retool AppFuse to be one or more Struts2 plugins based on  
various higher level app patterns.  (AppFuse Facebook, AppFuse  
Employee DB, AppFuse Blog, AppFuse Basic LDAP, AppFuse Basic Crowd).
&lt;br/&gt;&lt;br/&gt;
This all comes from the fact, that I have been wanting to refactor the  
AppFuse web layer for Struts.  One of the interesting aspects of  
AppFuse is that it works pretty much the same across all its web  
frameworks.  It does so with some lowest common denominator  
abstractions that can be ported and look and work the same across  
frameworks.  I have picked my tool(s): Struts 2 and Ruby On Rails when  
I want to pretend I am young again. I know Spring MVC, JSF, etc. but  
I have no desire to build significant apps on those platforms. It&apos;s  
not because they suck and Struts2 rules, it is because I know Struts 2  
the best, I am most efficient there and it provides everything I need  
to build great webapps (Let&apos;s not devolve to a framework debate). So,  
I would rather have a more Struts 2-specific web stack, that really  
leverages conventions born and raised there.  The nice thing about the  
Struts 2 web stack is that it is complemented nicely by AppFuse&apos;s data/service layer, since unlike Grails or Rails, Struts 2 has no data or service layer.
[&lt;a href=&quot;http://www.nabble.com/Re%3A-RE%3A-Getting-ready-for-Struts-2.1.1-p17461105s2369.html&quot;&gt;Read More &amp;raquo;&lt;/a&gt;]
&lt;/p&gt;
&lt;p&gt;Seems like a good idea to me. What do you think?&lt;/p&gt;
&lt;p&gt;Someday I&apos;d like to come up with a &quot;compatibility test&quot; that allows others to improve upon the ideas in AppFuse and develop their stacks independently. A suite of Selenium tests that require extensionless URLs might be a good start.</content>
    </entry>
    <entry>
        <id>https://raibledesigns.com/rd/entry/rest_and_seam_talks_at</id>
        <title type="html">REST and Seam Talks at Denver&apos;s JUG</title>
        <author><name>Matt Raible</name></author>
        <link rel="alternate" type="text/html" href="https://raibledesigns.com/rd/entry/rest_and_seam_talks_at"/>
        <published>2008-01-09T20:59:45-07:00</published>
        <updated>2008-01-11T21:08:48-07:00</updated> 
        <category term="/Java" label="Java" />
        <category term="rest" scheme="http://roller.apache.org/ns/tags/" />
        <category term="java" scheme="http://roller.apache.org/ns/tags/" />
        <category term="seam" scheme="http://roller.apache.org/ns/tags/" />
        <category term="djug" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">After a long hiatus, I decided to attend the &lt;a href=&quot;http://www.denverjug.org&quot;&gt;Denver JUG&lt;/a&gt; meeting this evening. Tonight there&apos;s a couple of interesting talks:
&lt;/p&gt;
&lt;ul class=&quot;glassList&quot;&gt;
&lt;li&gt;Give It a REST by &lt;a href=&quot;http://zepheira.com/team/brian/&quot;&gt;Brian Sletten&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Seam by &lt;a href=&quot;http://members.capmac.org/~orb/blog.cgi&quot;&gt;Norman Richards&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I&apos;ll do my best to live-blog these sessions, so hopefully you can read along and learn everything I do. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Give It a REST by Brian Sletten&lt;/strong&gt;&lt;br/&gt;
This talk isn&apos;t an implementation talk, it&apos;s more of a motivational talk. Brian is trying to answer the question &quot;Why do we care?&quot;. We care because we have a lot of WS-Dissatisfaction. &quot;Conventional&quot; Web Services are often:&lt;/p&gt;
&lt;ul class=&quot;glassList&quot;&gt;
&lt;li&gt;too difficult for non-trivial tasks (real complexity)&lt;/li&gt;
&lt;li&gt;too complex for trivial tasks (artificial complexity)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
RPC-based Web Services are mythically interoperable and time/process coupled in painful ways. SOAP has largely become popular because of marketing dollars behind in. REST is more like the &quot;hippy&quot; way that has grass-roots support with no corporate sponsor.&lt;/p&gt;
&lt;p&gt;What makes SOAP difficult? It&apos;s remote procedure calls and its tunneled using existing application protocols (HTTP). Furthermore, there are no nouns (mappings to business terms), only handlers. There are no semantics, only handlers. When you tie yourself to a contract/WSDL, you can have anything back that you want - so as long as its simple XML. This isn&apos;t entirely true because a lot of things can be shoved into XML (Word documents that are Base64 encoded).&lt;/p&gt;
&lt;p&gt;The main problem with SOAP is it solves a problem that most people don&apos;t have. It solves an edge case, rather than the main problem.&lt;/p&gt;
&lt;p&gt;Many people say &quot;SOAP is secure and REST isn&apos;t&quot;.&lt;/p&gt;
&lt;p&gt;Why do people believe this? It&apos;s because of the long list of SOAP-related security acronyms: XML Encryption, XML Signature, XKMS, SAML, XACML, WS-Security, WS-Trust, XrML. Even if you&apos;re using these in your system, there&apos;s no proof that your implementation is secure. REST is what we all use on the web with online shopping, etc. We don&apos;t seem to have a problem with the security we use everyday on the web, do we?&lt;/p&gt;
&lt;p&gt;SAO is an architectural style promoting loose coupling among software participants. Sompanies have rigid definitions of what constitutes a SOA. Many believe that SOAP is an essential piece, but it&apos;s not. SOAP 1.2 and Doc Lit are improvements, but are they necessary? Interestingly, 85% of Amazon&apos;s users chose REST over SOAP when given the choice.&lt;/p&gt;
&lt;p&gt;What is REST? The acronym stands for &lt;strong&gt;RE&lt;/strong&gt;presentational &lt;strong&gt;S&lt;/strong&gt;tate &lt;strong&gt;T&lt;/strong&gt;ransfer. It&apos;s an architectural style based on certain constraints designed to elicit properties of scalability and extensibility. It&apos;s an idealized notion of how the early web should work and helped drive the way it eventually did work. It&apos;s more than just URLs!&lt;/p&gt;
&lt;p&gt;Resource-Oriented Computing focuses on information spaces, not code or objects. It focuses on logical connections and reduces complexity by separating actions from nouns. In the history of the web, we started with URLs that pointed to documents. Eventually, these documents became dynamic and were generated on-the-fly.&lt;/p&gt;
&lt;p&gt;URLs are locations on the web that are horrible names because they change so much. URIs are good names that have no way of being resolved. Fundamentally, REST is a separation of the parts of the system: Nouns, Verbs and Representation. A Resource (in a REST architecture) can be a file, a service or a concept. It can also have different representations. Resources are named with Resource Identifiers. It&apos;s simply the means of naming a resource. It&apos;s a standard syntax that allows various schemes. Often known as URIs (or IRIs). It&apos;s orthogonal to satisfying the reference and it&apos;s one of the missing pieces of &quot;normal&quot; web services.&lt;/p&gt;
&lt;p&gt;Examples of Representation include 1) a particular dereferencing of a Resource Identifier to a Resource at a particular time, 2) a byte-stream tagged with metadata or 3) it could change based on request or processing/display capabilities of the client (Firefox vs. WAP). &lt;/p&gt;
&lt;p&gt;REST&apos;s verbs are design decisions to minimize the the complexity of implementing a system. GET retrieves a resource and always returns the exact same result. It doesn&apos;t change anything in the backend system. Because of this, it allows for easier layering of your system - particularly when you introduce caching for GETs. POST is used to create (or update) a Resource. It does not require a &quot;known URI&quot; and it supports the append operation. PUT creates (or updates) a Resource, but requires a &quot;known URI&quot; and also supports an overwrite operation. Lastly, there is DELETE, which removes a Resource. This is not supported in modern browsers. Just because browsers don&apos;t support them doesn&apos;t mean you can&apos;t implement them in your applications.&lt;/p&gt;
&lt;p&gt;REST&apos;s concepts were developed by &lt;a href=&quot;http://en.wikipedia.org/wiki/Roy_Fielding&quot;&gt;Roy Fielding&lt;/a&gt; in his &lt;a href=&quot;http://tinyurl.com/cvamh&quot;&gt;thesis&lt;/a&gt;. He was trying to create a system that had the following architectural properties: performance, scalability, generality, simplicity and modifiability. REST allows us to create true client-server applications. To satisfy scalability requirements, REST is stateless. All parameters travel with the request and no session information is maintained on the server. This improves scalability through load-balancing and allows visibility of intermediary processors.&lt;/p&gt;
&lt;p&gt;One of the first things that becomes a bottleneck in enterprise systems is the database. This works fine if you like paying Oracle. By using REST and HTTP concepts, it&apos;s easy to take advantage of a cache. This allows replication of an external data set where it&apos;s too large to copy locally. REST allows you to create Layered Systems that allow you to have managed dependencies between layers. Having a RESTful architecture allows you to swap out the backend without changing the front-end and vise-versa.&lt;/p&gt;
&lt;p&gt;Now Brian is going to do some demos using &lt;a href=&quot;http://1060.org/&quot;&gt;NetKernel&lt;/a&gt;. He recommends using HTML documents to describe services. The beauty of developing a RESTful system is there&apos;s nothing preventing you from appending ?wsdl to your URLs to return SOAP.&lt;/p&gt;
&lt;p&gt;Invoking functionality using web-friendly techniques is a very nice way to build web applications.&lt;/p&gt;
&lt;p&gt;What is controversial in REST? &lt;a href=&quot;http://www.w3.org/DesignIssues/Axioms.html&quot;&gt;When you are not dereferencing you should not look at the contents of the URI string to gain other information.&lt;/a&gt;. However, if you structure your URLs in your application in a hierarchical manner, people &lt;em&gt;will&lt;/em&gt; be able to use URIs in this way.&lt;/p&gt;
&lt;p&gt;What isn&apos;t controversial? No one believes you should rely on sessions or other state at the application level. They also believe using nouns, not verbs is an excellent idea.&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;&lt;strong&gt;Seam by Norman Richards&lt;/strong&gt;&lt;br/&gt;
Seam isn&apos;t just a web framework, it&apos;s an integration technology for building applications for the web. It&apos;s a technology that takes your persistence and web technologies and unifies them so you have a simpler view of your system. 
&lt;/p&gt;
&lt;p&gt;
First of all, what is Seam?
&lt;/p&gt;
&lt;ul class=&quot;glassList&quot;&gt;
&lt;li&gt;It&apos;s a unified component and event model - you access all your components the same way&lt;/li&gt;
&lt;li&gt;It has a declarative state with a rich context model&lt;/li&gt;
&lt;li&gt;It provides deep integration with minimal glue code&lt;/li&gt;
&lt;li&gt;It minimizes configuration, prefers annotations to XML&lt;/li&gt;
&lt;li&gt;It allows a freedom of architectures and technologies&lt;/li&gt;
&lt;li&gt;It also allows testing of components in context&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;With Seam, you have a number of technology choices to make. The first is which business component model you want to use (EJB 3 vs. POJO). You might choose EJB 3 if you want more clustering capabilities. For persistence, you can use Hibernate or any JPA implementation. Norman recommends using JPA if possible. You also have a choice of languages: Java or Groovy (and possibly Scala in the future). Seam gives you a choice of web frameworks. All the examples today will use JSF, but there&apos;s also support for GWT and 2.1 will have support for Wicket. Also, there&apos;s some non-committers developing support for Flex. Norman believes component-based web frameworks are the best way to develop web applications. While I hear this from a lot of &lt;span style=&quot;text-decoration: line-through&quot;&gt;folks&lt;/span&gt; component-based framework authors, it seems ironic that the &quot;best&quot; way to develop webapps is not the most popular way (PHP, Struts, Rails).
&lt;/p&gt;
&lt;p class=&quot;smokey&quot;&gt;I think it&apos;s ironic that there&apos;s a REST (no state) and a Seam (it&apos;s all about state) talk in the same night. I&apos;m tempted to ask why a stateful architecture is better than a REST one, but I&apos;m not really that interested in the answer. I think your architecture should be determined by the needs of your application, rather than choosing the architecture and then implementing an application with it.&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;In addition to choices, Seam gives you a number of tools: CRUD generation, Eclipse and NetBeans support and full IDE support in JBoss Tools / JBoss Developer Studio.&lt;/p&gt;
&lt;p&gt;Now Norman is doing a demo - starting by creating a new Seam Web Project in Eclipse. He mentions that he&apos;s skipped a number of steps: downloading and installing Seam, downloading and installing JBoss and configuring your Seam installation and database in Eclipse. He has two projects in Eclipse - apparently the New Project wizard creates two - one for the application and one for testing. It&apos;s strange that the tests don&apos;t go in the actual project. The directory structure has &lt;code&gt;src/action&lt;/code&gt; and &lt;code&gt;src/model&lt;/code&gt; for your Seam components. After doing some simple CRUD, Norman starts JBoss and looks at the master/detail screens it generates.
&lt;/p&gt;
&lt;p&gt;To make a Java class a Seam component, you usually only have to add a @Name annotation to the class. While trying to show us how the Authenticator/login works, Norman tried to open components.xml. Unfortunately, this crashed Eclipse and 30 seconds later - following a bevy of &quot;file does not exist&quot; errors, we&apos;re back in action. To inject dependencies in a Seam environment, you use the @In annotation. In the example class, here&apos;s what the code looks like:
&lt;/p&gt;
&lt;pre&gt;
try {
  currentUser = (Person) entityManager.createQuery(&quot;select p from Person p where&quot; + 
       &quot; p.email = #{identity.username} and p.password=#{identity.password}&quot;).getSingleResult();
} catch (NoSuchEntityException e) {
  currentUser = null;
}
&lt;/pre&gt;
&lt;p&gt;This example appears to encourage title coupling with the data layer, rather than loose coupling (i.e. a DAO layer). I&apos;m sure Seam doesn&apos;t prevent you from developing a more loosely coupled application.
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Bug Alert:&lt;/strong&gt; The &amp;lt;h:messages&gt; tag looks like it always has an &amp;lt;li&amp;gt; - even when there&apos;s only one message. Struts 2 has the same issue with its &amp;lt;s:errors&amp;gt; tag. It&apos;s disappointing that so many Java framework developers don&apos;t have more attention to HTML details.&lt;/p&gt;
&lt;p&gt;Probably the coolest part of Norman&apos;s demo is how Eclipse auto-synchronizes with JBoss so he never has to start/stop anything when he changes Facelets pages or Java classes. Of course, hot deploy should be possible with any web application if you&apos;re using Eclipse Web Tools effectively.&lt;/p&gt;
&lt;p class=&quot;smokey&quot;&gt;I do believe all-in-one starter frameworks like Seam, Rails, Grails and AppFuse are excellent. However, I also believe they&apos;re solving a problem that only 10% of companies have. Most companies don&apos;t have the ability to start applications from scratch - unless they&apos;re a startup. Most companies have an existing infrastructure in place for the backend and they simply need a better web framework to slap a pretty face on it. I don&apos;t know the best solution for this, but it seems like a logical choice to RESTify the backend (possibly with a web framework) and then use a modern web framework for the front-end. IMHO, the best web frameworks for a RESTified backend are &lt;a href=&quot;http://www.adobe.com/products/flex/&quot;&gt;Flex&lt;/a&gt;, &lt;a href=&quot;http://code.google.com/webtoolkit/&quot;&gt;GWT&lt;/a&gt; and &lt;a href=&quot;http://www.appcelerator.org&quot;&gt;Appcelerator&lt;/a&gt;. If nothing else, these appear to be the most hyped for 2008.&lt;/p&gt;
&lt;p&gt;Many of the enhancements that Seam has added to the Java web programming model are being pushed back into the &lt;a href=&quot;http://jcp.org/en/jsr/detail?id=299&quot;&gt;Web Beans JSR&lt;/a&gt;. With Seam, &lt;em&gt;injection&lt;/em&gt; is bi-directional (input and output), is continuous during application invocation and dis-injected after action is done. The whole purpose of this is to let Seam handle the state of your application. By not worrying about storing/maintaining state, you as a developer can concentrate on business logic more and get your applications done faster.
&lt;/p&gt;
&lt;p&gt;At this point, Norman started talking about Seam&apos;s events and how you can use them. Unfortunately, my battery ran out and I drifted off to do some other stuff. I&apos;m sure Seam&apos;s Event Model is pretty cool, I just missed it.
</content>
    </entry>
    <entry>
        <id>https://raibledesigns.com/rd/entry/go_light_with_apache_struts</id>
        <title type="html">Go Light with Apache Struts 2 and REST by Don Brown</title>
        <author><name>Matt Raible</name></author>
        <link rel="alternate" type="text/html" href="https://raibledesigns.com/rd/entry/go_light_with_apache_struts"/>
        <published>2007-11-15T18:12:58-07:00</published>
        <updated>2007-11-16T01:12:58-07:00</updated> 
        <category term="/Java" label="Java" />
        <category term="struts2" scheme="http://roller.apache.org/ns/tags/" />
        <category term="rest" scheme="http://roller.apache.org/ns/tags/" />
        <category term="donbrown" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">After attending &lt;a href=&quot;http://raibledesigns.com/rd/entry/building_scalable_reliable_and_secure&quot;&gt;Dan&apos;s talk on REST&lt;/a&gt;, I stayed in the same room and listened to Don Brown talk about &lt;a href=&quot;http://us.apachecon.com/us2007/program/talk/2058&quot;&gt;Struts 2&apos;s support for building RESTful applications&lt;/a&gt;. Below are my notes from the event.
&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;What is wrong with today&apos;s web applications? You&apos;re using a modern web framework and you&apos;ve cleanly separated your presentation and business logic. The biggest problem in modern web applications is Confusing URLs.
&lt;/p&gt;
&lt;p&gt;
A URL should be a resource indicator - not a method invocation. Often, web applications have little or no caching. People use GET to perform data manipulation and POST may or may not change state (especially with JSF). Another big issue with modern web frameworks is there&apos;s too many abstraction layers that hide HTTP headers and it&apos;s difficult to manipulate them.
&lt;/p&gt;
&lt;p&gt;
Today&apos;s applications are &quot;information silos&quot;. There&apos;s a lot of information in your applications, but it&apos;s all buried in HTML, JavaScript and CSS. There&apos;s no way to get this information out of your application unless you explicitly expose it.
&lt;/p&gt;
&lt;p&gt;
The answer to many of these problem is REST. It&apos;s the Way of the Web. To solve the information silo problem, you can create a single interface that has multiple representation of the same resource. There&apos;s one URI for all types of resources - be it XML, JSON or HTML. How does this work w/o modifying the URL? You modify the URL&apos;s extension.
&lt;/p&gt;
&lt;p&gt;
Struts 2 has a couple of plugins that make developing RESTful services easier. The first is the Codebehind plugin and the 2nd is the REST plugin. Don is doing a demo with the REST plugin and shows that there&apos;s no Struts configuration files needed (no struts.xml and no struts.properties). The only thing that&apos;s necessary is to specify an &quot;actionPackages&quot; init-param on the DispatcherFilter in web.xml. This activates the Codebehind plugin that uses conventions to determine the view template&apos;s path.
&lt;/p&gt;
&lt;p&gt;
In Don&apos;s demo, he&apos;s creating an &quot;OrdersController&quot; that implements ModelDriven. After implementing a setId() method (to set the id from the request parameters), a getModel() method (to return the Order object) and implementing a show() method that returns HttpHeaders, Don starts up his server and shows that http://localhost:8080/order/5 returns an HTML page. Changing the URL to end in /5.json returns JSON, /5.xml returns XML.
&lt;/p&gt;
&lt;pre&gt;
public HttpHeaders create() {
    service.save(order);
    return new DefaultHttpHeaders(&quot;success&quot;).setLocationId(order.getId());
}
&lt;/pre&gt;
&lt;p&gt;
The &lt;a href=&quot;https://addons.mozilla.org/en-US/firefox/addon/2691&quot;&gt;Poster Plugin for Firefox&lt;/a&gt; is great when you&apos;re working with REST services. Don used this plugin to show us that it&apos;s possible to post to JSON and get back JSON results. His demo was impressive, especially the fact that there was no XML configuration required for Struts. I also like how the DefaultHttpHeaders class allows you to manipulate headers in a type-safe manner. 
&lt;/p&gt;
&lt;p&gt;
To use the REST plugin, you&apos;ll want to use Struts 2.1. If you&apos;re using Maven, all you need to depend on is struts-rest-plugin. The struts-codebehind-plugin (as well as struts-core) will be pulled in by transitive dependencies.
&lt;/p&gt;
&lt;p&gt;
One disadvantage of REST vs. WS-* is you can&apos;t generate client code from a WSDL. You&apos;ll have to write your client by hand. However, one advantage of REST is there&apos;s already lots of clients - your browser, curl, etc.
&lt;/p&gt;
&lt;p&gt;
The Struts REST Plugin hasn&apos;t been officially released, but hopefully will be in Struts 2.1.1. You can checkout the code from SVN using the URL below. The documentation is located &lt;a href=&quot;http://struts.apache.org/2.x/docs/rest-plugin.html&quot;&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p style=&quot;margin-left: 10px&quot;&gt;
&lt;a href=&quot;http://svn.apache.org/repos/asf/struts/struts2/trunk/plugins/rest/&quot;&gt;http://svn.apache.org/repos/asf/struts/struts2/trunk/plugins/rest&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;Great talk Don - and excellent work on the REST plugin for Struts. I can&apos;t wait to try it out.</content>
    </entry>
    <entry>
        <id>https://raibledesigns.com/rd/entry/building_scalable_reliable_and_secure</id>
        <title type="html">Building scalable, reliable, and secure RESTful services with Dan Diephouse</title>
        <author><name>Matt Raible</name></author>
        <link rel="alternate" type="text/html" href="https://raibledesigns.com/rd/entry/building_scalable_reliable_and_secure"/>
        <published>2007-11-15T18:04:22-07:00</published>
        <updated>2007-11-16T01:04:22-07:00</updated> 
        <category term="/Java" label="Java" />
        <category term="rest" scheme="http://roller.apache.org/ns/tags/" />
        <category term="diephouse" scheme="http://roller.apache.org/ns/tags/" />
        <content type="html">This afternoon, I attended Dan Diephouse&apos;s &lt;a href=&quot;http://us.apachecon.com/us2007/program/talk/1965&quot;&gt;talk on RESTful services&lt;/a&gt;. Below are my notes from his presentation.
&lt;/p&gt;
&lt;p&gt;
Roy Fielding coined the term REST (REpresentative State Transfer) in a thesis. Everything is a resource and are addressable via URIs. Resources are self descriptive and manipulated with verbs via a &lt;em&gt;uniform interface&lt;/em&gt;. We don&apos;t want keys - we want links! Resources are hypertext. Hypertext is just data with links to other resources. Data model refers to other application states via links. This is possible because of the uniform interface!
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;REST and HTTP&lt;/strong&gt;&lt;br/&gt;
There&apos;s 5 main HTTP methods: GET, POST, PUT, DELETE and HEAD. Get is cacheable and safe (there&apos;s no side effects). POST is an unsafe operation and can&apos;t be repeated. HEAD is used to retrieve a resources metadata, without getting the method body.
&lt;/p&gt;
&lt;p&gt;To create a new resource, you use POST. The server will return an HTTP 201 (Created) with a Location header. After that, you&apos;ll do a PUT to the location and you&apos;ll get back an HTTP 200.
Another option is to have the client generate a unique id and PUT to it straight away - instead of doing the POST/PUT - where the POST generates the unique URL.&lt;/p&gt;
&lt;p&gt;The biggest problem with REST is firewalls. Many firewalls don&apos;t allow PUT or DELETE. Google fixes this by adding a header that specifies a method override.
&lt;/p&gt;
&lt;p&gt;One of the constraints of REST is all communication is stateless. Session state is kept on the client. The client is responsible for transitioning to new states. States are represented by URIs. The advantage is this improves visibility, reliability and scalability. You don&apos;t need to replicate session state on your services in a cluster.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;ETag header&lt;/strong&gt;&lt;br/&gt;
Resources may return an ETag header when it is accessed. On subsequent retrieval of the resource, client sends this ETag header back. The client can then use a &quot;If-None-Match&quot; header with the ETag value to communicate with the server. The server will send back a 304 (Not Modified) with no body if nothing has changed. &lt;strong&gt;LastModified&lt;/strong&gt; is a similar header that servers send back. The client will then send a &quot;If-Modified-Since&quot; header and get a similar result.&lt;/p&gt;
&lt;p&gt;REST allows scalability through Caching - a.k.a. &quot;cache the hell out of it&quot;. There&apos;s 3 types of cache:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Browser&lt;/li&gt;
&lt;li&gt;Proxy &lt;/li&gt;
&lt;li&gt;Gateway&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
How does caching actually work? A resource is eligible for caching if:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The HTTP response headers don&apos;t say not to cache it&lt;/li&gt;
&lt;li&gt;The response is not authenticated or secure&lt;/li&gt;
&lt;li&gt;No ETag or LastModified header is present&lt;/li&gt;
&lt;li&gt;The cache representation is fresh&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Is your cache fresh? Yes, if the expiry time has not been exceeded and the representation was LastModified a relatively long time ago. If it&apos;s stale, the remote server will be asked to grab a new copy of the resource and send it back to you.&lt;/p&gt;
&lt;p&gt;
HEAD allows you to get metadata about a resource without getting the resource itself. You can use it to test that a resource exists, that a link is valid or to check when a resource was last modified.
&lt;/p&gt;
&lt;p&gt;
There&apos;s an &quot;Expect 100 Continue&quot; header you can use to query the server to see if it&apos;s capable of receiving a message. The nice thing about this is you get client-server communication before sending the message body. An example was provided where you upload an image from your cell phone. You don&apos;t want to start sending the message body if authentication is required. Your phone can check for &quot;100 continue&quot; to determine if it should start uploading the file.
&lt;/p&gt;
&lt;p&gt;For doing batch operations with REST, you can use HTTP connection pipelining. Unfortunately it&apos;s broken by some firewalls. Another option is to POST a whole set of data. GData (an extension to the Atom Publishing Protocol) fixes this by allowing you to post a whole bunch of entries at once. Unfortunately, this approach has received a very cold reception from the community.&lt;/p&gt;
&lt;p&gt;The Atom Publishing Protocol is a RESTful protocol for building services. You can use it to create, edit, delete entries in a collection. It&apos;s an extensible protocol; examples include paging extensions, GData and OpenSearch. &lt;/p&gt;
&lt;p&gt;Why should you use APP for your application? Because it provides &lt;em&gt;ubiquitous&lt;/em&gt; elements which have meaning across all contexts. You can leverage existing solutions for security (HTTP Auth, WSEE, Google Login, XML Signatures and Encryption). It also eliminates the need for you to write much of the client/server code. Alternatives to APP include HTTPD, Java (Servlets, Restlets, Spring MVC), Ruby on Rails and many others.
&lt;/p&gt;
&lt;p&gt;
Limitations of REST are HTTP is NOT an RPC or message passing system. It also isn&apos;t as secure as other solutions. A lot of times, folks just use SSL and basic authentication - which isn&apos;t the most secure system.
&lt;/p&gt;
&lt;p&gt;
Dan posted his presentation on &lt;a href=&quot;http://netzooid.com/blog/2007/11/14/apachecon-rest-presentation/&quot;&gt;his blog&lt;/a&gt; if you&apos;d like to download it.</content>
    </entry>
</feed>

