我正在开发一个小型Web界面,从中可以测试对创建的Web Service的一些SOAP请求。
该界面提供了4种可能的操作:登录和3种不同的搜索类型。
当我执行登录过程时,一切顺利,并且我获得了访问令牌,而没有任何特殊问题。
用于登录过程的XSD部分
<xs:element name="loginRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="username" type="xs:string"/>
<xs:element name="time" type="xs:string"/>
<xs:element name="number" type="xs:string"/>
<xs:element name="hash" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="loginResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="operationOutcome" type="tns:OperationOutcome"/>
<xs:element name="accessToken" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="OperationOutcome">
<xs:sequence>
<xs:element name="statusCode" type="xs:int" />
<xs:element name="message" type="xs:string"/>
<xs:element name="errorsList" type="xs:string" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
用于登录过程的Java代码
@RestController
public class LoginController {
@Autowired
LoginServiceClient loginServiceClient;
@RequestMapping(value="/login/{user}", method= RequestMethod.GET)
public LoginResponse doSomething(@PathVariable("user") String username) {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("Model");
loginServiceClient.setMarshaller(marshaller);
loginServiceClient.setUnmarshaller(marshaller);
LoginResponse res = loginServiceClient.login(username, ZonedDateTime.now().toString(), "123456");
return res;
}
}
@Component
public class LoginServiceClient extends WebServiceGatewaySupport {
public LoginResponse login(String user, String data, String number){
String uri = "http://localhost:9001/ws/";
LoginRequest request = new LoginRequest();
request.setTime(data);
request.setNumber(number);
/* do hashing stuff */
request.setHash(hash);
request.setUsername(user);
LoginResponse response =(LoginResponse) getWebServiceTemplate()
.marshalSendAndReceive(uri, request);
return response;
}
}
我在询问以下端点时遇到问题。
问题端点的XSD部分
<xs:element name="getPOrderRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="accessToken" type="xs:string" />
<xs:element name="poNumber" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getPOrderResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="operationOutcome" type="tns:OperationOutcome"/>
<xs:element name="pOrder" type="tns:POrderXml" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="POrderXml">
<xs:sequence>
<xs:element name="poNumber" type="xs:string"/>
<xs:element name="deliveryDate" type="xs:dateTime" minOccurs="0"/>
<xs:element name="entityName" type="xs:string" />
<xs:element name="deliveryPortName" type="xs:string" minOccurs="0"/>
<xs:element name="status" type="xs:string" />
<xs:element name="createDate" type="xs:dateTime" />
<xs:element name="currency" type="xs:string"/>
<xs:element name="fullName" type="xs:string" minOccurs="0" />
<xs:element name="documentValue" type="xs:decimal" minOccurs="0"/>
<xs:element name="buyerGroup" type="xs:string"/>
<xs:element name="deliveryTerms" type="xs:string" />
<xs:element name="infoContainer" type="xs:string" minOccurs="0"/>
<xs:element name="documentComment" type="xs:string" minOccurs="0" />
<xs:element name="invoiceHolder" type="xs:string"/>
<xs:element name="invoiceAddress" type="xs:string"/>
<xs:element name="invoiceVatcode" type="xs:string"/>
<xs:element name="deliveryAt" type="xs:string" minOccurs="0"/>
<xs:element name="deliveryAddress" type="xs:string" minOccurs="0"/>
<xs:element name="deliveryShip" type="xs:string" minOccurs="0"/>
<xs:element name="logistic" type="xs:boolean" minOccurs="0"/>
<xs:element name="requiresLogistic" type="xs:boolean" default="false" minOccurs="0"/>
<xs:element name="orderLines" type="tns:POrderLineXml" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
问题部分的Java代码
@RestController
public class POrderController {
@Autowired
POrderServiceClient pOrderServiceClient;
@RequestMapping(value="/searchByPoNumber", method=RequestMethod.POST)
public GetPOrderResponse performPoNumberSearch(@RequestParam("poNumber") String poNumber, @RequestParam("token") String token) {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("Model");
pOrderServiceClient.setMarshaller(marshaller);
pOrderServiceClient.setUnmarshaller(marshaller);
GetPOrderResponse res = pOrderServiceClient.getPoNumberOrder(token,poNumber);
return res;
}
}
@Component
public class POrderServiceClient extends WebServiceGatewaySupport {
private String uri = "http://localhost:9001/ws/";
public GetOngoingPOrdersResponse getOngoingPOrders(String token){
GetOngoingPOrdersRequest request = new GetOngoingPOrdersRequest();
request.setAccessToken(token);
GetOngoingPOrdersResponse response =(GetOngoingPOrdersResponse) getWebServiceTemplate()
.marshalSendAndReceive(uri, request);
return response;
}
public GetPOrderResponse getPoNumberOrder(String token, String poNumber) {
GetPOrderRequest request = new GetPOrderRequest();
request.setAccessToken(token);
request.setPoNumber(poNumber);
GetPOrderResponse response = (GetPOrderResponse) getWebServiceTemplate()
.marshalSendAndReceive(uri, request);
return response;
}
}
问题是该请求实际上有效,但不会返回“ pOrder”元素:我已经在JAXB类中进行了调试,并且看到Web Service实际上在响应中填充了该字段,但是,在“解组”过程中,对象会丢失。
如果我尝试通过SOAP-UI询问Web服务,则仍将返回pOrder对象。
有人可以指出我正确的方向吗?