具有复杂数据类型接口的Web服务而不是POJO类作为服务参数/返回类型

时间:2014-01-24 23:36:24

标签: java web-services java-ee

如何将接口指定为参数/返回类型,而不是具体的Java POJO类用于Web服务操作。 ?

@XmlSeeAlso注释也不起作用。

数据类型界面:

public interface MyInput {
    public String getName() ;
    public void setName(String name);
}

public interface MyOutput{
    public String getResult() ;
    public void setResult(String result);
}

数据类型实施:

public class MyInputDataType implements MyInput {
     private String name;
      ...

     public String getName(){
        return this.name ;
     }

     public void setName(String name){
        this.name = name 
     }

 }



public class MyOutputDataType implements MyOutput{
     private String result;
       ...

     public String getResult(){
         return this.result;
      }

      public void setResult(String result){
         this.result= result
      }
 }

Web服务合同:

@WebService(name="MyWebService", portName="MyWebService", targetNamespace="http://somename.org", serviceName="MyWebService")
public interface MyWebService {
    @WebMethod
   public MyOutput executeOperation(MyInput  input) ;
 }

Web服务实现:

@WebService( portName="MyWebService", name="MyWebService", targetNamespace="http://somename.org", serviceName="MyWebService", endpointInterface="MyWebService")
public class MyWebServiceImpl implements MyWebService
{
      public MyOutput executeOperation(MyInput  input)
      {
          MyOutput output = new MyOutputDataType();
          output.setResult("executeOperation with input: " +  input.getName() );
          return output;
       }

 }

部署在WL 12c(JEE 6),JDK7

例外:

Exception Description: An error occurred unmarshalling the document
Internal Exception: org.xml.sax.SAXParseException; lineNumber: 0; columnNumber: 0;
Exception Description: The instance creation method [MyInput.<Default Constructor>],   with no parameters, does not exist, or is not accessible.
Internal Exception: java.lang.NoSuchMethodException: MyInput.<init>()
Descriptor: XMLDescriptor(MyInput --> [])]
    at com.sun.xml.ws.server.sei.TieHandler.readRequest(TieHandler.java:251)
    at com.sun.xml.ws.db.DatabindingImpl.deserializeRequest(DatabindingImpl.java:166)
    at com.sun.xml.ws.db.DatabindingImpl.deserializeRequest(DatabindingImpl.java:260)
    at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:89)
    at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:892)
    at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:841)
    at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:804)
    at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:706)
    at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:430)
    at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:640)
    at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:265)
    at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:163)
    at weblogic.wsee.jaxws.WLSServletAdapter.handle(WLSServletAdapter.java:171)
    at weblogic.wsee.jaxws.HttpServletAdapter$AuthorizedInvoke.run(HttpServletAdapter.java:708)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:146)
    at weblogic.wsee.util.ServerSecurityHelper.authenticatedInvoke(ServerSecurityHelper.java:103)
    at weblogic.wsee.jaxws.HttpServletAdapter$3.run(HttpServletAdapter.java:311)
    at weblogic.wsee.jaxws.HttpServletAdapter.post(HttpServletAdapter.java:336)
    at weblogic.wsee.jaxws.VerboseHttpProcessor.post(VerboseHttpProcessor.java:39)
    at weblogic.wsee.jaxws.JAXWSServlet.doRequest(JAXWSServlet.java:99)
    at weblogic.servlet.http.AbstractAsyncServlet.service(AbstractAsyncServlet.java:99)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:242)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:216)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:132)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:352)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:235)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3284)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3254)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
    at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
    at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2163)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2089)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2074)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1512)
    at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)

0 个答案:

没有答案