You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by prasad <pr...@thekpsoft.com> on 2011/10/09 16:28:10 UTC
BasicAuth - SoapHeaderInterceptor Nullpointer exception issue
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.
Re: BasicAuth - SoapHeaderInterceptor Nullpointer exception issue
Posted by prasad <pr...@thekpsoft.com>.
Christian,
I am running the service and the client test program from the same eclipse
project. service is running on the tomcat (6.0) instance inside the eclipse
workspace. I don't know where the second request is coming from. I noticed
the behavior after i look at the logs that there is a second request also.
After reviewing your note, I decided to create another project in eclipse
and run the client from there. Without any changes the results are much
better and the client program is now working. Does this make sense?
In case i run into the issue again, I would like to explore the suggestion
of preemptive authorization that you are mentioning, assuming that i need to
run this on the client. Please correct me if i am wrong.
should the below be added to the client:
<http-conf:conduit name="*.http-conduit">
<http-conf:authorization>
<sec:UserName>tomcat</sec:UserName>
<sec:Password>tomcat</sec:Password>
</http-conf:authorization>
</http-conf:conduit>
or directly to the calling java code as below:
HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
AuthorizationPolicy auth = conduit.getAuthorization();
if ( null == auth ) {
System.out.println (" auth policy is null");
auth = new AuthorizationPolicy();
}
auth.setUserName( "tomcat" );
auth.setPassword( "tomcat" );
thanks,
Prasad.
--
View this message in context: http://cxf.547215.n5.nabble.com/BasicAuth-SoapHeaderInterceptor-Nullpointer-exception-issue-tp4885314p4895591.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: BasicAuth - SoapHeaderInterceptor Nullpointer exception issue
Posted by Christian Schneider <ch...@die-schneider.net>.
I think the problem is that the client first sends a request without
Authorization. You have to reject this request with 401. The next
request will then be with Authentication.
You can also set the flag for preemptive authorization. Then it should work.
Christian
Am 11.10.2011 17:33, schrieb prasad:
> it appears that policy from "AuthorizationPolicy policy =
> message.get(AuthorizationPolicy.class)" is turning out to be null. Am i
> doing anything wrong here.
>
> Also please let me know if there is a different forum that i could contact
> for this.
>
> Thanks in advance,
> Prasad.
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/BasicAuth-SoapHeaderInterceptor-Nullpointer-exception-issue-tp4885314p4892162.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
--
--
Christian Schneider
http://www.liquid-reality.de
Open Source Architect
Talend Application Integration Division http://www.talend.com
Re: BasicAuth - SoapHeaderInterceptor Nullpointer exception issue
Posted by prasad <pr...@thekpsoft.com>.
it appears that policy from "AuthorizationPolicy policy =
message.get(AuthorizationPolicy.class)" is turning out to be null. Am i
doing anything wrong here.
Also please let me know if there is a different forum that i could contact
for this.
Thanks in advance,
Prasad.
--
View this message in context: http://cxf.547215.n5.nabble.com/BasicAuth-SoapHeaderInterceptor-Nullpointer-exception-issue-tp4885314p4892162.html
Sent from the cxf-user mailing list archive at Nabble.com.