| 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 | |
import java.util.Properties; |
| 21 | |
|
| 22 | |
import javax.naming.InitialContext; |
| 23 | |
import javax.xml.parsers.DocumentBuilder; |
| 24 | |
import javax.xml.parsers.DocumentBuilderFactory; |
| 25 | |
|
| 26 | |
import org.apache.commons.logging.Log; |
| 27 | |
import org.apache.commons.logging.LogFactory; |
| 28 | |
import org.apache.ws.scout.util.XMLUtils; |
| 29 | |
import org.w3c.dom.Document; |
| 30 | |
import org.w3c.dom.Element; |
| 31 | |
import org.w3c.dom.Node; |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | 0 | public class RMITransport implements Transport |
| 41 | |
{ |
| 42 | |
|
| 43 | 0 | private static Log log = LogFactory.getLog(RMITransport.class); |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
public Element send(Element request,URI endpointURI) |
| 49 | |
throws TransportException |
| 50 | |
{ |
| 51 | 0 | Element response = null; |
| 52 | |
|
| 53 | 0 | if (log.isDebugEnabled()) { |
| 54 | 0 | log.debug("\nRequest message:\n" + XMLUtils.convertNodeToXMLString(request)); |
| 55 | 0 | log.debug("Calling " + endpointURI + " using rmi"); |
| 56 | |
} |
| 57 | |
|
| 58 | |
try { |
| 59 | 0 | String host = endpointURI.getHost(); |
| 60 | 0 | int port = endpointURI.getPort(); |
| 61 | 0 | String scheme = endpointURI.getScheme(); |
| 62 | 0 | String service = endpointURI.getPath(); |
| 63 | 0 | String className = endpointURI.getQuery(); |
| 64 | 0 | String methodName = endpointURI.getFragment(); |
| 65 | 0 | Properties env = new Properties(); |
| 66 | |
|
| 67 | |
|
| 68 | 0 | String factoryInitial = SecurityActions.getProperty("java.naming.factory.initial"); |
| 69 | 0 | if (factoryInitial==null) factoryInitial = "org.jnp.interfaces.NamingContextFactory"; |
| 70 | 0 | String factoryURLPkgs = SecurityActions.getProperty("java.naming.factory.url.pkgs"); |
| 71 | 0 | if (factoryURLPkgs==null) factoryURLPkgs = "org.jboss.naming"; |
| 72 | 0 | env.setProperty("java.naming.factory.initial", factoryInitial); |
| 73 | 0 | env.setProperty("java.naming.factory.url.pkgs", factoryURLPkgs); |
| 74 | 0 | env.setProperty("java.naming.provider.url", scheme + "://" + host + ":" + port); |
| 75 | 0 | log.debug("Initial Context using env=" + env.toString()); |
| 76 | 0 | InitialContext context = new InitialContext(env); |
| 77 | 0 | log.debug("Calling service=" + service + ", Class = " + className + ", Method=" + methodName); |
| 78 | |
|
| 79 | 0 | Object requestHandler = context.lookup(service); |
| 80 | |
|
| 81 | 0 | Class<?> c = Class.forName(className); |
| 82 | |
|
| 83 | 0 | Method method = c.getMethod(methodName, Element.class); |
| 84 | |
|
| 85 | 0 | Node node = (Node) method.invoke(requestHandler, request); |
| 86 | |
|
| 87 | 0 | if (node.getFirstChild()!=null) { |
| 88 | 0 | response = (Element) node.getFirstChild(); |
| 89 | |
} |
| 90 | |
} |
| 91 | 0 | catch (Exception ex) { |
| 92 | 0 | throw new TransportException(ex); |
| 93 | 0 | } |
| 94 | 0 | if (log.isDebugEnabled()) { |
| 95 | 0 | log.debug("\nResponse message:\n" + XMLUtils.convertNodeToXMLString(response)); |
| 96 | |
} |
| 97 | 0 | return response; |
| 98 | |
} |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
public String send(String request,URI endpointURI) |
| 104 | |
throws TransportException |
| 105 | |
{ |
| 106 | 0 | String response = null; |
| 107 | 0 | log.debug("\nRequest message:\n" + request); |
| 108 | |
try { |
| 109 | 0 | DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
| 110 | 0 | DocumentBuilder parser = factory.newDocumentBuilder(); |
| 111 | 0 | Document document = parser.parse(request); |
| 112 | 0 | Element element = document.getDocumentElement(); |
| 113 | 0 | response= XMLUtils.convertNodeToXMLString(send(element, endpointURI)); |
| 114 | 0 | } catch (Exception ex) { |
| 115 | 0 | throw new TransportException(ex); |
| 116 | 0 | } |
| 117 | 0 | log.debug("\nResponse message:\n" + response); |
| 118 | 0 | return response; |
| 119 | |
} |
| 120 | |
|
| 121 | |
|
| 122 | |
} |