All,
I am new to setting basic auth in CXF and came accross the following issue.
It is not clear what i am doing wrong, please advise if you have come across
this before. Got some references from chris dail's posting at
http://chrisdail.com/2008/08/13/http-basic-authentication-with-apache-cxf-revisited/.
getting nullpointerexception on the getBackChannel call
System.out.println("inmessage is: " + inMessage);
Exchange exchange = inMessage.getExchange();
if (exchange == null )
System.out.println("Exchnage is null");
EndpointReferenceType target =
exchange.get(EndpointReferenceType.class);
if (target == null )
System.out.println("target is null");
Conduit conduit =
exchange.getDestination().getBackChannel(inMessage, null,
target);
exchange.setConduit(conduit);
return conduit;
Thanks in advance,
Prasad.
1. Created a basic auth interceptor per the code in the url above
2. create a web service using cxf 2.4.2
3. Configured spring context file as below:
<bean id="BasicAuthAuthorizationInterceptor"
class="com.company.auth.authorizer.basicauth.BasicAuthAuthorizationInterceptor">
<property name="users">
<map>
<entry key="tomcat" value="tomcat"/>
</map>
</property>
</bean>
<jaxws:endpoint id="auth"
implementor="com.company.auth.service.AuthServiceImpl"
address="/cxfAuth">
<jaxws:inInterceptors>
<ref bean="BasicAuthAuthorizationInterceptor"/>
</jaxws:inInterceptors>
</jaxws:endpoint>
4. client code is shown below:
String ws_url =
"http://localhost:8080/EmployeeAuthService/services/cxfAuth";
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.getInInterceptors().add(new
BasicAuthAuthorizationInterceptor());
factory.getOutInterceptors().add(new
BasicAuthAuthorizationInterceptor());
factory.setServiceClass(AuthService.class);
factory.setAddress(ws_url);
//
factory.setWsdlLocation("file:c://dev//junk//EmployeeAuthService.wsdl");
// factory.setWsdlLocation(ws_url);
AuthService client = (AuthService) factory.create();
//add username and password for container authentication
BindingProvider bp = (BindingProvider) client;
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY,
"tomcat");
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY,
"tomcat");
Employee employee;
try {
employee = client.getEmployee("0223938");
System.out.println("Server said: " + employee.getLastName() +
", " +
employee.getFirstName());
} catch (EmployeeNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
5. Getting exception in basicauthauthorizationinterceptor as shown below:
Caused by: java.lang.NullPointerException
at
com.company.auth.authorizer.basicauth.BasicAuthAuthorizationInterceptor.getConduit(BasicAuthAuthorizationInterceptor.java:98)
at
com.company.auth.authorizer.basicauth.BasicAuthAuthorizationInterceptor.sendErrorResponse(BasicAuthAuthorizationInterceptor.java:65)
at
com.company.auth.authorizer.basicauth.BasicAuthAuthorizationInterceptor.handleMessage(BasicAuthAuthorizationInterceptor.java:38)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:771)
at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1600)
--
View this message in context:
http://cxf.547215.n5.nabble.com/BasicAuth-SoapHeaderInterceptor-Nullpointer-exception-issue-tp4885314p4885314.html
Sent from the cxf-user mailing list archive at Nabble.com.