3

由于公司要求,我们不能使用 Glassfish 作为应用服务器。尽管如此,我还是想使用 Moxy。所以我试图让新的 Metro 版本 ( https://blogs.oracle.com/mgrebac/entry/metro_2_2_jaxb_2 ) 与 tomcat 7 一起使用。我管理它使用 Spring 引导 Moxy,就像 Metro 文档中描述的那样( http://metro.java.net/guide/user-guide.html#springa ) 但我没有设法让它与 Moxy 一起工作。

我已经尝试过 Metro 文档中提到的解决方案(http://metro.java.net/2.2/guide/ch17.html)和这里提到的解决方案(使用 Moxy 作为默认的 JAXB 实现)。

但我能从中得到的最多的是以下例外:

com.sun.xml.ws.spi.db.DatabindingException: Unknown JAXBContext implementation: class org.eclipse.persistence.jaxb.JAXBContext
    at com.sun.xml.ws.spi.db.BindingContextFactory.getJAXBFactory(BindingContextFactory.java:207)
    at com.sun.xml.ws.spi.db.BindingContextFactory.create(BindingContextFactory.java:149)
    at com.sun.xml.ws.message.jaxb.JAXBMessage.create(JAXBMessage.java:160)
    at com.sun.xml.ws.fault.SOAPFaultBuilder.createSOAP11Fault(SOAPFaultBuilder.java:423)
    at com.sun.xml.ws.fault.SOAPFaultBuilder.createSOAPFaultMessage(SOAPFaultBuilder.java:200)
    at com.sun.xml.ws.fault.SOAPFaultBuilder.createSOAPFaultMessage(SOAPFaultBuilder.java:188)
    at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:391)
    at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:640)
    at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:263)
    at com.sun.xml.ws.transport.http.servlet.ServletAdapter.invokeAsync(ServletAdapter.java:218)
    at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:159)
    at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:194)
    at com.sun.xml.ws.transport.http.servlet.WSSpringServlet.doPost(WSSpringServlet.java:52)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)

我的测试网络服务是:

@WebService
public class TestService {
    public String sayHello() throws JAXBException {
        System.out.println(org.eclipse.persistence.Version.getVersion());
        JAXBContext c = JAXBContext.newInstance(TestPojo.class);
        return "Hello";
    }
}

是的,moxy jars (org.eclipse.persistence.moxy-2.4.0.jar, org.eclipse.persistence.core-2.4.0.jar, org.eclipse.persistence.asm-3.3.1.v201206041142.jar ) 在类路径上。

谢谢帮助

杰比

4

1 回答 1

0

您始终可以使用 JAX-WSProvider机制来利用EclipseLink JAXB (MOXy)

示例 Web 服务

import javax.xml.bind.*;
import javax.xml.bind.util.JAXBSource;
import javax.xml.transform.Source;
import javax.xml.ws.*;

@ServiceMode(Service.Mode.PAYLOAD)
@WebServiceProvider(
    portName = "FindCustomerPort",
    serviceName = "FindCustomerService",
    targetNamespace = "http://service.jaxws.blog/",
    wsdlLocation = "WEB-INF/wsdl/FindCustomerService.wsdl")
public class FindCustomerService implements Provider<Source> {

    private JAXBContext jaxbContext;

    public FindCustomerService() {
        try {
            jaxbContext = JAXBContext.newInstance(FindCustomerResponse.class,
                    FindCustomerRequest.class);
        } catch (JAXBException e) {
            throw new WebServiceException(e);
        }
    }

    @Override
    public Source invoke(Source request) throws WebServiceException {
        try {
            Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
            FindCustomerRequest fcRequest = (FindCustomerRequest) unmarshaller
                    .unmarshal(request);

            Customer customer = new Customer();
            customer.setId(fcRequest.getArg0());
            customer.setFirstName("Jane");
            customer.setLastName("Doe");

            FindCustomerResponse response = new FindCustomerResponse();
            response.setValue(customer);

            return new JAXBSource(jaxbContext, response);
        } catch (JAXBException e) {
            throw new WebServiceException(e);
        }
    }

}

了解更多信息

于 2013-02-18T13:15:54.900 回答