2012-02-20 14 views
2

Spring 3 IOCを使用しているJAX-WS WebServiceがあります。私はSpringのアスペクトをコーディングして例外を処理し、コールを完了する前にWebServiceクラスでそれらが正しく処理されるようにしました。私のAspectでは、ユーザーのロケール(SOAPヘッダーで定義されている)にアクセスしたいと思っていますが、これを行う方法がわかりません。JAX-WSのSpring AspectからSOAPMessageにアクセスする方法は?

私はハンドラでロケールを取得できますが、それは私の面で私を助けません。私はWebServiceContextを注入しようとしましたが、それは常にnullです。

が周り掘り少しはそれを示すように思われhttps://issues.apache.org/jira/browse/CXF-2674に私を指摘:

  1. 春意図的にWebServiceContextのはSOAPMessageContext

ための薄いラッパーです

  • WebServiceContextのオブジェクトを注入していませんしかし、代わりにSOAPMessageContextをオートワイヤリングしようとすると、次のエラーメッセージでも失敗します。

    Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.xml.ws.handler.soap.SOAPMessageContext com.cws.cs.lendingsimulationservice.error.ServiceErrorInterceptor.webServiceContext; nested exception is java.lang.IllegalArgumentException: Can not set javax.xml.ws.handler.soap.SOAPMessageContext field com.cws.cs.lendingsimulationservice.error.ServiceErrorInterceptor.webServiceContext to java.util.LinkedHashMap 
         at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:502) [spring-beans-3.0.5.RELEASE.jar:] 
         at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84) [spring-beans-3.0.5.RELEASE.jar:] 
         at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282) [spring-beans-3.0.5.RELEASE.jar:] 
         ... 21 more 
    Caused by: java.lang.IllegalArgumentException: Can not set javax.xml.ws.handler.soap.SOAPMessageContext field com.cws.cs.lendingsimulationservice.error.ServiceErrorInterceptor.webServiceContext to java.util.LinkedHashMap 
         at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146) [:1.6.0_29] 
         at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150) [:1.6.0_29] 
         at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63) [:1.6.0_29] 
         at java.lang.reflect.Field.set(Field.java:657) [:1.6.0_29] 
         at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:498) [spring-beans-3.0.5.RELEASE.jar:] 
         ... 23 more 
    

    私は、ある情報の中からこの情報にアクセスする方法が必要であることを理解していますが、その方法を理解できないようです。

    SOAPMessageオブジェクトを代わりに注入しようとすると、org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [javax.xml.soap.SOAPMessage] found for dependencyというエラーメッセージが表示されます。

    誰かが正しい方向に私を向けることができますか?

    おかげで、

    エリック

  • +0

    'SOAPMessageContext'をオートワイヤリングの背後にあるアイデアは何ですか?アプリケーションレベルでは存在しません。メッセージが送受信される場合にのみ存在するため、一般的にはスコープが必要です。 IN JAX-WS 'SOAPMessageContext'がハンドラチェーンに渡されます。これは、あなたがそれを交差させ、あなたのアスペクトのためにスレッドローカルにバインドできる場所です。 –

    +0

    私の考えは間違っていたと思いますが、処理の特定の場所でSOAPHeaderの何かにアクセスする必要があるという考えがありました。エンドポイントでそれを抽出し、それをパラメータとして渡すことは正しいこととは思われないので、私は特定の情報が必要なときにヘッダー(そしてConscontently MessageContext)を挿入したかったのです。それがうまくいかなかったとき、私がやったことは、Handlerで情報を抽出し、それをリクエストスコープのオブジェクトに設定し、それを必要とするクラスに注入することです。私はちょうど良い解決策があるだろうと思っていた。 –

    +0

    私は同じトラック上にいると思います。「SOAPMessageContext」はSpringに関してスコープを必要とします。あなた自身の質問に対する答えとしていくつかのコードを投稿することができれば、コミュニティは感謝します。 –

    答えて

    2

    は私のソリューションは、ハンドラとリクエストスコープのオブジェクトを使用しています。 CGLIBを必要としないようにインターフェイスを持つSOAPHeaderDataImplは、基本的なPOJOである

    <!-- SOAPHeaderData --> 
    <bean id="soapHeaderData" class="com.cws.cs.lendingsimulationservice.header.SOAPHeaderDataImpl" scope="request"> 
        <aop:scoped-proxy proxy-target-class="false"/> 
    </bean> 
    

    (:SOAPHeaderDataの

    public class ServiceContextHandler implements SOAPHandler<SOAPMessageContext>{ 
    
        /** 
        * Logger 
        */ 
        private static final Logger logger = LoggerFactory.getLogger(ServiceContextHandler.class); 
    
        /** 
        * Request object 
        */ 
        @Autowired 
        private SOAPHeaderData soapHeaderData; 
    
        /** 
        * Ensure that the bean has its parameters injected appropriately 
        */ 
        @PostConstruct 
        public void init() { 
         SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this); 
        } 
    
        /** 
        * Nothing to do on end of message 
        */ 
        public void close(MessageContext context) { 
        } 
    
    
        /** 
        * Nothing to do for a fault 
        */ 
        public boolean handleFault(SOAPMessageContext context) { 
         return true; 
        } 
    
        /** 
        * Process the message 
        */ 
        public boolean handleMessage(SOAPMessageContext context) { 
         // no need to bother with outbound requests 
         if(!((Boolean) context.get(SOAPMessageContext.MESSAGE_OUTBOUND_PROPERTY)).booleanValue()) 
          process(context); 
         return true; 
        } 
    
        /** 
        * Doesn't handle any specific QNames in the header 
        */ 
        public Set<QName> getHeaders() { 
         return null; 
        } 
    
    
        /** 
        * Extract the header parameters 
        * @param context 
        */ 
        @SuppressWarnings("unchecked") 
        private void process(SOAPMessageContext context) { 
         // Creating the XML tree 
         try { 
          JAXBContext jc = JAXBContext.newInstance(ObjectFactory.class); 
          Object[] headers = context.getHeaders(new ObjectFactory().createServiceContext(null).getName(), jc, true); 
    
          // find the service context element 
          for(Object header : headers){ 
           if((header instanceof JAXBElement<?>) && ((JAXBElement<?>)header).getValue() instanceof ServiceContextType){ 
            // found the service context element 
            soapHeaderData.setServiceContext(((JAXBElement<ServiceContextType>)header).getValue()); 
            break; 
           } 
          } 
    
         } catch (JAXBException e) { 
          logger.error(ExceptionUtils.getStackTrace(e)); 
         } catch (WebServiceException e) { 
          logger.error(ExceptionUtils.getStackTrace(e)); 
         } 
        } 
    } 
    

    DEFN:うまくいけば他の誰かが将来

    ハンドラで、これは便利かもしれません)。

    希望すると便利です。何かが不明な場合は、私に知らせてください。

    おかげで、

    エリック

    +0

    コードを共有していただきありがとうございます。それは私のための日を救った! – Dmitry

    +0

    @ドミトリー喜んで助けになるかもしれません。すべてのことをきちんとやり遂げる方法を理解するまでには、しばらく時間がかかりました。 :) –

    +0

    このハンドラを使用するためにあなたのwebserviceで@Handlerchainを使用しませんでしたか? – Pretty

    関連する問題