2013-01-23 2 views
0

저는 아직 SOAP을 처음 접했고이 문제를 해결하는 데 어려움이 있습니다. 기본적으로 아래 코드는 API 서버에 보낼 SOAP 메시지를 만듭니다. 이 요청을 실행할 때마다 프로그램은 항상 NULL을 반환하고 API 설명서에 포함되지 않은 오류 코드를 반환합니다. 여기있는 누군가가 도울 수 있기를 바랍니다.글로브 LBS API가있는 SOAP 요청

public class LBSController { 
private static final String endpoint = "http://iplaypen.globelabs.com.ph:1881/axis2/services/Platform"; 

public static void main(String[] args) throws SOAPException { 
    //CREATE SOAP MESSAGE 
    SOAPMessage message = MessageFactory.newInstance().createMessage(); 
    SOAPHeader header = message.getSOAPHeader(); 
    header.detachNode(); 

    //SOAP SETTINGS 
    SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); 
    envelope.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/"); 

    SOAPBody body = message.getSOAPBody(); 
    QName bodyName = new QName("getConsent"); 
    SOAPBodyElement bodyElement = body.addBodyElement(bodyName); 

    //SET CONTENT 
    SOAPElement uName = bodyElement.addChildElement("uName"); 
    uName.addTextNode("k2r2t1zvc"); 
    SOAPElement uPin = bodyElement.addChildElement("uPin"); 
    uPin.addTextNode("21737629"); 
    SOAPElement MSISDN = bodyElement.addChildElement("MSISDN"); 
    MSISDN.addTextNode("09278328310"); 

    //CREATE CONNECTION 
    SOAPConnection connection = SOAPConnectionFactory.newInstance().createConnection(); 
    SOAPMessage response = connection.call(message, endpoint); 
    connection.close(); 

    SOAPBody responseBody = response.getSOAPBody(); 
    SOAPBodyElement responseElement = (SOAPBodyElement)responseBody.getChildElements().next(); 
    SOAPElement returnElement = (SOAPElement)responseElement.getChildElements().next(); 

    if(responseBody.getFault()!=null){ 
     System.out.println(returnElement.getValue()+" "+responseBody.getFault().getFaultString()); 
    } else { 
     System.out.println(returnElement.getValue()); 
    } 

    try { 
     System.out.println(getXmlFromSOAPMessage(message)); 
     System.out.println(getXmlFromSOAPMessage(response)); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
} 

private static String getXmlFromSOAPMessage(SOAPMessage msg) throws SOAPException, IOException { 
    ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream(); 
    msg.writeTo(byteArrayOS); 
    return new String(byteArrayOS.toByteArray()); 
} 

}

답변

0

봅니다 응답에서 RAW XML 코드를 인쇄합니다.

여기 코드

public class LBSController 
{ 
    private static final String endpoint = "http://iplaypen.globelabs.com.ph:1881/axis2/services/Platform"; 

public static void main(String[] args) throws SOAPException { 
//CREATE SOAP MESSAGE 
SOAPMessage message = MessageFactory.newInstance().createMessage(); 
SOAPHeader header = message.getSOAPHeader(); 
header.detachNode(); 

//SOAP SETTINGS 
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); 
envelope.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/"); 

SOAPBody body = message.getSOAPBody(); 
QName bodyName = new QName("getConsent"); 
SOAPBodyElement bodyElement = body.addBodyElement(bodyName); 

//SET CONTENT 
SOAPElement uName = bodyElement.addChildElement("uName"); 
uName.addTextNode("k2r2t1zvc"); 
SOAPElement uPin = bodyElement.addChildElement("uPin"); 
uPin.addTextNode("21737629"); 
SOAPElement MSISDN = bodyElement.addChildElement("MSISDN"); 
MSISDN.addTextNode("09278328310"); 

//CREATE CONNECTION 
SOAPConnection connection = SOAPConnectionFactory.newInstance().createConnection(); 
SOAPMessage response = connection.call(message, endpoint); 
connection.close(); 

SOAPBody responseBody = response.getSOAPBody(); 
SOAPBodyElement responseElement = (SOAPBodyElement)responseBody.getChildElements().next(); 
SOAPElement returnElement = (SOAPElement)responseElement.getChildElements().next(); 

if(responseBody.getFault()!=null){ 
    System.out.println(returnElement.getValue()+" "+responseBody.getFault().getFaultString()); 
} else { 
    System.out.println(returnElement.getValue()); 
} 

//PRINT OUT RAW XML 
ByteArrayOutputStream out = new ByteArrayOutputStream(); 
String xml = ""; 
try { 
    response.writeTo(out); 
    xml = out.toString("UTF-8"); 
} catch (Exception e) 
{ 
    System.out.println(""+e); 
    //log.error(e.getMessage(),e); 
}  
System.out.println(""+xml); 

/* 
try { 
    System.out.println(getXmlFromSOAPMessage(message)); 
    System.out.println(getXmlFromSOAPMessage(response)); 
} catch (IOException e) { 
    e.printStackTrace(); 
} 
* */ 
} 

run: 
    null 
    <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
<soapenv:Body><ns:getLocResponse xmlns:ns="http://ESCPlatform/xsd"> 
<ns:LocationReturn><ns:return>506</ns:return><ns:tranId>23737563092783283102013</ns:tranId> 
</ns:LocationReturn></ns:getLocResponse> 
</soapenv:Body> 
</soapenv:Envelope> 
    BUILD SUCCESSFUL (total time: 3 seconds) 
+0

안녕 위의 코드로부터의 응답 값, 답장을 보내 주셔서 감사합니다, 난 이미이 문제를 해결했습니다. "http : // ESCPlatform/xsd"선언에 문제가있는 것으로 보입니다. 어쨌든 고마워. –