pathum83 pathum83 - 23 days ago 11
Java Question

JAX-WS error in deserializing body of request message for operation

I'm creating a web service by using Aramex API (http://www.aramex.com/developers/aramex-apis/42007/Rates-Calculator-API) to calculate the shipping rate for a product (Refering http://docs.oracle.com/javaee/6/tutorial/doc/bnayn.html). Below is my testing class.

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);
}
}

}


When i run my main method it gives me below exception (when call the
calculateRate
method).




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)


I couldn't find exact reason for this. Can anyone help me?

Answer

You are using QName wrong. the single argument constructor does not take a namespace, it takes the "local name" of the element. you need to use one of the other constructors.

one way to find this problem on your own would have been to examine the xml request that your test code generated. you should become comfortable with this, as it is frequently necessary to examine the actual requests and responses when debugging problems with webservice calls.

Comments