In this tutorial I explain how to get a web service up and running using Spring 2.5 and Apache CXF 2.0, which is the combination of Celtix and XFire and is considered XFire 2.0. (I don’t know what the Celtix team would say about that, but that’s what the XFire site says.) Here I just treat the web service itself; to learn about consuming the web service using Spring and CXF, please see the article Make web services transparent with Spring 2.5 and Apache CXF 2.0.
CXF supports both WSDL-first and Java-first web service development. This article takes the Java-first approach.
Project setup
The first thing you’ll need to do is download CXF from the Apache CXF site. At the time of this writing the project is in incubator status and the latest version is 2.0.4. That’s the version I’m using.
You’ll also find it useful to know about the section of the CXF user documentation that deals with writing a service with Spring, but currently the docs describe how to integrate with Spring 2.0, and since I want to integrate with Spring 2.5, there are some differences worth highlighting along the way.
Also, the docs describe a “Hello, World” web service that just returns a string, and in this tutorial we want to go a little further than that and actually do a class databinding.
Here are the service-side dependencies you’ll need. Inside the distribution there is a file called WHICH_JARS that describes in a little more detail what the JARs are for and which ones you’ll really need, if you’re interested in that. But the following is essentially the list given in the user docs.
CXF itself
cxf-2.0.4-incubator.jar
CXF dependencies
Note that for CXF 2.0.4 the documented dependencies are almost but not quite the same as the JARs that are actually included in the distribution, once again, at the time of this writing (February 2008). Specifically the stax, neethi and XMLSchema JARs are not the ones listed. Here’s the corrected list for CXF 2.0.4:
commons-logging-1.1.jargeronimo-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-stax-api_1.0_spec-1.0.jargeronimo-ws-metadata_2.0_spec-1.1.1.jar (JSR 181)jaxb-api-2.0.jarjaxb-impl-2.0.5.jarjaxws-api-2.0.jarneethi-2.0.2.jarsaaj-api-1.3.jarsaaj-impl-1.3.jarwsdl4j-1.6.1.jarwstx-asl-3.2.1.jarXmlSchema-1.3.2.jarxml-resolver-1.2.jar
Aegis dependencies
In addition to the above, you will need to add jdom-1.0.jar since Aegis databinding uses it.
Spring dependencies
In this case ignore what’s in the CXF documentation, because we’re integrating with Spring 2.5 instead of Spring 2.0. I’m going to assume that you have Spring 2.5 already set up on your web services project, including Hibernate or anything else that your web services will need on the implementation side.
Just in case you were wondering, you don’t need the Spring MVC module’s DispatcherServlet as CXF comes with its own servlet, org.apache.cxf.transport.servlet.CXFServlet.
OK, that should be good for basic project setup. Let’s write a simple service.
Let’s write a simple web service
Let’s go basic but realistic and implement a “contact us” web service. The idea is that lots of different applications and/or web sites need to have a web-based form to allow end users to contact an admin team (business, tech support, development, whatever) responsible for monitoring such communications. We’ll implement a web service so that multiple applications can share it easily. There will be two operations:
- View the list of submitted messages: This allows the admin team to see what the end users are saying.
- Post a message: This allows end users to ask a question, tell us how great we are, demand their money back, etc.
Create the object model
As we want to explore more than the barest “Hello, World” functionality, let’s create a Message class that we can pass to the service and that we can get from the service. This will allow us to play a bit with Java/XML databindings.
Here’s the Message class:
package contactus;
import org.apache.cxf.aegis.type.java5.IgnoreProperty;
public final class Message {
private String firstName;
private String lastName;
private String email;
private String text;
public Message() { }
public Message(String firstName, String lastName, String email, String text) {
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.text = text;
}
public String getFirstName() { return firstName; }
public void setFirstName(String firstName) { this.firstName = firstName; }
public String getLastName() { return lastName; }
public void setLastName(String lastName) { this.lastName = lastName; }
@IgnoreProperty
public String getLastNameFirstName() { return lastName + ", " + firstName; }
public String getEmail() { return email; }
public void setEmail(String email) { this.email = email; }
public String getText() { return text; }
public void setText(String text) { this.text = text; }
}
In real life I might have a bunch of Hibernate annotations in there (I’m a fan of annotation-based configuration), and I would create a DAO. But as this is a tutorial, we’ll keep it simple.
If you look carefully, however, you can see that I did in fact include an annotation. The @IgnoreProperty annotation is part of the Aegis databinding mechanism, which comes with CXF but is not the default. (JAXB is the default.) I ended up using Aegis instead of JAXB because JAXB was giving me trouble when I tried to return complex data types like Message from a web service. Maybe it works and maybe it doesn’t—I don’t know—but when I plugged Aegis in it worked immediately and now I intend to use Aegis. (More on JAXB/Aegis a little later.) Anyway, @IgnoreProperty tells Aegis that I don’t want getLastNameFirstName() to show up in the auto-generated WSDL. It’s just a read-only convenience method.
Create the service interface
Now we define a service interface.
package contactus;
import java.util.List;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService
public interface ContactUsService {
List<Message> getMessages();
void postMessage(@WebParam(name = "message") Message message);
}
The @WebService and @WebParam are JAX-WS annotations. The first indicates that the interface defines a web service interface (we’ll use it to autogenerate a WSDL) and the second allows us to use an HTTP parameter called “message” to reference the operation’s argument instead of having to call it “arg0″, which is the default.
Create the service implementation
Here’s our simple implementation of the ContactUsService interface.
package contactus;
import java.util.ArrayList;
import java.util.List;
import javax.jws.WebService;
@WebService(endpointInterface = "contactus.ContactUsService")
public final class ContactUsServiceImpl implements ContactUsService {
@Override
public List<Message> getMessages() {
List<Message> messages = new ArrayList<Message>();
messages.add(new Message(
"Willie", "Wheeler", "willie.wheeler@xyz.com", "Great job"));
messages.add(new Message(
"Dardy", "Chen", "dardy.chen@xyz.com", "I want my money back"));
return messages;
}
@Override
public void postMessage(Message message) {
System.out.println(message);
}
}
Here the @WebService annotation is marking this class as a web service implementation, and also specifying that the WSDL should be generated using the ContactUsService interface.
With that, we have the Java backend for the web service. Let’s move on to configuration.
Configure your web service
We need to create web.xml and a Spring application context file.
web.xml configuration
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="services" version="2.5">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/appContext.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>/*</url-pattern>
</servlet-mapping>
</web-app>
Nothing surprising here. The main thing worth mentioning is that we’re using the CXFServlet to process all requests, which we’re assuming are all requests for web services.
As you might guess from the web.xml file above, we need to create a Spring application context file called appContext.xml.
appContext.xml configuration
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:cxf="http://cxf.apache.org/core"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"
default-autowire="byName">
<!-- Load CXF modules from cxf.jar -->
<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" />
<!-- Enable message logging using the CXF logging feature -->
<cxf:bus>
<cxf:features>
<cxf:logging/>
</cxf:features>
</cxf:bus>
<!-- The service bean -->
<bean id="contactUsServiceImpl" class="contactus.ContactUsServiceImpl"/>
<!-- Aegis data binding -->
<bean id="aegisBean"
class="org.apache.cxf.aegis.databinding.AegisDatabinding"
scope="prototype"/>
<bean id="jaxws-and-aegis-service-factory"
class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"
scope="prototype">
<property name="dataBinding" ref="aegisBean"/>
<property name="serviceConfigurations">
<list>
<bean class="org.apache.cxf.jaxws.support.JaxWsServiceConfiguration"/>
<bean class="org.apache.cxf.aegis.databinding.AegisServiceConfiguration"/>
<bean class="org.apache.cxf.service.factory.DefaultServiceConfiguration"/>
</list>
</property>
</bean>
<!-- Service endpoint -->
<!-- See http://incubator.apache.org/cxf/faq.html regarding CXF + Spring AOP -->
<jaxws:endpoint id="contactUsService"
implementorClass="contactus.ContactUsServiceImpl"
implementor="#contactUsServiceImpl"
address="/contactus">
<jaxws:serviceFactory>
<ref bean="jaxws-and-aegis-service-factory"/>
</jaxws:serviceFactory>
</jaxws:endpoint>
</beans>
Let’s talk about appContext.xml.
The first three imports just import some bean definitions from the CXF JAR file. I don’t know the details and I don’t think we’re supposed to care about the details.
The bus config just puts logging in. That’s optional. If you run this in a production environment you probably want to turn that off because it’s verbose.
The service bean definition is just telling Spring about the service bean we wrote. We’re going to put a web service endpoint in front of it.
The next piece on Aegis specifies the databinding mechanism we want to use for mapping back and forth between Java and XML. I mentioned earlier that I tried using the default JAXB but was having problems getting it to work, so someone recommended to me to try Aegis and that worked like a charm.
Finally we define the web service endpoint. The #contactUsServiceImpl piece connects the endpoint up to the service bean. (Yes, the hash mark is required.) We use the JAX-WS/Aegis service factory that we defined earlier so we can use the Aegis databinding.
I’m not using transactions or persistence in my simple service bean. In a realistic service you are going to have transactions and persistence. To make CXF play nicely with AOP (and hence Spring’s declarative transactions) you are going to need to include the implementorClass attribute as I’ve done. For more details on that see the CXF FAQs at http://incubator.apache.org/cxf/faq.html.
A validation annoyance in Eclipse
Though it in no way reflects a fault with Eclipse itself, if you are using Eclipse 3.3 you may be getting some annoying validation errors in the IDE, such as “cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'jaxws:endpoint'.” This is because the schema locations for the http://cxf.apache.org/core and http://cxf.apache.org/jaxws keys don’t actually point at real XSDs, so the validator won’t recognize elements from the cxf and jaxws namespaces. (That’s why I say it isn’t Eclipse’s fault.) This doesn’t create a problem with the actual build, but the IDE will complain as it tries to validate the Spring app context files against the missing XSDs. I haven’t yet discovered the “right” solution to this problem (I’d be delighted to have somebody tell me) but there are three workarounds I know about:
- You can map the
http://www.springframework.org/schema/beanskey to thehttp://www.springframework.org/schema/beans/spring-beans.xsdlocation (notice that I’ve removed the-2.5part). That gets rid of the validation errors though now you’re using the Spring 2.0 beans schema. That may be OK for you. - You can turn off XML validation. That seems pretty drastic but it’s an option (and in fact it’s what I’ve myself done).
- You can just ignore the errors. Can’t… bring… myself… to… do… it… .
There may be something you can do with Window → Preferences → Web and XML → XML Catalog but I didn’t see it: even if you put the core.xsd and jaxws.xsd in the catalog, those XSDs in turn reference other schema locations that don’t resolve to an XSD and it looks like a lot of work to me.
Anyway as I say if somebody knows the right way to handle this please let me know and I’ll gladly update the article and credit you. :-)
Let ‘er rip
At this point you should have a working web service. Try it out. The URLs are:
[path to CXFServlet]– List of web services[path to CXFServlet]/contactus?wsdl– WSDL for the Contact Us service[path to CXFServlet]/contactus/getMessages– getMessages operation. Take a look at
this and notice that, as promised, the individual messages don’t contain the
firstNameLastNameproperty, since we told Aegis to@IgnoreProperty.[path to CXFServlet]/contactus/postMessage?message=...– postMessage operation
So for example if you are running an out-of-the-box Tomcat instance then your URLs would be
http://localhost:8080/mywebserviceshttp://localhost:8080/mywebservices/contactus?wsdlhttp://localhost:8080/mywebservices/contactus/getMessageshttp://localhost:8080/mywebservices/contactus/postMessage?message=...
replacing mywebservices with whatever you happened to use for your context root.
That’s it! If you want to learn how to consume web services using Spring 2.5 and CXF, please see my follow-up article Make web services transparent with Spring 2.5 and Apache CXF 2.0.
Update (2008-09-03): Sam Brodkin was kind enough to create a Maven project for this article. Thanks Sam!

By Roger March 12, 2008 - 12:55 pm
Great tutorial — Used NB 6.0.1 and deployed into Glassfish V2 aok
Thank you
By Cristian Caprar March 21, 2008 - 8:29 am
Tutorial is ok but quite shallow information. Besides, it does not run with cfx-2.0.4 and spring-2.5.2 (known issue in cxf, solved in 2.0.5 snapshots).
Thank you.
By Willie Wheeler March 22, 2008 - 11:49 am
Thanks for the feedback guys, and @Cristian, thanks for the heads-up about Spring 2.5.2.
By Makarand April 4, 2008 - 1:13 pm
Awesome tutorial, had it working and debugging with Eclipse3.3, CXF2.0.5,Spring 2.5.2 with Tomcat5.5
Thank you
By Rajesh Pollepalli April 18, 2008 - 12:32 pm
This is great stuff/Good article.
Thank You
By Richard April 23, 2008 - 2:13 am
The attribute default-autowire=”byName” caused this example to fail for me.
By Gergely Kontra April 24, 2008 - 9:21 am
Hi!
Note: I am a beginner for CXF and Spring.
What I would like to know how one should start the webservice?
If using just CXF, there is a class with main method (e. g. here: http://svn.apache.org/repos/asf/incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/Server.java)
What is the case here?
What choices do I have?
thanks
By Prasannarupan April 24, 2008 - 9:21 am
Hi Willie,
this is my first web service application example in Java & I like the way you have put the tutorial in simple terms so that a beginner like me can understand it clearly as well.
I have a doubt though, can I pass parameters to postMessage method & if so how?
Please provide me the way to pass parameters in the URL.
Thanks
Cheers
prasannarupan
By Prasannarupan April 24, 2008 - 9:30 am
Hi Willie,
I also noticed the use of @overide annotation.
What is the purpose of it?.Is it a typo?
I also got a warning from Eclipse & I couldnt access the getMessages method when @override annotation was used when I deployed the application on JBoss AS 4.2.2GA.
I removed the annoation & the application is working fine now.
Thanks
prasanna
By Willie Wheeler April 24, 2008 - 2:11 pm
@Makarand and Rajesh: Thanks!
@Richard: Not sure why that is happening for you. If you provide more information I might be able to help. At any rate the autowiring part is optional. If you are having problems with that you can always manually wire the beans.
@Gergely: In my article, the web service is just part of a web application, so you would start it in your web container (e.g. Tomcat). As to the example you reference, that uses the JAX-WS Endpoint API to publish the web service. The idea is that it starts up a lightweight web server to host your web service. Here is a link for you:
http://weblogs.java.net/blog/jitu/archive/2006/01/web_service_end.html
@Prasannarupan: Glad you found the tutorial useful. As far as passing parameters to postMessage(), I’m not sure I’m following your meaning. We are in fact passing an argument to postMessage–namely, the Message object itself. The client doesn’t know that ContactUsService is backed by a web service and in particular it doesn’t know that HTTP parameters are involved at all (if that’s what you’re asking). Can you describe more generally what you are trying to do?
As far as @Override goes, it wasn’t a typo, but you are right to remove it. @Override tells the compiler that the method is supposed to override a method in an interface or a base class. (So if the compiler doesn’t find the overridden method, it complains. This helps avoid cases where you think you overrode a method but you really didn’t, like if you implement hashcode() instead of hashCode(), etc.) In Java 5 you can’t use @Override when the method in question is an interface method; it works only for methods defined in a base class. In Java 6 you can use @Override in either situation. I am using Java 6 in the article and I neglected to say anything about that. Thanks for highlighting this.
By Gergely Kontra April 25, 2008 - 2:44 am
Hi Willie!
Thanks for the quick reply.
Ok, the article shows how to do a web server, but spring is still not involved…
Since it may take up just a few lines of code, is it possible to complete the tutorial to a fully working example, or I’m just the only one who needs this extra.
By Willie Wheeler April 25, 2008 - 2:49 am
Hi Gergely. The tutorial’s example should be a fully working example :-) though the downloads are in my other Spring/CXF article (the second in the series) at
http://wheelersoftware.com/articles/spring-cxf-consuming-web-services-4.html
One of the links under Resources is the web service (i.e. the example in this article) and the other is the client code. You’ll need to grab the dependencies yourself but those are listed in the article itself. Let me know if you aren’t able to get the example to run.
By Willie Wheeler April 25, 2008 - 3:02 am
By the way, Gergely, I may be misunderstanding you when you say “spring is still not involved”, but in my article, Spring is very much involved. We’re using Spring to wire up the beans and (importantly) to abstract the service implementation, among other things. Then we’re taking the resulting web app (well, web services in this case, but bundled in a WAR) and dropping that into Tomcat or whatever servlet container you like.
The nice thing about Spring + CXF here is that as far as your application is concerned, it’s just working with service beans. It has no knowledge that the service beans are actually web service proxies. You can very easily replace web service remoting with some other remoting mechanism (e.g. RMI, Hessian, Burlap, HttpInvoker) and you don’t have to change the app at all–just the Spring config.
The app doesn’t even know that the service beans are making remote calls, so you can replace the web service proxies with the actual web service implementation bean and the app doesn’t know. In fact I did exactly that when I wrote the code for the comment service on this very web site. Originally I was making web service calls to a CommentService I wrote, and then I decided that there was no point and simply replaced the web service calls with a local service bean. Worked perfectly. :-)
By Gergely Kontra April 25, 2008 - 6:33 am
Hi!
Well, the problem for me is (maybe just for me…): who will know web.xml must be read and parsed, and where is this piece of information in the code?
ui: I said I’m a beginner in this area.
By the way, with using a Server.java, which is here:
[http://pastebin.com/m5204fe28]
The output of the program looks like this (exception at startup):
[http://pastebin.com/m6366ff96]
By Willie Wheeler April 25, 2008 - 11:59 am
Hi Gergely. It looks like you are trying to use the approach at
http://cwiki.apache.org/CXF20DOC/a-simple-jax-ws-service.html
which does not involve Spring or even a WAR. (So there is no web.xml involved with that.) That approach is not directly related to my article.
You might take a look at
http://cwiki.apache.org/CXF20DOC/writing-a-service-with-spring.html
instead, which is one of the other CXF 2.0 howtos (and it happens the one on which my article is based).
By alperen May 6, 2008 - 5:46 am
Hi,
it seems very usefull tutorial but when i try to do what you did, i got following exception
14:16:30.292 INFO [main] org.apache.cxf.aegis.type.XMLTypeCreator.<clinit>(XMLTypeCreator.java:125) >46> Parser doesn’t support setSchema. Not validating.
java.lang.UnsupportedOperationException: This parser does not support specification “null” version “null”
at javax.xml.parsers.DocumentBuilderFactory.setSchema(DocumentBuilderFactory.java:489)
i could not get rid of this problem.
By Alex Khvatov May 9, 2008 - 1:36 pm
When using Spring 2.4, Tomcat 6 and CXF 2.1 you need to add jaxen library to you classpath ortherwise AegisDatabinding bean won’t be created.
By Federico A. Ocampo May 14, 2008 - 12:45 pm
Man you saved my life… at least my work life. I’ve been working with CXF for a month without getting any test running well but simple services which return basic data types. When I’ve read your post I’ve realized about the JAXB problem with complex types and then I’ve took all necessary beans and Aegis configurations from your tutorial and my little service has worked!
Thanks a lot. Greetings from Argentina
PS: sorry about my english, it’s quite poor yet ;)
By Willie Wheeler May 15, 2008 - 1:08 am
@Federico: Really happy to hear that the article helped you. And your English is fine. A lot better than my Spanish. :-D
By Scott May 24, 2008 - 7:27 am
Thanks for putting this tutorial together. Was very helpful.
By Willie Wheeler May 24, 2008 - 7:28 am
I was just reading through the article and the bottom of page 3 mentions a validation annoyance in Eclipse. I checked to see whether the CXF team had yet posted the core and jaxws schemas to the specified schema locations and the answer is yes. So the validation annoyance I mentioned should not be a problem anymore. (Maybe it will still come up if you aren’t on the Internet but other than that…)
By Willie June 5, 2008 - 2:28 am
Willie, although CXF have posted those schemas to the sites, it still causes an issue if the machine that CXF + Spring 2.5 is behind a proxy with no access to the outside world. I do have a solution that I have used for Spring 2.5 in the past for other Schemas, and once I have tested that it works with this, I will post the answer here and on my blog.
By yelena July 28, 2008 - 4:23 am
I am using netbeans 6.0.1 added the jar files in the libraray and also using glassfish V2 server , and got the following errors while running the application .
Deployment error:
The module has not been deployed.
See the server log for details.
at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:163)
at org.netbeans.modules.j2ee.ant.Deploy.execute(Deploy.java:104)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor106.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
By tmaus July 29, 2008 - 3:19 am
nice doc .. thanks ..
running into a problem after deploying app on tomcat.
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element ‘cxf:bus’
The declarations inside my spring-beans.xml are 100% correct.
Error occurs on both, the ctx suffix as well as the jaxw suffix.
Using spring 2.5.5 and cxf 2.1 (tried older versions as well).
Manually added jdom 1.0 to maven build.
Was wondering if anyone stepped into same problems before .. thanks
By Alex August 4, 2008 - 9:50 am
Hi Willie,
Can you provide a specific example of the following?:
[path to CXFServlet]/contactus/postMessage?message=… – postMessage operation
By Willie Wheeler August 4, 2008 - 8:48 pm
@Alex: The specific examples are listed at the top of page 4. Basically you just need to include the URL up to and including the servlet name, so that would include your servlet context and the servlet name just like with any servlet.
By Kasturi September 8, 2008 - 3:20 pm
I am unable to get it working :( Can you please help?
My war is named cxfwheeler.war
So I access: http://localhost:8080/cxfwheeler/contactus?wsdl
I get a HTTP 404 error, requested resource not found :( :(
By Kasturi September 8, 2008 - 4:19 pm
I now understand that my context wasn’t being loaded due to Tomcat listenerStart error.
I get Tomcat listenerStart while deploying my webapp. Moreover, this deployment error is not predictable, in the sense that I do not get it every time I start Tomcat, may be 50-50 chances of getting the error or not.
INFO: Deploying web application archive insuranceApp.war
Sep 8, 2008 10:09:23 AM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
Sep 8, 2008 10:09:23 AM org.apache.catalina.core.StandardContext start
SEVERE: Context [/insuranceApp] startup failed due to previous errors
I am using Tomcat 6.0.14 with Spring 2.5.
What can be the reason? I saw there were 2 other threads in the Spring forum related to the exact same error, but they were being answered by newbies alike trying to guess the reason and thus not much useful.
As a workaround, I am now using the ContextLoaderServlet and commented out ContextLoaderListener. But I would still like to know the reason why.
<!– <listener>
<listener-class>
org.springframework.web.context.ContextLoaderListe ner
</listener-class>
</listener> –>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoade rServlet</servlet-class>
</servlet>
By Kasturi September 8, 2008 - 4:23 pm
I am now able to hit my context correctly, but I do not get any services listed.
Rather I get the following message at the url – http://localhost:8080/cxfwheeler/contactus?wsdl :
“No service was found.”
I am sorry for bothering you so much.
By Willie Wheeler September 8, 2008 - 10:37 pm
Hi Kasturi. No need to apologize; it’s no bother at all. :-)
The “No service was found” message comes from the CXFServlet, so at least your request is finding its way to the servlet itself. But somehow the contactus service isn’t being registered.
Can you take a look at your appContext.xml file and make sure your <jaxws:endpoint …/> definition matches the one on page 3 of my article? In particular you will need to make sure it says address=”/contactus”. (Check the case as well.)
That’s just a guess, but again the request is hitting the servlet, so it’s probably something in your appContext.xml. You might try just downloading the sample code if you haven’t already done so.
Let me know if you remain stuck.
By Craig September 12, 2008 - 2:23 pm
Great tutorial Willie – thanks much!
I also had the “No service was found.” issue that Kasturi as well. It seemed to be fixed after I got rid of the implementorClass attribute in the jaxws endpoint, as just the implementor reference to the service bean was sufficient.
Thanks again!
By Amit September 16, 2008 - 9:26 am
I am using CXF to test getMessages and it almost work expect for following namespace issue:
Here is getMessagesResponse SOAP message sent from Jboss to the CXF client:
<soap:Envelope xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/”><soap:Body><ns1:getMessagesResponse xmlns:ns1=”http:// service.texas.mycompany.com /”><return><ns2:Message xmlns:ns2=”http:// service.texas.mycompany.com “><ns2:email>willie.wheeler@xyz.com</ns2:email><ns2:firstName>Willie</ns2:firstName><ns2:lastName>Wheeler</ns2:lastName><ns2:text>Great job</ns2:text></ns2:Message><ns2:Message xmlns:ns2=”http:// service.texas.mycompany.com “><ns2:email>dardy.chen@xyz.com</ns2:email><ns2:firstName>Dardy</ns2:firstName><ns2:lastName>Chen</ns2:lastName><ns2:text>I want my money back</ns2:text></ns2:Message></return></ns1:getMessagesResponse></soap:Body></soap:Envelope>
Here is and warning on client side:
Sep 16, 2008 6:08:10 PM org.apache.cxf.aegis.type.TypeUtil getReadType
WARNING: xsi:type absent, and no type available for {http://service.texas.mycompany.com}email
Sep 16, 2008 6:08:10 PM org.apache.cxf.aegis.type.TypeUtil getReadType
WARNING: xsi:type absent, and no type available for {http://service. texas. mycompany.com}firstName
It seems like problem is in the fact that it is :
xmlns:ns2=”http:// service.texas.mycompany.com
My wsdl is available on the ip: http://localhost:8080/root/webservices/contactus?wsdl
How to fix this xmlns:ns2=”http:// service.texas.mycompany.com properly?
By Vivek September 22, 2008 - 10:14 pm
Great tutorial !!
I implemented it and its working.
Thanks for everything
By yogesh September 29, 2008 - 11:37 am
I am getting this error message … jars used are cxf-2.1.2.jar, jdom-1.1.jar (These two jar are of diferent version as listed)… All other jar are same as you mentioned… Did I miss something
13:32:58,024 INFO [STDOUT] 13:32:58,024 INFO [SettingsFactory] Named query checking : enabled
13:32:58,102 INFO [STDOUT] 13:32:58,102 INFO [SessionFactoryImpl] building session factory
13:32:58,446 INFO [STDOUT] 13:32:58,446 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
13:32:59,977 INFO [STDOUT] 13:32:59,977 INFO [DefaultListableBeanFactory] Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@2df: defining beans [cxf,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,org.apache.cxf.resource.ResourceManager,org.apache.cxf.configuration.Configurer,org.apache.cxf.binding.BindingFactoryManager,org.apache.cxf.transport.DestinationFactoryManager,org.apache.cxf.transport.ConduitInitiatorManager,org.apache.cxf.wsdl.WSDLManager,org.apache.cxf.phase.PhaseManager,org.apache.cxf.workqueue.WorkQueueManager,org.apache.cxf.buslifecycle.BusLifeCycleManager,org.apache.cxf.endpoint.ServerRegistry,org.apache.cxf.endpoint.ServerLifeCycleManager,org.apache.cxf.endpoint.ClientLifeCycleManager,org.apache.cxf.transports.http.QueryHandlerRegistry,org.apache.cxf.endpoint.EndpointResolverRegistry,org.apache.cxf.headers.HeaderManager,org.apache.cxf.catalog.OASISCatalogManager,org.apache.cxf.endpoint.ServiceContractResolverRegistry,org.apache.cxf.binding.soap.SoapBindingFactory,org.apache.cxf.binding.soap.SoapTransportFactory,org.apache.cxf.binding.soap.customEditorConfigurer,org.apache.cxf.transport.servlet.ServletTransportFactory,dataSource,mySessionFactory,myTransactionManager,contactUsServiceImpl,aegisBean,jaxws-and-aegis-service-factory,orderService,orderTarget,orderDAO,contactUsService]; root of factory hierarchy
13:33:00,008 INFO [STDOUT] 13:33:00,008 INFO [LocalSessionFactoryBean] Closing Hibernate SessionFactory
13:33:00,008 INFO [STDOUT] 13:33:00,008 INFO [SessionFactoryImpl] closing
13:33:00,008 INFO [STDOUT] 13:33:00,008 ERROR [ContextLoader] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘contactUsService’: Cannot resolve reference to bean ‘jaxws-and-aegis-service-factory’ while setting bean property ‘serviceFactory’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘jaxws-and-aegis-service-factory’ defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean ‘aegisBean’ while setting bean property ‘dataBinding’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘aegisBean’ defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.apache.cxf.aegis.databinding.AegisDatabinding]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/jdom/Parent
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3854)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4359)
By yogesh September 29, 2008 - 11:55 am
List of jars (I think this would be helpful to u)
ant-contrib.jar
antlr-2.7.6.jar
aopalliance.jar
aspectjrt.jar
aspectjtools.jar
c3p0-0.9.1-pre6.jar
commons-beanutils.jar
commons-collections.jar
commons-collections-3.1.jar
commons-digester.jar
commons-fileupload.jar
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
commons-lang.jar
commons-logging.jar
commons-validator.jar
cxf-2.1.2.jar
dom4j-1.6.1.jar
freemarker-2.3.12.jar
geronimo-activation_1.1_spec-1.0.2.jar
geronimo-annotation_1.0_spec-1.1.1.jar
geronimo-javamail_1.4_spec-1.3.jar
geronimo-servlet_2.5_spec-1.2.jar
geronimo-stax-api_1.0_spec-1.0.1.jar
geronimo-ws-metadata_2.0_spec-1.1.2.jar
hibernate3.jar
jakarta-oro.jar
javassist-3.4.GA.jar
jaxb-api-2.1.jar
jaxb-impl-2.1.7.jar
jaxws-api-2.0.jar
jboss-common-jdbc-wrapper.jar
jdbc2_0-stdext.jar
jdom-1.1.jar
jta-1.1.jar
jta-spec1_0_1.jar
junit.jar
log4j-1.2.9.jar
neethi-2.0.2.jar
ognl-2.6.11.jar
saaj-api-1.3.jar
saaj-impl-1.3.jar
slf4j-api-1.5.3.jar
slf4j-jcl-1.5.3.jar
slf4j-jdk14-1.5.3.jar
slf4j-log4j12-1.5.3.jar
slf4j-migrator-1.5.3.jar
slf4j-nop-1.5.3.jar
slf4j-simple-1.5.3.jar
spring-agent.jar
spring-aop.jar
spring-aspects.jar
spring-beans.jar
spring-context.jar
spring-context-support.jar
spring-core.jar
spring-hibernate3.jar
spring-jdbc.jar
spring-jms.jar
spring-orm.jar
spring-test.jar
spring-tomcat-weaver.jar
spring-tx.jar
spring-web.jar
spring-webmvc.jar
spring-webmvc-portlet.jar
spring-webmvc-struts.jar
struts.jar
struts2-core-2.1.2.jar
struts2-spring-plugin-2.0.6.jar
struts-legacy.jar
wsdl4j-1.6.2.jar
wstx-asl-3.2.4.jar
xml-resolver-1.2.jar
XmlSchema-1.4.2.jar
xwork-2.1.1.jar
By yogesh September 29, 2008 - 12:39 pm
Its a jar version problem
refering to http://www.apache.org/dist/geronimo/2.1.2/RELEASE_NOTES-2.1.2.txt
it doesnot support org/jdom/Parent know issue
I used cxf.2.0.8 jar and it worked
By Sam Smith October 5, 2008 - 8:46 am
hello,
I found this article to be very helpful, many thanks.
I am using latest CXF 2.1.2 and Spring 2.5.4 and the WS works just fine.
The issue I have with running the JUnit, I get the following error:
Exception in thread “main” org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘contactUsServiceClient’ defined in class path resource [contactus/spring-test.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public java.lang.Object org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create()] threw exception; nested exception is java.lang.VerifyError: (class: org/apache/cxf/aegis/type/basic/ObjectType, method: writeSchema signature: (Lorg/jdom/Element;)V) Incompatible argument to function
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:396)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:936)
Any ideas,
Sam
By len October 11, 2008 - 4:22 pm
I have jaxen-1.1.jar in my classpath on Tomcat 6, but I am still getting the following:
Oct 11, 2008 12:45:36 PM org.apache.cxf.aegis.type.XMLTypeCreator <clinit>
INFO: Parser doesn’t support setSchema. Not validating.
java.lang.UnsupportedOperationException: This parser does not support specification “null” version “null”
What should I do ?
By Willie Wheeler October 11, 2008 - 4:38 pm
@len: Yeah, alperen above said the same thing (May 6). I’m not sure what it is. If you’re adventurous, you might try cracking open the XMLTypeCreator (line 125) and DocumentBuilderFactory (line 489) source.
It’s hard to tell from the limited error message but my best guess would be that you either haven’t specified a default namespace or else you haven’t specified a schema location for that namespace. Can you post the namespace declarations you’re using here? (Don’t need the whole config file; just the namespace declarations at the top.)
By len October 13, 2008 - 6:43 am
Willie,
I used the code you have provided. I did not change anything in it, except the web application name under which I deployed the services.
The possible clue may be is it that I used CXF 2.1 ( instead of your example referring to 2.0.4) nad CXF web site states that there are significant changes regarding the use of Aeges 2.1 ( which is currently used by CXF 2.1).
But I would not like to go over source code.
May be you already know,what should be done in case of using CXF 2.1 and Aeges 2.1 ?
Thanks.
By Willie Wheeler October 13, 2008 - 9:10 pm
Hi Len. I didn’t already know, as I haven’t used CXF 2.1 yet, but I wouldn’t be surprised if that were the issue. Thanks for writing back and letting us know about this.
By Marcos de Sousa October 24, 2008 - 8:18 am
Awesome tutorial, had it working and debugging with Eclipse Ganymede, CXF 2.1.3, Spring 2.5.5 with Tomcat5.5
Attention:
CXF 2.1.3 with Java 6 requires jaxb-api-2.1.jar (you will need to download it since it doesn’t come with CXF 2.1.3 distribuition)
Thank you
By Paul VanderWall October 28, 2008 - 5:42 am
First off, great tutorial. I almost have my web services setup. I am running into a mapping/binding snag.
The service methods that take as a parameter or return a java.util.Set are having an issue. I attempted to reconfigure to Aegis as this tutorial suggests. I still encountered the issue. Below is a partial stacktrace when configured to use Aegis. Any suggestions greatly appreciated!
<Oct 27, 2008 10:14:09 PM EDT> <Warning> <HTTP> <BEA-101162> <User defined liste
ner org.springframework.web.context.ContextLoaderListener failed: org.springfram
ework.beans.factory.BeanCreationException: Error creating bean with name ‘Busine
ssUnitQueryService’: Invocation of init method failed; nested exception is javax
.xml.ws.WebServiceException: org.apache.cxf.aegis.DatabindingException: Error in
itializing parameters for operation {http://my.gfs.com/200810/IBusinessUnitQuery
}findBusinessUnitsByCompany: Cannot create mapping for java.util.Set, unspecifi
ed component type for method findBusinessUnitsByCompany parameter -1.
org.springframework.beans.factory.BeanCreationException: Error creating bean wit
h name ‘BusinessUnitQueryService’: Invocation of init method failed; nested exce
ption is javax.xml.ws.WebServiceException: org.apache.cxf.aegis.DatabindingExcep
tion: Error initializing parameters for operation {http://my.gfs.com/200810/IBus
inessUnitQuery}findBusinessUnitsByCompany: Cannot create mapping for java.util.
Set, unspecified component type for method findBusinessUnitsByCompany parameter
-1
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.initializeBean(AbstractAutowireCapableBeanFactory.java:1170)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:427)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb
ject(AbstractBeanFactory.java:249)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
y.getSingleton(DefaultSingletonBeanRegistry.java:155)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:246)
Truncated. see log file for complete stacktrace
javax.xml.ws.WebServiceException: org.apache.cxf.aegis.DatabindingException: Err
or initializing parameters for operation {http://my.gfs.com/200810/IBusinessUnit
Query}findBusinessUnitsByCompany: Cannot create mapping for java.util.Set, unsp
ecified component type for method findBusinessUnitsByCompany parameter -1
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:267)
at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:201)
at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:394)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
…
The service interface for IBusinessUnitQuery.findBusinessUnitsByCompany looks like this…
public Set findBusinessUnitsByCompany(Integer companyNumber);
I am using Spring 2.0.7 and have tried cxf 2.0.6 & 2.1.2.
Thanks
By Paul VanderWall October 29, 2008 - 5:32 am
I resolved my previous post/question by adding generics to the interface and implementation class.
So, my interface now looks like this…
public Set<BusinessUnitDO> findBusinessUnitsByCompany(@WebParam(name=”companyNumber”) Integer companyNumber);
By Gerson Galang November 6, 2008 - 8:51 pm
I’ve also had the same problem @len and @alperen reported
java.lang.UnsupportedOperationException: This parser does not support specification “null” version “null”
and fixed it by making the application use Xerces-2.9.1′s DocumentBuilderFactory implementation.
By VAIBHAV November 19, 2008 - 11:12 am
A pretty useful article for beginners!
By Benjamin December 3, 2008 - 7:07 pm
Thank you !
By arslan December 4, 2008 - 8:11 am
I tried your example and it worked. Good job. I cam accross one issue when I attempted to validate the out going and incoming SOAP messages. I added the following piece to the appContext.xml file:
<jaxws:endpoint id=”contactUsService” ……
<jaxws:properties>
<entry key=”schema-validation-enabled” value=”true” />
</jaxws:properties>
…………….
</jaxws:endpoint>
and I put the following annotations on the Message class method getFirstName.
@org.apache.cxf.aegis.type.java5.XmlType.XmlElement(nillable=false,minOccurs=”1″)
public String getFirstName() {
…..
}
Now when I call the postMessage method on the ContactUsService endpoint and didn’t pass the first name value in the Message, nothing happened. Its completely ignored.
Another thing if I remove the aegis binding from the appContext.xml file and changed the annotations to @javax.xml.bind.annotation.XmlElement(required=true) on the getFirstName field it validates the soap message correctly and sent back the following SoapFault message:
javax.xml.ws.soap.SOAPFaultException: Unmarshalling Error: cvc-complex-type.2.4.a: Invalid content was found starting with element ‘ns2:email’. One of ‘{email, firstName, lastName, text}’ is expected.
Any idea how can I do the soap message validation using Aegis? Or is there any other way I can do this validation using aegis?
I would really appreciate any help in this regards.
By arslan December 4, 2008 - 8:30 am
To correct my last comment, when I removed the aegis binding from the appContext.xml file it still didnt validate the Soap Messages correctly, I am keep on getting the following soap fault message:
javax.xml.ws.soap.SOAPFaultException: Unmarshalling Error: cvc-complex-type.2.4.a: Invalid content was found starting with element ‘ns2:email’. One of ‘{email, firstName, lastName, text}’ is expected.
Any help?
By fanjinchang December 15, 2008 - 9:45 pm
Hi Willie,
The class and interface on a different package to generate wsdl incomplete data
By Willie Wheeler December 15, 2008 - 9:51 pm
@fanjinchang: eh?
By fanjinchang December 15, 2008 - 10:12 pm
The class and interfaces written in a different package to generate wsdl, only “Wsdl: binding”, not (wsdl: message, wsdl: types, wsdl: portType),is not my configuration problems?
By fanjinchang December 15, 2008 - 10:56 pm
Hi Willie,
The class and interfaces written in a different package to generate wsdl, only “Wsdl: binding”, not (wsdl: message, wsdl: types, wsdl: portType),is not my configuration problems?
E-mail to tell me I made the case to your mailbox, please help me to see?
Thankyou!
By arslan December 22, 2008 - 1:47 pm
Hi Willie,
I tried your example and it worked. Good job.
After that I attempted to validate the SOAP Message. In order to do this I changed Message class and added the following aegis annotation on the getFirstName() method.
@org.apache.cxf.aegis.type.java5.XmlType.XmlElement(nillable=false,minOccurs=”1″)
public String getFirstName() {
…..
}
Also I added the following piece to the appContext.xml file:
<jaxws:endpoint id=”contactUsService” ……
<jaxws:properties>
<entry key=”schema-validation-enabled” value=”true” />
</jaxws:properties>
…………….
</jaxws:endpoint>
Now when I call the postMessage method on the ContactUsService endpoint and didn’t pass the first name value in the Message, nothing happened. Its completely ignored.
Another thing if I remove the aegis binding from the appContext.xml file and removed the aegis annotation from the getFirstName() method and replaced the annotations to @javax.xml.bind.annotation.XmlElement(required=true) on the getFirstName field it validates the soap message correctly and sent back the following SoapFault message:
javax.xml.ws.soap.SOAPFaultException: Unmarshalling Error: cvc-complex-type.2.4.a: Invalid content was found starting with element ‘ns2:email’. One of ‘{email, firstName, lastName, text}’ is expected.
Any idea how can I do the soap message validation using Aegis? Or is there any other way I can do this validation using aegis?
I would appreciate if anyone can tell me the way to validate SOAP message using aegis.
Regads,
arslan ali
By Mike Miller January 13, 2009 - 10:23 pm
Hi,
Great article! Hoping you can answer a question for me. Someone in our group is trying to deploy a client web service within JBoss 4.2.3. They are getting a NoSuchMethodException somewhere in the JAXB Data binding jar/implementation. This sounds like a classloader issue to me and I pointed them in that direction but I am wondering if you encountered anything like this and how you would approach it?
Thanks!
By Willie Wheeler January 13, 2009 - 10:26 pm
**@Mike:** Haven’t run into it, but to me it sounds like a JAR incompatibility issue, or else using an old JRE possibly. Can you post the stacktrace along with the JAR versions and JRE version?
By Amitava January 14, 2009 - 8:44 am
Hi ,
I want to replace the axis web services with CFX . Currently my application which using Axis and spring frame work is deployed in tomcat 6.0 .
Can some body please tell me what are the configurations files i need to modify/create? . also to migrate from axis to CFX is there any regression issue ? I dont want to change any java code .
Please suggest and let me know what are changes i need to do .?
Thanks in Advance .
Best Regards,
amitava
By Aruna February 5, 2009 - 11:40 pm
Hi Willie,
**Thanks for the wonderful example.
Im new to this CFX+Spring Webservice and so please forgive my ignorance.
I was trying to deploy your example and Im getting the below error which Im not able to resolve it.**
ERROR [STDERR] Feb 6, 2009 11:19:42 AM org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
INFO: Creating Service {http://contactus/}ContactUsServiceService from class contactus.ContactUsService
2009-02-06 11:19:43,706 ERROR [STDERR] Feb 6, 2009 11:19:43 AM org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
INFO: {http://contactus/}return part element name {http://contactus/}return references element {http://contactus/}return
{http://contactus/}message part element name {http://contactus/}message references element {http://contactus/}message
Please help in solving this.
By Aruna February 6, 2009 - 3:02 am
Im trying to deploy the service in jboss 4.3.0.. Please suggest me the method of deploying the service in jboss.
By Catherine February 9, 2009 - 1:50 am
Hi Willie
Tried your example and it works fine thanks. But I need to use restful webservices instead of SOAP. Somebody tell me what are the changes that needs to be done for restful..
Thanks in advance.
By hanasaki March 10, 2009 - 11:30 pm
with respect to the question on postMessage; would you give a specific example to of what to put on the command line to pass in a Message? how to pass an instance of Message in detail.
By Sachin April 30, 2009 - 3:40 am
Hi Willie I write a service following ur example and it ran successfully, then I tried to write a client to access this service, for this when I inspect the wsdl it has missing portType element and hence the XXXXport class is not generating, I am using clientgen of weblogic 9.
By Saravanan August 27, 2009 - 3:00 am
Hi Willie,
When I am deploying an application as the same like the one in the tutorial but returning a simple java object which is binded using default JAXB I am getting a response with a return tag in it. How to avoid or remove the return tag in the response.
By Sam September 18, 2009 - 9:37 am
I am trying to create a simple application using RAD 7.5 (WAS 6.1 test server, Servlet 2.4) with CXF 2.2.3 and Spring 2.5.
I have placed all the jar files that come from CXF 2.2.3 download in the web-inf/lib directory.
I am using your example as is for learning purposes.
When I start the WebSphere test server 6.1 (that comes bundled with RAD 7.5), the server starts, but shows the following errors:
<pre>
[9/18/09 10:58:07:668 EDT] 00000030 WorkSpaceMast E WKSP0012E: Exception while extracting cells/TSD-108078Node01Cell/applications/IBMUTC.ear/deployments/IBMUTC/deployment.xml from ConfigRepository–com.ibm.websphere.management.exception.DocumentNotFoundException: cells/TSD-108078Node01Cell/applications/IBMUTC.ear/deployments/IBMUTC/deployment.xml
at com.ibm.ws.management.repository.FileRepository.extractInternal
</pre>
<pre>
[9/18/09 10:59:24:335 EDT] 00000025 ContextLoader E org.springframework.web.context.ContextLoader initWebApplicationContext Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘contactUsService’: Invocation of init method failed; nested exception is javax.xml.ws.WebServiceException: Service endpoint interface does not have a @WebService annotation.
Caused by: javax.xml.ws.WebServiceException: Service endpoint interface does not have a @WebService annotation.
at org.apache.cxf.jaxws.support.JaxWsImplementorInfo.initialise(JaxWsImplementorInfo.java:284)
at org.apache.cxf.jaxws.support.JaxWsImplementorInfo.<init>(JaxWsImplementorInfo.java:57)
at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:251)
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:230)
</pre>
My web.xml looks like:
<pre>
<?xml version=”1.0″ encoding=”UTF-8″?>
<web-app id=”WebApp_ID” version=”2.4″ xmlns=”http://java.sun.com/xml/ns/j2ee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd“>
<display-name>
MyCxfWebService</display-name>
and the rest is code from this web site
</pre>
appContext.xml is the same as yours. Java class files are also the same as yours with the same package structure. I only commented out @override annotation.
The 2.2.3 download of CXF does not have jaxws-api-2.0.jar in it. I added it with not result.
I also get the following error as:
<pre>
Publishing failed
Deploying AocExampleWebService
Deployment from com.ibm.ast.ws.jaxws.deployer.JAXWSDeployer had errors:
Tools for WebSphere V6.1 must be installed in order to generate WebSphere V6.1 compliant code.
</pre>
Any suggestion will be appreciated.
By Jugash September 23, 2009 - 7:29 am
Hi I tried to model my web service along this tutorial. I can’t acess the
ws<br>
When I try to hit the url http://localhost:8080/security/ws/calculatorWsService I get the following message. <br>
WARNING: Can’t find the request for http://localhost:8080/security/ws/calculatorWsService's Observer<br>
Tomcat startup logs show no errors
INFO: Initializing Spring FrameworkServlet ‘calculator-http’
Sep 23, 2009 6:46:24 PM
org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass<br>
INFO: Creating Service {http://remoting.spring.ajtetris.com/}SimpleCalculatorService from class com.ajtetris.spring.remoting.SimpleCalculator
Sep 23, 2009 6:46:24 PM org.apache.cxf.endpoint.ServerImpl initDestination<br>
INFO: Setting the server’s publish address to be /ws/calculatorWsService<br>
.<br>
.<br>
INFO: Starting Coyote HTTP/1.1 on http-8080
Sep 23, 2009 6:47:34 PM org.apache.cxf.transport.servlet.CXFServlet updateContext<br>
INFO: Load the bus with application context<br>
Sep 23, 2009 6:47:34 PM org.apache.cxf.bus.spring.BusApplicationContext getConfigResources<br>
INFO: No cxf.xml configuration file detected, relying on defaults.
Sep 23, 2009 6:47:35 PM org.apache.cxf.transport.servlet.AbstractCXFServlet replaceDestinationFactory<br>
INFO: Replaced the http destination factory with servlet transport factory<br>
.<br>
.<br>
Hitting the CXF url http://localhost:8080/security/ws/ says ‘No services have been found.’
There were some discussions about this problem in the earlier comments but i didn’t find any solution. Can you please help me debug this issue?
FYI I am using spring-3.0.0.M3 jars.
By jugash September 23, 2009 - 9:50 am
Found out the problem. I was initially using DispatcherServlet in my web.xml and when I replaced it with the CXF servlet I didn’t add the myApp-servlet.xml file to the contextConfigLocation(DispatcherServlet loads it automatically). My bad
By Terry Trippany October 8, 2009 - 1:26 pm
RE: validation annoyance in Eclipse
This is a strange error. I get this error on Eclipse Gallileo using the Spring beans validator and found that it can be eliminated by turning the validation off, hitting OK and then turning it back on. This appears to work fine but is still unsettling. – Trip
By prefer to be anon December 30, 2012 - 10:58 pm
I got the same error. Turned out I had a typo of in my web.xml.
By David Dyer November 7, 2009 - 9:44 am
Good simple tutorial, I followed it to build something similar.
However I’m getting an error when my WS tries to return its response object.
The object contains a Set (using a TreeSet implementation) of HistorySummary (a custom POJO class) objects.
When the service implementation class tries to add HistorySummary instances to the Set (which will then be inserted into the response object). I get the following error:
org.apache.cxf.interceptor.Fault: Couldn’t instantiate class. com.artifact_software.portal.history.messages.retrieve.HistorySummary. Nested exception is java.lang.InstantiationException: com.artifact_software.portal.history.messages.retrieve.HistorySummary (I’ll spare you the full stacktrace).
Oddly enough, if I instantiate the HistorySummary object but never add it to the TreeSet the error doesn’t occur, although then of course, I have an empty Set.
Any ideas what might be causing this?
By Zaim AKINÖZ December 5, 2009 - 2:37 am
great article, thanks…
By Vivek Pandian December 5, 2009 - 4:12 am
Hi,
I tired the sample project given here. It’s not working completely. I could access the webservice through the url http://localhost:9083/CXF/contactus/getMessages and get the soap response back. When i tiy accessign the wsdl file. i get the following exception on server console. ( I am using websphere 6.1, CXF 2.2.5 and spring 2.5)
[12/5/09 16:38:36:371 IST] 00000022 ServletWrappe E SRVE0068E: Uncaught exception thrown in one of the service methods of the servlet: CXFServlet. Exception thrown : java.lang.IncompatibleClassChangeError
at org.apache.cxf.wsdl11.ServiceWSDLBuilder.addExtensibilityElements(ServiceWSDLBuilder.java:229)
at org.apache.cxf.wsdl11.ServiceWSDLBuilder.buildBindingInput(ServiceWSDLBuilder.java:355)
at org.apache.cxf.wsdl11.ServiceWSDLBuilder.buildBindingOperation(ServiceWSDLBuilder.java:324)
at org.apache.cxf.wsdl11.ServiceWSDLBuilder.buildBinding(ServiceWSDLBuilder.java:305)
at org.apache.cxf.wsdl11.ServiceWSDLBuilder.build(ServiceWSDLBuilder.java:193)
at org.apache.cxf.wsdl11.ServiceWSDLBuilder.build(ServiceWSDLBuilder.java:148)
at org.apache.cxf.transport.http.WSDLQueryHandler.writeResponse(WSDLQueryHandler.java:146)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:156)
at org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:142)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:179)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:108)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:159)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:966)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:463)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3129)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:238)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:811)
at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1433)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:93)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:465)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:394)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:274)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:152)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:213)
at com.ibm.io.async.AbstractAsyncFuture.fireCompletionActions(AbstractAsyncFuture.java:195)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:194)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:741)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:863)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1510)
Please help me in this regard.
P.S : I tried the 2 fixes for Websphere given in CXF site. Still no use. I get the same excpetion.
Thanks and Regards,
–Vivek–
By Software companies UK January 4, 2010 - 7:33 am
Nice post,
This is a great tutorial,
It was very easy to follow and the results are pretty outstanding…
Keep up the good work
By Vasav Shah February 11, 2010 - 1:47 am
Hi Willie,
Thanks for your wonderful tutorial. It is written in great manner.
I have a problem while running the webservice.
The jars which I am using are as follows
1. commons-logging-1.1.jar
2. geronimo-activation_1.1_spec-1.0-M1.jar
3. geronimo-annotation_1.0_spec-1.1.jar
(JSR 250)
4. geronimo-javamail_1.4_spec-1.0-M1.jar
5. geronimo-servlet_2.5_spec-1.1-M1.jar
6. geronimo-stax-api_1.0_spec-1.0.jar
7. geronimo-ws-metadata_2.0_spec-1.1.1.jar
(JSR 181)
8. jaxb-api-2.0.jar
9. jaxb-impl-2.0.5.jar
10. jaxws-api-2.0.jar
11. neethi-2.0.2.jar
12. saaj-api-1.3.jar
13. saaj-impl-1.3.jar wsdl4j-1.6.1.jar
14. wstx-asl-3.2.1.jar
15. XmlSchema-1.3.2.jar
16. xml-resolver-1.2.jar
Spring jars are as follows
1) spring-aop-2.5.6.jar
2) spring-beans-2.5.6.jar
3) spring-context-2.5.6.jar
4) spring-core-2.5.6.jar
5) spring-jdbc-2.5.6.jar
6) spring-jms-2.5.6.jar
7) spring-orm-2.5.6.jar
8) spring-tx-2.5.6.jar
9) spring-web-2.5.6.jar
10)spring-webmvc-2.5.6.jar
I am getting following error while I am accessing the WSDL file through URL
java.lang.IncompatibleClassChangeError: Expected static method org.apache.ws.commons.schema.XmlSchemaSerializer.serializeSchema(Lorg/apache/ws/commons/schema/XmlSchema;Z)[Lorg/w3c/dom/Document;
at org.apache.cxf.wsdl11.ServiceWSDLBuilder.buildTypes(ServiceWSDLBuilder.java:197)
at org.apache.cxf.wsdl11.ServiceWSDLBuilder.build(ServiceWSDLBuilder.java:135)
at org.apache.cxf.wsdl11.ServiceWSDLBuilder.build(ServiceWSDLBuilder.java:105)
at org.apache.cxf.transport.http.WSDLQueryHandler.writeResponse(WSDLQueryHandler.java:128)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:127)
at org.apache.cxf.transport.servlet.CXFServlet.invoke(CXFServlet.java:261)
at org.apache.cxf.transport.servlet.CXFServlet.doGet(CXFServlet.java:243)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)
Please help me to resolve this error.
Thanks,
Vasav
By faheem March 29, 2010 - 9:38 pm
Will you post instructions on how to turn XML validation off.
Thanks for the tutorial
By J.H. Veldhorst April 15, 2010 - 12:18 am
First of all, thanks for your tutorial. It is very usefull (even when using rest)
Secondly, I have a tip for everybody that has a “No service found” and/or “Can’t find the request for “. If you have this problem, then make sure the beans (applicationContext) is initialized before the CXFServlet.
E.g. if you have multiple servlets and load the applicationContext in one of them by setting the parameter. Then make sure that this servlet is the first servlet loaded.
In my case I use camel-servlet and cxf. For Camel the applicationContext cannot be initialized before the servlet is initialized. In my case I had to set it as following.
1. Load CamelServlet
2. Initialize applicationContext (I used Springs old ContextLoaderServlet, but there are plenty of ways)
3. Load CXFServlet
With kind regards
By Nitin April 26, 2010 - 3:54 am
I am getting
WARNING:
Can’t find the
request for http://localhost:8080/mywebservices/getMessages's Observer
Anybody pls help me on this.
thanks
Nitin
By Gaurav June 23, 2010 - 11:59 pm
hi, I am able to deploy the webservice on weblogic server and can see it registered on server. but when i tried to consume the webservice i am getting the following exception
<br><br>
java.lang.IllegalArgumentException: Unable to access unsupported property javax.xml.stream.supportDTD
at weblogic.xml.stax.ConfigurationContextBase.check(ConfigurationContextBase.java:60)
at weblogic.xml.stax.ConfigurationContextBase.setProperty(ConfigurationContextBase.java:54)
at weblogic.xml.stax.XMLStreamInputFactory.setProperty(XMLStreamInputFactory.java:280)
at org.apache.cxf.staxutils.StaxUtils.createXMLInputFactory(StaxUtils.java:160)
at org.apache.cxf.staxutils.StaxUtils.getXMLInputFactory(StaxUtils.java:131)
at org.apache.cxf.staxutils.StaxUtils.createXMLStreamReader(StaxUtils.java:923)
at org.apache.cxf.interceptor.StaxInInterceptor.handleMessage(StaxInInterceptor.java:83)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:243)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:104)
at org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:99)
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:358)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:187)
at org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:163)
at org.apache.cxf.transport.servlet.AbstractCXFServlet.doPost(AbstractCXFServlet.java:141)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:226)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:124)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3395)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2140)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2046)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1366)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:200)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:172)
<br><br>
Please help.
By Legna June 24, 2010 - 2:53 pm
Such a great article that I?m really missing the ?print friendly? or the ?pdf? button!
By Legna June 24, 2010 - 4:31 pm
Out of your Message class I created a Message interface which is what I would like to code against ? it broke the data binding. Now what postMessage receives is a proxy object but every get-call returns null. What should I do to code using interfaces instead of classes? You said that you would create a DAO, so you would probably expect an interface.
By satish July 11, 2012 - 7:59 am
Hey Willi,
This article is so nice and useful. Its very helpful for the beginners who will work on SPRING+CXF. Could you please provide me a good example for some shopping cart application with code.
Thanks in advance for anyhelp. If possible please send me the code to the e-mail id entioned in this note.
Thanks
Satish
By REST Web Service Frameworks : SL Tech Umbrella October 22, 2012 - 11:05 am
[...] http://springinpractice.com/2008/02/29/web-services-with-spring-2-5-and-apache-cxf-2-0/ [...]
By Spring : SL Tech Umbrella October 24, 2012 - 2:06 pm
[...] http://springinpractice.com/2008/02/29/web-services-with-spring-2-5-and-apache-cxf-2-0/ [...]