2015-01-09 3 views
3

라고하지 않을 때 실패하지만 내가 만든 후 내가 전화하면 내가 그것을 생략 할 때 내는 SOAPMessage의 서비스 호출이 성공적으로 완료 SOAPMessage.writeTo(out)하지만 실패합니다.SOAP 서비스 호출은 SOAPMessage.writeTo가 나는 <strong>SOAP</strong> 서비스를 호출하려고

저는 전화를 걸기 전에 반드시 writeTo()이 필수 단계가 아니며 잘못된 것을하고 있다고 확신합니다.

아이디어가 있으십니까? 여기

은 세부 사항입니다

내 고객

public class Test { 
    public static void main(String args[]) throws Exception { 
     // Create SOAP Connection 
     SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); 
     SOAPConnection soapConnection = soapConnectionFactory.createConnection(); 

     // Send SOAP Message to SOAP Server 
     String url = "https://mydomain.com/webservices/gateway/IdMgt/CorporateDirectoryLookupPort"; 
     SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url); 

     // print SOAP Response 
     soapResponse.writeTo(System.out); 
     soapConnection.close(); 
    } 

    private static SOAPMessage createSOAPRequest() throws Exception { 

     String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" 
       + "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" 
       + "<soapenv:Header>" 
       + "<ns1:Security soapenv:mustUnderstand=\"0\" xmlns:ns1=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">" 
       + "<ns1:UsernameToken>" 
       + "<ns1:Username></ns1:Username>" 
       + "<ns1:Password></ns1:Password>" 
       + "</ns1:UsernameToken>" 
       + "</ns1:Security>" 
       + "</soapenv:Header>" 
       + "<soapenv:Body>" 
       + "<GetAccountDetailsRequest2 xmlns=\"http://anotherdomain/schema/tCorporateDirectoryLookupV1\">" 
       + "<MessageHeader xmlns=\"\"/><UserID xmlns=\"\"></UserID>" 
       + "<AccountID xmlns=\"\">ServiceDeskAPIprd</AccountID>" 
       + "</GetAccountDetailsRequest2></soapenv:Body>" 
       + "</soapenv:Envelope>"; 

     InputStream is = new ByteArrayInputStream(xml.getBytes()); 
     SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(
       null, is); 

     /* Print the request message */ 
     soapMessage.writeTo(System.out); 
     System.out.println(); 
     return soapMessage; 
    } 
} 

createSOAPRequest에서 soapMessage.writeTo(System.out)내가 유효한 응답을 주석 처리하지이지만이 주석 때 나는

<?xml version="1.0" encoding="utf-8"?> 
<soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<soapenv:Body> 
    <soapenv:Fault> 
    <faultcode xmlns:ns1="http://xml.apache.org/axis/">ns1:Client.NoSOAPAction</faultcode> 
    <faultstring>no SOAPAction header!</faultstring> 
    <detail> 
    <ns2:hostname xmlns:ns2="http://xml.apache.org/axis/">lxvirt150</ns2:hostname> 
    </detail> 
    </soapenv:Fault> 
</soapenv:Body> 
</soapenv:Envelope> 
+0

나는 아주 똑같은 문제에 직면 해있다. 나는 "messageByteCount"SoapMessage의 필드가 writeTo 메소드 (나의 경우 0에서 524까지)를 호출 한 후에 업데이트되었다는 것을 알아 차렸다. writeTo 메서드를 실행하는 동안 saveMessage 메서드가 호출 된 것을 알았 기 때문에 MessageFactory를 호출 한 직후에 writeTo를 호출하는 대신 해당 메서드를 시도했지만 실제로는 사용하지 않았습니다. 알아 냈어? –

답변

1
를 얻을 수

writeTo 메소드의 구현을 살펴보면, 나는 그들이 "SOAPAction" 그래서 당신은, 당신이 실제로 바로 그 SOAPMessage의 작성 후 헤더를 직접 설정할 수는, writeTo 메소드의 호출을 피하려면

if (isCorrectSoapVersion(4)) { 
     String[] soapAction = this.headers.getHeader("SOAPAction"); 

     if ((soapAction == null) || (soapAction.length == 0)) { 
      this.headers.setHeader("SOAPAction", "\"\""); 
    } 
} 

: 그것의 끝에 헤더

SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(
      null, is); 
soapMessage.getMimeHeaders().addHeader("SOAPAction", "\"\""); 

그 나를 위해 일했다. 도움이 되었길 바래요!

피에르

0

나는 방법은 그것을 해결() 같은 문제를 경험하지만, saveChanges를 발견했다. 자바 문서에서 :

Updates this SOAPMessage object with all the changes that 
have been made to it. This method is called automatically when 
SOAPMessage writeTo(OutputStream) is called. However, if 
changes are made to a message that was received or to one that has 
already been sent, the method saveChanges needs to be 
called explicitly in order to save the changes. The method saveChanges also generates any changes that can be read back (for example, a MessageId in profiles that support a message id). All MIME headers in a message that is created for sending purposes are guaranteed to have valid values only after saveChanges has been called. 
In addition, this method marks the point at which the data from all 
constituent AttachmentPart objects are pulled into the 
message.