01: /*
02: * Copyright 2001-2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package samples.proxy;
18:
19: import org.apache.axis.AxisFault;
20: import org.apache.axis.Handler;
21: import org.apache.axis.Message;
22: import org.apache.axis.MessageContext;
23: import org.apache.axis.SimpleTargetedChain;
24: import org.apache.axis.client.Call;
25: import org.apache.axis.client.Service;
26: import org.apache.axis.message.SOAPEnvelope;
27: import org.w3c.dom.Document;
28: import samples.transport.tcp.TCPSender;
29: import samples.transport.tcp.TCPTransport;
30:
31: /**
32: * Proxy sample. Relays message on to hardcoded URL.
33: * Soon, URL becomes configurable (via deployment?!);
34: * later, URL becomes specifiable in custom header.
35: *
36: * @author Rob Jellinghaus <robj@unrealities.com>
37: */
38:
39: public class ProxyService {
40: /**
41: * Process the given message, treating it as raw XML.
42: */
43: public void proxyService(SOAPEnvelope env1, SOAPEnvelope env2)
44: throws AxisFault {
45: try {
46: // Get the current Message Context
47: MessageContext msgContext = MessageContext
48: .getCurrentContext();
49:
50: // Look in the message context for our service
51: Handler self = msgContext.getService();
52:
53: // what is our target URL?
54: String dest = (String) self.getOption("URL");
55:
56: // use the server's client engine in case anything has
57: // been deployed to it
58: Service service = new Service();
59: service.setEngine(msgContext.getAxisEngine()
60: .getClientEngine());
61: Call call = (Call) service.createCall();
62:
63: SimpleTargetedChain c = new SimpleTargetedChain(
64: new TCPSender());
65: // !!! FIXME
66: //service.getEngine().deployTransport("tcp", c);
67:
68: // add TCP for proxy testing
69: call.addTransportPackage("samples.transport");
70: call.setTransportForProtocol("tcp", TCPTransport.class);
71:
72: // NOW set the client's URL (since now the tcp handler exists)
73: call.setTargetEndpointAddress(new java.net.URL(dest));
74:
75: call.setRequestMessage(msgContext.getRequestMessage());
76:
77: call.invoke();
78:
79: Message msg = call.getResponseMessage();
80:
81: msgContext.setResponseMessage(msg);
82: } catch (Exception exp) {
83: throw AxisFault.makeFault(exp);
84: }
85: }
86: }
|