As Sergey alluded to, if the interceptors are configured on the Bus, they will 
be applied to EVERYTHING in the Bus.   Those interceptors generally have to be 
a bit more generic so that they can apply to REST and SOAP endpoints and such.  
 
Soap specific things should probably be configured on the endpoints if the bus 
is used for both soap and rest things.

Dan


On Tue January 19 2010 4:58:50 pm Pydipati, Karuna wrote:
> Hi
> 
> I have a strange issue. I intend to write a SOAP Interceptor and wrote
> something like this and it is working for SOAP calls. But, when REST
> call is coming, same SOAPInterceptor gets invoked and throwing
> exception. My questions is..why is this CredentialsCheckInterceptor
> which is extending AbstractSoapInterceptor being called for REST calls?
> As far as I know.., this interceptor should be invoked for SOAP calls
> only. Correct me, if I am wrong. If this SOAPinterceptor is being called
> for both SOAP and REST..then..how to write an interceptor which will be
> invoked only at SOAP time.., not at REST call time. Please advise me.
> Thanks ahead.
> 
> 
> Exception:
> ----------
> 
> java.lang.ClassCastException: org.apache.cxf.message.XMLMessage
>         at
> com.xxx.webservices.common.CredentialsCheckInterceptor.handleMessage(Cre
> dentialsCheckInterceptor.java:30)
>         at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC
> hain.java:236)
>         at
> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiati
> onObserver.java:104)
>         at
> org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestin
> ation.java:99)
>         at
> org.apache.cxf.transport.servlet.ServletController.invokeDestination(Ser
> vletController.java:452)
>         at
> org.apache.cxf.transport.servlet.ServletController.invoke(ServletControl
> ler.java:159)
>         at
> org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFSe
> rvlet.java:220)
>         at
> org.apache.cxf.transport.servlet.AbstractCXFServlet.doGet(AbstractCXFSer
> vlet.java:158)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
> 
> 
> 
> Interceptor intended for SOAP calls only
> -------------------------------------------------------
> 
> public class CredentialsCheckInterceptor extends AbstractSoapInterceptor
> {
> 
>  /** The Constant log. */
>  private static final Log log =
> LogFactory.getLog(CredentialsCheckInterceptor.class);
>  // private StubnetUserSessionFacade stubnetSessionFacade;
> 
>  public static final String HTTP_REQUEST = "HTTP.REQUEST";
> 
>  private static final List<String> NON_AUTHENTICATED_SERVICE_LOCAL_NAMES
> = new LinkedList<String>();
> 
>  static {
>   NON_AUTHENTICATED_SERVICE_LOCAL_NAMES.add("createStubnetSession");
>  }
> 
>  public CredentialsCheckInterceptor() {
>   super(Phase.PRE_INVOKE);
>   //  addAfter(EndpointSelectionInterceptor.class.getName());
>  }
> 
>  public void handleMessage(SoapMessage message) {
>   log.debug("CredentialsCheckInterceptor.handleMessage..." );
>   boolean valid = false;
> 
>   Object rawQname =
> message.getMessage().get("javax.xml.ws.wsdl.operation");;
>   if (rawQname != null && rawQname instanceof QName) {
>    QName qname =
> (QName)message.getMessage().get("javax.xml.ws.wsdl.operation");
>    String opName = qname.getLocalPart();
>    for (String nonAuthServiceName :
> NON_AUTHENTICATED_SERVICE_LOCAL_NAMES) {
>     if (nonAuthServiceName.equals( opName )) {
>      valid = true;
>      break;
>     }
>    }
>   } else {
>    log.warn("Did not find an instance of QName in SoapMessage
> representing 'javax.xml.ws.wsdl.operation'; instead, found: " +
> rawQname);
>   }
> 
>   if (!valid) {
>    List contentList = message.getContent(java.util.List.class);
>    for (Iterator iter = contentList.iterator(); iter.hasNext(); ) {
>     Object o = iter.next();
>     if (o instanceof AuthHeader) {
>      AuthHeader authHeader = (AuthHeader)o;
>      valid = validateAuthHeader(authHeader);
>     }
>    }
>   }
> 
>   if (!valid) {
>    List<Header> headers = message.getHeaders();
>    for (Header header : headers) {
>     QName qname = header.getName();
>     log.info("Found a SOAP header : " + qname);
>     if (qname.getLocalPart().equalsIgnoreCase("authHeader")) {
>      Element element = (Element)header.getObject();
>      valid = validateAuthHeaderElement(element);
>     }
>    }
>   }
> 
>   if (!valid) {
>    throw new UnauthenticatedRequestException();
>   }
> 
>  }
> 
> 
> 
> Regards
> 
> Karuna Pydipati
> 
> StubHub/eBay - Platform & Services
> 
> Phone: (415)222-8752
> 
> Email: [email protected] <mailto:[email protected]>
> 

-- 
Daniel Kulp
[email protected]
http://www.dankulp.com/blog

Reply via email to