Note that there are some explanatory texts on larger screens.

plurals
  1. POJava REST client without schema
    primarykey
    data
    text
    <h2>Goal</h2> <p>Java client for Yahoo's HotJobs <a href="http://developer.yahoo.com/hotjobs/resume_search_user_guide/index.html" rel="nofollow noreferrer">Resumé Search REST API</a>. </p> <h2>Background</h2> <p>I'm used to writing web-service clients for SOAP APIs, where <a href="https://jax-ws.dev.java.net/jax-ws-ea3/docs/wsimport.html" rel="nofollow noreferrer">wsimport</a> generates proxy stubs and you're off and running. But this is a REST API, which is new to me.</p> <h2>Details</h2> <ul> <li><a href="http://en.wikipedia.org/wiki/Representational_State_Transfer" rel="nofollow noreferrer">REST</a> API</li> <li>No <a href="http://en.wikipedia.org/wiki/Web_Application_Description_Language" rel="nofollow noreferrer">WADL</a></li> <li>No formal XML schema (XSD or DTD files). There are <a href="http://developer.yahoo.com/hotjobs/resume_search_user_guide/auth.html" rel="nofollow noreferrer">example XML request/response pairs</a>.</li> <li>No example code provided</li> </ul> <h2>Progress</h2> <p>I looked at question <a href="https://stackoverflow.com/questions/221442/rest-clients-for-java">Rest clients for Java?</a>, but the automated solutions there assume you are providing both the server and the client, with JAXB invoked on POJOs to generate a schema and a REST API.</p> <p>Using <a href="http://jersey.java.net/" rel="nofollow noreferrer">Jersey</a> (a <a href="http://jcp.org/en/jsr/detail?id=311" rel="nofollow noreferrer">JAX-RS</a> implementation), I have been able to make a manual HTTP request:</p> <pre><code>import com.sun.jersey.api.client.*; ... ClientConfig clientConfig = new DefaultClientConfig(); Client client = Client.create(clientConfig); WebResource webResource = client.resource("https://hj.yahooapis.com/v1/HJAuthTokens"); webResource.accept("application/xml"); // body is a hard-coded string, with replacements for the variable bits String response = webResource.post(String.class, body); // parse response into a org.w3c.dom.Document // interface with Document via XPATH, or write my own POJO mappings </code></pre> <p>The response can look like:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Response&gt; &lt;ResponseCode&gt;0&lt;/ResponseCode&gt; &lt;ResponseMessage&gt;Login successful&lt;/ResponseMessage&gt; &lt;Token&gt;NTlEMTdFNjk3Qjg4NUJBNDA3MkJFOTI3NzJEMTdDNDU7bG9jYWxob3N0LmVnbGJwLmNvcnAueWFob28uY29tO0pVNWpzRGRhN3VhSS4yQVRqRi4wWE5jTWl0RHVVYzQyX3luYWd1TjIxaGx6U0lhTXN3LS07NjY2MzM1OzIzNDY3NTsxMjA5MDE2OTE5OzZCM1RBMVNudHdLbl9VdFFKMFEydWctLQ==&lt;/Token&gt; &lt;/Response&gt; </code></pre> <p>Or, it can look like:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;yahoo:error xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" xml:lang="en-US"&gt; &lt;yahoo:description&gt;description&lt;/yahoo:description&gt; &lt;yahoo:detail&gt; &lt;ErrorCode&gt;errorCode&lt;/ErrorCode&gt; &lt;/yahoo:detail&gt; &lt;/yahoo:error&gt; </code></pre> <h2>Questions</h2> <ul> <li>Is there a way to auto-generate <a href="http://en.wikipedia.org/wiki/POJO" rel="nofollow noreferrer">POJOs</a> which can be marshalled/unmarshalled without a formal schema? </li> <li>Should I attempt to generate those POJOs by hand, with <a href="http://jaxb.java.net/" rel="nofollow noreferrer">JAXB</a> annotations?</li> <li><strong><em>Is there some tool I should be leveraging so I don't have to do all this manually?</em></strong></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload