首页 > 解决方案 > spring soap SAAJ0511:无法从给定源创建信封

问题描述

无法获得肥皂请求,每次都会出现“SAAJ0511:无法从给定来源创建信封”错误。网络服务配置:

@EnableWs
@Configuration
public class WebServiceConfig {

    @Bean
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean(servlet, "/ws/*");
    }


    @Bean(name = "order")
    public DefaultWsdl11Definition orderWsdlDefinition() {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("OrderPort");
        wsdl11Definition.setLocationUri("/ws");
        wsdl11Definition.setTargetNamespace(OrderEndpoint.NAMESPACE_URL);
        wsdl11Definition.setSchema(xsdOrderSchema());
        return wsdl11Definition;
    }

    @Bean("orderSchema")
    public XsdSchema xsdOrderSchema() {
        return new SimpleXsdSchema(new ClassPathResource("ws/order.xsd"));
    }
}

订单端点:

@Endpoint
public class OrderEndpoint {

    public static final String NAMESPACE_URL = "http://geerbrains.com/spring/security/demo/ws/order";

    private OrderService orderService;

    public OrderEndpoint(OrderService orderService) {
        this.orderService = orderService;
    }

    @PayloadRoot(namespace = NAMESPACE_URL, localPart = "getOrderRequest")
    @ResponsePayload
    public GetOrderResponse getOrder(String userName)
            throws DatatypeConfigurationException {
        GetOrderResponse response = new GetOrderResponse();
        orderService.findAllOrdersByUser(userName)
                .forEach(order -> response.getOrder().add(createOrderWS(order)));
        return response;
    }

    private OrderWS createOrderWS(Order order){
        OrderWS ws = new OrderWS();
        ws.setId(order.getId());
        ws.setTotalPrice(String.valueOf(order.getTotalPrice()));
        ws.setCondition(String.valueOf(order.getCondition()));
        return ws;
    }
}

OrderService(仅需要 getUser 的部分 - 是正确的,在另一个代码上进行了测试):

 public List<Order> findAllOrdersByUser(String email) {
        return orderRepository.findOrdersByUser(userService.findUserByEmail(email));
    }

订购服务:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "orderWS", propOrder = {
    "id",
    "totalPrice",
    "condition"
})
public class OrderWS {

    protected long id;
    @XmlElement(required = true)
    protected String totalPrice;
    @XmlElement(required = true)
    protected String condition;

    public long getId() {
        return id;
    }

    public void setId(long value) {
        this.id = value;
    }

    public String getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(String value) {
        this.totalPrice = value;
    }

    public String getCondition() {
        return condition;
    }

    public void setCondition(String value) {
        this.condition = value;
    }

}

Order.wsdl 文件:

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:sch="http://geekbrains.com/spring/security/demo/ws/order" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://geerbrains.com/spring/security/demo/ws/order" targetNamespace="http://geerbrains.com/spring/security/demo/ws/order">
<wsdl:types>
<xs:schema xmlns:tns="http://geekbrains.com/spring/security/demo/ws/order" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://geekbrains.com/spring/security/demo/ws/order">
<xs:element name="getOrderRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="userName" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getOrderResponse">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="1" name="order" type="tns:orderWS"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="orderWS">
<xs:sequence>
<xs:element name="id" type="xs:long"/>
<xs:element name="totalPrice" type="xs:string"/>
<xs:element name="condition" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="getOrderRequest">
<wsdl:part element="sch:getOrderRequest" name="getOrderRequest"> </wsdl:part>
</wsdl:message>
<wsdl:message name="getOrderResponse">
<wsdl:part element="sch:getOrderResponse" name="getOrderResponse"> </wsdl:part>
</wsdl:message>
<wsdl:portType name="OrderPort">
<wsdl:operation name="getOrder">
<wsdl:input message="tns:getOrderRequest" name="getOrderRequest"> </wsdl:input>
<wsdl:output message="tns:getOrderResponse" name="getOrderResponse"> </wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="OrderPortSoap11" type="tns:OrderPort">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getOrder">
<soap:operation soapAction=""/>
<wsdl:input name="getOrderRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getOrderResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="OrderPortService">
<wsdl:port binding="tns:OrderPortSoap11" name="OrderPortSoap11">
<soap:address location="http://localhost:8189/ws"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

邮递员 POST 请求:

<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:gre="http:gre="http://geekbrains.com/spring/security/demo/ws/order">
  <x:Header/>
  <x:Body>
    <gre:getOrderRequest>
        <gre:userName>user1</gre:userName>
    </gre:getOrderRequest>
  </x:Body>
</x:Envelope>

如果需要更多信息,我会附上

标签: javaxmlspringweb-servicessoap

解决方案


推荐阅读