1 Reply Latest reply on Oct 20, 2008 3:52 AM by Gert Vanthienen

    CXFBC Baic Authentication

    Neena Mathew Newbie

      Does CXFBC support basic authentication?

       

      I tried by writing a interceptor for cxfBC consumer. When I tried to invoke the service it asked me for userid password, but later it failed on unmarshing my message saying the reuired elements are missing. Eventhough I send all required fields.

       

      Here is my Interceptor class

       

               @Override public void handleMessage(Message message) throws Fault {

                   // This is set by CXF

                   AuthorizationPolicy policy = message.get(AuthorizationPolicy.class);

                    

                   // If the policy is not set, the user did not specify credentials

                   // A 401 is sent to the client to indicate that authentication is required

                   if (policy == null) {

                       if (log.isDebugEnabled()) {

                           log.debug("User attempted to log in with no credentials");

                       }

                       sendErrorResponse(message, HttpURLConnection.HTTP_UNAUTHORIZED);

                       return;

                   }

                    

                   if (log.isDebugEnabled()) {

                       log.debug("Logging in use: " + policy.getUserName());

                   }

                    

                   // Verify the password

                   String realPassword = users.get(policy.getUserName());

                   if (realPassword == null || !realPassword.equals(policy.getPassword())) {

                       log.warn("Invalid username or password for user: " + policy.getUserName());

                       sendErrorResponse(message, HttpURLConnection.HTTP_FORBIDDEN);

                   }

               }

       

       

      Here is my xbean

       

       

       

      Here is the error I am getting

       

      Oct 3, 2008 9:38:53 AM org.apache.cxf.phase.PhaseInterceptorChain doIntercept

      INFO: Interceptor has thrown exception, unwinding now

      org.apache.cxf.interceptor.Fault: Unmarshalling Error: cvc-complex-type.2.4.a: Invalid content was f

      ound starting with element 'm0:Message'. One of '{"http://services.apache.org/sample/funds/wir

      e/types":Messages, "http://services.apache.org/sample/funds/wire/types":CashTotalAmount}' is e

      xpected.

              at org.apache.servicemix.cxfbc.CxfBcConsumer$JbiPostInvokerInterceptor.handleMessage(CxfBcCo

      nsumer.java:560)

              at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)

              at org.apache.cxf.phase.PhaseInterceptorChain.resume(PhaseInterceptorChain.java:198)

              at org.apache.servicemix.cxfbc.CxfBcConsumer.process(CxfBcConsumer.java:203)

              at org.apache.servicemix.cxfbc.CxfBcConsumer$JbiInvokerInterceptor.handleMessage(CxfBcConsum

      er.java:536)

              at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)

              at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:7

      7)

              at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestinat

      ion.java:278)

              at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.j

      ava:252)

              at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:70)

              at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)

              at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:2

      06)

              at org.mortbay.jetty.handler.HandlerList.handle(HandlerList.java:49)

              at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)

              at org.mortbay.jetty.Server.handle(Server.java:324)

              at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)

              at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)

              at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)

              at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)

              at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)

              at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)

              at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)

      Caused by: org.apache.cxf.interceptor.Fault: Unmarshalling Error: cvc-complex-type.2.4.a: Invalid co

      ntent was found starting with element 'm0:Message'. One of '{"http://services..apache.org/sample/funds/wire/types":Messages, "http://services.apache.org/sample/funds/wire/types":CashTotalAm

      ount}' is expected.

              at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:598)

              at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:499)

              at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:40)

              at org.apache.cxf.binding.jbi.interceptor.JBIWrapperInInterceptor.handleMessage(JBIWrapperIn

      Interceptor.java:124)

              at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)

              at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:7

      7)

              at org.apache.cxf.transport.jbi.JBIDispatcherUtil.dispatch(JBIDispatcherUtil.java:156)

              at org.apache.servicemix.cxfse.CxfSeEndpoint.process(CxfSeEndpoint.java:232)

              at org.apache.servicemix.common.AsyncBaseLifeCycle.doProcess(AsyncBaseLifeCycle.java:540)

              at org.apache.servicemix.common.AsyncBaseLifeCycle.processExchange(AsyncBaseLifeCycle.java:4

      92)

              at org.apache.servicemix.common.BaseLifeCycle.onMessageExchange(BaseLifeCycle.java:46)

              at org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.processInBound(DeliveryChannelImp

      l.java:610)

              at org.apache.servicemix.jbi.nmr.flow.AbstractFlow.doRouting(AbstractFlow.java:172)

              at org.apache.servicemix.jbi.nmr.flow.seda.SedaFlow.doRouting(SedaFlow.java:167)

              at org.apache.servicemix.jbi.nmr.flow.seda.SedaQueue$1.run(SedaQueue.java:134)

              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)

              at java.lang.Thread.run(Thread.java:595)

      Caused by: javax.xml.bind.UnmarshalException

      - with linked exception:

      [org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with elem

      ent 'm0:Message'. One of '{"http://services.apache.org/sample/funds/wire/types":Messages, "htt

      p://services.apache.org/sample/funds/wire/types":CashTotalAmount}' is expected.]

              at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(Unmarshal

      lerImpl.java:395)

              at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.jav

      a:334)

              at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java

      :311)

              at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:583)

              ... 17 more

      Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting

      with element 'm0:Message'. One of '{"http://services.freddiemac.com/treasury/funds/wire/types":Mess

      ages, "http://services.apache.org/sample/funds/wire/types":CashTotalAmount}' is expected.

              at com.sun.org.apache.xerces.internal.jaxp.validation.Util.toSAXParseException(Util.java:109

      )

              at com.sun.org.apache.xerces.internal.jaxp.validation.ErrorHandlerAdaptor.error(ErrorHandler

      Adaptor.java:104)

              at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.jav

      a:382)

              at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.jav

      a:316)

              at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportErro

      r(XMLSchemaValidator.java:429)

              at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchema

      Validator.java:3185)

              at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchem

      aValidator.java:1831)

              at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValid

      ator.java:705)

              at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.startElement(Vali

      datorHandlerImpl.java:335)

              at com.sun.xml.bind.v2.runtime.unmarshaller.ValidatingUnmarshaller.startElement(ValidatingUn

      marshaller.java:73)

              at com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVis

      itor.java:35)

              at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStrea

      mConnector.java:200)

              at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.j

      ava:134)

              at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.jav

      a:332)

              ... 19 more