2017-06-02 59 views
0

從SpringBoot應用程序使用SOAP服務,應用程序正在將詳細信息記錄在* .log文件中.SOAP請求在xml中具有請求的用戶名和密碼,如何禁用要禁用的憑證從打印日誌文件中獲取。應用程序正在使用logback-spring.xml進行日誌記錄config.I希望日誌中的SOAP請求xml,但不需要用戶名和密碼。在SOAP服務日誌跟蹤中禁用打印憑證

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> 

搖籃依賴關係:

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