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 | 336 | public class LocalTransport implements Transport |
39 | |
{ |
40 | 6 | private static Log log = LogFactory.getLog(LocalTransport.class); |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
public Element send(Element request,URI endpointURI) |
46 | |
throws TransportException |
47 | |
{ |
48 | 1746 | Element response = null; |
49 | |
|
50 | 1746 | if (log.isDebugEnabled()) { |
51 | 1746 | log.debug("\nRequest message:\n" + XMLUtils.convertNodeToXMLString(request)); |
52 | 1746 | log.debug("Calling " + endpointURI + " locally"); |
53 | |
} |
54 | |
try { |
55 | 1746 | String className = endpointURI.getPath(); |
56 | 1746 | String methodName = endpointURI.getFragment(); |
57 | 1746 | log.debug("Calling class=" + className); |
58 | 1746 | log.debug("Method=" + methodName); |
59 | 1746 | Class<?> c = Class.forName(className); |
60 | 1746 | Object requestHandler = c.newInstance(); |
61 | 1746 | Method method = c.getMethod(methodName, Element.class); |
62 | 1746 | Node node = (Node) method.invoke(requestHandler, request); |
63 | 1746 | response = (Element) node.getFirstChild(); |
64 | |
} |
65 | 0 | catch (Exception ex) { |
66 | 0 | throw new TransportException(ex); |
67 | 1746 | } |
68 | 1746 | if (log.isDebugEnabled()) { |
69 | 1746 | log.debug("\nResponse message:\n" + XMLUtils.convertNodeToXMLString(response)); |
70 | |
} |
71 | 1746 | return response; |
72 | |
} |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
public String send(String request,URI endpointURI) |
78 | |
throws TransportException |
79 | |
{ |
80 | 0 | String response = null; |
81 | 0 | log.debug("\nRequest message:\n" + request); |
82 | |
try { |
83 | 0 | DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
84 | 0 | DocumentBuilder parser = factory.newDocumentBuilder(); |
85 | 0 | Document document = parser.parse(request); |
86 | 0 | Element element = document.getDocumentElement(); |
87 | 0 | response= XMLUtils.convertNodeToXMLString(send(element, endpointURI)); |
88 | 0 | } catch (Exception ex) { |
89 | 0 | throw new TransportException(ex); |
90 | 0 | } |
91 | 0 | log.debug("\nResponse message:\n" + response); |
92 | 0 | return response; |
93 | |
} |
94 | |
|
95 | |
|
96 | |
} |