This project has retired. For details please refer to its
Attic page.
LocalTransport xref
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 private static Log log = LogFactory.getLog(LocalTransport.class);
41 private String nodeName;
42 private String managerName;
43
44 public LocalTransport(){};
45
46 public LocalTransport(String nodeName, String managerName) {
47 super();
48 this.nodeName = nodeName;
49 this.managerName = managerName;
50 }
51
52
53
54
55 public Element send(Element request,URI endpointURI)
56 throws TransportException
57 {
58 Element response = null;
59
60 if (log.isDebugEnabled()) {
61 log.debug("\nRequest message:\n" + XMLUtils.convertNodeToXMLString(request));
62 log.debug("Calling " + endpointURI + " locally");
63 }
64 try {
65 String className = endpointURI.getPath();
66 String methodName = endpointURI.getFragment();
67 log.debug("Calling class=" + className);
68 log.debug("Method=" + methodName);
69 Class<?> c = Class.forName(className);
70 Object requestHandler = c.newInstance();
71 Node node = null;
72 if (managerName!=null) {
73 Method method = c.getMethod(methodName, Element.class, String.class, String.class);
74 node = (Node) method.invoke(requestHandler, request, nodeName, managerName);
75 } else {
76 Method method = c.getMethod(methodName, Element.class);
77 node = (Node) method.invoke(requestHandler, request);
78 }
79 if (node!=null && node.getFirstChild()!=null) {
80 response = (Element) node.getFirstChild();
81 }
82 } catch (Exception ex) {
83 throw new TransportException(ex);
84 }
85 if (log.isDebugEnabled()) {
86 log.debug("\nResponse message:\n" + XMLUtils.convertNodeToXMLString(response));
87 }
88 return response;
89 }
90
91
92
93
94 public String send(String request,URI endpointURI)
95 throws TransportException
96 {
97 String response = null;
98 log.debug("\nRequest message:\n" + request);
99 try {
100 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
101 DocumentBuilder parser = factory.newDocumentBuilder();
102 Document document = parser.parse(request);
103 Element element = document.getDocumentElement();
104 response= XMLUtils.convertNodeToXMLString(send(element, endpointURI));
105 } catch (Exception ex) {
106 throw new TransportException(ex);
107 }
108 log.debug("\nResponse message:\n" + response);
109 return response;
110 }
111
112
113 }