1 22 package org.jboss.mq.il.http; 23 24 import java.io.ObjectInputStream ; 25 import java.io.ObjectOutputStream ; 26 import java.net.HttpURLConnection ; 27 import java.net.MalformedURLException ; 28 import java.net.URL ; 29 30 import org.jboss.invocation.http.interfaces.Util; 31 import org.jboss.logging.Logger; 32 33 43 public class HTTPClient 44 { 45 private static final String CONTENT_TYPE = "application/x-java-serialized-object; class=org.jboss.mq.il.http.HTTPILRequest"; 46 47 private static Logger log = Logger.getLogger(HTTPClient.class); 48 49 public static Object post(URL url, HTTPILRequest request) throws Exception 50 { 51 if (log.isTraceEnabled()) 52 { 53 log.trace("post(URL " + url.toString() + ", HTTPILRequest " + request.toString() + ")"); 54 } 55 HttpURLConnection connection = (HttpURLConnection )url.openConnection(); 56 Util.configureHttpsHostVerifier(connection); 57 58 connection.setDoInput(true); 59 connection.setDoOutput(true); 60 connection.setUseCaches(false); 61 connection.setRequestProperty("ContentType", CONTENT_TYPE); 62 connection.setRequestMethod("POST"); 63 ObjectOutputStream outputStream = new ObjectOutputStream (connection.getOutputStream()); 64 outputStream.writeObject(request); 65 outputStream.close(); 66 ObjectInputStream inputStream = new ObjectInputStream (connection.getInputStream()); 67 HTTPILResponse response = (HTTPILResponse)inputStream.readObject(); 68 inputStream.close(); 69 Object responseValue = response.getValue(); 70 if (responseValue instanceof Exception ) 71 { 72 throw (Exception )responseValue; 73 } 74 return responseValue; 75 } 76 77 public static URL resolveServerUrl(String url) throws MalformedURLException 78 { 79 return Util.resolveURL(url); 80 } 81 } 82 | Popular Tags |