gpt4 book ai didi

java - 反序列化操作请求消息正文时出现 JAX-WS 错误

转载 作者:行者123 更新时间:2023-11-30 04:19:39 24 4
gpt4 key购买 nike

我正在使用 Aramex API 创建 Web 服务根据 this 计算产品的运费教程。以下是我的测试类:

package com.test;

import net.aramex.ws.shippingapi.v1.*;

import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import javax.xml.ws.WebServiceRef;
import java.net.URL;

public class AramexRateCalculatorClient {

@WebServiceRef(wsdlLocation = "C:\\aramex-rates-calculator-wsdl.wsdl")
private static Service10_Service service;

public static void main(String [] args) {

try {

service = new Service10_Service();

RateCalculatorRequest request = new RateCalculatorRequest();
ClientInfo clientInfo = new ClientInfo();
clientInfo.setUserName("mymail@gmail.com");
clientInfo.setPassword("abcd1234");
clientInfo.setVersion("v1.0");

Transaction transaction = new Transaction();
transaction.setReference1("001");

Address orgAddress = new Address();
orgAddress.setCity("Amman");
orgAddress.setCountryCode("JO");

Address dstAddress = new Address();
dstAddress.setCity("Dubai");
dstAddress.setCountryCode("AE");

ShipmentDetails shipmentDetails = new ShipmentDetails();
shipmentDetails.setPaymentType("P");
shipmentDetails.setProductGroup("EXP");
shipmentDetails.setProductType("PPX");

Weight weight = new Weight();
weight.setUnit("KG");
weight.setValue(5);
Weight cweight = new Weight();
cweight.setUnit("KG");
cweight.setValue(5);
shipmentDetails.setActualWeight(weight);
shipmentDetails.setChargeableWeight(cweight);
shipmentDetails.setNumberOfPieces(5);

JAXBElement<ClientInfo> jaxbElementClientInfo = new JAXBElement(new QName("http://ws.aramex.net/ShippingAPI/v1/") , ClientInfo.class , clientInfo);
request.setClientInfo(jaxbElementClientInfo);

JAXBElement<Transaction> jaxbElementTransaction = new JAXBElement(new QName("http://ws.aramex.net/ShippingAPI/v1/") , Transaction.class , transaction);
request.setTransaction(jaxbElementTransaction);

JAXBElement<Address> jaxbElementorgAddress = new JAXBElement(new QName("http://ws.aramex.net/ShippingAPI/v1/") , Address.class , orgAddress);
request.setOriginAddress(jaxbElementorgAddress);

JAXBElement<Address> jaxbElementDstAddress = new JAXBElement(new QName("http://ws.aramex.net/ShippingAPI/v1/") , Address.class , dstAddress);
request.setDestinationAddress(jaxbElementDstAddress);

JAXBElement<ShipmentDetails> jaxbElementShipmentDetails = new JAXBElement(new QName("http://ws.aramex.net/ShippingAPI/v1/") , ShipmentDetails.class , shipmentDetails);
request.setShipmentDetails(jaxbElementShipmentDetails);


RateCalculatorResponse response = service.getService10().calculateRate(request);
System.out.println("success");

} catch (Exception ex) {
System.out.println(ex);
}
}
}

当我运行 main 方法时,它给出以下异常(调用 calculateRate 方法时):

com.sun.xml.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'CalculateRate'. Name cannot begin with the '/' character, hexadecimal value 0x2F. Line 1, position 244. Please see the server log to find more detail regarding exact cause of the failure.
at com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:193)
at com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:134)
at com.sun.xml.ws.client.sei.StubHandler.readResponse(StubHandler.java:252)
at com.sun.xml.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:181)
at com.sun.xml.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:262)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:128)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:102)
at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:154)
at $Proxy35.calculateRate(Unknown Source)
at com.aeturnum.ajlan.AramexRateCalculatorClient.main(AramexRateCalculatorClient.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

此错误的原因是什么以及如何修复它?

最佳答案

您使用的QName错误。单参数构造函数采用命名空间,它采用元素的“本地名称”。您需要使用其他构造函数之一。

自行发现此问题的一种方法是检查测试代码生成的 xml 请求。您应该对此感到满意,因为在调试 Web 服务调用问题时经常需要检查实际请求和响应。

关于java - 反序列化操作请求消息正文时出现 JAX-WS 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17406944/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com