1 22 package org.jboss.console.remote; 23 28 public class Util 29 { 30 31 private static String REQUEST_CONTENT_TYPE = 32 "application/x-java-serialized-object; class=org.jboss.console.remote.RemoteMBeanInvocation"; 33 private static org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(Util.class); 34 35 static 36 { 37 48 } 49 50 54 public static Object invoke (java.net.URL externalURL, RemoteMBeanInvocation mi) throws Exception 55 { 56 if( log.isTraceEnabled() ) 57 log.trace("invoke, externalURL="+externalURL); 58 62 java.net.HttpURLConnection conn = (java.net.HttpURLConnection ) externalURL.openConnection(); 63 74 conn.setDoInput(true); 76 conn.setDoOutput(true); 77 conn.setRequestProperty("ContentType", REQUEST_CONTENT_TYPE); 78 conn.setRequestMethod("POST"); 79 java.io.OutputStream os = conn.getOutputStream(); 80 java.io.ObjectOutputStream oos = new java.io.ObjectOutputStream (os); 81 oos.writeObject(mi); 82 oos.flush(); 83 84 java.io.InputStream is = conn.getInputStream(); 86 java.io.ObjectInputStream ois = new java.io.ObjectInputStream (is); 87 org.jboss.invocation.MarshalledValue mv = (org.jboss.invocation.MarshalledValue) ois.readObject(); 88 ois.close(); 89 oos.close(); 90 91 Object value = mv.get(); 93 94 if( value instanceof org.jboss.invocation.InvocationException ) 95 throw (Exception ) (((org.jboss.invocation.InvocationException)value).getTargetException ()); 96 97 if( value instanceof Exception ) 98 throw (Exception ) value; 99 100 return value; 101 } 102 103 public static Object getAttribute (java.net.URL externalURL, RemoteMBeanAttributeInvocation mi) throws Exception 104 { 105 if( log.isTraceEnabled() ) 106 log.trace("invoke, externalURL="+externalURL); 107 111 java.net.HttpURLConnection conn = (java.net.HttpURLConnection ) externalURL.openConnection(); 112 123 conn.setDoInput(true); 125 conn.setDoOutput(true); 126 conn.setRequestProperty("ContentType", REQUEST_CONTENT_TYPE); 127 conn.setRequestMethod("POST"); 128 java.io.OutputStream os = conn.getOutputStream(); 129 java.io.ObjectOutputStream oos = new java.io.ObjectOutputStream (os); 130 oos.writeObject(mi); 131 oos.flush(); 132 133 java.io.InputStream is = conn.getInputStream(); 135 java.io.ObjectInputStream ois = new java.io.ObjectInputStream (is); 136 org.jboss.invocation.MarshalledValue mv = (org.jboss.invocation.MarshalledValue) ois.readObject(); 137 ois.close(); 138 oos.close(); 139 140 Object value = mv.get(); 142 143 if( value instanceof org.jboss.invocation.InvocationException ) 144 throw (Exception ) (((org.jboss.invocation.InvocationException)value).getTargetException ()); 145 146 if( value instanceof Exception ) 147 throw (Exception ) value; 148 149 return value; 150 } 151 } 152 | Popular Tags |