Spring的WebServiceTemplate:响应超出输入令牌限制

时间:2019-11-02 04:04:58

标签: spring soap saaj webservicetemplate

我正在尝试集成基于SOAP的Web服务进行文件解析。它接受预定义的SOAP消息,其内容为base64binary格式。

它适用于大小为100KB的小文件,但是对于带有消息的大文件,它会在响应时抛出错误。输入文本包含42374个令牌,超过了20000个限制。

这是我的配置代码

    public WebServiceTemplate createWebServiceTemplate() throws Exception {
        SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory(MessageFactory.newInstance());
        WebServiceTemplate webServiceTemplate = new WebServiceTemplate(messageFactory);

        messageFactory.afterPropertiesSet();

        Jaxb2Marshaller marshaller = createMarshaller();

        webServiceTemplate.setDefaultUri(this.properties.getUrl());
        webServiceTemplate.setMarshaller(marshaller);
        webServiceTemplate.setUnmarshaller(marshaller);

        webServiceTemplate.setMessageSender(createMessageSender());
        webServiceTemplate.afterPropertiesSet();

        return webServiceTemplate;
    }

    @Bean
    public Jaxb2Marshaller createMarshaller() throws Exception {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();

        marshaller.setContextPath("com.xxx.client.xxx.api");
        marshaller.afterPropertiesSet();

        return marshaller;
    }

    @Bean
    public HttpComponentsMessageSender createMessageSender() {
        return new HttpComponentsMessageSender(createHttpClient());
    }

    @Bean
    public HttpClient createHttpClient() {
        List<Header> headers = new ArrayList<>();

        String userAndPassword = String.format("%s:%s", this.properties.getUsername(), this.properties.getPassword());
        String encodeUserPassword = Base64.getEncoder().encodeToString(userAndPassword.getBytes());

        BasicHeader authHeader = new BasicHeader("Authorization", "Basic " + encodeUserPassword);
        headers.add(authHeader);

        return HttpClients.custom()
                .addInterceptorFirst(new HttpComponentsMessageSender.RemoveSoapHeadersInterceptor())
                .addInterceptorLast(new RequestDefaultHeaders(headers))
                .build();
    }

这是对Web服务的呼叫

JAXBElement result = (JAXBElement) webServiceTemplate.marshalSendAndReceive(this.properties.getUrl(), parse);

parse 是肥皂对象,其内容为base64binary

0 个答案:

没有答案