KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > net > axis > message > addressing > handler > AddressingHandler


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the docs/licenses/apache-1.1.txt file.
7  */

8 package org.jboss.net.axis.message.addressing.handler;
9
10 import org.apache.axis.EngineConfiguration;
11 import org.apache.axis.MessageContext;
12 import org.apache.axis.client.Call;
13 import org.apache.axis.client.Service;
14 import org.apache.axis.message.addressing.Action;
15 import org.apache.axis.message.addressing.AddressingHeaders;
16 import org.apache.ws.axis.security.WSDoAllConstants;
17 import org.jboss.net.axis.server.JMXEngineConfigurationFactory;
18
19 import java.util.StringTokenizer JavaDoc;
20 import java.util.Vector JavaDoc;
21
22 /**
23  * <dl>
24  * <dt><b>Title: </b><dd>WS-Addressing Handler</dd>
25  * <p/>
26  * <dt><b>Description: </b><dd>This Subclass of the org.apache.axis.message.addressing.handler.AddressingHandler will
27  * properly use the wsa:Action header to direct the incoming messages to the proper services. It also
28  * correctly fetches the client config when sending a response via the ReplyTo header. wss4j properties are also
29  * moved into the new request (server response) so encryption / signing can happen after addressing.<p>
30  * <p/>
31  * This handler can be placed in the global (or transport) request and response chains to handle messages with ws-addressing
32  * headers. For added security, have the ws-security (wss4j) handlers sign any ws-addressing headers that contain addresses
33  * (To, From, ReplyTo, FaultTo). This means that wss4j will have to process incoming messages BEFORE addressing, and it will
34  * have to process outgoing messages AFTER addressing.
35  * <p/>
36  * The parameters transportPackages, and transports can be configured in the DD to allow the response objects to
37  * understand any special transports that may be in use. @see #initializeCall()
38  * </dd>
39  * <p/>
40  * <dt><b>Copyright: </b><dd>Copyright (c) 2004</dd>
41  * <dt><b>Company: </b><dd>Green River Computing Services</dd>
42  * </dl>
43  *
44  * @author <a HREF="mailto:jasone@greenrivercomputing.com">Jason Essington</a>
45  * @version $Revision: 1.1.6.3 $
46  */

47 public class AddressingHandler extends org.apache.axis.message.addressing.handler.AddressingHandler
48 {
49    /* (non-Javadoc)
50     * @see org.apache.axis.Handler#init()
51     */

52    public void init()
53    {
54       super.init();
55       initializeCall();
56    }
57
58    /**
59     * Invokes the static addTransportPackage, and setTransportForProtocol methods on Call
60     * so that our transport will be recognised.<p>
61     * Add transportPackages with the option addTransportPackages, and a comma separated list of packages<br>
62     * &lt;parameter name="transportPackages" value="com.some.transport,com.some.other.transport"/&gt;<p>
63     * <p/>
64     * Add transports with a comma separated list of transportName:transportClassName<br>
65     * &lt;parameter name="transports" value="http:com.my.transport.http.HTTPTransport,mail:com.my.transport.mail.MailTransport"/&gt;
66     */

67    private void initializeCall()
68    {
69       String JavaDoc transportPackages = null; //(String) getOption("transportPackages");
70
if (transportPackages != null)
71       {
72          StringTokenizer JavaDoc t = new StringTokenizer JavaDoc(transportPackages, ",");
73          while (t.hasMoreTokens())
74          {
75             Call.addTransportPackage(t.nextToken().trim());
76          }
77       }
78
79       String JavaDoc transports = null; //(String) getOption("transports");
80
if (transports != null)
81       {
82          StringTokenizer JavaDoc t = new StringTokenizer JavaDoc(transports, ",");
83          while (t.hasMoreTokens())
84          {
85             String JavaDoc tToken = t.nextToken().trim();
86             String JavaDoc[] transport = new String JavaDoc[2];
87
88             if (tToken.indexOf(':') < 0 || tToken.indexOf(':') != tToken.lastIndexOf(':'))
89             {
90                log.warn(tToken + " is not in the proper form of [transport]:[class]");
91                continue;
92             }
93             else
94             {
95                transport[0] = tToken.substring(0, tToken.indexOf(':'));
96                transport[1] = tToken.substring(tToken.indexOf(':') + 1);
97             }
98
99             String JavaDoc tName = transport[0];
100             String JavaDoc tClassName = transport[1];
101             Class JavaDoc tClass = null;
102             try
103             {
104                tClass = Class.forName(tClassName);
105             }
106             catch (ClassNotFoundException JavaDoc e)
107             {
108                log.warn("Unable to locate the class " + tClassName + " for the transport " + tName);
109                continue;
110             }
111             Call.setTransportForProtocol(tName, tClass);
112          }
113       }
114    }
115
116    /* (non-Javadoc)
117     * @see org.apache.axis.message.addressing.handler.AddressingHandler#configureCall(org.apache.axis.client.Call, org.apache.axis.MessageContext)
118     */

119    protected void configureCall(Call call, MessageContext msgContext)
120    {
121       // TODO Auto-generated method stub
122
//super.configureCall(call, msgContext);
123

124       // WSS4J expects to find the results of processing the incoming message when processing the response.
125
if (msgContext != null)
126       {
127          Vector JavaDoc wssResults = null;
128          wssResults = (Vector JavaDoc)msgContext.getProperty(WSDoAllConstants.RECV_RESULTS);
129          call.setProperty(WSDoAllConstants.RECV_RESULTS, wssResults);
130       }
131    }
132
133    /* (non-Javadoc)
134     * @see org.apache.axis.message.addressing.handler.AddressingHandler#getService(org.apache.axis.MessageContext)
135     */

136    protected Service getService(MessageContext msgContext)
137    {
138       String JavaDoc engineName = null; //(String)getOption("engineName");
139
EngineConfiguration config = JMXEngineConfigurationFactory.newJMXFactory(engineName)
140               .getClientEngineConfig();
141       return new Service(config);
142    }
143
144    /**
145     * We set the target service based upon the Action header since email addresses don't have
146     * path attributes.
147     */

148    protected void setTargetService(MessageContext msgCtx, AddressingHeaders headers) throws Exception JavaDoc
149    {
150       if (log.isDebugEnabled())
151          log.debug("Entering: invoke(MessageContext)");
152       Action action = headers.getAction();
153
154       if (action != null)
155       {
156          String JavaDoc actionURI = null; //action.toString();
157
msgCtx.setUseSOAPAction(true);
158          msgCtx.setSOAPActionURI(actionURI);
159          msgCtx.setTargetService(actionURI);
160       }
161       else
162       {
163          // fault ?
164
}
165    }
166 }
Popular Tags