You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fx-dev@ws.apache.org by Andrew Fielden <af...@tibco.com> on 2006/11/09 15:57:08 UTC

Dynamic registration of handlers with Axis2/Rampart

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: wss4j-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: wss4j-dev-help@ws.apache.org


Re: Dynamic registration of handlers with Axis2/Rampart

Posted by Ruchith Fernando <ru...@gmail.com>.
Hi Andrew,

Please have a look at basic/sample11 in the set of samples available
in Rampart [1]. You can try samples in [1] with the axis2-bin distro
from here [2].

Thanks,
Ruchith

[1] http://ws.zones.apache.org/dist/rampart/nightly/rampart-1.1-SNAPSHOT.zip
[2] http://ws.zones.apache.org/dist/axis2/nightly/axis2-1.1-SNAPSHOT.zip

On 11/9/06, Andrew Fielden <af...@tibco.com> wrote:
> 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: wss4j-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: wss4j-dev-help@ws.apache.org
>
>


-- 
www.ruchith.org

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


Re: Dynamic registration of handlers with Axis2/Rampart

Posted by Ruchith Fernando <ru...@gmail.com>.
Hi Andrew,

Please have a look at basic/sample11 in the set of samples available
in Rampart [1]. You can try samples in [1] with the axis2-bin distro
from here [2].

Thanks,
Ruchith

[1] http://ws.zones.apache.org/dist/rampart/nightly/rampart-1.1-SNAPSHOT.zip
[2] http://ws.zones.apache.org/dist/axis2/nightly/axis2-1.1-SNAPSHOT.zip

On 11/9/06, Andrew Fielden <af...@tibco.com> wrote:
> 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: wss4j-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: wss4j-dev-help@ws.apache.org
>
>


-- 
www.ruchith.org

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