You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wss4j-dev@ws.apache.org by rsridharrao <sr...@gmail.com> on 2007/11/09 15:17:23 UTC

Re: Nullpointer exception after adding UsernameToken from client

Hi,

Can someone post workaround/solution to this issue. I'm currently
experiencing the same issue.

Thanks in advance,
-Sri


Sathwik BP wrote:
> 
> Hi,
> 
>   Problem description: I have a service method that expects a
> UsernameToken in the header. Right now am sending the password as plain
> text over a secure transport. The client side handler adds this
> UsernameToken into the soap envelope.
> 
> If there is an soap fault throws from this service method, I get a Null
> pointer at the client side. I found it strange, bcos when I see the
> outgoing soap envelope from the server, it contains proper soap fault
> details.
> 
> Enviroment: Axis 1.4, Jboss 4.0.1 sp1, WSS4J 1.5.1
> 
> Client side request handler adds usernametoken in this manner
> 
> package client;
> 
> import org.apache.axis.AxisFault;
> import org.apache.axis.Message;
> import org.apache.axis.MessageContext;
> import org.apache.axis.handlers.BasicHandler;
> import org.apache.axis.message.SOAPEnvelope;
> import org.apache.axis.message.SOAPHeaderElement;
> import org.apache.axis.session.Session;
> import  org.apache.axis.transport.http.HTTPConstants;
> import org.apache.ws.security.WSConstants;
> import org.apache.ws.security.message.WSSecHeader;
> import org.apache.ws.security.message.WSSecUsernameToken;
> import org.w3c.dom.Document;
> 
> public class RequestHandler extends BasicHandler {
> 
>     public void invoke(MessageContext messageContext) throws AxisFault {
>         MessageContext currContext = messageContext.getCurrentContext();
>         Message message = currContext .getRequestMessage();
>         SOAPEnvelope envelope = message.getSOAPEnvelope();
>         
>         try {
>             Document doc = envelope.getAsDocument();
>             WSSecHeader secHeader = new  WSSecHeader("",false);
>             secHeader.insertSecurityHeader(doc);
> 
>             String username = "user1";
>             String password = "password";
>             
>             WSSecUsernameToken builder = new WSSecUsernameToken();
>             builder.setPasswordType(WSConstants.PASSWORD_TEXT);
>             builder.setUserInfo(username, password);
>             builder.prepare(doc);
>             builder.appendToHeader(secHeader);
>              
>             envelope.addHeader(new
> SOAPHeaderElement(secHeader.getSecurityHeader()));            
>             
>         } catch (Exception e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         }        
>     }
> }
> 
> This is the out going SOAP envelpe from client
> -------------------------------------------------------------------
> <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Header><wsse:Security
> xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
> soapenv:actor="" soapenv:mustUnderstand="0">
> <wsse:UsernameToken wsu:Id="UsernameToken-24964246"
> xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
> xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsse:Username
> xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">user1</wsse:Username><wsse:Password
> Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"
> xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">password</wsse:Password></wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><getOperationRequest
> xmlns="http://www.example.org/WSExample/"><in
> xmlns="">in</in></getOperationRequest></soapenv:Body></soapenv:Envelope>
> 
> 
> This is the retured soap envelope from server
> ----------------------------------------------------------------
> <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Server.generalException</faultcode><faultstring></faultstring><detail><ns1:PolicyException
> xmlns:ns1="http://www.example.org/contents"><ns1:error_code>code</ns1:error_code><ns1:error_text>text</ns1:error_text></ns1:PolicyException><ns2:exceptionName
> xmlns:ns2="http://xml.apache.org/axis/">org.example.www.contents.PolicyException</ns2:exceptionName><ns3:hostname
> xmlns:ns3="http://xml.apache.org/axis/">home</ns3:hostname></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>
> 
> This is the exception on client side
> --------------------------------------------------
> AxisFault
>  faultCode:
> {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
>  faultSubcode: 
>  faultString: java.lang.NullPointerException
>  faultActor: 
>  faultNode: 
>  faultDetail: 
>     {http://xml.apache.org/axis/}stackTrace:java.lang.NullPointerException
>     at  org.apache.axis.client.Call.invokeEngine(Call.java:2816)
>     at org.apache.axis.client.Call.invoke(Call.java:2767)
>     at org.apache.axis.client.Call.invoke(Call.java:2443)
>     at org.apache.axis.client.Call.invoke(Call.java:2366)
>     at org.apache.axis.client.Call.invoke(Call.java:1812)
>     at client.NewBindingStub.getOperation(NewBindingStub.java:203)
>     at client.WSExampleTest.main(WSExampleTest.java:28)
> 
>     {http://xml.apache.org/axis/}hostname:home
> 
> java.lang.NullPointerException
>     at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
>     at org.apache.axis.client.Call.invoke(Call.java:2446)
>     at org.apache.axis.client.Call.invoke(Call.java:2366)
>     at org.apache.axis.client.Call.invoke(Call.java:1812)
>     at  client.NewBindingStub.getOperation(NewBindingStub.java:203)
>     at client.WSExampleTest.main(WSExampleTest.java:28)
> Caused by: java.lang.NullPointerException
>     at org.apache.axis.client.Call.invokeEngine(Call.java:2816)
>     at org.apache.axis.client.Call.invoke(Call.java:2767)
>     at org.apache.axis.client.Call.invoke(Call.java:2443)
>     ... 4 more
> 
> 
> please help.
>  				
> ---------------------------------
>  Here’s a new way to find what you're looking for - Yahoo! Answers 
> 

-- 
View this message in context: http://www.nabble.com/Nullpointer-exception-after-adding-UsernameToken-from-client-tf2993682.html#a13667698
Sent from the WSS4J mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: wss4j-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: wss4j-dev-help@ws.apache.org