1 38 package com.gargoylesoftware.htmlunit; 39 40 import java.io.IOException ; 41 import java.net.URL ; 42 import java.util.List ; 43 import java.util.Map ; 44 45 import org.org.apache.commons.httpclient.HttpState; 46 47 56 public abstract class WebConnection { 57 private final String proxyHost_; 58 private final int proxyPort_; 59 private final WebClient webClient_; 60 61 62 67 public WebConnection( final WebClient webClient ) { 68 webClient_ = webClient; 69 proxyHost_ = null; 70 proxyPort_ = 0; 71 } 72 73 74 81 public WebConnection( final WebClient webClient, final String proxyHost, final int proxyPort ) { 82 webClient_ = webClient; 83 proxyHost_ = proxyHost; 84 proxyPort_ = proxyPort; 85 } 86 87 94 public abstract WebResponse getResponse(final WebRequestSettings webRequestSettings) 95 throws IOException ; 96 97 108 public WebResponse getResponse( 109 final URL url, 110 final SubmitMethod submitMethod, 111 final List parameters, 112 final Map requestHeaders ) 113 throws 114 IOException { 115 final WebRequestSettings wrs = new WebRequestSettings(url); 116 wrs.setSubmitMethod(submitMethod); 117 wrs.setRequestParameters(parameters); 118 wrs.setAdditionalHeaders(requestHeaders); 119 return getResponse(wrs); 120 } 121 122 134 public WebResponse getResponse( 135 final URL url, 136 final FormEncodingType encType, 137 final SubmitMethod submitMethod, 138 final List parameters, 139 final Map requestHeaders ) 140 throws 141 IOException { 142 final WebRequestSettings wrs = new WebRequestSettings(url); 143 wrs.setEncodingType(encType); 144 wrs.setSubmitMethod(submitMethod); 145 wrs.setRequestParameters(parameters); 146 wrs.setAdditionalHeaders(requestHeaders); 147 return getResponse(wrs); 148 } 149 150 154 public final WebClient getWebClient() { 155 return webClient_; 156 } 157 158 159 163 public final String getProxyHost() { 164 return proxyHost_; 165 } 166 167 168 172 public final int getProxyPort() { 173 return proxyPort_; 174 } 175 176 177 182 public abstract HttpState getStateForUrl( final URL url ); 183 } 184 185 | Popular Tags |