Web Services Tutorial with Apache CXF
I created a web service today with CXF and wanted to share the steps it took to get it up and running in this quick tutorial. Apache CXF was created by the merger of the Celtix and XFire projects. I chose to implement my service in CXF because some colleagues had been using XFire and would likely want to upgrade at some point. I am using the latest version, which is 2.0.4. While the library itself seems to be of high quality, the documentation is still a work in progress. However, do not fret because this CXF tutorial will get you up and running in no time. I will be creating a simple web service that will allow the retrieval of employee information. The service will return this simple POJO (Plain Old Java Object) bean with matching getters and setters:
package com.company.auth.bean;
import java.io.Serializable;
import java.util.Set;
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
private String gid;
private String lastName;
private String firstName;
private Set<String> privileges;
public Employee() {}
public Set<String> getPrivileges() {
return privileges;
}
public void setPrivileges(Set<String> privileges) {
this.privileges = privileges;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getGid() {
return gid;
}
public void setGid(String gid) {
this.gid = gid;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public boolean isUserInRole(String role) {
if(privileges == null) { return false; }
else { return privileges.contains(role); }
}
}
First off, you need to download Apache CXF and drop the necessary .jars in your WEB-INF/lib directory:
aopalliance-1.0.jar
commons-logging-1.1.jar
cxf-2.0-incubator.jar
geronimo-activation_1.1_spec-1.0-M1.jar (or Sun’s Activation jar)
geronimo-annotation_1.0_spec-1.1.jar (JSR 250)
geronimo-javamail_1.4_spec-1.0-M1.jar (or Sun’s JavaMail jar)
geronimo-servlet_2.5_spec-1.1-M1.jar (or Sun’s Servlet jar)
geronimo-ws-metadata_2.0_spec-1.1.1.jar (JSR 181)
jaxb-api-2.0.jar
jaxb-impl-2.0.5.jar
jaxws-api-2.0.jar
jetty-6.1.5.jar
jetty-util-6.1.5.jar
neethi-2.0.jar
saaj-api-1.3.jar
saaj-impl-1.3.jar
spring-core-2.0.4.jar
spring-beans-2.0.4.jar
spring-context-2.0.4.jar
spring-web-2.0.4.jar
stax-api-1.0.1.jar
wsdl4j-1.6.1.jar
wstx-asl-3.2.1.jar
XmlSchema-1.2.jar
xml-resolver-1.2.jar
The first thing which needed to be done was to create the service interface. The service interface defines which methods the web service client will be able to call. It’s pretty standard Java with just two JWS (Java Web Service) annotations thrown in:
package com.company.auth.service;
import javax.jws.WebService;
import javax.jws.WebParam;
import com.company.auth.bean.Employee;
@WebService
public interface AuthService {
Employee getEmployee(@WebParam(name="gid") String gid);
}
The @WebParam annotation is in fact optional, but highly recommended since it will make like easier for the end consumers of your service. Without it, your parameter would be named arg0 making it less clear what parameters your service actually takes.
Implementing the actual service comes next:
package com.company.auth.service;
import javax.jws.WebService;
import com.company.auth.bean.Employee;
import com.company.auth.dao.EmployeeDAO;
@WebService(endpointInterface = "com.company.auth.service.AuthService", serviceName = "corporateAuthService")
public class AuthServiceImpl implements AuthService {
public Employee getEmployee(String gid) {
EmployeeDAO dao = new EmployeeDAO();
return dao.getEmployee(gid);
}
}
I then had to tell Spring (which is used by CXF) where to find my Java classes. I created the following cxf.xml file inside my package directory (com/company/auth/service):
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint id="auth"
implementor="com.company.auth.service.AuthServiceImpl"
address="/cxfAuth"/>
</beans>
Finally, I updated my WEB-INF/web.xml file to let CXF know where my cxf.xml file was and define the CXF servlet:
<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Auth Manager</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:com/company/auth/service/cxf.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<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>
</web-app>
The most frustrating portion of getting the CXF web service up and running was the following exception:
Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.jws.WebService.portName()Ljava/lang/String;
This is due to the fact that I am running WebLogic 9.2, which contains a library with an older version of JSR (Java Specification Request) 181. The quickest solution for me was to prepend geronimo-ws-metadata_2.0_spec-1.1.1.jar to the WebLogic classpath. This will likely not be the solution I choose to implement in the end, but it got me back up and running. It seemed I also had to clear my WebLogic cache for this fix to take effect. Because I often find instances where this seems necessary, I have created a Windows script to clear the Weblogic Cache. If you run into app server related issues, this was one area I found the Apache CXF docs to be helpful.
Also, if you are running Hibernate, you may encounter ASM incompatibilities between Hibernate’s CGLib and the version of ASM which CXF requires. But do not fret because this is easy enough to solve.
Once this was solved, the list of services was available. The context root for my web project is authManager, so my regular web index page is available at http://localhost:7001/authManager/. The list of web services is then automagically generated by CXF at http://localhost:7001/authManager/services/.
The final step is to build the client. This was very easy when compared to getting the server up and running because I was able to simply swipe the code from the Apache CXF documentation. So, without further ado:
package com.company.auth.client;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import com.company.auth.bean.Employee;
import com.company.auth.service.AuthService;
public final class Client {
private Client() {
}
public static void main(String args[]) throws Exception {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setServiceClass(AuthService.class);
factory.setAddress("http://localhost:7001/authManager/services/cxfAuth");
AuthService client = (AuthService) factory.create();
Employee employee = client.getEmployee("0223938");
System.out.println("Server said: " + employee.getLastName() + ", " + employee.getFirstName());
System.exit(0);
}
}
Wow! Wasn’t that cool? (Yes, I’m a dork :o) You should now be up and running with a CXF web service.
If you are looking for something to learn next then may I suggest our tutorial on adding security to your web service. That tutorial will also show you how to setup the client using Spring, which you may find helpful as well.
Thx, great article. Got the juices flowing in the cxf-grinder in no time 😉
Thank you Espen. I’m so happy to hear the CXF tutorial was helpful. As a new blogger, I’m always open to suggestions, so feel free to let me know if there was anything that wasn’t clear enough.
-Ben
Hi Ben
Even if I’m a newbie at webservices I found your tutorial very useful, thanks.
Anyway I have a doubt: everything works just fine if I had a method returning, for example a String. If I try to make it returning an Object (for example an Employee) I get a message about the marshalling process of my bean (Employee).
Any advice?
Thanks, Alessandro
Alessandro,
Glad to hear you’re part way there!
It sounds to me like you’ve encountered a problem serializing your Object to XML. CXF and other web services take your object, turn it into XML, and then transmit it over HTTP as XML. Since it is having trouble turning your Object into XML, there is probably some object member that is not a simple data type or composed of them. You can return your custom Objects composed of standard Java classes as you can see from my example bean above. If your class has something like say a File or BufferedImage in it then it’s a lot less likely that JAXB will know how to turn that into XML. I’d comment out anything that’s not a standard data element and see if it works. Adding them back in one at a time, you should be able to see which cause you problems. If that’s what’s wrong then a good place to start in the documentation would be http://cwiki.apache.org/CXF20DOC/databindings.html If you’re really unable to turn your objects into XML, then CXF can handle other bindings like CORBA, but I’m not sure that any of that is out of the box yet. I think JAXB and Aegis are the two supported right now with XMLBeans, Castor, and JiBX to come in CXF 2.1. There’s some integration with Yoko I believe, but that’s not an area I’d be able to help with.
Ben,
thanks for your very quick reply.
Yes, my problem is that CXF can’t serialize my class to XML, and the error I get is
‘org.apache.cxf.interceptor.Fault: Marshalling Error: SdrProcess is not known to this context’.
I’m tryin’ to make CXF marshalling automatically by putting annotation in my class, like follows:
I’m expecting CXF to do the marshalling by itself, am I right or am I missing some configuration?
I’m not putting the class full qualified name (w/package). is it maybe that?
I’m not sure about the link you posted about the wiki: it doesn’t work, are you sure it is that?
Thanks a lot!
Alessandro
is it possible to post the source up here?
Dom,
Which source specifically do you want to see? Basically all of the source code is already in the post.
Alessandro,
You DO need the fully qualified class name of your service implementation in the cxf.xml Spring configuration file. You also, DO need the fully qualified class name of your service interface when specifying the endpoint interface in your service implementation.
You don’t need any annotations in your bean for CXF. It will work correctly with just a POJO (Plain Old Java Object). However, I don’t think CXF will like having only getters. If I remember correctly, you need to have matching getters and setters.
Also, I corrected the link in my previous comment.
-Ben
Hi ben , just the employees stuff, i am getting an error saying : org.apache.xbean.propertyeditor.PropertyEditorException: Value is not an instance of Map
thanks for spending the time to write all of this.
Dom
Dom,
I added the code for my bean to the post. As I stated, it really is just a simple POJO.
I’m not sure where you are getting the error you mentioned, but I’d make sure whatever method you call in the stack trace that is expecting a Map is actually being passed a class which implements the Map interface such as a HashMap.
-Ben
Would you be able to post your DAO up as well? Sorry i am very new to this and i am just trying to get a working example. My lastest error that i am getting is : Non-default namespace can not map to empty URI (as per Namespace 1.0 # 2) in XML 1.0 documents. Any thoughts would be geat 🙂
here what i have done for my DAO.
Hi Dom,
I’ve edited a few lines in your comment to fix some null pointer exceptions that would occur if your code was run so as not to confuse other people that might see it. You might want to update your DAO using the corrections.
-Ben
[…] cover adding an authentication component to your web service though WS-Security. If you need an overview of how to setup CXF then you may find our previous tutorial helpful. Another helpful resource is CXF’s own […]
I’m getting exactly the same thing as Alessandro regarding marshalling. The root cause is
Caused by: javax.xml.bind.JAXBException: com.xyz.SimpleComment is not known to this context
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:538)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:82)
… 37 more
I get it when trying to return a List of complex types (in this case, a List of SimpleComments). If I return a List of Strings then there’s no problem. I tried Ben’s suggestion above regarding removing properties from the SimpleComment–in fact I removed everything except a single String property–but no luck. Just curious whether other people are running into this when trying to return a complex type.
I would think your best bet is to look into other data bindings as I mentioned earlier. I tried to get Aegis working today, but didn’t have any luck. I’ll try a bit more and update you if I get it working. In the meantime, would you be able to use a Set instead of a List? A Set worked for me using JAXB and unless the ordering matters to you that might be a quick fix.
Hi Ben,
Thanks for the good tutorial. I wanted to know how can we do logging of soap request and response using CXF. using configuration files. I used following url ( http://cwiki.apache.org/CXF20DOC/configuration.html ) to do it through configuration but it gives me following exception. Please let me know what iam doing wrong
INFO: Load the bus with application context
20 Feb 2008 20:27:19,653 ERROR [[/MyCXFWebservice],] StandardWrapper.Throwable
java.lang.NullPointerException
at org.apache.cxf.transport.servlet.CXFServlet.loadSpringBus(CXFServlet.java:104)
at org.apache.cxf.transport.servlet.CXFServlet.loadBus(CXFServlet.java:63)
at org.apache.cxf.transport.servlet.AbstractCXFServlet.init(AbstractCXFServlet.java:86)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1139)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:966)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3956)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4230)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:825)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:714)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:490)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:448)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
I found someone else on the mailing list getting your same error. Here was his fix: “I just tried copying the xml files I’m importing in spring.xml into my WEB-INF/classes directory. This fixed the NullPointerException (not sure why it couldn’t find them with the default imports on the classpath).” So I’d check if you’re having a classpath issue.
If you’d like another example, you can see that I added logging in a similar manner in my Spring WS-Security post: http://www.lumidant.com/blog/apache-cxf-tutorial-ws-security-with-spring/
Thanks Ben for the suggestions. I will give the Set and Aegis ideas a try and see what happens. If I have any luck I’ll report back.
Hi Ben,
Thanks for your response i used ur example and it worked fine but i cannot see the <soap> message in the log file do i need to add anything in order to view ?
thanks in advance
Sada
Ben–your suggestion to use Aegis worked great. Thanks dude.
p.s. You mentioned that you didn’t get Aegis working. Let me know if you need help with that. Here’s what I put in my Spring config:
Great Blog!! Hope you come out with more such example based articles.
I had a question on Interceptors. I wrote my custom outboundInterceptor. I am trying to get the soap envelope message and log it to a custom logger.
But all my attempts have failed. Turning to you for some help.
Hi Rama,
I’m afraid I have not created any custom interceptors yet. However, setting up the logging interceptors provided with CXF is relatively easy and might be worth a look. There’s an example of it in the tutorial on this blog which covers CXF with Spring enabled WS-Security.
-Ben
Thanks for your response. I did some research and found a way to do it. Actually the Nabble forum on CXF is a wonderful resource. The reason my buffer was empty was because i accessed the buffer before the caching from outputstream could complete. So I had to write a LoggerCallback as illustrated in the Nabble forum. So here is what I did..
Thanks for your example Rama! Also, I’ll second the Nabble forums being a great resource for CXF. Some of the developers hang out there and have been quite helpful.
I mentioned Aegis to a few people and it sounds like it’s been pretty promising, so I may update the tutorial soon with some Aegis tips. There’s an Aegis bug that’s stopping me from getting it up and running in my environment. However, Dan Kulp and Benson Margulies have been absolutely great in helping me out and I’m expecting a fix at some point. Regarding the test case I sent him, Dan says:
When developing a web service this way, does it not create a wsdl file? I’ve tried starting with a class and running java2wsdl but no luck, I keep getting the following exception : org.apache.xerces.dom.DocumentImpl.getInputEncoding()Ljava./lang/String; I need to have a wsdl because that is what we will publish to our clients. Any idea what is going on?
Yes, CXF does generate a wsdl. You do not need to run java2wsdl. Simply visit your equivalent of http://localhost:7001/authManager/services/
I am working on a project to call web services from VBScript code of an Outlook form. Do you have any suggestions for useful links or any samples?
thanks
Mansour
(I sent the following after I read your article above but I sent it to a different thread by mistake. So here I copy that)
Thanks. It was very helpful. I had been reading about CXF for the past four or five hours when I found your article. Things came together after that. It was clear and easy to understand. Being a professional requires you to be able to transfer your knowledge efficiently and in a simple way. And it shows you are one.
Mansour
Thanks for the great blog.
I am hoping someone reading this will be able to help me.
I am returning a List from my webservice. The response (sans the headers) look like this:
…SomeObject1
…SomeObject2
without a root element. How do I add a root element to my response?
Any help appreciated.
Hi,
I am trying to use CXF (2.0.5) as a web service client, on weblogic 9.2.
I managed to run the client as a standalone, but when I add the relevant CXF jars to the classpath of weblogic I get the below exception, since you managed to deploy can you please assist or state exactly what were your steps in making it work.
Thx
Ron
#### <>
#### <>
#### <>
#### <>
#### <> <[WebAppModule(bea_wls_internal:bea_wls_internal.war)] Error parsing descriptor in Web appplication “D:\csc_75\config\cscjmsdomain\servers\cscjmsserver\tmp\.internal\bea_wls_internal.war”
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(String.java:558)
at weblogic.servlet.internal.WebAppReader2.getText(WebAppReader2.java:160)
at weblogic.application.descriptor.BasicMunger2._onDTD(BasicMunger2.java:485)
… more
Hi,
I am newbie to Apache-CXF. I need a basic tutorial. Also give me a complete idea of the above code. How to run it and test it.
Thanks in Advance
Hi Baskar,
This was meant to be a tutorial for those who had never used CXF before, so let me know if there is a particular portion that is not clear. Do you have much experience with Java in general?
As far as running and testing the code is concerned, to run the server-side portion you should create a web project, deploy it to your server, and then start the server. The server-side portion will start up along with your web application because of the servlet mapping that I showed how to create in your web.xml. You can the run the client by running the main method that I included in the example Client class, which will contact the server to get some data.
Hi Ben,
Thanks for your prompt reply. I managed to run it successfully. Will get back to you if i need further help from you. Also send me some good PDF or tutorial to dig into details about Apache CXF.
Thanks in Advance,
Baskar.S
Hi Ben,
You have given an example for Java to WSDL. Can you provide an example for WSDL to java?
Thanks,
Baskar.S
Hi Baskar,
I’d recommend you check out the CXF wiki docs.
-Ben
Hi,
I am newbie to Apache-CXF. I am trying to use it but I have encountered some problems with the binding. Each time I try to send a message, I obtain the following exception:
org.apache.cxf.interceptor.Fault: Couldn’t instantiate class. constant manager.business.model.dtos.ConstantFilterDTO. Nested exception is java.lang.InstantiationException: constantmanager.business.model.dtos.ConstantFilterDTO
…
Caused by: org.apache.cxf.aegis.DatabindingException: Couldn’t instantiate class
constantmanager.business.model.dtos.ConstantFilterDTO. Nested except
Can you help me?
Thanks in Advance,
Diego A.
PD.
How can I be sure CXF is using Aegis for the binding. Now I am forcing the client with the line:
factory.getServiceFactory().setDataBinding(new AegisDatabinding());
But I am not sure whether the application in the server is correctly configured .
Hi,
I deployed this Apaxhe CXF example in Tomcat and ran it successfully. But i would like to deploy the same in JBoss. I am new to JBoss. Can anyone help me to deploy the above Apache CXF example in JBoss and test the same.
Thanks,
Baskar.S
Hi people,
I tried to run this tutorial and got exception like:
2008-06-19 16:31:28,687 ERROR [] org.springframework.web.context.ContextLoader – Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘auth’: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: com/sun/xml/bind/marshaller/NamespacePrefixMapper
Caused by: java.lang.NoClassDefFoundError: com/sun/xml/bind/marshaller/NamespacePrefixMapper
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.createDefaultDataBinding(ReflectionServiceFactoryBean.java:173)
at org.apache.cxf.service.factory.AbstractServiceFactoryBean.getDataBinding(AbstractServiceFactoryBean.java:56)
at org.apache.cxf.frontend.ServerFactoryBean.applyExtraClass(ServerFactoryBean.java:201)
at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:104)
at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:160)
at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:322)
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:244)
at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:194)
at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:380)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
…
Any idea?
Regards,
Mandish
Hi Mandish,
It looks like you’re missing a jar file. I’d guess that class is contained in the JAXB jar or similar.
-Ben
I follow your tutorial , it was built successfully and I got the wsdl generated at http://localhost:8080/WebApplication5/services/swAuth?wsdl . but when I tried to run the client program it gave me errors like :
og4j:WARN No appenders could be found for logger (org.apache.cxf.bus.spring.BusApplicationContext).
log4j:WARN Please initialize the log4j system properly.
Jul 29, 2008 1:52:20 PM org.apache.cxf.bus.spring.BusApplicationContext getConfigResources
INFO: No cxf.xml configuration file detected, relying on defaults.
Jul 29, 2008 1:52:24 PM org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
INFO: Creating Service {http://service.auth.company.com/}AuthServiceService from class com.company.auth.service.AuthService
Jul 29, 2008 1:52:26 PM org.apache.cxf.interceptor.LoggingOutInterceptor$LoggingCallback onClose
INFO: Outbound Message
—————————
Encoding: UTF-8
Headers: {SOAPAction=[“”], Accept=[*]}
Messages:
Payload: 0223938
————————————–
Jul 29, 2008 1:52:26 PM org.apache.cxf.interceptor.LoggingInInterceptor logging
INFO: Inbound Message
—————————-
Encoding: UTF-8
Headers: {Content-Length=[227], X-Powered-By=[Servlet/2.5], Date=[Tue, 29 Jul 2008 08:22:26 GMT], Server=[Sun Java System Application Server 9.1_01], content-type=[text/xml;charset=UTF-8]}
Messages:
Message:
Payload: soap:ServerFault occurred while processing.
————————————–
Exception in thread “main” javax.xml.ws.soap.SOAPFaultException: Fault occurred while processing.
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:199)
at $Proxy43.getEmployee(Unknown Source)
at com.company.auth.client.Client.main(Client.java:25)
Caused by: org.apache.cxf.binding.soap.SoapFault: Fault occurred while processing.
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:70)
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:35)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:221)
at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:96)
at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:65)
at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:221)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:449)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1996)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1832)
at org.apache.cxf.io.CacheAndWriteOutputStream.postClose(CacheAndWriteOutputStream.java:47)
at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:159)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:591)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:221)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:296)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:242)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:178)
… 2 more
Java Result: 1
BUILD SUCCESSFUL (total time: 11 seconds)
can you enlighten what has happened ?
Yelena,
There was an exception on the server side (“Payload: soap:ServerFault occurred while processing.”). You should investigate further there. What you posted is the client output, which does help point in the right direction since it tells you to look at the server, but ultimately won’t get you to the final answer
-Ben
Yelena
The fault exception you are seeing might be from the buggy EmployeeDAO object that Dom posted. Employee was only declared but never created. Privileges was also only declared but never created. Good work Ben.
Hi Bhaskar/Ben,
Can you let me know how you run client from eclipse. My service is up and running on server but when I run my Client program as “Run on server” getting bellow error message. I tried to run as “Run as Java application” but no luck.
please let me know how to run client to access employee services.
Error:
Encoding: UTF-8
Headers: {SOAPAction=[“”], Accept=[*]}
Messages:
Payload: 0223938
————————————–
Oct 29, 2008 7:42:48 AM org.apache.cxf.phase.PhaseInterceptorChain doIntercept
INFO: Interceptor has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Could not send Message.
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:296)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:242)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:178)
at $Proxy43.getEmployee(Unknown Source)
at com.company.auth.client.Client.main(Client.java:25)
Caused by: java.io.IOException: Not Found
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1962)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1865)
at org.apache.cxf.io.CacheAndWriteOutputStream.postClose(CacheAndWriteOutputStream.java:47)
at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:170)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:593)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
… 7 more
Exception in thread “main” javax.xml.ws.soap.SOAPFaultException: Could not send Message.
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:199)
at $Proxy43.getEmployee(Unknown Source)
at com.company.auth.client.Client.main(Client.java:25)
Caused by: org.apache.cxf.interceptor.Fault: Could not send Message.
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:296)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:242)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:178)
… 2 more
Caused by: java.io.IOException: Not Found
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1962)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1865)
at org.apache.cxf.io.CacheAndWriteOutputStream.postClose(CacheAndWriteOutputStream.java:47)
at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:170)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:593)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
… 7 more
can you let me know how you deployed on outside server Tomcat and accessed services using this client. Out side means outside eclipse tomcat server.
Thanks
eduser
Hi Eduser,
You should choose “Run as Java Application”. “Run on Server” is meant for running a servlet.
I’m not sure from the stack trace you posted exactly what your problem is. Perhaps you can try the cxf-user mailing list: http://www.nabble.com/cxf-user-f16914.html
-Ben
Thanks for reply Ben….
I tried to run like that also “Run as Java Application” but no luck getting same as above error message.
is there any specific procedure we need to follow to run client to access this webservice?
Thanks
eduser
Hi Eduser,
All you should need to do is run the service on an application server such as JBoss or Tomcat and then run the client like a normal Java program.
Thanks for this tutorial. It worked for me.
Cheers,