jaxws两个web方法命名相同的webservice导致java.lang.ClassCastException:CLASS1无法转换为CLASS2

时间:2018-07-31 19:21:51

标签: java jax-ws classcastexception webmethod

我遇到了为应用程序创建Web服务的问题。该应用程序具有具有唯一ID(即GUID)的实体。每个实体都有一个“ loadByGuid”功能。我正在为每个实体创建一个Web服务,但是由于“ loadByGuid”函数返回错误的类型,所以我遇到了强制转换异常。

我创建了两个简单的Web服务来演示该问题:

NumberGetter:

package test;

import javax.jws.WebService;
import javax.jws.WebMethod;

@WebService(serviceName = "NumberGetter")
public class NumberGetter {
    @WebMethod(operationName = "getValue")
    public int getValue() {
        return 42;
    }
}

第二个是“ DateGetter”,但实际上返回了一个字符串。

package test;

import javax.jws.WebService;
import javax.jws.WebMethod;

@WebService(serviceName = "DateGetter")
public class DateGetter {

    @WebMethod(operationName = "getValue")
    public String getValue() {
        return "Hello world!";
    }
}

然后,当我“测试”时,这两个代码之一将作为生成的代码使用该数据类型。另一个给我以下错误:

java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
    at test.jaxws.GetValueResponse$JaxbAccessorF__return.set(FieldAccessor_Integer.java:65)
    at com.sun.xml.bind.v2.runtime.reflect.Accessor.setUnadapted(Accessor.java:161)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl$5.set(JAXBContextImpl.java:944)
    at com.sun.xml.ws.db.glassfish.RawAccessorWrapper.set(RawAccessorWrapper.java:79)
    at com.sun.xml.ws.server.sei.EndpointResponseMessageBuilder$DocLit.build(EndpointResponseMessageBuilder.java:278)
    at com.sun.xml.ws.server.sei.EndpointResponseMessageBuilder$JAXB.createMessage(EndpointResponseMessageBuilder.java:103)
    at com.sun.xml.ws.server.sei.TieHandler.createResponseMessage(TieHandler.java:316)
    at com.sun.xml.ws.server.sei.TieHandler.createResponse(TieHandler.java:263)
    at com.sun.xml.ws.server.sei.TieHandler.serializeResponse(TieHandler.java:341)
    at com.sun.xml.ws.db.DatabindingImpl.serializeResponse(DatabindingImpl.java:230)
    at com.sun.xml.ws.db.DatabindingImpl.serializeResponse(DatabindingImpl.java:83)
    at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:99)
    at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:1136)
    at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:1050)
    at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:1019)
    at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:877)
    at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:136)
    at org.glassfish.webservices.MonitoringPipe.process(MonitoringPipe.java:142)
    at com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:119)
    at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:1136)
    at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:1050)
    at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:1019)
    at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:877)
    at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:136)
    at com.sun.enterprise.security.webservices.CommonServerSecurityPipe.processRequest(CommonServerSecurityPipe.java:209)
    at com.sun.enterprise.security.webservices.CommonServerSecurityPipe.process(CommonServerSecurityPipe.java:141)
    at com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:119)
    at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:1136)
    at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:1050)
    at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:1019)
    at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:877)
    at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:419)
    at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:868)
    at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:422)
    at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:169)
    at org.glassfish.webservices.JAXWSServlet.doPost(JAXWSServlet.java:169)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
    at java.lang.Thread.run(Thread.java:745)

我假设正在为所有Web服务生成一个“ test.jaxws.GetValueResponse”,但是每个Web服务的返回类型都不相同?!?!我找不到生成的代码,也不想用返回类型命名函数,因为这是为每个实体提供Web服务的目的。

0 个答案:

没有答案