1 6 7 package org.jfox.ioc.connector.soap; 8 9 import java.util.Vector ; 10 import java.io.Serializable ; 11 import java.io.IOException ; 12 import java.io.ByteArrayOutputStream ; 13 import java.io.ObjectOutputStream ; 14 import java.rmi.RemoteException ; 15 import java.net.URL ; 16 import java.net.HttpURLConnection ; 17 18 import org.apache.xmlrpc.XmlRpcHandler; 19 import org.apache.xmlrpc.XmlRpcClientLite; 20 import org.jfox.ioc.connector.Invocation; 21 import org.jfox.ioc.connector.ConnectorRemote; 22 23 30 31 public class SOAPConnectorRemote implements ConnectorRemote, Serializable { 32 private transient XmlRpcHandler client; 33 private String soapURL; 34 35 public SOAPConnectorRemote(String soapUrl) { 36 this.soapURL = soapUrl; 37 try { 38 client = new XmlRpcClientLite(soapUrl); 39 } 40 catch(Exception e) { 41 e.printStackTrace(); 42 } 43 } 44 45 public String getProtocol() throws RemoteException { 46 return "SOAP"; 47 } 48 49 public Object invoke(Invocation invocation) throws RemoteException { 50 Vector params = new Vector (1); 51 params.add(marshelledObject(invocation)); 52 try { 53 return client.execute("xmlrpc", params); 55 } 56 catch(Exception e) { 57 throw new RemoteException (e.getMessage(), e); 58 } 59 60 } 61 62 69 private void readObject(java.io.ObjectInputStream in) throws IOException , ClassNotFoundException { 70 in.defaultReadObject(); 71 client = new XmlRpcClientLite(soapURL); 72 } 73 74 public void ping() throws RemoteException { 75 HttpURLConnection conn = null; 76 try { 77 conn = (HttpURLConnection ) new URL (soapURL).openConnection(); 78 } 79 catch(Exception e) { 80 throw new RemoteException ("can't get connection with the soap url: " + soapURL, e); 81 } 82 finally { 83 if(conn != null) { 84 try { 85 conn.disconnect(); 86 } 87 catch(Exception e) { 88 } 89 } 90 } 91 } 93 94 private static byte[] marshelledObject(Serializable obj) { 95 ByteArrayOutputStream out = new ByteArrayOutputStream (); 96 try { 97 ObjectOutputStream oos = new ObjectOutputStream (out); 98 oos.writeObject(obj); 99 oos.flush(); 100 oos.close(); 101 } 102 catch(IOException e) { 103 e.printStackTrace(); 104 } 105 return out.toByteArray(); 106 } 107 108 public static void main(String [] args) { 109 110 } 111 } | Popular Tags |