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.
Related
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
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.
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.
I am creating a web service with spring + jetty + cxf using the following:
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint id="helloWorld" implementor="com.test.EndpointImp" address="http://localhost:9002/test">
</jaxws:endpoint>
This all works as expected and very well. Now I need to "serve" some servlets. Is there anyway I can get to the jetty Server instance that is created for this, so that I can add the servlets? I dont want to create another Jetty instance on another port just for the servlets I need to use.
Any information will be greatly appreciated.
The solution you are looking for is described in this article. The key points (which I also mentioned in my post) are to use org.apache.cxf.transport.servlet.CXFServlet in your web.xml, don't forget to import META-INF/cxf/cxf-servlet.xml (you did so) and also use relative address="/myservice" attribute. In this case CXF routines will not launch embedded Jetty but use this servlet for processing the inbound requests.
Of course a webapp can handle at the same time some WebServices and servlets.
I suppose your web services are in a web application.
Thus you should have a web.xml (in WEB-INF). You can add your servlets declarations in this web.xml.
Jetty should start your webapp.
We can't help you more if you don't give us more details of your project (Maven based or not, how do you launch Jetty, etc...).
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?