2011-09-13 5 views
1

나는 한달 이상이 문제에 직면하고있다. 그래서 나는 정말로 당신의 도움으로 기뻐할 것이다. 사실 SOAP 메시지 (요청)를 파싱하여 필요한 정보를 검색 할 수있는 방법을 묻고있다. 보안 정보로이 메시지 나 응답에 대한SOAP 메시지를 자바로 비 정렬 화하거나 단순히 SOAP 메시지를 파싱 하시겠습니까?


감사의 몸에서 어떠한 정보를하지만, 내가 WS-SecurityPolicy와 또 다른 problerm 처리하고 알고 난은 XML을 구문 분석 마침내해야하는 경우 이와 같은 파일 : <?xml version="1.0" encoding="UTF-8"?>

<sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"> 
     <wsp:Policy> 
     <sp:TransportToken> 
      <wsp:Policy> 
      <sp:HttpsToken RequireClientCertificate="false"/> 
      </wsp:Policy> 
     </sp:TransportToken> 
     <sp:AlgorithmSuite> 
      <wsp:Policy> 
      <sp:Basic128/> 
      </wsp:Policy> 
     </sp:AlgorithmSuite> 
     <sp:Layout> 
      <wsp:Policy> 
      <sp:Lax/> 
      </wsp:Policy> 
     </sp:Layout> 
     <sp:IncludeTimestamp/> 
     </wsp:Policy> 
    </sp:TransportBinding> 
    <sp:SignedSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"> 
     <wsp:Policy> 
      <sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient" /> 
     </wsp:Policy> 
    </sp:SignedSupportingTokens> 

'

이 XML 파일의 이름이 Policy.xml이고 WS-SecurityPolicy 규칙이 있어야 함을 알고 있습니다.

+0

영어로만 게시 할 수 있습니까? 감사. – Kev

답변

4

메시지 내용에 따라 다릅니다. 귀하의 질문에 jaxb으로 태그를 지정했기 때문에 비누 메시지 안에 xml 데이터가 직렬화되어 있다고 생각합니다. 이 경우 당신은 자바 클래스의 인스턴스에 메시지를 변환하는 JAXB의 Unmarshaller에 사용할 수 :

JAXBContext jbc = JAXBContext.newInstance("com.mypackage"); 
Unmarshaller um = jbc.createUnmarshaller(); 

JAXBElement<MyClass> element = um.unmarshal(parameterNode, MyClass.class); 
MyClass data = element.getValue(); 
1

당신은 이미 비누 객체를 갖고 있으며 메시지 내용을 구문 분석하려고합니다.

// assumptions: soapMessage contains the SoapMessage 
     final ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
     soapMessage.writeTo(baos); 
     final InputSource inputSource = new InputSource(new StringReader(
      new String(baos.toByteArray()))); 
     final DocumentBuilderFactory dbFactory = DocumentBuilderFactory 
      .newInstance(); 
     final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); 
     final Document doc = dBuilder.parse(inputSource); 
     doc.normalize(); 
// after this use Xpath to process the soapMessage 

비누 메시지가 문자열 인 경우 문자열을 사용하여 Document 개체를 만들 수 있습니다.

2

나는 POJO 클래스에, 내가 도움이 될 희망 SOAPResponse 메시지에서 비 직렬화하기 위해이 코드를 발견했습니다.

//unmarshalling 
    JAXBContext jc = JAXBContext.newInstance(MyPOJO.class); 
    Unmarshaller um = jc.createUnmarshaller(); 
    MyPOJO output = (MyPOJO)um.unmarshal(soapResponse.getSOAPBody().extractContentAsDocument());