简体   繁体   English

通过 Apache CXF 框架生成 Web 服务时出错

[英]Error generating web services through the Apache CXF framework

I am trying to generate web services in Eclipse by using the Apache CXF framework.我正在尝试使用 Apache CXF 框架在 Eclipse 中生成 Web 服务。 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.首先,我创建与所需 Web 服务相对应的 Java 类,然后生成两个动态 Web 项目,一个用于 Web 服务(wsdl 文件),另一个用于客户端。 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. Web Web 服务在我创建后运行良好,但经过一段时间(一到三天)后,我在服务器启动时看到图像中显示的错误。

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:然后,当我尝试从项目调用 Web 服务时,出现以下错误:

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?是什么导致此错误仅在重复使用 Web 服务后才会出现?

http://i.stack.imgur.com/4mTNZ.jpg http://i.stack.imgur.com/4mTNZ.jpg
http://i.stack.imgur.com/rYkQb.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:上周我发现了一个有趣的文档,其中推荐了以下调用 Web 服务的方法:

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.我想指定我有一组基本/简单的 Web 服务,然后基于这些 Web 服务,我创建了一个复杂的 Web 服务,我在其中获取每个简单 Web 服务的上下文以获取其功能,并且作为您说(据我所知)这不是正确的方法。

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.我为每个 Web 服务客户端创建了一个 client_beans xml 文件。 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?您能否提供一个示例,说明如何调用 Web 服务以及仅保存一个应用程序上下文的方式?

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).我会为您提供我的电子邮件地址 < berlindutza@yahoo.com > 以防您想更轻松地进行交流,因为我已经看到我们限制了一定数量的字符(对于添加评论部分)。

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.在这里猜测:您可能正在为每个请求重新创建 CXF 客户端,而不是创建一次,将其保留为单例并为每个后续请求使用这个实例。

Ideally you should be able to generate the client using the webservice interface.理想情况下,您应该能够使用 Web 服务接口生成客户端。 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.如果您明确指定了 wsdl,cxf 将根据 WSDL 生成一个代理,这似乎是您正在发生的事情。 Once in a while the service which serves out the wsdl fails and you get this error.偶尔提供 wsdl 的服务会失败,并且您会收到此错误。

If you are using Spring, you can do something along these lines:如果您使用的是 Spring,您可以按照以下方式进行操作:

<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" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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