cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cybercxf <navendug...@yahoo.com>
Subject Need Help with JAX-WS and JAX-RS example
Date Tue, 28 Apr 2009 23:29:07 GMT

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.


Mime
View raw message