2017-04-15 9 views
1

wsdl操作名(SOAPAction)を取得しようとしていますが、nullが返されます。私はラクダの青写真にリクエストインターセプタを書いています。行うには
TASK:目的は、Webサービス要求は、ユーザが要求したのSOAPAction /のoperationNameを消費する権利を持っているかどうかのヘッダー&チェックからユーザ名&パスワードを取得傍受することです。どのように私はこれを達成することができますか?これを行うための他のアプローチはありますか?CXF要求インターセプタのSoapMessageからWSDL操作名を取得する方法

public class Interceptor extends AbstractSoapInterceptor { 

    Logger _log = Logger.getLogger(Interceptor.class); 

    public Interceptor() { 
     super(Phase.PRE_LOGICAL); 
    } 

    @Override 
    public void handleMessage(SoapMessage message) { 
     _log.info(".... IM HERE INTERCEPTOR"); 

     Map<String, List<String>> headers = CastUtils.cast((Map) message.get(Message.PROTOCOL_HEADERS)); 
     _log.info(".... IM HERE INTERCEPTOR:::: " + headers.size()); 

     for (Entry<String, List<String>> entry : headers.entrySet()) { 
      _log.info(entry.getKey() + " /// " + entry.getValue().get(0)); 
     } 
    } 
} 

私のコードのログはここにある:以下

.... IM HERE INTERCEPTOR 
.... IM HERE INTERCEPTOR:::: 9 
accept-encoding /// gzip,deflate 
connection /// keep-alive 
Content-Length /// 351 
content-type /// text/xml;charset=UTF-8 
Host /// localhost:8181 
password /// herman 
SOAPAction /// "" 
User-Agent /// Apache-HttpClient/4.1.1 (java 1.5) 
username /// herman 

ここ青写真

<?xml version="1.0" encoding="UTF-8"?> 
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" 
    xmlns:camel="http://camel.apache.org/schema/blueprint" 
    xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0" 
    xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf" 
    xmlns:cxfcore="http://cxf.apache.org/blueprint/core" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="    http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd    http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd    http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd    http://cxf.apache.org/schemas/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd    http://cxf.apache.org/blueprint/jaxws http://cxf.apache.org/blueprint/jaxws.xsd"> 
    <bean class="pk.com.herman.log.query.QueryProcessor" id="QueryProcessor"/> 
    <bean class="pk.com.herman.get.query.QueryGetProcessor" id="QueryGetProcessor"/> 
    <bean class="pk.com.herman.interceptors.Interceptor" id="requestInterceptor"/> 
    <cxfcore:bus bus="cxf"> 
     <cxfcore:inInterceptors> 
      <ref component-id="requestInterceptor"/> 
     </cxfcore:inInterceptors> 
    </cxfcore:bus> 
    <cxf:cxfEndpoint address="/query/" id="queryEndpoint" serviceClass="pk.com.herman.log.query.QueryService"/> 
    <camelContext id="camelContext-282c3eaf-a6ba-4f22-bee7-9ad3fd7ae3ca" xmlns="http://camel.apache.org/schema/blueprint"> 
     <route id="cxf"> 
      <!-- route starts from the cxf webservice in POJO mode --> 
      <from id="_from1" uri="cxf:bean:queryEndpoint"/> 
      <recipientList id="_recipientList1"> 
       <simple>direct:${header.operationName}</simple> 
      </recipientList> 
     </route> 
     <route id="query"> 
      <from id="_from2" uri="direct:reportQuery"/> 
      <log id="_log1" message="Query Call"/> 
      <process id="_process1" ref="QueryProcessor"/> 
      <to id="_to1" uri="log:output"/> 
     </route> 
    </camelContext> 
</blueprint> 

答えて

2

あるソリューションです:)

@Override 
public void handleMessage(SoapMessage message) { 
    _log.info(".... IM HERE INTERCEPTOR"); 

    HttpServletRequest httpRequest = (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST); 

    Message inMessage = message.getExchange().getInMessage(); 
    MessageInfo mi = (MessageInfo) inMessage.get(MessageInfo.class); 
    OperationInfo operationInfo = mi.getOperation(); 

    _log.info("username:: " + httpRequest.getHeader("username")); 
    _log.info("password:: " + httpRequest.getHeader("password")); 

    if (operationInfo != null) { 
     _log.info("operationInfo:: " + operationInfo.getInputName()); 
    } 
} 

ログ:

username:: herman 
password:: herman 
operationInfo:: getQuery 
0

コードの下に試してみてください:。。。。

// SOAPMessageのメッセージ 文字列methodNameの= message.getExchange()getBindingOperationInfo()getOperationInfo()のgetName()getLocalPart(); System.out.println(methodName);

+0

すでにコメント行が回答として与えられています。 – Anmol

関連する問題