home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VPage / Java.bin / CLASSES.ZIP / sun / rmi / transport / proxy / HttpSendSocket.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-07-08  |  5.1 KB  |  194 lines

  1. package sun.rmi.transport.proxy;
  2.  
  3. import java.io.DataInputStream;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.OutputStream;
  7. import java.io.PrintStream;
  8. import java.net.InetAddress;
  9. import java.net.Socket;
  10. import java.net.SocketException;
  11. import java.net.SocketImpl;
  12. import java.net.URL;
  13. import java.net.URLConnection;
  14. import java.net.UnknownHostException;
  15. import java.rmi.server.LogStream;
  16.  
  17. class HttpSendSocket extends Socket implements RMISocketInfo {
  18.    protected String host;
  19.    protected int port;
  20.    protected URL url;
  21.    protected URLConnection conn;
  22.    // $FF: renamed from: in java.io.InputStream
  23.    protected InputStream field_0;
  24.    protected OutputStream out;
  25.    protected HttpSendInputStream inNotifier;
  26.    protected HttpSendOutputStream outNotifier;
  27.  
  28.    public HttpSendSocket(String var1, int var2, URL var3) throws IOException {
  29.       super((SocketImpl)null);
  30.       if (RMIMasterSocketFactory.logLevel >= 20) {
  31.          LogStream.log("proxy").println("HttpSendSocket.<init>: host = " + var1 + ", port = " + var2 + ", url = " + var3);
  32.       }
  33.  
  34.       this.host = var1;
  35.       this.port = var2;
  36.       this.url = var3;
  37.       this.inNotifier = new HttpSendInputStream((InputStream)null, this);
  38.       this.outNotifier = new HttpSendOutputStream(this.writeNotify(), this);
  39.    }
  40.  
  41.    public HttpSendSocket(String var1, int var2) throws IOException {
  42.       this(var1, var2, new URL("http", var1, var2, "/"));
  43.    }
  44.  
  45.    public HttpSendSocket(InetAddress var1, int var2) throws IOException {
  46.       this(var1.getHostName(), var2);
  47.    }
  48.  
  49.    public boolean isReusable() {
  50.       return false;
  51.    }
  52.  
  53.    public synchronized OutputStream writeNotify() throws IOException {
  54.       if (this.conn != null) {
  55.          throw new IOException("attempt to write on HttpSendSocket after request has been sent");
  56.       } else {
  57.          this.conn = this.url.openConnection();
  58.          this.conn.setDoOutput(true);
  59.          this.conn.setUseCaches(false);
  60.          this.conn.setRequestProperty("Content-type", "application/octet-stream");
  61.          this.inNotifier.deactivate();
  62.          this.field_0 = null;
  63.          return this.out = this.conn.getOutputStream();
  64.       }
  65.    }
  66.  
  67.    public synchronized InputStream readNotify() throws IOException {
  68.       if (RMIMasterSocketFactory.logLevel >= 20) {
  69.          LogStream.log("proxy").println("HttpSendSocket.readNotify: sending request and activating input stream");
  70.       }
  71.  
  72.       this.outNotifier.deactivate();
  73.       this.out.close();
  74.       this.out = null;
  75.  
  76.       try {
  77.          this.field_0 = this.conn.getInputStream();
  78.       } catch (IOException var16) {
  79.          IOException var1 = var16;
  80.          if (RMIMasterSocketFactory.logLevel >= 10) {
  81.             LogStream var2 = LogStream.log("proxy");
  82.             synchronized(var2){}
  83.  
  84.             try {
  85.                ((PrintStream)var2).print("HttpSendSocket.readNotify: failed to get input stream, exception: ");
  86.                ((Throwable)var1).printStackTrace(var2);
  87.             } catch (Throwable var15) {
  88.                throw var15;
  89.             }
  90.          }
  91.  
  92.          throw new IOException("HTTP request failed");
  93.       }
  94.  
  95.       String var19 = this.conn.getContentType();
  96.       if (var19 != null && this.conn.getContentType().equals("application/octet-stream")) {
  97.          return this.field_0;
  98.       } else {
  99.          if (RMIMasterSocketFactory.logLevel >= 10) {
  100.             LogStream var20 = LogStream.log("proxy");
  101.             synchronized(var20){}
  102.  
  103.             try {
  104.                if (var19 == null) {
  105.                   ((PrintStream)var20).println("HttpSendSocket.readNotify: missing content type in response");
  106.                } else {
  107.                   ((PrintStream)var20).println("HttpSendSocket.readNotify: invalid content type in response: " + var19);
  108.                }
  109.  
  110.                ((PrintStream)var20).print("HttpSendSocket.readNotify: response body: ");
  111.  
  112.                try {
  113.                   DataInputStream var5 = new DataInputStream(this.field_0);
  114.  
  115.                   String var6;
  116.                   while((var6 = var5.readLine()) != null) {
  117.                      ((PrintStream)var20).println(var6);
  118.                   }
  119.                } catch (IOException var17) {
  120.                }
  121.             } catch (Throwable var18) {
  122.                throw var18;
  123.             }
  124.          }
  125.  
  126.          throw new IOException("HTTP request failed");
  127.       }
  128.    }
  129.  
  130.    public InetAddress getInetAddress() {
  131.       try {
  132.          return InetAddress.getByName(this.host);
  133.       } catch (UnknownHostException var1) {
  134.          return null;
  135.       }
  136.    }
  137.  
  138.    public InetAddress getLocalAddress() {
  139.       try {
  140.          return InetAddress.getLocalHost();
  141.       } catch (UnknownHostException var1) {
  142.          return null;
  143.       }
  144.    }
  145.  
  146.    public int getPort() {
  147.       return this.port;
  148.    }
  149.  
  150.    public int getLocalPort() {
  151.       return -1;
  152.    }
  153.  
  154.    public InputStream getInputStream() throws IOException {
  155.       return this.inNotifier;
  156.    }
  157.  
  158.    public OutputStream getOutputStream() throws IOException {
  159.       return this.outNotifier;
  160.    }
  161.  
  162.    public void setTcpNoDelay(boolean var1) throws SocketException {
  163.    }
  164.  
  165.    public boolean getTcpNoDelay() throws SocketException {
  166.       return false;
  167.    }
  168.  
  169.    public void setSoLinger(boolean var1, int var2) throws SocketException {
  170.    }
  171.  
  172.    public int getSoLinger() throws SocketException {
  173.       return -1;
  174.    }
  175.  
  176.    public synchronized void setSoTimeout(int var1) throws SocketException {
  177.    }
  178.  
  179.    public synchronized int getSoTimeout() throws SocketException {
  180.       return 0;
  181.    }
  182.  
  183.    public synchronized void close() throws IOException {
  184.       if (this.out != null) {
  185.          this.out.close();
  186.       }
  187.  
  188.    }
  189.  
  190.    public String toString() {
  191.       return "HttpSendSocket[host=" + this.host + ",port=" + this.port + ",url=" + this.url + "]";
  192.    }
  193. }
  194.