// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) braces deadcode fieldsfirst 
// Source File Name:   SOAPHTTPConnection.java
// Class Version:      45.3

package org.apache.soap.transport.http;

import java.io.*;
import java.net.URL;
import java.util.Hashtable;
import javax.mail.MessagingException;
import org.apache.soap.*;
import org.apache.soap.encoding.SOAPMappingRegistry;
import org.apache.soap.encoding.soapenc.Base64;
import org.apache.soap.rpc.SOAPContext;
import org.apache.soap.transport.SOAPTransport;
import org.apache.soap.transport.TransportMessage;
import org.apache.soap.util.net.HTTPUtils;

// flag ACC_SUPER is set
public class SOAPHTTPConnection
    implements SOAPTransport
{
    // Constants:          236
    // Interfaces:         1
    // Fields:             14
    // Methods:            20
    // Class Attributes:   1


    private BufferedReader responseReader;
    private Hashtable responseHeaders;
    private SOAPContext responseSOAPContext;
    private String httpProxyHost;
    private int httpProxyPort;
    private int timeout;
    private String userName;
    private String password;
    private String proxyUserName;
    private String proxyPassword;
    private boolean maintainSession;
    private String cookieHeader;
    private String cookieHeader2;
    private int outputBufferSize;

    // Decompiling method: <init>  Signature: ()V
    // Max stack: 2, #locals: 1, #params: 1
    // Code length: 23 bytes, Code offset: 3484
    // Line Number Table found: 5 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/transport/http/SOAPHTTPConnection; At 0 23 Range 0 22 Init 0 fixed
    // RetValue   1 added: Name <returnValue> Type V At 0 23 Range 0 22 Init 0 fixed
    public SOAPHTTPConnection()
    {
        super();
        httpProxyPort = 80;
        maintainSession = true;
        outputBufferSize = 512;
        return;
    }

    // Decompiling method: encodeAuth  Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    // Max stack: 3, #locals: 2, #params: 2
    // Code length: 30 bytes, Code offset: 3561
    // Line Number Table found: 1 entries
    // Parameter  0 added: Name s Type Ljava/lang/String; At 0 30 Range 0 29 Init 0
    // Parameter  1 added: Name s1 Type Ljava/lang/String; At 0 30 Range 0 29 Init 0
    // RetValue   2 added: Name <returnValue> Type Ljava/lang/String; At 0 30 Range 0 29 Init 0 fixed
    private static String encodeAuth(String s, String s1)
    {
        return Base64.encode((s + ":" + s1).getBytes());
    }

    // Decompiling method: getHeaders  Signature: ()Ljava/util/Hashtable;
    // Max stack: 1, #locals: 1, #params: 1
    // Code length: 5 bytes, Code offset: 3629
    // Line Number Table found: 1 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/transport/http/SOAPHTTPConnection; At 0 5 Range 0 4 Init 0 fixed
    // RetValue   1 added: Name <returnValue> Type Ljava/util/Hashtable; At 0 5 Range 0 4 Init 0 fixed
    public Hashtable getHeaders()
    {
        return responseHeaders;
    }

    // Decompiling method: getMaintainSession  Signature: ()Z
    // Max stack: 1, #locals: 1, #params: 1
    // Code length: 5 bytes, Code offset: 3672
    // Line Number Table found: 1 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/transport/http/SOAPHTTPConnection; At 0 5 Range 0 4 Init 0 fixed
    // RetValue   1 added: Name <returnValue> Type Z At 0 5 Range 0 4 Init 0 fixed
    public boolean getMaintainSession()
    {
        return maintainSession;
    }

    // Decompiling method: getOutputBufferSize  Signature: ()I
    // Max stack: 1, #locals: 1, #params: 1
    // Code length: 5 bytes, Code offset: 3715
    // Line Number Table found: 1 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/transport/http/SOAPHTTPConnection; At 0 5 Range 0 4 Init 0 fixed
    // RetValue   1 added: Name <returnValue> Type I At 0 5 Range 0 4 Init 0 fixed
    public int getOutputBufferSize()
    {
        return outputBufferSize;
    }

    // Decompiling method: getProxyHost  Signature: ()Ljava/lang/String;
    // Max stack: 1, #locals: 1, #params: 1
    // Code length: 5 bytes, Code offset: 3758
    // Line Number Table found: 1 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/transport/http/SOAPHTTPConnection; At 0 5 Range 0 4 Init 0 fixed
    // RetValue   1 added: Name <returnValue> Type Ljava/lang/String; At 0 5 Range 0 4 Init 0 fixed
    public String getProxyHost()
    {
        return httpProxyHost;
    }

    // Decompiling method: getProxyPort  Signature: ()I
    // Max stack: 1, #locals: 1, #params: 1
    // Code length: 5 bytes, Code offset: 3801
    // Line Number Table found: 1 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/transport/http/SOAPHTTPConnection; At 0 5 Range 0 4 Init 0 fixed
    // RetValue   1 added: Name <returnValue> Type I At 0 5 Range 0 4 Init 0 fixed
    public int getProxyPort()
    {
        return httpProxyPort;
    }

    // Decompiling method: getResponseSOAPContext  Signature: ()Lorg/apache/soap/rpc/SOAPContext;
    // Max stack: 1, #locals: 1, #params: 1
    // Code length: 5 bytes, Code offset: 3844
    // Line Number Table found: 1 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/transport/http/SOAPHTTPConnection; At 0 5 Range 0 4 Init 0 fixed
    // RetValue   1 added: Name <returnValue> Type Lorg/apache/soap/rpc/SOAPContext; At 0 5 Range 0 4 Init 0 fixed
    public SOAPContext getResponseSOAPContext()
    {
        return responseSOAPContext;
    }

    // Decompiling method: getTimeout  Signature: ()I
    // Max stack: 1, #locals: 1, #params: 1
    // Code length: 5 bytes, Code offset: 3887
    // Line Number Table found: 1 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/transport/http/SOAPHTTPConnection; At 0 5 Range 0 4 Init 0 fixed
    // RetValue   1 added: Name <returnValue> Type I At 0 5 Range 0 4 Init 0 fixed
    public int getTimeout()
    {
        return timeout;
    }

    // Decompiling method: receive  Signature: ()Ljava/io/BufferedReader;
    // Max stack: 1, #locals: 1, #params: 1
    // Code length: 5 bytes, Code offset: 3930
    // Line Number Table found: 1 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/transport/http/SOAPHTTPConnection; At 0 5 Range 0 4 Init 0 fixed
    // RetValue   1 added: Name <returnValue> Type Ljava/io/BufferedReader; At 0 5 Range 0 4 Init 0 fixed
    public BufferedReader receive()
    {
        return responseReader;
    }

    // Decompiling method: send  Signature: (Ljava/net/URL;Ljava/lang/String;Ljava/util/Hashtable;Lorg/apache/soap/Envelope;Lorg/apache/soap/encoding/SOAPMappingRegistry;Lorg/apache/soap/rpc/SOAPContext;)V
    // Max stack: 6, #locals: 12, #params: 7
    // Code length: 544 bytes, Code offset: 3973
    // Exception table: 5 entries
    //           start  210 end 253 handler 256 type MessagingException
    //           start  210 end 253 handler 283 type UnsupportedEncodingException
    //           start  0 end 480 handler 483 type IllegalArgumentException
    //           start  0 end 480 handler 503 type MessagingException
    //           start  0 end 480 handler 523 type IOException
    // Line Number Table found: 64 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/transport/http/SOAPHTTPConnection; At 0 544 Range 0 543 Init 0 fixed
    // Parameter  1 added: Name url Type Ljava/net/URL; At 0 544 Range 0 543 Init 0
    // Parameter  2 added: Name s Type Ljava/lang/String; At 0 544 Range 0 543 Init 0
    // Parameter  3 added: Name hashtable Type Ljava/util/Hashtable; At 0 544 Range 0 543 Init 0
    // Parameter  4 added: Name envelope Type Lorg/apache/soap/Envelope; At 0 544 Range 0 543 Init 0
    // Parameter  5 added: Name soapmappingregistry Type Lorg/apache/soap/encoding/SOAPMappingRegistry; At 0 544 Range 0 543 Init 0
    // Parameter  6 added: Name soapcontext Type Lorg/apache/soap/rpc/SOAPContext; At 0 544 Range 0 543 Init 0
    // RetValue  12 added: Name <returnValue> Type V At 0 544 Range 0 543 Init 0 fixed
    // LocalVar   7 added: Name obj Type A At 1 215 Range 1 215 Init 1
    // LocalVar   8 added: Name stringwriter Type Ljava/io/StringWriter; At 15 15 Range 15 29 Init 15
    // LocalVar   7 chged: Name s1 Oname obj Type Ljava/lang/String; At 33 183 Range 1 215 Init 1
    // LocalVar   9 added: Name transportmessage Type Lorg/apache/soap/transport/TransportMessage; At 222 10 Range 222 231 Init 222
    // LocalVar   8 added: Name transportmessage1 Type Lorg/apache/soap/transport/TransportMessage; At 251 104 Range 251 354 Init 251
    // LocalVar   9 added: Name reader Type Ljava/io/Reader; At 315 14 Range 315 328 Init 315
    // LocalVar  10 added: Name s2 Type Ljava/lang/String; At 380 10 Range 380 389 Init 380
    // LocalVar  11 added: Name i Type I At 402 16 Range 402 417 Init 402
    // LocalVar  10 added: Name s3 Type Ljava/lang/String; At 436 10 Range 436 445 Init 436
    // LocalVar  11 added: Name j Type I At 458 16 Range 458 473 Init 458
    // LocalVar   9 added: Name messagingexception Type Ljavax/mail/MessagingException; At 256 17 Range 256 272 Init 256
    // LocalVar   9 added: Name unsupportedencodingexception Type Ljava/io/UnsupportedEncodingException; At 283 17 Range 283 299 Init 283
    // LocalVar   7 added: Name illegalargumentexception Type Ljava/lang/IllegalArgumentException; At 483 16 Range 483 498 Init 483
    // LocalVar   7 added: Name messagingexception1 Type Ljavax/mail/MessagingException; At 503 16 Range 503 518 Init 503
    // LocalVar   7 added: Name ioexception Type Ljava/io/IOException; At 523 16 Range 523 538 Init 523
    // LocalVar  10 name s3(Ljava/lang/String;) merged out into s2(Ljava/lang/String;)
    public void send(URL url, String s, Hashtable hashtable, Envelope envelope, SOAPMappingRegistry soapmappingregistry, SOAPContext soapcontext)
        throws SOAPException
    {
        try
        {
            String s1 = null;
            if(envelope != null)
            {
                StringWriter stringwriter = new StringWriter();
                envelope.marshall(stringwriter, soapmappingregistry, soapcontext);
                s1 = stringwriter.toString();
            }
            if(hashtable == null)
            {
                hashtable = new Hashtable();
            }
            if(maintainSession)
            {
                if(cookieHeader2 != null)
                {
                    hashtable.put("Cookie2", cookieHeader2);
                }
                if(cookieHeader != null)
                {
                    hashtable.put("Cookie", cookieHeader);
                }
            }
            hashtable.put("SOAPAction", s == null ? "" : ((Object) ('"' + s + '"')));
            if(userName != null)
            {
                hashtable.put("Authorization", "Basic " + encodeAuth(userName, password));
            }
            if(proxyUserName != null)
            {
                hashtable.put("Proxy-Authorization", "Basic " + encodeAuth(proxyUserName, proxyPassword));
            }
            TransportMessage transportmessage;
            try
            {
                TransportMessage transportmessage1 = new TransportMessage(s1, soapcontext, hashtable);
                transportmessage1.save();
                transportmessage = HTTPUtils.post(url, transportmessage1, timeout, httpProxyHost, httpProxyPort, outputBufferSize);
            }
            catch(MessagingException messagingexception1)
            {
                throw new IOException("Failed to encode mime multipart: " + messagingexception1);
            }
            catch(UnsupportedEncodingException unsupportedencodingexception)
            {
                throw new IOException("Failed to encode mime multipart: " + unsupportedencodingexception);
            }
            java.io.Reader reader = transportmessage.getEnvelopeReader();
            if(reader != null)
            {
                responseReader = new BufferedReader(reader);
            } else
            {
                responseReader = null;
            }
            responseSOAPContext = transportmessage.getSOAPContext();
            responseHeaders = transportmessage.getHeaders();
            if(maintainSession)
            {
                String s2 = (String)responseHeaders.get("Set-Cookie2");
                if(s2 != null)
                {
                    cookieHeader2 = s2;
                    int i = cookieHeader2.indexOf(59);
                    if(i != -1)
                    {
                        cookieHeader2 = cookieHeader2.substring(0, i);
                    }
                }
                s2 = (String)responseHeaders.get("Set-Cookie");
                if(s2 != null)
                {
                    cookieHeader = s2;
                    int j = cookieHeader.indexOf(59);
                    if(j != -1)
                    {
                        cookieHeader = cookieHeader.substring(0, j);
                    }
                }
            }
        }
        catch(IllegalArgumentException illegalargumentexception)
        {
            throw new SOAPException(Constants.FAULT_CODE_CLIENT, illegalargumentexception.getMessage(), illegalargumentexception);
        }
        catch(MessagingException messagingexception)
        {
            throw new SOAPException(Constants.FAULT_CODE_CLIENT, messagingexception.getMessage(), messagingexception);
        }
        catch(IOException ioexception)
        {
            throw new SOAPException(Constants.FAULT_CODE_CLIENT, ioexception.getMessage(), ioexception);
        }
        return;
    }

    // Decompiling method: setMaintainSession  Signature: (Z)V
    // Max stack: 2, #locals: 2, #params: 2
    // Code length: 21 bytes, Code offset: 4857
    // Line Number Table found: 5 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/transport/http/SOAPHTTPConnection; At 0 21 Range 0 20 Init 0 fixed
    // Parameter  1 added: Name flag Type Z At 0 21 Range 0 20 Init 0
    // RetValue   2 added: Name <returnValue> Type V At 0 21 Range 0 20 Init 0 fixed
    public void setMaintainSession(boolean flag)
    {
        maintainSession = flag;
        if(!flag)
        {
            cookieHeader = null;
            cookieHeader2 = null;
        }
        return;
    }

    // Decompiling method: setOutputBufferSize  Signature: (I)V
    // Max stack: 2, #locals: 2, #params: 2
    // Code length: 6 bytes, Code offset: 4932
    // Line Number Table found: 2 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/transport/http/SOAPHTTPConnection; At 0 6 Range 0 5 Init 0 fixed
    // Parameter  1 added: Name i Type I At 0 6 Range 0 5 Init 0
    // RetValue   2 added: Name <returnValue> Type V At 0 6 Range 0 5 Init 0 fixed
    public void setOutputBufferSize(int i)
    {
        outputBufferSize = i;
        return;
    }

    // Decompiling method: setPassword  Signature: (Ljava/lang/String;)V
    // Max stack: 2, #locals: 2, #params: 2
    // Code length: 6 bytes, Code offset: 4980
    // Line Number Table found: 2 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/transport/http/SOAPHTTPConnection; At 0 6 Range 0 5 Init 0 fixed
    // Parameter  1 added: Name s Type Ljava/lang/String; At 0 6 Range 0 5 Init 0
    // RetValue   2 added: Name <returnValue> Type V At 0 6 Range 0 5 Init 0 fixed
    public void setPassword(String s)
    {
        password = s;
        return;
    }

    // Decompiling method: setProxyHost  Signature: (Ljava/lang/String;)V
    // Max stack: 2, #locals: 2, #params: 2
    // Code length: 6 bytes, Code offset: 5028
    // Line Number Table found: 2 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/transport/http/SOAPHTTPConnection; At 0 6 Range 0 5 Init 0 fixed
    // Parameter  1 added: Name s Type Ljava/lang/String; At 0 6 Range 0 5 Init 0
    // RetValue   2 added: Name <returnValue> Type V At 0 6 Range 0 5 Init 0 fixed
    public void setProxyHost(String s)
    {
        httpProxyHost = s;
        return;
    }

    // Decompiling method: setProxyPassword  Signature: (Ljava/lang/String;)V
    // Max stack: 2, #locals: 2, #params: 2
    // Code length: 6 bytes, Code offset: 5076
    // Line Number Table found: 2 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/transport/http/SOAPHTTPConnection; At 0 6 Range 0 5 Init 0 fixed
    // Parameter  1 added: Name s Type Ljava/lang/String; At 0 6 Range 0 5 Init 0
    // RetValue   2 added: Name <returnValue> Type V At 0 6 Range 0 5 Init 0 fixed
    public void setProxyPassword(String s)
    {
        proxyPassword = s;
        return;
    }

    // Decompiling method: setProxyPort  Signature: (I)V
    // Max stack: 2, #locals: 2, #params: 2
    // Code length: 6 bytes, Code offset: 5124
    // Line Number Table found: 2 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/transport/http/SOAPHTTPConnection; At 0 6 Range 0 5 Init 0 fixed
    // Parameter  1 added: Name i Type I At 0 6 Range 0 5 Init 0
    // RetValue   2 added: Name <returnValue> Type V At 0 6 Range 0 5 Init 0 fixed
    public void setProxyPort(int i)
    {
        httpProxyPort = i;
        return;
    }

    // Decompiling method: setProxyUserName  Signature: (Ljava/lang/String;)V
    // Max stack: 2, #locals: 2, #params: 2
    // Code length: 6 bytes, Code offset: 5172
    // Line Number Table found: 2 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/transport/http/SOAPHTTPConnection; At 0 6 Range 0 5 Init 0 fixed
    // Parameter  1 added: Name s Type Ljava/lang/String; At 0 6 Range 0 5 Init 0
    // RetValue   2 added: Name <returnValue> Type V At 0 6 Range 0 5 Init 0 fixed
    public void setProxyUserName(String s)
    {
        proxyUserName = s;
        return;
    }

    // Decompiling method: setTimeout  Signature: (I)V
    // Max stack: 2, #locals: 2, #params: 2
    // Code length: 6 bytes, Code offset: 5220
    // Line Number Table found: 2 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/transport/http/SOAPHTTPConnection; At 0 6 Range 0 5 Init 0 fixed
    // Parameter  1 added: Name i Type I At 0 6 Range 0 5 Init 0
    // RetValue   2 added: Name <returnValue> Type V At 0 6 Range 0 5 Init 0 fixed
    public void setTimeout(int i)
    {
        timeout = i;
        return;
    }

    // Decompiling method: setUserName  Signature: (Ljava/lang/String;)V
    // Max stack: 2, #locals: 2, #params: 2
    // Code length: 6 bytes, Code offset: 5268
    // Line Number Table found: 2 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/transport/http/SOAPHTTPConnection; At 0 6 Range 0 5 Init 0 fixed
    // Parameter  1 added: Name s Type Ljava/lang/String; At 0 6 Range 0 5 Init 0
    // RetValue   2 added: Name <returnValue> Type V At 0 6 Range 0 5 Init 0 fixed
    public void setUserName(String s)
    {
        userName = s;
        return;
    }
}
