~ubuntu-branches/debian/squeeze/axis/squeeze

« back to all changes in this revision

Viewing changes to samples/proxy/ProxyService.java

  • Committer: Bazaar Package Importer
  • Author(s): Vladimír Lapáček
  • Date: 2006-09-06 22:31:39 UTC
  • Revision ID: james.westby@ubuntu.com-20060906223139-l7m5edxeositeppl
Tags: upstream-1.4
Import upstream version 1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2001-2004 The Apache Software Foundation.
 
3
 * 
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 * 
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 * 
 
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
    {
 
46
        try {
 
47
            // Get the current Message Context
 
48
            MessageContext msgContext = MessageContext.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().getClientEngine() );
 
60
            Call    call = (Call) service.createCall();
 
61
 
 
62
            SimpleTargetedChain c = new SimpleTargetedChain(new TCPSender());
 
63
            // !!! FIXME
 
64
            //service.getEngine().deployTransport("tcp", c);
 
65
    
 
66
            // add TCP for proxy testing
 
67
            call.addTransportPackage("samples.transport");
 
68
            call.setTransportForProtocol("tcp", TCPTransport.class);
 
69
            
 
70
            // NOW set the client's URL (since now the tcp handler exists)
 
71
            call.setTargetEndpointAddress(new java.net.URL(dest));
 
72
    
 
73
            call.setRequestMessage(msgContext.getRequestMessage());
 
74
            
 
75
            call.invoke();
 
76
            
 
77
            Message msg = call.getResponseMessage();
 
78
 
 
79
            msgContext.setResponseMessage(msg);
 
80
        }
 
81
        catch( Exception exp ) {
 
82
            throw AxisFault.makeFault( exp );
 
83
        }
 
84
    }
 
85
}
 
86