<story><title>The Modern Java Ecosystem (for the Sinatra or web.py lover)</title><url>http://arantaday.com/the-modern-java-ecosystem</url><text></text></story><parent_chain></parent_chain><comment><author>hello_moto</author><text>I&apos;d like to add a few things here.&lt;p&gt;Jersey is an implementation of JAX-RS. It has 3 major pieces: jersey-core, jersey-client, jersey-server. (The name should be obvious what they are for).&lt;p&gt;If you&apos;re writing JAX-RS services, you can return a few different formats: XML, JSON, ATOM. All you need to do is to annotate the method with the following annotation:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  // will return XML or JSON depending on the request from the client.

  @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) 
&lt;/code&gt;&lt;/pre&gt;
This is a big win if you need to support both.&lt;p&gt;&lt;pre&gt;&lt;code&gt;  - Object to XML conversion is done by JAXB.
  - Object to JSON conversion is done by Jackson via JAXB.
&lt;/code&gt;&lt;/pre&gt;
Jersey is part of JavaEE 6 standard (part of your Application Server if it supports it).&lt;p&gt;What&apos;s lacking from JavaEE 6 is an MVC framework which is targeted for JavaEE 7.&lt;p&gt;Another key feature is JAX-WS (the plain old SOAP WebService). The nice thing about JavaEE 6 is that the minimum differences in the programming style between JAX-RS and JAX-WS.&lt;p&gt;JAX-RS operates according to resources (e.g.: give me all students, give me student with id=1, delete student with id=1, etc). So some of the examples would be:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  // Rough pseudo-code, omitting a few JAX-RS annotation

  public class StudentResource{

  @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })

  public &amp;#60;List&amp;#62; all(){}

  @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })

  public Student get(long id){}
  }
&lt;/code&gt;&lt;/pre&gt;
JAX-WS operates according to services (e.g.: initiateInvoiceWorkflow, performPayment, etc).&lt;p&gt;&lt;pre&gt;&lt;code&gt;  public interface AccountingService{

    @WebMethod(operationName=&quot;initiateInvoiceWorkflow&quot; ...)

    Invoice initiateInvoiceWorkFlow();

  }

  // have your implementation...
&lt;/code&gt;&lt;/pre&gt;
So in theory, you can have something that&apos;s called StudentRepository where you can use that repository with both JAX-RS (REST) and JAX-WS (WebService) implementation easily (I&apos;ve done this and it&apos;s quite straightforward) if your &quot;Enterprise client&quot; forces you to do so.&lt;p&gt;The important bit here is testing. You can easily test both JAX-RS and JAX-WS implementation in both unit-test or integration-test. You can easily do unit-test because you don&apos;t need to deploy them to the server: they&apos;re just normal Java classes. You can do integration test by deploying them to the server and generates the client implementation (in which I&apos;ll cover next).&lt;p&gt;The client-side implementation of JAX-RS is also similar to that of JAX-WS programming style.&lt;p&gt;In JAX-WS, you grab a WSDL, throw it to a generator tool that comes with JDK to generate the model (Invoice, Student, etc) and the proxy client-side to call the server-side. Very very straightforward, 5 minute job.&lt;p&gt;In JAX-RS, you&apos;d use jersey-client to perform HTTP call as follow:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  // url  =&amp;#62; is a string that points to JAX-RS end-point e.g.: student/1
  // header =&amp;#62; json? xml? atom?
  // type =&amp;#62; (typeof Student) (well... it&apos;s Java).
  Student student = Client.create().resource(url).accept(header).get(type);
&lt;/code&gt;&lt;/pre&gt;
Keep in mind that in the client-side, your Student class must have roughly the same structure and must be annotated using JAXB XML annotation (the client-side also relies on JAXB -&amp;#62; Jackson -&amp;#62; Java object conversion for the case of JSON, or just JAXB -&amp;#62; JAva object for the case of XML).&lt;p&gt;So no hacking using XPath or something like that (I work in Ruby once in a while and when I read some of the 3rd-party libraries/gems that implement client-side API against popular service provider, most of the implementations do brute force using XPath querying node element and stuff).&lt;p&gt;PS: Excuse me for the poor formatting, where can I learn to format my comment?&lt;p&gt;UPDATE: fix the format.&lt;p&gt;Oh and one more thing: JAX-RS (Jersey) is just an implementation on top of Servlet. So all of your previous knowledge regarding to Servlet (Context, deployment, URL, Filter) will be definitely useful.</text></comment>
<story><title>The Modern Java Ecosystem (for the Sinatra or web.py lover)</title><url>http://arantaday.com/the-modern-java-ecosystem</url><text></text></story><parent_chain></parent_chain><comment><author>scorchin</author><text>For those looking for something more like Sinatra in Java, check out webbit: &lt;a href=&quot;https://github.com/joewalnes/webbit&quot; rel=&quot;nofollow&quot;&gt;https://github.com/joewalnes/webbit&lt;/a&gt;&lt;p&gt;Here&apos;s an example of a simple Websocket chat server: &lt;a href=&quot;https://gist.github.com/1421652&quot; rel=&quot;nofollow&quot;&gt;https://gist.github.com/1421652&lt;/a&gt;&lt;p&gt;&lt;i&gt;Disclaimer: It&apos;s an open source project that I have some commits to&lt;/i&gt;</text></comment>