You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Tamara Hills <t...@traversenetworks.com> on 2005/04/18 17:17:59 UTC
Setting the user and pw in headers using wsdl2java generated classes
Hello,
I'm an axis newbie. I've used wsdl2java to generate some java classes
from a wsdl file. The service I'm trying to connect to requires a
username and password Base64 encoded in the header.
I'm not sure but I think the way to do this is through the
MessageContext. The problem I'm having is that I want to use the
wsdl2java generated classes but somehow wind up with a null
MessageContext ( no matter how I get to it) Below is what I'm doing.
I've tried getting the MessageContext in many different ways and it
always turns up null. Also, I want to use the classes that wsdl2java
created for me...
I know there is a way to use the Call object to set the user and pw, but
I'm unsure of how to get to the Call object and still be able to use the
Class objects that wsdl2java has generated for me.
String sUser = Base64.encode("Administrator");
String sPw = Base64.encode("password");
AXLAPIServiceLocator loc = new AXLAPIServiceLocator();
AXLPort port = loc.getAXLPort();
AxisEngine eng = loc.getEngine();
if(eng != null)
{
MessageContext msgCont = eng.getCurrentMessageContext();
//MessageContext msgCont =
MessageContext.getCurrentContext();
if(msgCont != null) {
msgCont.setPassword(sPw);
msgCont.setUsername(sUser);
}
else
System.out.println("null message context");
}
else
System.out.println("null engine");
Any help is greatly appreciated.
Regards,
-tamara
Re: Setting the user and pw in headers using wsdl2java generated classes
Posted by Gerry Gao <gj...@hotmail.com>.
Hi,
First of all, I assume you want to use basic authentication mechanism, if so, you don't need to encode the UN and PW by yourself. Just give the plain text to AXIS. AXIS will put a HTTP header like:
Authentication: Basic 239jva0nkdfj0sdgj
in request to authenticate the client.
Two ways to get rid of this problem:
1. Cast your stub to Stub and set the un and pw:
((Stub)yourGenneratedStub).setUsername(un);
((Stub)yourGenneratedStub).setPassword(pw);
OR
2. Modify your generated stub.
You can find a method named createCall(). Set the UN and PW to the call object before it is returned.
Gerry
----- Original Message -----
From: Tamara Hills
To: axis-user@ws.apache.org
Sent: Monday, April 18, 2005 11:17 PM
Subject: Setting the user and pw in headers using wsdl2java generated classes
Hello,
I'm an axis newbie. I've used wsdl2java to generate some java classes from a wsdl file. The service I'm trying to connect to requires a username and password Base64 encoded in the header.
I'm not sure but I think the way to do this is through the MessageContext. The problem I'm having is that I want to use the wsdl2java generated classes but somehow wind up with a null MessageContext ( no matter how I get to it) Below is what I'm doing. I've tried getting the MessageContext in many different ways and it always turns up null. Also, I want to use the classes that wsdl2java created for me...
I know there is a way to use the Call object to set the user and pw, but I'm unsure of how to get to the Call object and still be able to use the Class objects that wsdl2java has generated for me.
String sUser = Base64.encode("Administrator");
String sPw = Base64.encode("password");
AXLAPIServiceLocator loc = new AXLAPIServiceLocator();
AXLPort port = loc.getAXLPort();
AxisEngine eng = loc.getEngine();
if(eng != null)
{
MessageContext msgCont = eng.getCurrentMessageContext();
//MessageContext msgCont = MessageContext.getCurrentContext();
if(msgCont != null) {
msgCont.setPassword(sPw);
msgCont.setUsername(sUser);
}
else
System.out.println("null message context");
}
else
System.out.println("null engine");
Any help is greatly appreciated.
Regards,
-tamara
Re: Setting the user and pw in headers using wsdl2java generated
classes
Posted by Mike Haller <Mi...@Innovations.de>.
I tried the following way, so i didn't have to change the generated
classes nor to cast to stubs:
1) use a client-config.wsdd (some sort of configuration file for the
wsdl2java generator) and include a requestFlow handler called
"my.package.AuthenticateHandler"
<deployment ..>
<globalConfiguration>
<requestFlow>
<handler type="java:my.package.AuthenticateHandler"/>
</requestFlow>
..
2) my.package.AuthenticateHandler extends BasicHandler. In the invoke()
method, you get the message context.
public void invoke(MessageContext msgContext) throws AxisFault {
msgContext.setUsername("myName");
msgContext.setPassword("mySecret");
}
regards
Mike
Tamara Hills schrieb:
> Hello,
>
>
>
> I'm an axis newbie. I’ve used wsdl2java to generate some java classes
> from a wsdl file. The service I’m trying to connect to requires a
> username and password Base64 encoded in the header.
>
>
>
> I’m not sure but I think the way to do this is through the
> MessageContext. The problem I’m having is that I want to use the
> wsdl2java generated classes but somehow wind up with a null
> MessageContext ( no matter how I get to it) Below is what I’m doing.
> I've tried getting the MessageContext in many different ways and it
> always turns up null. Also, I want to use the classes that wsdl2java
> created for me...
>
>
>
> I know there is a way to use the Call object to set the user and pw, but
> I’m unsure of how to get to the Call object and still be able to use the
> Class objects that wsdl2java has generated for me.
>
>
>
>
>
> String sUser = Base64.encode("Administrator");
>
> String sPw = Base64.encode("password");
>
>
>
> AXLAPIServiceLocator loc = new AXLAPIServiceLocator();
>
> AXLPort port = loc.getAXLPort();
>
> AxisEngine eng = loc.getEngine();
>
> if(eng != null)
>
> {
>
> MessageContext msgCont = eng.getCurrentMessageContext();
>
> //MessageContext msgCont = MessageContext.getCurrentContext();
>
> if(msgCont != null) {
>
> msgCont.setPassword(sPw);
>
> msgCont.setUsername(sUser);
>
> }
>
> else
>
> System.out.println("null message context");
>
> }
>
> else
>
> System.out.println("null engine");
>
>
>
>
>
> Any help is greatly appreciated.
>
>
>
> Regards,
>
>
>
> -tamara
>
>
>