Spring-WS:尝试使用 WebServicesParserFactory setNameSpaceAware 时出现 NullPointerException

发布于 2024-12-09 21:33:02 字数 3163 浏览 0 评论 0原文

这是一个很遥远的事情,但我正在尝试使用 Spring-WS 编写一个 Web 服务客户端。我收到一个 NullPointerException ,代码如下:

public class WebServiceProcess {
    private WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
    private CommonsHttpMessageSender messageSender = new CommonsHttpMessageSender();
    private SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory();
    private Jaxb2Marshaller marshaller = new Jaxb2Marshaller();

    private void init() {
        Resource schema = new ClassPathResource("/WEB-INF/mySchema.xsd");
        marshaller.setSchema(schema);
        marshaller.setContextPaths("list of packages with JAXB classes...");
        webServiceTemplate.setMarshaller(marshaller);
        webServiceTemplate.setUnmarshaller(marshaller);
        webServiceTemplate.setMessageSender(messageSender);
    }

    public TestResponse sendRequest(TestRequest request) {
        init();
        return response = (TestResponse) webServiceTemplate.marshalSendAndReceive("myEndpointURI", request);
    }
}

堆栈跟踪:

Exception in thread "main" java.lang.NullPointerException
    at com.ibm.ws.webservices.engine.utils.WebServicesParserFactory.setNamespaceAware(WebServicesParserFactory.java:160)
    at com.ibm.ws.webservices.engine.utils.XMLUtils.initSAXFactory(XMLUtils.java:437)
    at com.ibm.ws.webservices.engine.utils.XMLUtils.getSAXParser(XMLUtils.java:490)
    at com.ibm.ws.webservices.engine.encoding.DeserializationContextImpl.parse(DeserializationContextImpl.java:293)
    at com.ibm.ws.webservices.engine.SOAPPart._getSOAPEnvelope(SOAPPart.java:1064)
    at com.ibm.ws.webservices.engine.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:628)
    at com.ibm.ws.webservices.engine.SOAPPart.getEnvelope(SOAPPart.java:656)
    at org.springframework.ws.soap.saaj.support.SaajUtils.getSaajVersion(SaajUtils.java:155)
    at org.springframework.ws.soap.saaj.SaajSoapMessage.getSaajVersion(SaajSoapMessage.java:257)
    at org.springframework.ws.soap.saaj.SaajSoapMessage.getImplementation(SaajSoapMessage.java:342)
    at org.springframework.ws.soap.saaj.SaajSoapMessage.<init>(SaajSoapMessage.java:117)
    at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:184)
    at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:58)
    at org.springframework.ws.transport.AbstractWebServiceConnection.receive(AbstractWebServiceConnection.java:90)
    at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:548)
    at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:496)
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:343)
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:333)
    at com.lmig.processing.WebServiceProcess.sendRequest(WebServiceProcess.java:66)
    at com.lmig.processing.TestProcess.main(MainProcess.java:57)

任何帮助将不胜感激......我知道我没有太多事情要做。谢谢。

This is a long shot, but I'm trying to write a web service client with Spring-WS. I'm getting a NullPointerException with the following code:

public class WebServiceProcess {
    private WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
    private CommonsHttpMessageSender messageSender = new CommonsHttpMessageSender();
    private SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory();
    private Jaxb2Marshaller marshaller = new Jaxb2Marshaller();

    private void init() {
        Resource schema = new ClassPathResource("/WEB-INF/mySchema.xsd");
        marshaller.setSchema(schema);
        marshaller.setContextPaths("list of packages with JAXB classes...");
        webServiceTemplate.setMarshaller(marshaller);
        webServiceTemplate.setUnmarshaller(marshaller);
        webServiceTemplate.setMessageSender(messageSender);
    }

    public TestResponse sendRequest(TestRequest request) {
        init();
        return response = (TestResponse) webServiceTemplate.marshalSendAndReceive("myEndpointURI", request);
    }
}

Stack trace:

Exception in thread "main" java.lang.NullPointerException
    at com.ibm.ws.webservices.engine.utils.WebServicesParserFactory.setNamespaceAware(WebServicesParserFactory.java:160)
    at com.ibm.ws.webservices.engine.utils.XMLUtils.initSAXFactory(XMLUtils.java:437)
    at com.ibm.ws.webservices.engine.utils.XMLUtils.getSAXParser(XMLUtils.java:490)
    at com.ibm.ws.webservices.engine.encoding.DeserializationContextImpl.parse(DeserializationContextImpl.java:293)
    at com.ibm.ws.webservices.engine.SOAPPart._getSOAPEnvelope(SOAPPart.java:1064)
    at com.ibm.ws.webservices.engine.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:628)
    at com.ibm.ws.webservices.engine.SOAPPart.getEnvelope(SOAPPart.java:656)
    at org.springframework.ws.soap.saaj.support.SaajUtils.getSaajVersion(SaajUtils.java:155)
    at org.springframework.ws.soap.saaj.SaajSoapMessage.getSaajVersion(SaajSoapMessage.java:257)
    at org.springframework.ws.soap.saaj.SaajSoapMessage.getImplementation(SaajSoapMessage.java:342)
    at org.springframework.ws.soap.saaj.SaajSoapMessage.<init>(SaajSoapMessage.java:117)
    at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:184)
    at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:58)
    at org.springframework.ws.transport.AbstractWebServiceConnection.receive(AbstractWebServiceConnection.java:90)
    at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:548)
    at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:496)
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:343)
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:333)
    at com.lmig.processing.WebServiceProcess.sendRequest(WebServiceProcess.java:66)
    at com.lmig.processing.TestProcess.main(MainProcess.java:57)

Any help would be appreciated.... I know I don't have a lot to go on. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空城仅有旧梦在 2024-12-16 21:33:02

解决了。我的类路径上有错误的 WebSphere jar。我有 com.ibm.ws.admin.client_7.0.0.jar 而不是 com.ibm.ws.webservices.thinclient_7.0.0.jar。

Solved it. I had the wrong WebSphere jar on my classpath. I had com.ibm.ws.admin.client_7.0.0.jar rather than com.ibm.ws.webservices.thinclient_7.0.0.jar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文