1 22 package org.jboss.invocation.http.interfaces; 23 24 import java.io.IOException ; 25 import java.io.Externalizable ; 26 import java.io.ObjectInput ; 27 import java.io.ObjectOutput ; 28 import java.lang.reflect.InvocationTargetException ; 29 import java.lang.reflect.Method ; 30 import java.net.MalformedURLException ; 31 import java.net.URL ; 32 import java.rmi.ServerException ; 33 34 import org.jboss.invocation.Invocation; 35 import org.jboss.invocation.InvocationException; 36 import org.jboss.invocation.Invoker; 37 import org.jboss.invocation.MarshalledInvocation; 38 import org.jboss.invocation.MarshalledValue; 39 import org.jboss.logging.Logger; 40 41 48 public class HttpInvokerProxy 49 implements Invoker, Externalizable 50 { 51 private static Logger log = Logger.getLogger(HttpInvokerProxy.class); 53 54 55 static final long serialVersionUID = -8249272784108192267L; 56 57 59 protected String externalURLValue; 61 protected transient URL externalURL; 62 63 public HttpInvokerProxy() 65 { 66 } 68 69 73 public HttpInvokerProxy(String externalURLValue) 74 { 75 this.externalURLValue = externalURLValue; 76 } 77 78 80 public String getServerHostName() throws Exception 81 { 82 if( externalURL == null ) 83 externalURL = Util.resolveURL(externalURLValue); 84 return externalURL.getHost(); 85 } 86 public String getExternalURLValue() 87 { 88 return externalURLValue; 89 } 90 public URL getExternalURL() 91 { 92 return externalURL; 93 } 94 95 public String toString() 96 { 97 StringBuffer tmp = new StringBuffer (super.toString()); 98 tmp.append('('); 99 tmp.append("externalURL:"); 100 tmp.append(externalURL); 101 tmp.append(')'); 102 return tmp.toString(); 103 } 104 105 108 public Object invoke(Invocation invocation) 109 throws Exception 110 { 111 MarshalledInvocation mi = new MarshalledInvocation(invocation); 113 114 if( externalURL == null ) 115 externalURL = Util.resolveURL(externalURLValue); 116 try 117 { 118 Object value = Util.invoke(externalURL, mi); 119 return value; 120 } 121 catch (InvocationException e) 122 { 123 Throwable t = e.getTargetException(); 125 if( t instanceof Exception ) 126 throw (Exception ) t; 127 else if (t instanceof Error ) 128 throw (Error ) t; 129 throw new InvocationTargetException (t); 130 } 131 catch (IOException e) 132 { 133 throw new ServerException ("IOE", e); 134 } 135 } 136 137 139 public void writeExternal(final ObjectOutput out) 140 throws IOException 141 { 142 out.writeObject(externalURLValue); 143 } 144 145 147 public void readExternal(final ObjectInput in) 148 throws IOException , ClassNotFoundException 149 { 150 externalURLValue = (String ) in.readObject(); 151 externalURL = Util.resolveURL(externalURLValue); 152 } 153 154 } 155 | Popular Tags |