简体   繁体   中英

Error generating web services through the Apache CXF framework

I am trying to generate web services in Eclipse by using the Apache CXF framework. First I am creating the Java class corresponding to the desired web service and then I generate two dynamic web projects, one for the web service (wsdl file) and another one for the clients. The web web services work well after I create them but after some time (one-three days) I get the error displayed in the image at the server startup.

INFO: Starting service Catalina
Dec 7, 2011 9:27:55 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.4
Dec 7, 2011 9:27:55 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(C:\Documents and Settings\user\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\Prosys_Doctorat_Servicii_FAS_servicii\WEB-INF\lib\geronimo-servlet_3.0_spec-1.0.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
Dec 7, 2011 9:27:59 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1672)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1517)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4287)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4816)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1028)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:773)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1028)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:278)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:429)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:662)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:592)
    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)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:290)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:418)
Dec 7, 2011 9:27:59 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)
Dec 7, 2011 9:27:59 PM org.apache.catalina.core.StandardContext startInternal

Then when I try to call a web service from the project I get the following error:

Exception in thread "main" javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
    at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:149)
    at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:90)
    at javax.xml.ws.Service.<init>(Unknown Source)
    at read_variable_value.ReadVariableNodeService1Service.<init>(ReadVariableNodeService1Service.java:50)
    at FAS.Model2_FAS.asociere_valori(Model2_FAS.java:206)
    at FAS.Model2_FAS.main(Model2_FAS.java:2596)
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
    at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:93)
    at org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:203)
    at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:147)
    ... 5 more
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: Problem parsing 'http://localhost:8081/Prosys_Doctorat_Servicii_FAS_servicii/services/ReadVariableNodeService1Port?wsdl'.: java.io.FileNotFoundException: http://localhost:8081/Prosys_Doctorat_Servicii_FAS_servicii/services/ReadVariableNodeService1Port?wsdl
    at com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
    at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:239)
    at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:186)
    at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:91)
    ... 7 more
Caused by: java.io.FileNotFoundException: http://localhost:8081/Prosys_Doctorat_Servicii_FAS_servicii/services/ReadVariableNodeService1Port?wsdl
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    ... 13 more

What can cause this error which only appears after the web services are used repeatedly?

http://i.stack.imgur.com/4mTNZ.jpg
http://i.stack.imgur.com/rYkQb.jpg


Hi, the client is automatically generated in the following way:

private static final QName SERVICE_NAME = new  QName("http://read_variable/", "ReadVariableNodeServiceService");
URL wsdlURL = ReadVariableNodeServiceService.WSDL_LOCATION;
ReadVariableNodeServiceService ss = new ReadVariableNodeServiceService(wsdlURL, SERVICE_NAME);
SEIReadValue port = ss.getReadVariableNodeServicePort();  
      {
        System.out.println("Invoking getValue...");
        java.lang.String _getValue_arg0 = "Alina";
        java.lang.String _getValue_arg1 = "WorkspaceS1";
        try {
            double _getValue__return = port.getValue(_getValue_arg0, _getValue_arg1);
            System.out.println("getValue.result=" + _getValue__return);
        ................

Last week I have found an interesting documentation which recommends the following way to call a web service:

ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext(new String[]{"read_variable/client3_beans.xml"});
    SEIReadValue port = (SEIReadValue) context.getBean("readvariableClient");
{
    System.out.println("Invoking getValue...");
    java.lang.String _getValue_arg0 = "Alina";
    java.lang.String _getValue_arg1 = "WorkspaceS1";
    try {
        double _getValue__return = port.getValue(_getValue_arg0, _getValue_arg1);
        System.out.println("getValue.result=" + _getValue__return);
        .........

What do you think? May this be the reason for my error?


I am very happy that I have almost found out the cause of my error. But I am a beginner in web services and I haven't understood your message entirely. I want to specify that I have a set of basic/simple web services, and then based on these web services I have created a complex web service where I obtain the context of each simple web service in order to obtain its functionality, and as you said (as I understood) this is not the right approach.

ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext(new String[]{"write_a_matrix/client2_beans.xml"});
SEIWriteMatrix port = (SEIWriteMatrix) context.getBean("write_a_matrix_Client");
...........................................................
ClassPathXmlApplicationContext context_WV=new ClassPathXmlApplicationContext(new String[]{"write_value/client1_beans.xml"});
SEIWriteValue port_WV = (SEIWriteValue) context_WV.getBean("write_a_value_Client");
........................................................... 

I have created a client_beans xml file for each web service client. Is it ok? Can you provide me an example of how to call a web service and the way to hold just one App context?

I will provide you my email address < berlindutza@yahoo.com > in case you want to communicate much easier because I have seen that we are limited to a certain number of characters (for the add comment section).

Thank you a lot!

Guessing here: You are probably recreating the CXF client for every request, instead of creating it once, keeping it as a singleton and using this one instance for every subsequent request.

Ideally you should be able to generate the client using the webservice interface. If you have explicitly specified a wsdl, cxf will generate a proxy based on the WSDL, which is what seems to be happening for you. Once in a while the service which serves out the wsdl fails and you get this error.

If you are using Spring, you can do something along these lines:

<bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
    <property name="serviceClass" value="...wsInterface" />
    <property name="address" value="serviceURL" />
</bean>

<bean id="client" class="...wsInterface" factory-bean="clientFactory" factory-method="create" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM