cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sergey Beryozkin" <sbery...@progress.com>
Subject Re: Need Help with JAX-WS and JAX-RS example
Date Thu, 30 Apr 2009 08:46:18 GMT
>>>>      @Path("/receive")
>>>        public void receive(@PathParam("*/*")String itemXML) {
>>>                System.out.println(itemXML);
>>>        }

@Post
@PathParam value is wrong. @PathParam is meant to capture tempate variable instances, for
ex
@Path("/receive/{item}")
public void receive(@PathParam("item") String item) {
      System.out.println(itemXML);
}

so a path like /receive/2 will result in "2" being passed to a method. If you'd like a request
body to be mapped into 'item' then 
you just need to remove @PathParam.

Cheers, Sergey


----- Original Message ----- 
From: "cybercxf" <navendugarg@yahoo.com>
To: <dev@cxf.apache.org>
Sent: Wednesday, April 29, 2009 5:43 PM
Subject: Re: Need Help with JAX-WS and JAX-RS example


>
> I did but I am not sure if I am using right annotations of Restful services.
> Can you verify that for me by taking a look at the code I had attached in
> my first post.
>
> thanks.
>
>
> Eoghan Glynn-4 wrote:
>>
>> BTW to answer the other part of your question, it is possible use the
>> JAX-RS and JAX-WS annotations on the same implementation class.
>>
>> See the BookStoreJaxrsJaxws[1] system test for an example.
>>
>> Cheers,
>> Eoghan
>>
>> [1]
>> http://svn.apache.org/repos/asf/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java
>>
>> 2009/4/29 Eoghan Glynn <eoglynn@gmail.com>:
>>> I'd suspect you've a mismatch between the version of
>>> cxf-rt-frontend-jaxrs and the cxf-api jars.
>>>
>>> The former depends on the Message.REQUEST_URI field, which is defined
>>> in the latter.
>>>
>>> This field was introduced on 2008-10-21, so you'll need a version of
>>> the API jar from after this date (2.0.10/2.1.4/2.2 or later).
>>> Preferably exactly the same version as you use for the JAX-RS stuff.
>>>
>>> Cheers,
>>> Eoghan
>>>
>>> 2009/4/29 cybercxf <navendugarg@yahoo.com>:
>>>>
>>>> When I run the RestClient.java, it is giving me error
>>>>
>>>> java.lang.NoSuchFieldError: REQUEST_URI
>>>>
>>>> Can someone help me, what should be the @Path. Is the code for using the
>>>> same service class (HelloWorldImpl.java) for both JAX-WS, JAX-RS?
>>>>
>>>> Please see all the code below and let me know.
>>>>
>>>> thanks.
>>>>
>>>>
>>>> Code
>>>> ====
>>>>
>>>>
>>>> HelloWorld.java (Inteface)
>>>> ===================
>>>>
>>>> import javax.jws.WebParam;
>>>> import javax.jws.WebService;
>>>> import javax.jws.WebParam.Mode;
>>>>
>>>> @WebService(name = "HelloWorld")
>>>> public interface HelloWorld {
>>>>        void receive(@WebParam(name = "itemXML", mode = Mode.IN) String
>>>> itemXML);
>>>> }
>>>>
>>>> HelloWorldImpl.java
>>>> ==============
>>>>
>>>> import javax.jws.WebMethod;
>>>> import javax.jws.WebService;
>>>> import javax.ws.rs.Consumes;
>>>> import javax.ws.rs.POST;
>>>> import javax.ws.rs.Path;
>>>> import javax.ws.rs.PathParam;
>>>>
>>>> @Path("/HelloWorld")
>>>> @WebService(endpointInterface = "org.openpipeline.services.HelloWorld",
>>>> serviceName = "HelloWorld")
>>>> @Consumes("application/xml")
>>>> public class HelloWorldImpl implements HelloWorld{
>>>>        @WebMethod
>>>>        @POST
>>>>        @Path("/receive")
>>>>        public void receive(@PathParam("*/*")String itemXML) {
>>>>                System.out.println(itemXML);
>>>>        }
>>>> }
>>>>
>>>> Server.java
>>>> ========
>>>>
>>>> import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
>>>> import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
>>>> import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
>>>>
>>>> public class Server {
>>>>        public static void main(String[] args){
>>>>                HelloWorldImpl implementor = new HelloWorldImpl();
>>>>
>>>>                /*
>>>>                 * Start JAX-WS service
>>>>                 */
>>>>                JaxWsServerFactoryBean svrFactory = new
>>>> JaxWsServerFactoryBean();
>>>>                svrFactory.setServiceClass(HelloWorld.class);
>>>>                svrFactory.setAddress("http://localhost:9000/");
>>>>                svrFactory.setServiceBean(implementor);
>>>>                svrFactory.create();
>>>>
>>>>                /*
>>>>                 * Start JAX-RS service
>>>>                 */
>>>>        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
>>>>        sf.setResourceClasses(HelloWorldImpl.class);
>>>>        sf.setResourceProvider(HelloWorldImpl.class,
>>>>            new SingletonResourceProvider(new HelloWorldImpl()));
>>>>        sf.setAddress("http://localhost:9001/");
>>>>
>>>>        sf.create();
>>>>
>>>>        }
>>>> }
>>>>
>>>>
>>>> RestClient.java
>>>> ============
>>>>
>>>> import org.apache.commons.httpclient.HttpClient;
>>>> import org.apache.commons.httpclient.methods.PostMethod;
>>>> import org.apache.commons.httpclient.methods.RequestEntity;
>>>> import org.apache.commons.httpclient.methods.StringRequestEntity;
>>>>
>>>> public class RestClient {
>>>>
>>>>        public static void main(String args[]) throws Exception {
>>>>
>>>>                PostMethod post = new
>>>> PostMethod("http://localhost:9001/HelloWorld/receive/");
>>>>                post.addRequestHeader("Accept", "application/xml");
>>>>                RequestEntity entity = new
>>>> StringRequestEntity("<root>Hello REST!</root>",
>>>> "application/xml", "ISO-8859-1");
>>>>                post.setRequestEntity(entity);
>>>>                HttpClient httpclient = new HttpClient();
>>>>
>>>>                try {
>>>>                        int result = httpclient.executeMethod(post);
>>>>                        System.out.println("Response status code: " +
>>>> result);
>>>>                        System.out.println("Response body: ");
>>>>                } finally {
>>>>                        // Release current connection to the connection
>>>> pool once you are
>>>>                        // done
>>>>                        post.releaseConnection();
>>>>                }
>>>>
>>>>                System.out.println("\n");
>>>>                System.exit(0);
>>>>        }
>>>> }
>>>>
>>>> Client.java
>>>> ========
>>>>
>>>> public class Client {
>>>>        public static void main(String[] args){
>>>>                JaxWsProxyFactoryBean factory = new
>>>> JaxWsProxyFactoryBean();
>>>>                factory.getInInterceptors().add(new
>>>> LoggingInInterceptor());
>>>>                factory.getOutInterceptors().add(new
>>>> LoggingOutInterceptor());
>>>>                factory.setServiceClass(HelloWorld.class);
>>>>
>>>>                factory.setAddress("http://localhost:9000/HelloWorld");
>>>>                HelloWorld client = (HelloWorld) factory.create();
>>>>                Item item = new Item();
>>>>                item.importXML("<root>Hello</root>");
>>>>                client.receive(item.toString());
>>>>        }
>>>> }
>>>>
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/Need-Help-with-JAX-WS-and-JAX-RS-example-tp23287998p23287998.html
>>>> Sent from the cxf-dev mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/Need-Help-with-JAX-WS-and-JAX-RS-example-tp23287998p23296139.html
> Sent from the cxf-dev mailing list archive at Nabble.com.
>
> 


Mime
View raw message