You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Santosh Kulkarni <sk...@jcpenney.com> on 2008/08/01 15:53:20 UTC

Marshalling interceptors

Sorry about previous posting on another thread. Here goes.

Hi, 

I wanted to intercept the marshalling process and catch the exception 
and throw a generic fault instead of the standard fault that I see when 
I turn on validation. 
I tried putting in a validation as given at the end of the email. 
Questions: 
1) Why doesn't this work?(My sysout doesn't show up) Is my phase
constant wrong? 
2) Is this the best way to intercept the marshalling process? 
Thanks 
Santosh 


Spring configuration 
<bean name="theInterceptor" 
                class="com.company.MarshallInterceptor"> 
        </bean> 
</cxf:features> 
        <cxf:inInterceptors> 
                        <ref bean="theInterceptor" /> 
                </cxf:inInterceptors> 
    </cxf:bus> 
<jaxws:endpoint 
        id="paymentService" 
        implementor="com.company.ComeServiceImpl" 
        wsdlLocation="config/wsdl/someService.wsdl" 
        address="/someService"> 
        <jaxws:properties> 
            <entry key="schema-validation-enabled" value="true" /> 
        </jaxws:properties> 
    </jaxws:endpoint> 


Interceptor code: 

package com.company; 

import java.io.IOException; 

import javax.xml.bind.helpers.AbstractMarshallerImpl; 

import org.apache.cxf.attachment.AttachmentDeserializer; 
import org.apache.cxf.interceptor.Fault; 
import org.apache.cxf.message.Message; 
import org.apache.cxf.phase.AbstractPhaseInterceptor; 
import org.apache.cxf.phase.Phase; 

public class MarshallInterceptor extends 
AbstractPhaseInterceptor<Message> { 
    public MarshallInterceptor() { 
        super(Phase.PRE_MARSHAL); 
    } 

    public void handleMessage(Message message) { 
        String contentType = (String) message.get(Message.CONTENT_TYPE);

        System.out.println("handling the message "+contentType); 
    } 

    public void handleFault(Message messageParam) { 
    System.out.println("there was a fault "); 
    } 
}


RE: Marshalling interceptors

Posted by Santosh Kulkarni <sk...@jcpenney.com>.
I did, exactly the way you suggest. No dice. It does not print the
sysout.
Santosh

-----Original Message-----
From: Daniel Kulp [mailto:dkulp@apache.org] 
Sent: Friday, August 01, 2008 11:19 AM
To: users@cxf.apache.org
Subject: Re: Marshalling interceptors


Can you try adding it to the endpoint itself:

<jaxws:endpoint
         id="paymentService"
         implementor="com.company.ComeServiceImpl"
         wsdlLocation="config/wsdl/someService.wsdl"
         address="/someService">
         <jaxws:properties>
             <entry key="schema-validation-enabled" value="true" />
         </jaxws:properties>
         <jaxws:inInterceptors>
                 <ref bean="theInterceptor" />
         </jaxws:inInterceptors>     </jaxws:endpoint>

Dan


On Aug 1, 2008, at 9:53 AM, Santosh Kulkarni wrote:

> Sorry about previous posting on another thread. Here goes.
> Hi,
>
> I wanted to intercept the marshalling process and catch the exception
> and throw a generic fault instead of the standard fault that I see  
> when
> I turn on validation.
> I tried putting in a validation as given at the end of the email.
> Questions:
> 1) Why doesn't this work?(My sysout doesn't show up) Is my phase  
> constant wrong?
> 2) Is this the best way to intercept the marshalling process?
> Thanks
> Santosh
>
>
> Spring configuration
> <bean name="theInterceptor"
>                 class="com.company.MarshallInterceptor">
>         </bean>
> </cxf:features>
>         <cxf:inInterceptors>
>                         <ref bean="theInterceptor" />
>                 </cxf:inInterceptors>
>     </cxf:bus>
> <jaxws:endpoint
>         id="paymentService"
>         implementor="com.company.ComeServiceImpl"
>         wsdlLocation="config/wsdl/someService.wsdl"
>         address="/someService">
>         <jaxws:properties>
>             <entry key="schema-validation-enabled" value="true" />
>         </jaxws:properties>
>     </jaxws:endpoint>
>
>
> Interceptor code:
>
> package com.company;
>
> import java.io.IOException;
>
> import javax.xml.bind.helpers.AbstractMarshallerImpl;
>
> import org.apache.cxf.attachment.AttachmentDeserializer;
> import org.apache.cxf.interceptor.Fault;
> import org.apache.cxf.message.Message;
> import org.apache.cxf.phase.AbstractPhaseInterceptor;
> import org.apache.cxf.phase.Phase;
>
> public class MarshallInterceptor extends
> AbstractPhaseInterceptor<Message> {
>     public MarshallInterceptor() {
>         super(Phase.PRE_MARSHAL);
>     }
>
>     public void handleMessage(Message message) {
>         String contentType = (String)  
> message.get(Message.CONTENT_TYPE);
>         System.out.println("handling the message "+contentType);
>     }
>
>     public void handleFault(Message messageParam) {
>     System.out.println("there was a fault ");
>     }
> }
> The information transmitted is intended only for the person or  
> entity to
> which it is addressed and may contain confidential and/or privileged
> material.  If the reader of this message is not the intended  
> recipient,
> you are hereby notified that your access is unauthorized, and any  
> review,
> dissemination, distribution or copying of this message including any
> attachments is strictly prohibited.   If you are not the intended
> recipient, please contact the sender and delete the material from any
> computer.

---
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog





Re: Marshalling interceptors

Posted by Daniel Kulp <dk...@apache.org>.
Can you try adding it to the endpoint itself:

<jaxws:endpoint
         id="paymentService"
         implementor="com.company.ComeServiceImpl"
         wsdlLocation="config/wsdl/someService.wsdl"
         address="/someService">
         <jaxws:properties>
             <entry key="schema-validation-enabled" value="true" />
         </jaxws:properties>
         <jaxws:inInterceptors>
                 <ref bean="theInterceptor" />
         </jaxws:inInterceptors>     </jaxws:endpoint>

Dan


On Aug 1, 2008, at 9:53 AM, Santosh Kulkarni wrote:

> Sorry about previous posting on another thread. Here goes.
> Hi,
>
> I wanted to intercept the marshalling process and catch the exception
> and throw a generic fault instead of the standard fault that I see  
> when
> I turn on validation.
> I tried putting in a validation as given at the end of the email.
> Questions:
> 1) Why doesn't this work?(My sysout doesn’t show up) Is my phase  
> constant wrong?
> 2) Is this the best way to intercept the marshalling process?
> Thanks
> Santosh
>
>
> Spring configuration
> <bean name="theInterceptor"
>                 class="com.company.MarshallInterceptor">
>         </bean>
> </cxf:features>
>         <cxf:inInterceptors>
>                         <ref bean="theInterceptor" />
>                 </cxf:inInterceptors>
>     </cxf:bus>
> <jaxws:endpoint
>         id="paymentService"
>         implementor="com.company.ComeServiceImpl"
>         wsdlLocation="config/wsdl/someService.wsdl"
>         address="/someService">
>         <jaxws:properties>
>             <entry key="schema-validation-enabled" value="true" />
>         </jaxws:properties>
>     </jaxws:endpoint>
>
>
> Interceptor code:
>
> package com.company;
>
> import java.io.IOException;
>
> import javax.xml.bind.helpers.AbstractMarshallerImpl;
>
> import org.apache.cxf.attachment.AttachmentDeserializer;
> import org.apache.cxf.interceptor.Fault;
> import org.apache.cxf.message.Message;
> import org.apache.cxf.phase.AbstractPhaseInterceptor;
> import org.apache.cxf.phase.Phase;
>
> public class MarshallInterceptor extends
> AbstractPhaseInterceptor<Message> {
>     public MarshallInterceptor() {
>         super(Phase.PRE_MARSHAL);
>     }
>
>     public void handleMessage(Message message) {
>         String contentType = (String)  
> message.get(Message.CONTENT_TYPE);
>         System.out.println("handling the message "+contentType);
>     }
>
>     public void handleFault(Message messageParam) {
>     System.out.println("there was a fault ");
>     }
> }
> The information transmitted is intended only for the person or  
> entity to
> which it is addressed and may contain confidential and/or privileged
> material.  If the reader of this message is not the intended  
> recipient,
> you are hereby notified that your access is unauthorized, and any  
> review,
> dissemination, distribution or copying of this message including any
> attachments is strictly prohibited.   If you are not the intended
> recipient, please contact the sender and delete the material from any
> computer.

---
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog