users@jersey.java.net

[Jersey] Re: Digest for list users_at_jersey.java.net

From: Simon Roberts <simon_at_dancingcloudphotography.com>
Date: Fri, 16 May 2014 06:02:16 -0700

Your handler method needs to @Consumes(MediaType.APPLICATION_JSON) as well
as produce it



On Thu, May 15, 2014 at 8:05 PM, <users-request_at_jersey.java.net> wrote:

> Table of contents:
>
> 1. [Jersey] New user not able to subscribe. - David G <
> davidg.1111_at_hotmail.com>
> 2. [Jersey] How to require @Path to end with a slash? - cowwoc <
> cowwoc_at_bbs.darktech.org>
>
>
>
> ---------- Forwarded message ----------
> From: David G <davidg.1111_at_hotmail.com>
> To: "users_at_jersey.java.net" <users_at_jersey.java.net>
> Cc:
> Date: Thu, 15 May 2014 12:11:24 +0000
> Subject: [Jersey] New user not able to subscribe.
> Hi,
>
> I am a new user here. I am trying to learn Jersey 2.8. I am facing a
> problem with Json Moxy. I need help. I am trying to subsribe to mailing
> list but it always return with Mail Delivery failure.
>
> I have built small HelloWorld application. It works well for GET and POST
> request but now I want to send and receive JSON request using Moxy. I added
> dependencies in Maven
>
>
> <dependencies>
> <dependency>
> <groupId>org.glassfish.jersey.containers</groupId>
> <artifactId>jersey-container-servlet-core</artifactId>
> <!-- use the following artifactId if you don't need servlet
> 2.x compatibility -->
> <!-- artifactId>jersey-container-servlet</artifactId -->
> </dependency>
>
> <dependency>
> <groupId>org.glassfish.jersey.media</groupId>
> <artifactId>jersey-media-moxy</artifactId>
> </dependency>
>
> </dependencies>
>
>
> I am using tomcat 7 server.
>
>
> My Resource is
>
> package com.test.jersey1;
>
> import javax.ws.rs.Consumes;
> import javax.ws.rs.FormParam;
> import javax.ws.rs.GET;
> import javax.ws.rs.POST;
> import javax.ws.rs.Path;
> import javax.ws.rs.PathParam;
> import javax.ws.rs.Produces;
> import javax.ws.rs.core.MediaType;
> import javax.ws.rs.core.MultivaluedMap;
>
> @Path("hello")
> public class HelloWorldResource {
>
>
> @POST
> @Produces(MediaType.APPLICATION_JSON)
> @Path("echo")
> public Person echo(Person person) {
> return person;
> }
> }
>
>
> client is
>
>
> package com.test.jersey1;
>
> import javax.ws.rs.client.Client;
> import javax.ws.rs.client.ClientBuilder;
> import javax.ws.rs.client.Entity;
> import javax.ws.rs.client.WebTarget;
> import javax.ws.rs.core.Form;
> import javax.ws.rs.core.MediaType;
>
>
> public class HelloClient {
>
> public static void main(String[] args) {
> Client client = ClientBuilder.newClient();
>
>
>
> WebTarget target = client.target("
> http://localhost:8080/jersey1/hello/echo");
> Person person = new Person(1,"david");
> Person personRet =
> target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.entity(person,
> MediaType.APPLICATION_JSON), Person.class);
> System.out.println(personRet.getName());
>
>
> }
>
> }
>
>
> My Person POJO is
>
> package com.test.jersey1;
>
> import javax.xml.bind.annotation.XmlRootElement;
>
> @XmlRootElement
> public class Person {
> private int id;
> private String name;
> public int getId() {
> return id;
> }
> public void setId(int id) {
> this.id = id;
> }
> public String getName() {
> return name;
> }
> public void setName(String name) {
> this.name = name;
> }
>
> public Person() {
>
> }
>
> public Person(int id,String name) {
> this.id = id;
> this.name = name;
> }
>
> }
>
>
> I get following error
>
> Exception in thread "main" javax.ws.rs.NotAllowedException: HTTP 405
> Method Not Allowed
> at
> org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:920)
> at
> org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:770)
> at
> org.glassfish.jersey.client.JerseyInvocation.access$500(JerseyInvocation.java:90)
> at
> org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:671)
> at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
> at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
> at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
> at
> org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:424)
> at
> org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:667)
> at
> org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:423)
> at
> org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:326)
> at com.test.jersey1.HelloClient.main(HelloClient.java:26)
>
>
>
> ---------- Forwarded message ----------
> From: cowwoc <cowwoc_at_bbs.darktech.org>
> To: users_at_jersey.java.net
> Cc:
> Date: Thu, 15 May 2014 21:10:06 -0400
> Subject: [Jersey] How to require @Path to end with a slash?
> Hi,
>
> I have a root resource @Path("companies/") but Jersey 2.8 is responding to
> http://example.com/companies.
>
> Is there a way to configure Jersey to match http://example.com/companies/but not
> http://example.com/companies?
>
> This is important because AJAX resolves relative paths differently
> depending on whether or not the current URL ends with a slash (see
> http://stackoverflow.com/a/4765962/14731)
>
> Any ideas?
> Gili
>
> End of digest for list users_at_jersey.java.net - Fri, 16 May 2014
>
>


-- 
Simon Roberts
Certified Professional Photographer
http://dancingcloudphotography.com
(303) 249 3613