How to expose a JaxWS webservice endpoint at a different URL? - java

I have a class named AppService, annotated with JaxWS annotations: #WebService, #WebMethod.
It deploys correctly, and exposes an endpoint at the URL http://myhost/myapp/AppService.
I need to respond to a slightly different URL, at http://myhost/myapp/services/AppService (notice the 'services' segment).
How should I change the annotations or xml files in the application in order to expose the services under this new URL ?
This application is deployed on IBM WebSphere. Usage of standard JavaEE API would be preferred, but WebSphere specific instructions are fair game as well.

You need to add a servlet mapping in the web.xml: Change JAX-WS Service URL

Related

Is it possible to setup apache-cxf without web.xml?

Is it possible to create a webservice with apache cxf (soap/rest) by "using the servlet transport without Spring and without web.xml file"?
No Its not possible.
The service will be needing the web deployment descriptor.
You can extend
CXFNonSpringJaxrsServlet for REST
and
CXFNonSpringServlet for SOAP
web-services in Apache CXF to avoid using Spring, but then you need to register them in web.xml.
You have to either use Spring configuration or web.xml.
Refer: Apache CXF - How to register a SOAP service without Spring?
It is possible. Took me quite a bit of work to figure this out for my own project and thought I'd share.
In my context, we're using OSGi HTTP Service to publish JAX-RS resources using a Jersey Servlet container and I wanted to do the same thing with CXF for JAX-WS resources.
Your class extending CXFNonSpringServlet should include the following:
private Object obj; // JAX-WS resource singleton
#Override
public void loadBus(ServletConfig conf)
{
super.loadBus(conf);
JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
factory.setBus(getBus());
factory.setAddress("/some/path");
factory.setServiceBean(obj);
Server cxfServer = factory.create();
}
Note that you may load as many resources within a single servlet as you find needful. Also note that the path in factory.setAddress() is appended to the path at which you register the servlet.
Also note that I'm using the singleton pattern, rather than the handler-class pattern. I'm sure this could be modified simply to fit the other paradigm.

Jetty and Jersey: How does everything fits together?

I am looking for using jersey with embedded Jetty for implementing web APIs for our service. I see code where ServletContextHandler , ServletHolder and all these classes are used to let Jetty know about the Jersey handlers. I am interested to know under the hood, like what happens when we compile this code, how jetty actually discovers the jersey handlers. I know that if I start reading the documentation, I will be able to figure out, however, looking for some quick links that covers this topic. Is there any such link?
Thanks.
Jetty can act as a http server and also a servlet container who deals with the lifecycle of servlets (init, service, destroy)
etc. A servlet is a java class that extends HttpServlet class and can override init, service, destroy methods etc. Once jetty
receives a request whose URL matches with that of a servlet, it loads the servlet in memory (if not already there), calls
service method, and keeps it in memory until it destroys it.
Jersey library has provided a standard way of writing RESTful APIs where classes are annotated with tags like say GET/POST
etc and the URL. These classes are called resource classes. It has also provided a servlet whose name is ServletContainer
to hook up with Jetty's servlet container, that intercepts Jetty's request to process servlet (like for any servlet request to jetty
this is the one class, that receives the request first).
What this servlet does is it examines the request, matches with the resource classes URL that it is informed about, and then transfers
control to that method of that resource class (i think it uses reflection for this routing). Therefore, the resource
classes are not servlet itself, but the ServletContainer class of jersey is the only servlet active in the system.
The list of resource classes ServletContainer knows about is configured by this property called "com.sun.jersey.config.property.packages"
The benefit of using Jersey is implementing your REST APIs is you are using standard way of writing your code that you can
deploy to any other standard servlet container if needed in future like tomcat, ...

Can I use a SimpleJaxWsServiceExporter with a javax.servlet.Filter?

I would like to set up a webservice endpoint using Spring's SimpleJaxWsServiceExporter for ease of use, but I also need to protect the webservice using a subclass of Jespa's HttpSecurityFilter
I suspect this does not work out of the box as SimpleJaxWsServiceExporter is using a separate HTTP server to the host webapp containing the filter - how should I accomplish this?
I have a class annotated with #WebService and in my applicationContext.xml
<bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter"
p:baseAddress="http://localhost:9581/"/>
I found a couple of alternative ways to host the endpoint within the same HTTP server (behind the filter)
Either using JAX-WS WSSpringServlet and registering my #WebService beans via the wss:binding xml tag under the http://jax-ws.dev.java.net/spring/servlet namespace, or my preferred option, as JAX-WS Spring integration has Maven dependencies on Spring 2, using CXF.

Exposing the web service using CXF

I have a requirement to expose a webservice using CXF. I am following this easy tutorial link text and did the following steps
Created a service and an implementation with #WebService annotations
Added the standard xml snippet of including cxf.xml and other xmls specified
Now I need to deploy this webservice in multiple containers. In a normal web app, I just added the CXF Servlet config but I have another application which is a bespoke framework built on top of Jetty and some handlers/exporters where there is no specific web.xml as such. In such a scenario is there any spring configuration which when declared does the equivalent of this servlet configuration bit?

apache cxf: multiple endpoints or multiple CXFServlet servlets?

I have implemented an Apache CXF Webservice with multiple endpoints.
I have successfully deployed the webservice.
The problem I have is all the endpoints WSDL appear in the same servlet URL.
Can I have two servlets of type org.apache.cxf.transport.servlet.CXFServlet in the same web.xml and have each servlet serve one endpoint so that I the following ? ...
Endpoint 1 at http:/localhost/app/endpoint1
and
Endpoint 2 at http:/localhost/app/endpoint2
What is the motivation for using 2 CXFServlets? CXF supports multiple endpoints per servlet instance.
Can be configured numerous ways. One example:
<jaxws:endpoint id="endpoint1"
implementor="#service1Impl"
address="/endpoint1">...</jaxws:endpoint>
<jaxws:endpoint id="endpoint2"
implementor="#service2Impl"
address="/endpoint2">...</jaxws:endpoint>
..where service1Impl and service2Impl are beans implementing your service interfaces.
Can you provide more detail about your deployment? Jetty? Tomcat? Something else?
From the docs, it looks like it's as simple as
Endpoint.publish("/service1", new ServiceOneImpl());
Endpoint.publish("/service2", new ServiceTwoImpl());
But I have not tried that myself.

Categories

Resources