Hi,

I need services to be exposed as both GET and POST. 
Issue with GET: Not able to access from client.
Error: 
No message body reader found for class : interface com.tfs.pe.HelloWorld,
ContentType : application/json.
Exception in thread "main" javax.ws.rs.WebApplicationException:
javax.ws.rs.WebApplicationException
        at 
org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:595)
        at
org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:580)
        at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:552)
        at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:289)
        at org.apache.cxf.jaxrs.client.WebClient.get(WebClient.java:356)
        at com.tfs.pe.Client.main(Client.java:29)
Caused by: javax.ws.rs.WebApplicationException
        at
org.apache.cxf.jaxrs.client.AbstractClient.reportNoMessageHandler(AbstractClient.java:449)
        at
org.apache.cxf.jaxrs.client.AbstractClient.readBody(AbstractClient.java:408)
        at 
org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:589)
        ... 5 more

Am able to access the URL with browser.

Issue with POST: Not able to access with browser/Client code.
Error: 
org.apache.cxf.interceptor.Fault: Could not send Message.
        at
org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64)
        at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
        at
org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:573)
        at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:552)
        at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:289)
        at org.apache.cxf.jaxrs.client.WebClient.get(WebClient.java:356)
        at com.tfs.pe.Client.main(Client.java:29)
Caused by: java.io.IOException: Server returned HTTP response code: 405 for
URL: http://localhost:8081/SampleRestProject/helloWorld/customer
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at
sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1296)
        at java.security.AccessController.doPrivileged(Native Method)
        at
sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1290)
        at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:944)
        at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:2166)
        at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:2057)
        at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1982)
        at 
org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
        at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:637)
        at
org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
        ... 6 more
Caused by: java.io.IOException: Server returned HTTP response code: 405 for
URL: http://localhost:8081/SampleRestProject/helloWorld/customer
        at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1241)
        at 
java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)
        at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:2081)
        ... 11 more
Exception in thread "main" javax.ws.rs.WebApplicationException
        at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:292)
        at org.apache.cxf.jaxrs.client.WebClient.get(WebClient.java:356)
        at com.tfs.pe.Client.main(Client.java:29)

Code:

public interface HelloWorld 
{
        Customer getCustomer(@PathParam ("id" ) int customerId); 

        Customer getCustomers();
}

@Path("/")
@Produces("application/json")
public class HelloWorldImpl implements HelloWorld
{
             @GET
        @Produces("application/json")
        @Consumes("application/json")
        @Path("/customers")
        public Customer getCustomers()
        {
                //getList("", null);
                Customer customer = new Customer();
                customer.setId(1);
                customer.setName("Padma");
                return customer;
        }

        @POST
        @Produces("application/json")
        @Consumes("application/json")
        @Path("/customer")
        public Customer getCustomer(int customerId)
        {
                Customer customer = new Customer();
                customer.setId(1);
                customer.setName("Padma");
                return customer;
        }

}
Bean.xml:
<beans xmlns="http://www.springframework.org/schema/beans";
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
        xmlns:jaxws="http://cxf.apache.org/jaxws";
        xmlns:cxf="http://cxf.apache.org/core";
        xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd 
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd";>

<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http-binding.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
        <jaxrs:server id="helloWorld" address="/HelloWorld" >
                        <jaxrs:serviceBeans>
                                <ref bean="helloWorldImpl"/>
                        </jaxrs:serviceBeans>
                        
                        <jaxrs:extensionMappings>
                                <entry key="json" value="application/json"/>
                        </jaxrs:extensionMappings>
        </jaxrs:server>         
        <bean id="helloWorldImpl" class="com.tfs.pe.HelloWorldImpl"/>
                
</beans>

Client:
// For POST
WebClient web = WebClient.create("http://localhost:8081/SampleRestProject";);
web.path("/helloWorld/customer");
web.type("application/json");
web.accept("application/json");
HelloWorld helloWorld = (HelloWorld)web.get(HelloWorld.class);
helloWorld.getCustomers();

// For GET
WebClient web = WebClient.create("http://localhost:8081/SampleRestProject";);
web.path("/helloWorld/customers");
web.type("application/json");
web.accept("application/json");
HelloWorld helloWorld = (HelloWorld)web.get(HelloWorld.class);
helloWorld.getCustomers();


Sergey Beryozkin-2 wrote:
> 
> 
> Hi,
> 
> I'm not sure what is happening, can you please post a sample resource
> class containing this method, and capture what actually goes on the wire
> from the client ? 
> 
> is it GET or POST that you'd like a client to do ?
> cheers, Sergey
> 
> -----Original Message-----
> From: Padmam [mailto:[email protected]]
> Sent: Mon 1/4/2010 2:12 AM
> To: [email protected]
> Subject: Re: JAXRS - POST
>  
> 
> Yes, it is annotated with @GET and @Produces.
> I also tried by setting the content type. Still getting the same error...
> 
> Thanks
> Padma
> 
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Re%3A-JAXRS---POST-tp26904409p27011961.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to