The following test code registers a callback handler in order to add a
username token to the outgoing SOAP message.
My question is how this could be achieved when using Axis2 and Rampart.
The Axis2 API is quite different to Axis, and all the examples I can
find revolve around the existence of a client deployment descriptor. In
the context of my application, the target web service is dynamic and not
known until run-time. 

In particular, how do programmatically access the handler chain?

Any code fragments or advice would be appreciated.

Andrew.


import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringBufferInputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.List;

import javax.xml.namespace.QName;
import javax.xml.rpc.Call;
import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Service;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

public class WSClient
{
        static
        {
                BasicConfigurator.configure();
        }
        
    private static final Logger log = Logger.getLogger(WSClient.class);

    public static void main(String[] args)
    {
        

        String webService = "StockQuoteServiceService";
        String port = "StockQuoteService";
        String operation = "getQuote";
        
        log.debug("Beginning work");
        
                QName servQN = new
QName("http://stockquote",webService);
                        
                log.debug("Web service service: " + servQN.toString());
                
                QName portQN = new QName(servQN.getNamespaceURI(),
port);

                log.debug("Web service port: " + portQN.toString());
                
                Service service = null;

                
        try {
                System.out.println("about to generate certificate");
                service = new
Service("https://localhost:9443/SecureStockQuote/services/StockQuoteServ
ice/wsdl/StockQuoteService.wsdl",servQN);
                        System.out.println("Loaded service ok");
                } catch (ServiceException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                }
        service.setCacheWSDL(false);
        
        List list =
service.getHandlerRegistry().getHandlerChain(portQN);
        list.add(new
javax.xml.rpc.handler.HandlerInfo(WSSCallbackHandler.class,null,null));

                Call call = null;
                
        try
        {
            call = service.createCall(portQN, operation);
            System.out.println("Created call ok");
        } 
        catch (ServiceException e3)
        {
            // TODO Auto-generated catch block
            e3.printStackTrace();
        }
        
        System.out.println("Web service operation: " + operation);
                        
                try
        {
            Object result = call.invoke(new Object[] {});
            System.out.println("Response is: "+result);
        } 
                catch (RemoteException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
                        
    }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to