users@jersey.java.net

Re: [Jersey] 404 error code with RESTful web service and and java application

From: Oscar Calderon <oscar.kalderon_at_gmail.com>
Date: Thu, 11 Feb 2010 16:44:15 -0600

Whoa, sorry to all because is a stupid error from mine. Thanks for
answer me.

El 2/11/2010 4:39 PM, Pavel Bucek escribió:
> Hello Oscar,
>
> you defined Path annotation as:
>
> @Path("recargas")
>
> so your resource would be available through
> "http://localhost:8089/MyProject/*recargas*/", not
> "http://localhost:8089/MyProject/*resources*/"
>
>
> Regards,
> Pavel
>
>
>
> Oscar Calderon wrote:
>> Hi to all, this is my first email here. First sorry for my bad
>> english. I have a problem with a RESTful web service and a simple
>> java application that i do to consume a POST resource of the RESTful
>> ws. I'm using Jersey API client to consume my ws. First, the code of
>> ws is this:
>>
>> import javax.ws.rs.core.Context;
>> import javax.ws.rs.core.UriInfo;
>> import javax.ws.rs.Consumes;
>> import javax.ws.rs.FormParam;
>> import javax.ws.rs.PUT;
>> import javax.ws.rs.Path;
>> import javax.ws.rs.GET;
>> import javax.ws.rs.POST;
>> import javax.ws.rs.Produces;
>>
>> @Path("recargas")
>> public class RecargasResource {
>> @Context
>> private UriInfo context;
>>
>> /** Creates a new instance of RecargasResource */
>> public RecargasResource() {
>> }
>>
>> @GET
>> @Path("methodGet")
>> @Produces("application/xml")
>> public String getMethod()
>> {
>> return "<xml><message>Saying Hello from GET
>> method</message></xml>";
>> }
>>
>> @POST
>> @Path("methodPost")
>> public String recargaSaldo(
>> )
>> {
>> return "<?xml version=\"1.0\" encoding='UTF-8'?>" +
>> "<recarga>" +
>> "<codResult>" + "00" + "</codResult>" +
>> "</recarga>";
>> }
>> }
>>
>> When i run in netbeans the URI of the resource is this:
>> http://localhost:8089/MyProject/resources
>>
>> So i developed a simple command-line java application, the code is this:
>>
>> import java.io.BufferedReader;
>> import java.io.IOException;
>> import java.io.InputStreamReader;
>> import java.net.HttpURLConnection;
>> import java.net.URL;
>> import com.sun.jersey.api.client.Client;
>> import com.sun.jersey.api.client.ClientResponse;
>> import com.sun.jersey.api.client.WebResource;
>> import com.sun.jersey.api.client.config.ClientConfig;
>> import com.sun.jersey.api.client.config.DefaultClientConfig;
>> import com.sun.jersey.core.impl.provider.entity.StringProvider;
>>
>> public class Main {
>>
>> public static void main(String[] args) throws IOException {
>>
>> ClientConfig config = new DefaultClientConfig();
>> config.getClasses().add(StringProvider.class);
>> Client clienteWs = Client.create(config);
>> WebResource webResource =
>> clienteWs.resource("http://localhost:8089/MyProject/resources/");
>> webResource.path("methodPost");
>> String s = webResource.post(String.class);
>> System.out.println("Aqui esta la respuesta gracias a Jersey:
>> " + s.toString());
>> }
>>
>> }
>>
>> But, when i run it with java -jar myproject.jar i get this error:
>> Exception in thread "main"
>> com.sun.jersey.api.client.UniformInterfaceException: POST
>> http://localhost:8089/MyProject/resources returned a response status
>> of 404 ...
>>
>> But i don't understand why doesn't work.
>>
>> Regards
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>

-- 
Oscar Calderon
JAVA Tutorials and How to's? Visit http://www.javahowto.net/