Note that there are some explanatory texts on larger screens.

plurals
  1. PONewbie Java EE, Json webservice getting a HTTP 404, using Jersey SDK
    primarykey
    data
    text
    <p>Just started to write my JSON webservices for a carpool engine. I am getting a HTTP 404 error as I try to write my registration API's. </p> <p>This is where my problem is</p> <pre><code>"http://localhost:8081/mCruiseOnCarPool4All/carpool4all/Registration" HTTP/1.1 405 Method Not Allowed "http://localhost:8081/mCruiseOnCarPool4All/carpool4all/Registration/Request" HTTP/1.1 500 Internal Server Error "http://localhost:8081/mCruiseOnCarPool4All/Registration/Request" HTTP/1.1 404 Not Found "http://localhost:8081/mCruiseOnCarPool4All/Registration" HTTP/1.1 404 Not Found </code></pre> <p>I know I am missing something really silly here.</p> <p>Web.xml (Jersey Library)</p> <pre><code>&lt;servlet&gt; &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt; &lt;servlet-class&gt;com.sun.jersey.spi.container.servlet.ServletContainer&lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;com.sun.jersey.config.property.packages&lt;/param-name&gt; &lt;param-value&gt;com.mcruiseon.carpool4all&lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt; &lt;url-pattern&gt;/carpool4all/*&lt;/url-pattern&gt; </code></pre> <p></p> <p>RegistrationService.java, only coded the Post method. I am returning errors on all exceptions and ok with <code>sessionkey</code> when successful. You can ignore the code in the post method, I just wanted to share so that you understand my error handling.</p> <pre><code>package com.mcruiseon.carpool4all; @Path("/Registration") public class RegistrationService { private ClientSession clientSession ; private String sessionKey ; private SessionManager sessionManager ; @Context UriInfo uriInfo; @Context Request request; @POST @Path ("Request") @Consumes({ MediaType.APPLICATION_JSON }) public Response post(JAXBElement&lt;AMessageStrategy&gt; element) { try { clientSession = new ClientSession(God.mCruiseOnServer) ; } catch (InvalidServerDNSorIPException e) { e.printStackTrace(); return Response.serverError().build() ; } sessionKey = sessionManager.setClientSession(clientSession) ; clientSession.setSessionKey(sessionKey) ; clientSession.getSendQueue().sendRequest(element.getValue()) ; try { clientSession.waitAndGetResponse(element.getValue()) ; } catch (WaitedLongEnoughException e) { return Response.serverError().build() ; } catch (UnableToResolveResponseException e) { return Response.serverError().build() ; } return Response.ok(sessionKey).build(); } } </code></pre> <p>Junit test case (removed all the HttpConnection code)</p> <pre><code>ClientIdentityConcrete clientIdentity = new ClientIdentityConcrete("username", "password", "secretkey") ; RegistrationRequest register = new RegistrationRequest(clientIdentity); String jsonStr = mapper.writeValueAsString(clientIdentity); HttpPost request = new HttpPost("http://localhost:8081/mCruiseOnCarPool4All/Registration/Request"); </code></pre>
    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.
    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