2013-07-01 1 views
1

this 자습서를 기반으로 제품의 배송비를 계산하기 위해 Aramex API을 사용하여 웹 서비스를 만들고 있습니다. 내 주요 방법을 실행하면합니다 (calculateRate 메서드를 호출 할 때)작동을위한 요청 메시지 본문을 역 직렬화 할 때 JAX-WS 오류

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("[email protected]"); 
    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); 
    } 
    } 
} 

, 그것은 나에게 다음과 같은 예외를 제공합니다 : 다음은 내 테스트 클래스이 오류의 원인은 무엇

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) 

및 어떻게 해결할 수 있습니까?

+0

xml 요청은 어떻게 생겼습니까? – jtahlborn

답변

2

QName을 잘못 사용하고 있습니다. 단일 인수 생성자가 이 아니고 네임 스페이스를 사용하면 요소의 "로컬 이름"을 사용합니다. 다른 생성자 중 하나를 사용해야합니다.

이 문제를 스스로 발견하는 한 가지 방법은 테스트 코드가 생성 한 XML 요청을 검사하는 것입니다. 웹 서비스 호출의 문제점을 디버깅 할 때 실제 요청과 응답을 검사해야하는 경우가 많으므로이 문제에 익숙해 져야합니다.