在WebServiceGatewaySupport中设置用户代理

时间:2016-06-16 11:49:29

标签: spring user-agent

如何在Spring的WebServiceGatewaySupport中设置用户代理?这是我已经尝试但失败的原因:

@Bean
    public DiscreteGateway discreteGateway() throws SOAPException {
        Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
        jaxb2Marshaller.setContextPath(CONTEXT_PATH);
        Map<String, String> propertyMap = new HashMap<>();
        propertyMap.put("User-Agent", "Tough-User");
        SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory(MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL));
        messageFactory.setMessageProperties(propertyMap);
        DiscreteGateway discreteGateway = new DiscreteGateway();
        discreteGateway.setMarshaller(jaxb2Marshaller);
        discreteGateway.setUnmarshaller(jaxb2Marshaller);
        discreteGateway.setMessageFactory(messageFactory);
        discreteGateway.setDefaultUri(Discrete_URI);
        return discreteGateway;
    }

请注意DiscreteGateway扩展WebServiceGatewaySupport ...

1 个答案:

答案 0 :(得分:0)

所以找到here就是我所要做的就是设置VM args http.agent=MY_AGENT并且它有效。