无法在Glassfish中将JAX-WS部署为OSGi包

时间:2012-06-08 20:31:34

标签: glassfish jax-ws osgi

当我通过Glassfish将JAX-WS部署为标准Web应用程序服务时,一切正常。

相同的JAR文件也是OSGi包(因此是WAB)。如果我尝试安装为OSGi包,我会收到有关返回属性不存在响应的错误。这是Web服务类:

package org.example;

import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.xml.ws.ResponseWrapper;

@WebService
public class ExampleComponent {
   private String message = new String("Hello, ");

   public ExampleComponent() {
   }

   public String sayHello(String name) {
       return message + name + ".";


   }
}

这是我得到的错误:

javax.xml.ws.WebServiceException: class org.example.Wrapper do not have a property of the name return
at com.sun.xml.ws.server.sei.EndpointResponseMessageBuilder$DocLit.<init>(EndpointResponseMessageBuilder.java:217)
at com.sun.xml.ws.server.sei.TieHandler.createResponseMessageBuilder(TieHandler.java:210)
at com.sun.xml.ws.server.sei.TieHandler.<init>(TieHandler.java:116)
at com.sun.xml.ws.db.DatabindingImpl.<init>(DatabindingImpl.java:108)
at com.sun.xml.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:74)
at com.sun.xml.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:58)
at com.sun.xml.ws.db.DatabindingFactoryImpl.createRuntime(DatabindingFactoryImpl.java:130)
at com.sun.xml.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:433)
at com.sun.xml.ws.server.EndpointFactory.create(EndpointFactory.java:268)
at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:145)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:569)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:552)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:623)
at org.glassfish.webservices.WSServletContextListener.registerEndpoint(WSServletContextListener.java:282)
at org.glassfish.webservices.WSServletContextListener.contextInitialized(WSServletContextListener.java:102)
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:4750)
at com.sun.enterprise.web.WebModule.contextListenerStart(WebModule.java:550)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5366)
at com.sun.enterprise.web.WebModule.start(WebModule.java:498)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:917)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:901)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:733)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2018)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1669)
at com.sun.enterprise.web.WebApplication.start(WebApplication.java:109)
at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
at org.glassfish.osgijavaeebase.OSGiDeploymentRequest.deploy(OSGiDeploymentRequest.java:183)
at org.glassfish.osgijavaeebase.OSGiDeploymentRequest.execute(OSGiDeploymentRequest.java:118)
at org.glassfish.osgijavaeebase.AbstractOSGiDeployer.deploy(AbstractOSGiDeployer.java:121)
at org.glassfish.osgijavaeebase.OSGiContainer.deploy(OSGiContainer.java:154)
at org.glassfish.osgijavaeebase.JavaEEExtender.deploy(JavaEEExtender.java:107)
at org.glassfish.osgijavaeebase.JavaEEExtender.access$200(JavaEEExtender.java:61)
at org.glassfish.osgijavaeebase.JavaEEExtender$HybridBundleTrackerCustomizer$1.call(JavaEEExtender.java:151)
at org.glassfish.osgijavaeebase.JavaEEExtender$HybridBundleTrackerCustomizer$1.call(JavaEEExtender.java:148)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Caused by: javax.xml.bind.JAXBException: return is not a valid property on class org.example.Wrapper
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getElementPropertyAccessor(JAXBContextImpl.java:981)
at com.sun.xml.ws.db.glassfish.JAXBRIContextWrapper.getElementPropertyAccessor(JAXBRIContextWrapper.java:121)
at com.sun.xml.ws.server.sei.EndpointResponseMessageBuilder$DocLit.<init>(EndpointResponseMessageBuilder.java:214)
... 42 more

如果我将以下注释添加到方法并创建一个包装类,它有点工作:

@WebMethod
@ResponseWrapper(className="org.example.Wrapper")

使用这些注释,安装时没有错误,我能够检索WSDL。但是,测试人员无法工作,我从浏览器收到此消息:

Exceptions details : java.lang.RuntimeException: Cannot find the correct port class.
javax.servlet.ServletException: java.lang.RuntimeException: Cannot find the correct port class. at
org.glassfish.webservices.monitoring.WebServiceTesterServlet.initializePort(WebServiceTesterServlet.java:572) at 
org.glassfish.webservices.monitoring.WebServiceTesterServlet.doGet(WebServiceTesterServlet.java:169) at 
org.glassfish.webservices.monitoring.WebServiceTesterServlet.invoke(WebServiceTesterServlet.java:104) at 
org.glassfish.webservices.JAXWSServlet.doGet(JAXWSServlet.java:186) at javax.servlet.http.HttpServlet.service(HttpServlet.java:668) at 
javax.servlet.http.HttpServlet.service(HttpServlet.java:770) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542) at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281) at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at 
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331) at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) at 
com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317) at 
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849) 
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045) at 
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228) at 
com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) at 
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at 
com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) at 
com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) at com.sun.grizzly.ContextTask.run(ContextTask.java:71) at 
com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) at 
com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) at java.lang.Thread.run(Thread.java:680) Caused by: java.lang.RuntimeException: 
Cannot find the correct port class. at org.glassfish.webservices.monitoring.WebServiceTesterServlet.initializePort(WebServiceTesterServlet.java:559) ... 29 more 

我宁愿不必为每个方法和包装类添加这些注释,只是为了让事情发挥作用,甚至这样做,仍然不是最佳的。

更新:以下是WSDL文件:

 <!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Metro/2.2-b13 (branches/2.2-6964; 2012-01-09T18:04:18+0000) JAXWS-RI/2.2.6-promoted-b20 JAXWS/2.2 svn-revision#unknown. -->
 <!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Metro/2.2-b13 (branches/2.2-6964; 2012-01-09T18:04:18+0000) JAXWS-RI/2.2.6-promoted-b20 JAXWS/2.2 svn-revision#unknown. -->
 <definitions targetNamespace="http://example.org/" name="ExampleComponentService">
   <types>
     <xsd:schema>
       <xsd:import namespace="http://example.org/" schemaLocation="http://localhost:8080/test-jaxws/ExampleComponentService?xsd=1"/>
     </xsd:schema>
   </types>
   <message name="sayHello">
     <part name="parameters" element="tns:sayHello"/>
   </message>
   <message name="sayHelloResponse">
     <part name="parameters" element="tns:sayHelloResponse"/>
   </message>
   <portType name="ExampleComponent">
     <operation name="sayHello">
       <input wsam:Action="http://example.org/ExampleComponent/sayHelloRequest" message="tns:sayHello"/>
       <output wsam:Action="http://example.org/ExampleComponent/sayHelloResponse" message="tns:sayHelloResponse"/>
     </operation>
   </portType>
   <binding name="ExampleComponentPortBinding" type="tns:ExampleComponent">
     <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> 
     <operation name="sayHello"><soap:operation soapAction=""/>
       <input>
         <soap:body use="literal"/>
       </input>
       <output>
         <soap:body use="literal"/>
       </output>
     </operation>
   </binding>
   <service name="ExampleComponentService">
     <port name="ExampleComponentPort" binding="tns:ExampleComponentPortBinding">
       <soap:address location="http://localhost:8080/test-jaxws/ExampleComponentService"/>
     </port>
   </service>
 </definitions>

2 个答案:

答案 0 :(得分:1)

我不确定这是否是您的确切问题,但在尝试部署简单的测试WebService时遇到了类似的异常。它在堆栈底部有这些例外:

javax.xml.ws.WebServiceException: class com.test.AddResponse do not have a property of the name return
javax.xml.bind.JAXBException: return is not a valid property on class com.test.AddResponse

在查看Sahoo的示例代码之后,我在osgi.properties中看到了它的webservices测试包:

# See http://java.net/jira/browse/GLASSFISH-16551 as to why the WAB needs to import JAXB classes
DynamicImport-Package=javax.xml.bind, javax.xml.bind.*

该链接解释了问题发生的原因以及解决问题的方法,您可以将这些包作为动态导入包含在内。

答案 1 :(得分:0)

我知道这不是你问题的解决方案,但也许你可以看看http://cxf.apache.org/。 CXF是专门用于SOAP / REST Web服务的服务框架,与OSGi配合使用。也许这可以解决你的问题。