1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.apache.ws.scout.transport; |
17 | |
|
18 | |
import java.lang.reflect.Method; |
19 | |
import java.net.URI; |
20 | |
|
21 | |
import javax.xml.parsers.DocumentBuilder; |
22 | |
import javax.xml.parsers.DocumentBuilderFactory; |
23 | |
|
24 | |
import org.apache.commons.logging.Log; |
25 | |
import org.apache.commons.logging.LogFactory; |
26 | |
import org.apache.ws.scout.util.XMLUtils; |
27 | |
import org.w3c.dom.Document; |
28 | |
import org.w3c.dom.Element; |
29 | |
import org.w3c.dom.Node; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public class LocalTransport implements Transport |
39 | |
{ |
40 | 0 | private static Log log = LogFactory.getLog(LocalTransport.class); |
41 | |
private String nodeName; |
42 | |
private String managerName; |
43 | |
|
44 | 0 | public LocalTransport(){}; |
45 | |
|
46 | |
public LocalTransport(String nodeName, String managerName) { |
47 | 0 | super(); |
48 | 0 | this.nodeName = nodeName; |
49 | 0 | this.managerName = managerName; |
50 | 0 | } |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
public Element send(Element request,URI endpointURI) |
56 | |
throws TransportException |
57 | |
{ |
58 | 0 | Element response = null; |
59 | |
|
60 | 0 | if (log.isDebugEnabled()) { |
61 | 0 | log.debug("\nRequest message:\n" + XMLUtils.convertNodeToXMLString(request)); |
62 | 0 | log.debug("Calling " + endpointURI + " locally"); |
63 | |
} |
64 | |
try { |
65 | 0 | String className = endpointURI.getPath(); |
66 | 0 | String methodName = endpointURI.getFragment(); |
67 | 0 | log.debug("Calling class=" + className); |
68 | 0 | log.debug("Method=" + methodName); |
69 | 0 | Class<?> c = Class.forName(className); |
70 | 0 | Object requestHandler = c.newInstance(); |
71 | 0 | Node node = null; |
72 | 0 | if (managerName!=null) { |
73 | 0 | Method method = c.getMethod(methodName, Element.class, String.class, String.class); |
74 | 0 | node = (Node) method.invoke(requestHandler, request, nodeName, managerName); |
75 | 0 | } else { |
76 | 0 | Method method = c.getMethod(methodName, Element.class); |
77 | 0 | node = (Node) method.invoke(requestHandler, request); |
78 | |
} |
79 | 0 | if (node!=null && node.getFirstChild()!=null) { |
80 | 0 | response = (Element) node.getFirstChild(); |
81 | |
} |
82 | 0 | } catch (Exception ex) { |
83 | 0 | throw new TransportException(ex); |
84 | 0 | } |
85 | 0 | if (log.isDebugEnabled()) { |
86 | 0 | log.debug("\nResponse message:\n" + XMLUtils.convertNodeToXMLString(response)); |
87 | |
} |
88 | 0 | return response; |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
public String send(String request,URI endpointURI) |
95 | |
throws TransportException |
96 | |
{ |
97 | 0 | String response = null; |
98 | 0 | log.debug("\nRequest message:\n" + request); |
99 | |
try { |
100 | 0 | DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
101 | 0 | DocumentBuilder parser = factory.newDocumentBuilder(); |
102 | 0 | Document document = parser.parse(request); |
103 | 0 | Element element = document.getDocumentElement(); |
104 | 0 | response= XMLUtils.convertNodeToXMLString(send(element, endpointURI)); |
105 | 0 | } catch (Exception ex) { |
106 | 0 | throw new TransportException(ex); |
107 | 0 | } |
108 | 0 | log.debug("\nResponse message:\n" + response); |
109 | 0 | return response; |
110 | |
} |
111 | |
|
112 | |
|
113 | |
} |