In my application I am trying to expose one soap web service and doing basic operations. This is what I have done:
Created Interface with soap operations as per JAX-WS standard. Added all needed annotations
in WEB.xml added
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/webservices/*</url-pattern>
</servlet-mapping>
created one route
from uri="cxf:/myservice?serviceClass="x.x.x.myInterface&dataFormat=PAYLOAD"
I am able to see the WSDL details in browser (localhost:8080/pro/webservices/myservice?wsdl), but if I hit the service using SOAP UI project my request is not coming through. I'm getting the below error in SOAP UI project:
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>org/apache/cxf/frontend/MethodDispatcher</faultstring>
</soap:Fault>
If I use dataFormat=MESSAGE my service is invoked by SOAPUI and getting response. But my WSDL is not coming in browser. Please tell which dataFormat i have to use in cxf component.
It jar issue. After using latest Jar it is working fine
Related
I was going through a demo project setup for Restful webservice using Apache CXF, where I happened to come by a piece of code inside web.xml:
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
I did not really understand the use of a servlet class in this web.xml. I googled for org.apache.cxf.transport.servlet.CXFServlet and found:
The CXFServlet class, which is defined by Apache CXF, is generated and
registered to handle incoming requests.
Now, I really do not understand what that line means
Does this servlet pose as a front-controller, like in Spring MVC flow?
What is the actual purpose of using this servlet class?
How does CXF use Spring to provide XML configuration of services defined in the project?
Does org.glassfish.jersey.servlet.ServletContainer serve the same purpose in Jersey Implementation as org.apache.cxf.transport.servlet.CXFServlet with Apache CXF?
Help me clarify these questions.
The JAX-RS specification is built on top of the Servlet specification. Each implementation should have a Servlet as an entry point to the application. When a request comes in, it gets processed by that Servlet. CXFServlet is CXF's implementation of that entry point Servlet.
Does this servlet pose as a front-controller, like in Spring MVC flow?
Pretty much. It's analogous to Spring MVC's DispatcherServlet
What is the actual purpose of using this servlet class?
As mentioned above, it's the entry point to the JAX-RS (CXF) application.
How does CXF use Spring to provide XML configuration of services defined in the project?
It uses Spring to wire up components; connect all of them together. But it's not required (see also).
Does org.glassfish.jersey.servlet.ServletContainer serve the same purpose in Jersey Implementation as org.apache.cxf.transport.servlet.CXFServlet with Apache CXF?
Pretty much.
So here I am writing my first REST Service and one thing regarding which my understanding is not clear is that there is an entry for a servlet in my web.xml file as follows:
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
So how is my service using this servlet?As in what's the use of a servlet in a REST Service?Is the service just a framework that uses the servlet's built in HTTP methods?
CXFServlet is one of the transport Apache CXF uses in order to publish rest services. In other words CXF uses under the hood when publishing a Rest services JAXRS annotated (#Path) a simple Java Servlet.
So the final URL where your rest services will be deployed is a concatenation between CXFServlet mapping and your rest services path.
There are other kind of transport. See http://cxf.apache.org/docs/transports.html just to understand that they are more options.
Hope this clarify you.
I developed a GWT application and make a AsyncCallback a jfreechart generated in server side. But there is an error returning a InvocationException.
The detailed error message is here
404 html
com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:209)
callback.onResponseReceived(this, response);
I used GWT 2.5.1 and jre7 and eclipse juno 4.2
My Service Interface, Asynchronous Interface and Implementing Service codes are the same as this example
http://www.jfree.org/phpBB2/viewtopic.php?t=19080&sid=f627bee2b70f0f512009d737957b8eee
I have added servlet in my web.xml
<servlet>
<servlet-name>ChartGenerator</servlet-name>
<servlet-class>com.test.server.ChartGeneratorImpl</servlet-class>
</servlet>
<servlet>
<servlet-name>DisplayChart</servlet-name>
<servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ChartGenerator</servlet-name>
<url-pattern>/comp/ChartGenerator</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DisplayChart</servlet-name>
<url-pattern>/comp/DisplayChart</url-pattern>
</servlet-mapping>
I checked the documentation of RPC and it said
InvocationException can happen for many reasons: the network may be disconnected, a DNS server might not be available, the HTTP server might not be listening, and so on.
My internet is working well.
Any suggestion?
Many thanks!
Helen
Prefix "/context_root" in url pattern defined in web.xml. In your case the url pattern will be "/comp/ChartGenerator".
Use annotation #RemoteServiceRelativePath("ChartGenerator") in RemoteService interface.
I'm trying to send an attachment from JAX-WS/Metro server to a client.
I have a standard Tomcat 7/JDK 6 environment and simple project generated from WSDL with single operation.
Many guides say how to configure MTOM, I added base64Binary type to my response and #MTOM anotation to my service implementation. I did not add anything else.
When I call
public static void main (String args[]){
Endpoint.publish("http://localhost:8080/sampleService", new SampleService()); ;
}
It works fine and I see attachments coming from the server.
Now I want to create a web app that does the same thing.
Here is part of my web.xml
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>SampleService</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SampleService</servlet-name>
<url-pattern>/SampleService</url-pattern>
</servlet-mapping>
I downloaded jaxws-ri dependencies and put them inside Tomcat/lib folder.
Also created the following sun-jaxws.xml in WEB-INF directory:
<?xml version="1.0" encoding="UTF-8"?>
<endpoints
xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"
version="2.0">
<endpoint
name="SampleService"
implementation="com.example.SampleService"
url-pattern="/SampleService"
mtom-enabled="true"
/>
</endpoints>
Notice mtom-enabled property.
Then I deployed it and it works, but MTOM does not work, responses contain inlined Base64-encoded binary data instead of attachments.
The code is exactly the same, the difference is only the way of running it and additional web.xml and sun-jaxws.xml files.
Did I miss something?
I experienced the same problem, eventually I could solve it, in my case the MTOM was disabled because a custom handler serialized the soap message which is not invoked when I used the direct jax-ws service.
So try to disable all the implementation LogicalHandler and SOAPHandler
in our case we set up the handlers in the web service config:
final SpringService springService = new SpringService();
springService.setBean(endpoint);
springService.setHandlers(getHandlers());
where getHandlers was private List getHandlers();
I hope it helps.
I use Jersey and Jackson to implement RESTful services provided by my server. Data is exchanged between the client and server as JSON documents. Jackson does the mapping between the JSON documents and the POJOs. This works well.
But I ran into one issue. When calling a service with a malformed JSON document, the server returns with an 500 error. I would expect a 400 BAD-Request error instead. Some searching in the Jersey docs showed me that ExceptionMappers can be used to archive this behavior. I also found out that Jackson already has a implementation a JsonParseExceptionMapper but it never gets called.
Do I have to register the mapper and if so how can I do this outside of the source code.?
Ok I found out how to register the mapper classes.
In your web.xml where Jersery ServletContainer is registered you have to pass the Jackson package name org.codehaus.jackson.jaxrs beside your package name e.g. com.example.myapp.api;. The server then scans these packages on start up and registers the listener it find.
<servlet>
<servlet-name>Jersey</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.example.myapp.api;org.codehaus.jackson.jaxrs</param-value>
</init-param>
</servlet>