cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <sbery...@progress.com>
Subject Re: SOAP interceptor being invoked for REST calls also
Date Wed, 20 Jan 2010 09:42:25 GMT
Hi

Have you registered this interceptor with the jaxws:endpoint only ? Can you post the example
showing how you configured the jaxws 
and jaxrs endpoints

cheers, Sergey

----- Original Message ----- 
From: "Pydipati, Karuna" <kpydipati@stubhub.com>
To: <users@cxf.apache.org>
Sent: Tuesday, January 19, 2010 9:58 PM
Subject: SOAP interceptor being invoked for REST calls also


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: kpydipati@ebay.com <mailto:kpydipati@ebay.com>






Mime
View raw message