Hi, Andreas,

Thanks for the hint, I'll do so.

But would there be a solution for my problem using axis2?

Thanks,
Markus


-----Ursprüngliche Nachricht-----
Von: Andreas Veithen [mailto:[email protected]]
Gesendet: Do 09.09.2010 20:49
An: [email protected]
Betreff: Re: Axis and WS-Security on a standalone client
 
As part of the promotion of the Axis project to a top level project,
we have decided to create separate mailing lists for Axis 1 and Axis2.
For all Axis 1 related questions please subscribe and post to
[email protected]. Thanks!

Andreas


On Thu, Sep 9, 2010 at 17:58, Markus Schaber <[email protected]> wrote:
> Hello,
>
> I'm struggling with creating a standalone soap client that employs
> WS-Security against a windows (WCF / .NET 3.5) server.
>
> When removing the WS-Security requirement from the server, everything
> works fine. But I just cannot get the java client to send the
> appropriate SOAP headers with username and password.
>
> Most tutorials / FAQs I googled talk about deployment descriptors in
> Tomcat, but I do not have that, I just have some small standalone java
> application.
>
> My current state of the art is:
>
> package test;
>
> import java.io.IOException;
> import java.net.MalformedURLException;
> import java.net.URL;
>
> import javax.security.auth.callback.Callback;
> import javax.security.auth.callback.CallbackHandler;
> import javax.security.auth.callback.UnsupportedCallbackException;
> import javax.xml.rpc.ServiceException;
>
> import org.apache.ws.security.WSConstants;
> import org.apache.ws.security.WSPasswordCallback;
> import org.apache.ws.security.handler.WSHandlerConstants;
> import org.apache.ws.security.message.token.UsernameToken;
>
> import de.soloplan.TestServices.GPSPosition;
> import de.soloplan.TestServices.TestServiceLocator;
> import de.soloplan.TestServices.TestServices;
> import de.soloplan.TestServices.TestServicesBindingStub;
>
> public class TestClass {
>
>        /**
>         * @param args
>         * @throws ServiceException
>         * @throws MalformedURLException
>         */
>        public static void main(String[] args) throws Exception {
>
> System.getProperties().setProperty("javax.net.ssl.trustStore",
> "/home/schabi/.keystore");
>
> System.getProperties().setProperty("javax.net.ssl.keyStore",
> "/home/schabi/.keystore");
>
> System.getProperties().setProperty("javax.net.ssl.keyStorePassword",
> "foobar");
>
> System.getProperties().setProperty("javax.net.ssl.keyStoreType", "JKS");
>
>                URL url = new
> URL("https://localhost:62615/TestService";);
>
>                TestServiceLocator locator = new TestServiceLocator();
>
>                TestServices service = locator.getTestServicesSOAP(url);
>
>                TestServicesBindingStub stub = (TestServicesBindingStub)
> service;
>
>                stub._setProperty(UsernameToken.PASSWORD_TYPE,
> WSConstants.PASSWORD_DIGEST);
>                stub._setProperty(WSHandlerConstants.USER, "test1");
>                stub._setProperty(WSHandlerConstants.PW_CALLBACK_REF,
> new PWCallback());
>
>                GPSPosition position = service.getCurrentLocation(-42);
>
>                System.out.format("Position of vechile %s: Lat: %s,
> Long: %s, Height: %s", vehicle, position.getLatitude(),
> position.getLongitude(), position.getHeight());
>        }
>
>        public static class PWCallback implements CallbackHandler {
>            /**
>             * @see
> javax.security.auth.callback.CallbackHandler#handle(javax.security.auth.
> callback.Callback[])
>             */
>            public void handle(Callback[] callbacks) throws IOException,
>                            UnsupportedCallbackException {
>                System.err.println("Called with " + callbacks.length + "
> callbacks.");
>                for (int i = 0; i < callbacks.length; i++) {
>                    if (callbacks[i] instanceof WSPasswordCallback) {
>                        WSPasswordCallback pc =
> (WSPasswordCallback)callbacks[i];
>                        // set the password given a username
>                        if ("test1".equals(pc.getIdentifier())) {
>                            pc.setPassword("1tset");
>                            System.err.println("Set password.");
>                        } else {
>                                System.err.println("No password
> found.");
>                        }
>                    } else {
>                        throw new
> UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
>                    }
>                }
>            }
>        }
> }
>
> The stub and locator was autogenerated by eclipse, but if you have any
> better Idea, please tell me. I'm also not tied to axis, this was just
> what my eclipse autogenerated from the WSDL.
>
> I tried several different methods I found in google, all that I deemed
> to work without a tomcat running, but non success. The application
> started fine with no exceptions, but simply did not send the WS-Security
> headers to the server.
>
> With .NET, it is some lines in the App.Config and then barely 20 lines
> of code, and it works:
>
> namespace Soloplan. SoapServer.Tests
> {
>  using System;
>  using System.Diagnostics;
>  class TestConsoleApp
>  {
>    public static void Main()
>    {
>      var client = new
> ServiceReference1.TestServicesClient("TestServicesSOAP",
> "https://localhost:62615/TestService";);
>      Debug.Assert(client.ClientCredentials != null, "No client
> credentials");
>      client.ClientCredentials.UserName.UserName = "test1";
>      client.ClientCredentials.UserName.Password = "1tset";
>      Console.WriteLine("got client, sending request");
>      var location = client.GetCurrentLocation(-42);
>      Console.WriteLine("Got location: {0}/{1}", location.longitude,
> location.latitude);
>      Console.ReadLine();
>    }
>  }
> }
>
>
> Any ideas?
> Markus Schaber
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


<<winmail.dat>>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to