Почему я получаю исключение javax.xml.bind.UnmarshalException при вызове мыльного веб-сервиса - PullRequest
0 голосов
/ 08 мая 2019

Я пытаюсь использовать веб-службу SOAP, и я написал свой клиент SOAP с использованием Spring-ws. Это также включало подписание сообщения. Однако, когда я пытаюсь вызвать запрос, я получаю исключение. С точки зрения сервера, сервер отправляет успешный ответ, но я не могу его отменить.

Я последовал довольно многим советам, включая одно из этого UnmarshallingFailureException, непредвиденный элемент (uri: "http://schemas.xmlsoap.org/soap/envelope/", local:" Fault ")

Однако по указанной выше ссылке исключено исключение, но в свою очередь я получаю нулевой объект ответа и не могу отследить, где пропал ответ.

Это мои методы класса Config:

    public WebServiceTemplate accountsInquiryWebServiceTemplate() throws Exception {
        WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
        Jaxb2Marshaller accountsInquiryMarshaller = accountsInquiryMarshaller();
        webServiceTemplate.setMarshaller(accountsInquiryMarshaller);
        webServiceTemplate.setUnmarshaller(accountsInquiryMarshaller);
        ClientInterceptor[] clientInterceptors = new ClientInterceptor[1];
        clientInterceptors[0] = wsClientSecurityInterceptor();
        webServiceTemplate.setInterceptors(clientInterceptors);
        webServiceTemplate.setCheckConnectionForFault(true);
        webServiceTemplate.setDefaultUri(serviceURL);

        return webServiceTemplate;
    }
private Jaxb2Marshaller accountsInquiryMarshaller() {
        Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
        jaxb2Marshaller.setContextPaths(new String[]{
             "com.accounting.integrationservice"
});
        return jaxb2Marshaller;
    }
private Wss4jSecurityInterceptor wsClientSecurityInterceptor() throws Exception {
        Wss4jSecurityInterceptor wss4jSecurityInterceptor = new Wss4jSecurityInterceptor();
        wss4jSecurityInterceptor.setSecurementActions("Signature");
        wss4jSecurityInterceptor.setSecurementUsername(username);
        wss4jSecurityInterceptor.setSecurementPassword(password);
        wss4jSecurityInterceptor.setSecurementSignatureCrypto(clientCrypto());
        wss4jSecurityInterceptor.setValidationActions("Signature");

        return wss4jSecurityInterceptor;
    }
private Crypto clientCrypto() throws Exception {
        CryptoFactoryBean cryptoFactoryBean = new CryptoFactoryBean();
        cryptoFactoryBean.setKeyStoreLocation(resourceLoader.getResource("classpath:accountsInquiry/keystore/" + keyStoreLocation));
        cryptoFactoryBean.setKeyStorePassword(keyStorePassword);
        cryptoFactoryBean.afterPropertiesSet();
        return cryptoFactoryBean.getObject();
    }

Клиент звонит, как показано ниже:

Response response = accountsWebServiceTemplate.marshalSendAndReceive(request);

Стек исключений, который я получаю, выглядит следующим образом: он аналогичен ссылке, указанной выше, поэтому не помещать весь стек исключений

org.springframework.ws.soap.security.AbstractWsSecurityInterceptor.handleResponse(AbstractWsSecurityInterceptor.java:247)
 - Could not validate request: No WS-Security header found
org.springframework.oxm.UnmarshallingFailureException: JAXB unmarshalling exception; nested exception is javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Fault"). Expected elements are http://www.qualityaccounts.com/IntegrationService/schemas/ProductInfo/v1}
    at org.springframework.oxm.jaxb.Jaxb2Marshaller.convertJaxbException(Jaxb2Marshaller.java:911)
    at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:784)
    at org.springframework.ws.support.MarshallingUtils.unmarshal(MarshallingUtils.java:62)
    at org.springframework.ws.client.core.WebServiceTemplate$3.extractData(WebServiceTemplate.java:413)
    at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:619)
    at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555)
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390)
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:383)

1 Ответ

0 голосов
/ 10 мая 2019

Хорошо. Итак, я пытался использовать «Подпись» для проверки заголовка безопасности ответа, хотя заголовка не было.Но дело в том, что если я не указал действие ValidationAction, оно выдавало исключение NullPointerException, поэтому ожидалось хотя бы одно действие ValidationAction.

Чтобы противостоять всему этому, я сказал безопасности Spring не проверять ответ этого куска кода.

wss4jSecurityInterceptor.setValidateResponse(false);

Благодаря этой статье Spring Security - Wss4jSecurityInterceptor - Nullpointer

...