But Ashok, aren't you supposed to be able to use the stubs created by
wsdl2java? I could (and probably will) try what you suggest, but I just hate
coding thing in such a loosely coupled way :)
I've tried to cast the remote object and the axisPort object into a
StockQuoteService object, but that doesn't seem to work, the callback is
never called and no headers are added to the soap request. My code looks
like this:
StockQuoteServiceService locator = new
StockQuoteServiceServiceLocator();
PWCallback pwCallback = new PWCallback();
Remote remote = locator.getPort(StockQuoteService.class);
Stub axisPort = (Stub)remote;
axisPort._setProperty(UsernameToken.PASSWORD_TYPE,
WSConstants.PASSWORD_DIGEST);
axisPort._setProperty(WSHandlerConstants.USER, "wss4j");
axisPort._setProperty(WSHandlerConstants.PW_CALLBACK_REF,
pwCallback);
StockQuoteService service =
(StockWss01SoapBindingStub)remote; //cast the remote into a stock quote
service
System.out.println("Calling service...");
float quote = service.getQuote(args[0]);
System.out.println("stock quote service returned " + args[0]
+ ": "
+ quote);
What I get back is this:
Calling service...
Exception in thread "main" AxisFault
faultCode:
{http://schemas.xmlsoap.org/soap/envelope/}Server.generalException
faultSubcode:
faultString: WSDoAllReceiver: Request does not contain required
Security header
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}hostname:winxpsp2
WSDoAllReceiver: Request does not contain required Security header
at
org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:2
21)
at org.apache.axis.m.... and so on.
Again, thanks for any help! I could never guess it would be so hard
to get this thingy going :)
/Johan
-----Original Message-----
From: Ashok Shah [mailto:[EMAIL PROTECTED]
Sent: den 19 januari 2005 02:56
To: [EMAIL PROTECTED]
Cc: [email protected]
Subject: Re: Problems setting Username and callback handlers dynamically
Johan,
Herez another way to do it
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
System.setProperty("axis.ClientConfigFile",
"conf/ecl_client_deploy.wsdd");
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL("service endpoint
goes
here") );
call.setOperationName(new QName("uri:method", "method name goes
here"));
call.setUsername(this.userName);
call.setProperty("action", this.action);
call.setProperty(WSConstants.PASSWORD_TYPE_ATTR,
WSConstants.PASSWORD_DIGEST);
call.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS,
this.passwordCallbackClass);
call.setReturnType( org.apache.axis.encoding.XMLType.XSD_STRING );
String str = (String)call.invoke();
If(str==results){
System.out.println("yaay.. I did it");
}else{
System.out.println("the whole world is gonna burn in hell");
}
You could set as many properties needed in the "call" object. For
e.g. if
you want to add the encryption feature as well. You could say
call.setProperty(WSHandlerConstants.ENCRYPTION_USER, "encryption user
goes
here");
call.setProperty(WSHandlerConstants.ENC_PROP_FILE, "property file
goes here
check wss4j property files for encryption");
and you are all good to go for the encryption as well.
These properties are passed on to the MessageContext object which is
created. The "MessageContext" object is used by WSS4J to extract
those
properties.
Cheers
Ashok.
On Tue, 18 Jan 2005 23:34:31 +0100 [EMAIL PROTECTED] wrote:
> Hi,
>
> I'm following the tutorial by Rami Jaamour and trying the
last
thing
> he wrote about setting the username and pw callback handler
dynamically in
> run-time, but it doesn't seem to work. Whatever I try, my callback
is
never
> called. This is what the documentation says:
>
> Another way to do this is to have the client application
set the
> username and CallbackHandler implementation programmatically
instead of
> client_deploy.wsdd:
>
> ...
> import org.apache.axis.client.Stub;
> ...
>
> Remote remote = locator.getPort(StockQuoteService.class);
> Stub axisPort = (Stub)remote;
> axisPort._setProperty(UsernameToken.PASSWORD_TYPE,
> WSConstants.PASSWORD_DIGEST);
> axisPort._setProperty(WSHandlerConstants.USER, "wss4j");
> axisPort._setProperty(WSHandlerConstants.PW_CALLBACK_REF,
> pwCallback);
>
> where "pwCallback" is a reference to a PWCallback
> implementation. See
> the Axis handler for WSS4J documentation for more details on this.
>
> I would like to get a complete sample if that's possible. I
tried
> this piece of code, but the callback is never called and I get
errors from
> the web service about the wsse header is missing:
>
> StockQuoteServiceService locator = new
> StockQuoteServiceServiceLocator();
> StockQuoteService service =
locator.getStockWss01();
>
> PWCallback pwCallback = new PWCallback();
> Remote remote =
locator.getPort(StockQuoteService.class);
> Stub axisPort = (Stub)remote;
> axisPort._setProperty(UsernameToken.PASSWORD_TYPE,
> WSConstants.PASSWORD_DIGEST);
> axisPort._setProperty(WSHandlerConstants.USER,
"wss4j");
>
axisPort._setProperty(WSHandlerConstants.PW_CALLBACK_REF,
> pwCallback);
>
>
> System.out.println("Calling service...");
> float quote = service.getQuote(args[0]);
> System.out.println("stock quote service returned "
+
args[0]
> + ": "
> + quote);
>
> I guess I shouldn't call service.getQuote() like that, but
instead
> call the remote method through the Stub, but I'm not sure how to do
that.
> Can anyone help me out before I spend another day in the sample
code? :D
>
> Thanks for any help!
> Johan
>
>