2017-06-02 13 views
0

SOAPサービスはSpringBootアプリケーションから消費され、アプリケーションは* .logファイルの詳細を記録します.SOAP要求にはxmlの要求のユーザー名とパスワードがあります。ログファイルには印刷されません。アプリケーションはログを記録するためにlogback-spring.xmlを使用しています。ログにはSOAPリクエストxmlが必要ですが、ユーザー名とパスワードは必要ありません。SOAPサービスのログのトレースで印刷資格情報を無効にする

:* .logの

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Header> 
     <wsse:Security soap:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
     xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
     <wsse:UsernameToken wsu:Id="UsernameToken-sometokenvalue"> 
      <wsse:Username>Username</wsse:Username> 
      <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Password</wsse:Password> 
     </wsse:UsernameToken> 
     </wsse:Security> 
    </soap:Header> 
    <soap:Body> 
     <ns2:GetRequest xmlns="http://serviceapi.userwebsite.com/common/v1/serviceHeader" xmlns:ns2="http://serviceapi.userwebsite.com/service/v1" > 
     <RequestHeader> 
      <ServiceVersion>0.0.0</ServiceVersion> 
      <UserID>userID</UserID> 
     </RequestHeader> 
     <ns2:UserInfo StartAt=""> 
      <ns2:ID>P/O</ns2:ID> 
     </ns2:UserInfo> 
     </ns2:GetRequest> 
    </soap:Body> 
</soap:Envelope> 

logback-spring.xml

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <include resource="org/springframework/boot/logging/logback/base.xml" /> 

    <springProperty name="logsPath" source="app.logs.path" /> 

    <springProfile name="test,dev"> 

     <appender name="dailyRollingFileAppender" 
      class="ch.qos.logback.core.rolling.RollingFileAppender"> 
      <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 
       <FileNamePattern>${logsPath}UserApp%d{MMddyyyy}.log 
       </FileNamePattern> 
       <maxHistory>30</maxHistory> 
      </rollingPolicy> 

      <encoder> 
       <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{35}-%msg %n</Pattern> 
      </encoder> 
     </appender> 
     <root level="INFO"> 
      <appender-ref ref="dailyRollingFileAppender" /> 
     </root> 
    </springProfile> 

のGradleの依存関係にあるユーザー名とパスワードで

SOAPリクエスト

apply plugin: "no.nils.wsdl2java" wsdl2javaExt { cxfVersion = "3.1.7" } dependencies { compile("org.springframework.boot:spring-boot-starter-web") compile("org.springframework.boot:spring-boot-starter-batch") compile("org.springframework.boot:spring-boot-starter-mail") compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.5' compile group: 'org.apache.cxf', name: 'cxf-spring-boot-starter-jaxws', version: '3.1.10' compile group: 'org.apache.cxf', name: 'cxf-rt-ws-security', version: '3.1.10' testCompile('org.springframework.boot:spring-boot-starter-test') } 

答えて

1

カスタムSOAPHandlerを実装して、SoapMessageにアクセスし、必要に応じて出力ログメッセージを変換することができます。

@Override 
public boolean handleMessage(SOAPMessageContext arg0) { 
    SOAPMessage message = arg0.getMessage(); 
    boolean isOutboundMessage = (Boolean) arg0.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); 
    if (isOutboundMessage) { 
     System.out.println("OUTBOUND MESSAGE"); 
    } else { 
     System.out.println("INBOUND MESSAGE"); 
    } 
    try { 
     Source source = message.getSOAPPart().getContent(); 

     Transformer transformer = TransformerFactory.newInstance().newTransformer(); 

     transformer.setOutputProperty(OutputKeys.INDENT, "yes"); 
     transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); 

     transformer.transform(source, new StreamResult(System.out)); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    return true; 
} 

応答をhere

+0

感謝を参照してください、apacheの-CFXベースlibと他の依存関係のため、このフィットは、前述したのか? – sunleo

+0

@sunleoよろしくお願いします。私はそれがapache-cfxで動作すると思います。私はJAX-WSでこのアプローチを使用しました –

+0

ありがとう、便利でしたが、最新バージョンでは多くの違いがあります。 – sunleo

関連する問題