首页 > 解决方案 > SendShortMessageRequest 及其任何超类对此上下文都是已知的

问题描述

我有一个 Spring Boot 应用程序,我正在尝试访问 SOAP Web 服务

SendShortMessageRequest request = new SendShortMessageRequest();
AddressList addressList = new AddressList();

List<Address> recipientAddresses = new ArrayList<>();

Address recipientAddress = new Address();
recipientAddress.setAddr(recipient);
recipientAddresses.add(recipientAddress);
addressList.setAddress(recipientAddresses);

Address originator = new Address();
originator.setAddr(sender);

request.setText(validationCode);
request.setRecipients(addressList);
request.setOriginator(originator);

SendShortMessageResponse response = (SendShortMessageResponse) getWebServiceTemplate()
        .marshalSendAndReceive(messagesLocation, request, new SoapActionCallback(sendShortMessageAction));

我得到了一个肥皂例外。知道这有什么问题。

org.springframework.oxm.UncategorizedMappingException: Unknown JAXB exception; nested exception is javax.xml.bind.JAXBException: class com.openmind.primecast.webservices.wsdl.SendShortMessageRequest nor any of its super class is known to this context.
    at org.springframework.oxm.jaxb.Jaxb2Marshaller.convertJaxbException(Jaxb2Marshaller.java:913)
    at org.springframework.oxm.jaxb.Jaxb2Marshaller.marshal(Jaxb2Marshaller.java:682)
    at org.springframework.ws.support.MarshallingUtils.marshal(MarshallingUtils.java:81)
    at org.springframework.ws.client.core.WebServiceTemplate$2.doWithMessage(WebServiceTemplate.java:399)
    at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:590)
    at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555)
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390)
    at com.openmind.primecast.webservices.impl.PhoneNumberConfirmationMessageClientImpl.sendConfirmationMessage(PhoneNumberConfirmationMessageClientImpl.java:94)
    at com.openmind.primecast.service.UserService.setupContactNumber(UserService.java:290)

谢谢你

标签: springspring-bootspring-ws

解决方案


我已经注册了类 SendShortMessageRequest @XmlRegistry 它开始工作。

@XmlRegistry
public class ObjectFactory {
    /**
     * Create an instance of {@link SendShortMessageRequest }
     *
     */
    public SendShortMessageRequest createSendShortMessageRequest() {
        return new SendShortMessageRequest();
    }
    
    /**
     * Create an instance of {@link SendShortMessageResponse }
     *
     */
    public SendShortMessageResponse createSendShortMessageResponse() {
        return new SendShortMessageResponse();
    }
}

推荐阅读