01: /*
02: * Created on Jan 6, 2005
03: */
04: package uk.org.ponder.servletutil;
05:
06: import uk.org.ponder.saxalizer.XMLProvider;
07:
08: /**
09: * An endpoint handler of requests passing through WebAppTool and
10: * WebAppToolSink that works in a canonical way - it dispatches
11: * "like-for-like" in that HTTP GETs and POSTs originating from the
12: * client are mapped onto the same, and the remote servlet is
13: * provided with enough context to allow it to compute ultimate
14: * URLs by itself, obviating the need for rewriting.
15: * <p>Individual tool handlers override the <code>adjustRequest</code>
16: * method which is provided with a freely writeable parameter map
17: * object into which should be put any extra parameters required
18: * to deal with the request (e.g. authentication and url base).
19: * @author Antranig Basman (antranig@caret.cam.ac.uk)
20: */
21: public class DirectURLDispatcher implements WebServiceDispatcher {
22:
23: // The name of this dispatcher within the collection
24: String name;
25:
26: Object clientrequestinfo;
27: String remoteurlbase;
28:
29: public static void copyBase(DirectURLDispatcher source,
30: DirectURLDispatcher dest) {
31: dest.name = source.name;
32: dest.remoteurlbase = source.remoteurlbase;
33: dest.xmlprovider = source.xmlprovider;
34: }
35:
36: public WebServiceDispatcher copy() {
37: DirectURLDispatcher togo = new DirectURLDispatcher();
38: copyBase(this , togo);
39: return togo;
40: }
41:
42: private XMLProvider xmlprovider;
43:
44: public String getName() {
45: return name;
46: }
47:
48: public void setName(String name) {
49: this .name = name;
50: }
51:
52: public String getRemoteURLBase() {
53: return remoteurlbase;
54: }
55:
56: /** Set the base URL of the remote servlet, including trailing slash */
57: public void setRemoteURLBase(String urlbase) {
58: this .remoteurlbase = urlbase;
59: }
60:
61: public void setXMLProvider(XMLProvider xmlprovider) {
62: this .xmlprovider = xmlprovider;
63: }
64:
65: public void setClientRequestInfo(Object clientrequestinfo) {
66: this .clientrequestinfo = clientrequestinfo;
67: }
68:
69: public void handleRequest(ServletForwardPackage forwardpackage) {
70: //No - this is WRONG! the resourceurlbase should be configured statically
71: //in consumerinfo.xml, and in general even left blank if the server's
72: //own URL is globally usable.
73: //consumerinfo.resourceurlbase = forwardpackage.localurlbase;
74:
75: String clientrequestinfostring = xmlprovider
76: .toString(clientrequestinfo);
77: forwardpackage.addParameter(
78: WebServiceDispatcher.REQUEST_INFO_PARAMETER,
79: clientrequestinfostring);
80:
81: forwardpackage.setUnwrapRedirect(true);
82: forwardpackage.dispatchTo(forwardpackage.targeturl);
83: }
84:
85: }
|