1 16 17 18 package org.apache.xmlrpc; 19 20 import java.io.InputStream ; 21 import java.io.OutputStream ; 22 import java.io.IOException ; 23 import java.net.URL ; 24 import java.net.URLConnection ; 25 import org.apache.xmlrpc.util.HttpUtil; 26 27 37 public class DefaultXmlRpcTransport implements XmlRpcTransport 38 { 39 protected URL url; 40 protected String auth; 41 protected URLConnection con; 42 43 52 public DefaultXmlRpcTransport(URL url, String auth) 53 { 54 this.url = url; 55 this.auth = auth; 56 } 57 58 63 public DefaultXmlRpcTransport(URL url) 64 { 65 this(url, null); 66 } 67 68 public InputStream sendXmlRpc(byte [] request) 69 throws IOException 70 { 71 con = url.openConnection(); 72 con.setDoInput(true); 73 con.setDoOutput(true); 74 con.setUseCaches(false); 75 con.setAllowUserInteraction(false); 76 con.setRequestProperty("Content-Length", 77 Integer.toString(request.length)); 78 con.setRequestProperty("Content-Type", "text/xml"); 79 if (auth != null) 80 { 81 con.setRequestProperty("Authorization", "Basic " + auth); 82 } 83 OutputStream out = con.getOutputStream(); 84 out.write(request); 85 out.flush(); 86 out.close(); 87 return con.getInputStream(); 88 } 89 90 96 public void setBasicAuthentication(String user, String password) 97 { 98 auth = HttpUtil.encodeBasicAuthentication(user, password); 99 } 100 101 public void endClientRequest() 102 throws XmlRpcClientException 103 { 104 try 105 { 106 con.getInputStream().close(); 107 } 108 catch (Exception e) 109 { 110 throw new XmlRpcClientException("Exception closing URLConnection", e); 111 } 112 } 113 } 114 | Popular Tags |