Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to host a SOAP service and REST service at the same port?

Does anyone know how to configure it so that a SOAP service and REST service can share the same port using Jersey (Grizzly) outside of an application server?

  • My soap service is at www.someurl.com:port/soap/crm
  • My rest service is at www.someurl.com:port/crm

These services share the same port but not the same base url and therefor should be able to run side by side on that port. However, there is a port bind error ..

All of this is in a custom service application and there is no web.xml or such.

The REST service is using Jersey and the Soap service is a class 'ReceptionService' published on an endpoint.

URI soapUri = URI.create("192.168.0.0:1234\soap\Crm")
URI restUri = URI.create("192.168.0.0:1234\crm")

// START SOAP SERVICE
Object reception = getObjectResource(ReceptionService.class);
Endpoint e = Endpoint.publish(soapUri, reception);

// START REST SERVICE    
ResourceConfig rc = new ResourceConfig().packages("company.rest");
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(restUri, rc);

When I try this, Grizzly spits out 'java.net.BindException: Address already in use: bind'

My soap service reception is setup like this:

    @WebService(targetNamespace = "company.crm")
    @SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL,      parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
    public class Reception implements ReceptionService {
     ... methods
    }

My rest service classes are annotated as usual like ...

@Path("hello/{username}")
public class Hello { ... }

I am a bit of a newbie at this and any pointers would be appreciated. And please, don't bother suggesting I run an application server. That is not the problem here -- the problem is how do I get around the port-bind issue without moving to some other webservice framework?

NOTE RE BOUNTY: I CANNOT ITERATE THIS ENOUGH

"The bounty winner will demonstrate how to use Jersey for REST and a Java SOAP service (annotated JAX-WS) together on the same endpoint. The answer will not require changes to the Rest and Soap annotated classes. However, and HTTP server code changes or configuration changes to make it work are acceptable. Switching to Jetty or some other application server are not acceptable The solution must be 100% embedded and run using Java SE and Java web service libraries."

like image 581
The Coordinator Avatar asked Jul 15 '13 06:07

The Coordinator


People also ask

Can REST and SOAP be used together?

SOAP cannot use REST because SOAP is a protocol and REST has an architectural style. REST can use SOAP as a protocol for web services. SOAP uses WSDL to expose supported methods and technical details.

Can a REST service call a SOAP service?

Instead of an API reference, which gives you the Request and Response formats and requirements, SOAP publishes a WSDL. So if you've got one of these SOAP Services which breaks standards, if you can get the text of a successful Request, you can use REST to make the call with that request body.


1 Answers

Jetty's overlay feature allows you to deploy two different webapps with different paths on the same Jetty instance/port.

You would have one web.xml with your Jersey servlet (for REST) and the other web.xml with the SOAP servlet.

http://www.eclipse.org/jetty/documentation/current/overlay-deployer.html

like image 198
marathon Avatar answered Nov 07 '22 12:11

marathon