gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 05:34:18 25 4
gpt4 key购买 nike

我正在尝试使用 Apache CXF 框架在 Eclipse 中生成 Web 服务。首先,我创建与所需 Web 服务相对应的 Java 类,然后生成两个动态 Web 项目,一个用于 Web 服务(wsdl 文件),另一个用于客户端。 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

然后,当我尝试从项目调用 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

是什么原因导致这个只有在重复使用网络服务后才会出现的错误?

/image/4mTNZ.jpg
/image/rYkQb.jpg

<小时/>

您好,客户端是通过以下方式自动生成的:

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);
................

上周我发现了一个有趣的文档,其中推荐了以下调用 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);
.........

你觉得怎么样?这可能是我错误的原因吗?

<小时/>

我很高兴我几乎找到了错误的原因。但我是网络服务的初学者,我还没有完全理解你的信息。我想指定我有一组基本/简单的 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");
...........................................................

我为每个 Web 服务客户端创建了一个 client_beans xml 文件。可以吗?您能给我提供一个如何调用 Web 服务以及仅保存一个应用程序上下文的示例吗?

我会向您提供我的电子邮件地址 ,以防您希望更轻松地沟通,因为我发现我们限制了一定数量的字符(用于 添加评论 部分)。

非常感谢!

最佳答案

这里猜测:您可能会为每个请求重新创建 CXF 客户端,而不是创建一次,将其保留为单例并为每个后续请求使用这个实例。

理想情况下,您应该能够使用 Web 服务接口(interface)生成客户端。如果您显式指定了 wsdl,cxf 将根据 WSDL 生成一个代理,这似乎就是您正在发生的事情。有时,提供 wsdl 的服务会失败,您会收到此错误。

如果您使用 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" />

关于java - 通过 Apache CXF 框架生成 Web 服务时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8421446/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com