java - Spring Boot 服务器无法识别 HTTP header SOAPAction 的值

标签 java spring spring-boot

<分区>

我正在尝试使用这个 web-service但我得到了 SoapExeption

下面是我发送请求的方法。我该如何在 Spring boot 中解决这个问题?

public class CalcClient extends WebServiceGatewaySupport {

    private static final Logger LOGGER = LoggerFactory.getLogger(CalcClient.class);
    private ObjectFactory objectFactory;

    @Autowired
    public void setObjectFactory(ObjectFactory objectFactory) {
        this.objectFactory = objectFactory;
    }

    public JAXBElement<AddResponse> sendAndReceive() {
        Add request = objectFactory.createAdd();
        request.setIntA(12);
        request.setIntB(12);
        LOGGER.info("Sending request");
        JAXBElement<AddResponse> response = (JAXBElement<AddResponse>) getWebServiceTemplate().marshalSendAndReceive("http://www.dneonline.com/calculator.asmx", request);
        return response;
    }
}

最佳答案

我在访问此服务时遇到了同样的问题,尝试将 AddResponse 绑定(bind)到 JAXBElement 时会出现错误。您需要在代码中设置 soapAction,如下所示使用 WebServiceMessageCallback

public AddResponse sendAndReceive() {
    Add request = objectFactory.createAdd();
    request.setIntA(12);
    request.setIntB(12);
    LOGGER.info("Sending request");
    AddResponse response = (AddResponse) getWebServiceTemplate().marshalSendAndReceive("http://www.dneonline.com/calculator.asmx", request, new WebServiceMessageCallback() {
        @Override
        public void doWithMessage(WebServiceMessage webServiceMessage) throws IOException, TransformerException {
            ((SoapMessage)webServiceMessage).setSoapAction("http://tempuri.org/Add");
        }
    });
    return response;
}

关于java - Spring Boot 服务器无法识别 HTTP header SOAPAction 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42320662/

相关文章:

java - org.apache.commons.fileupload.servlet.ServletFileUpload 似乎没有方法 setProgressListener

Spring MVC 和 Jetty : Prevent jsessionid from being used in RedirectView on redirect to external site

java - spring-boot-starter-mail 使用后的 "Application failed to start"

java - OrderedRequestContextFilter 上的 Spring Boot 应用程序意外登录

java - 增强的 for 循环性能

java - ListView 刷新而不通知DataSetChanged

java - 将父类放入扩展类中

java - 使用 Spring Controller 处理 Paypal IPN 请求?

maven - Spring : java. lang.ClassNotFoundException : org. springframework.boot.SpringApplication 未找到

java - HttpsURLConnection 验证两次?