本文整理汇总了Java中org.apache.commons.httpclient.HostConfiguration类的典型用法代码示例。如果您正苦于以下问题:Java HostConfiguration类的具体用法?Java HostConfiguration怎么用?Java HostConfiguration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HostConfiguration类属于org.apache.commons.httpclient包,在下文中一共展示了HostConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSuccessfulVerifyTargetOverHttps
import org.apache.commons.httpclient.HostConfiguration; //导入依赖的package包/类
public void testSuccessfulVerifyTargetOverHttps() throws Exception
{
//Stub HttpClient so that executeMethod returns a 200 response
when(mockedHttpClient.executeMethod(any(HostConfiguration.class), any(HttpMethod.class),
any(HttpState.class))).thenReturn(200);
target.setEndpointProtocol(HTTPS_PROTOCOL);
target.setEndpointPort(HTTPS_PORT);
//Call verifyTarget
transmitter.verifyTarget(target);
ArgumentCaptor<HostConfiguration> hostConfig = ArgumentCaptor.forClass(HostConfiguration.class);
ArgumentCaptor<HttpMethod> httpMethod = ArgumentCaptor.forClass(HttpMethod.class);
ArgumentCaptor<HttpState> httpState = ArgumentCaptor.forClass(HttpState.class);
verify(mockedHttpClient).executeMethod(hostConfig.capture(), httpMethod.capture(), httpState.capture());
assertEquals("port", HTTPS_PORT, hostConfig.getValue().getPort());
assertTrue("socket factory",
hostConfig.getValue().getProtocol().getSocketFactory() instanceof SecureProtocolSocketFactory);
assertEquals("protocol", HTTPS_PROTOCOL.toLowerCase(),
hostConfig.getValue().getProtocol().getScheme().toLowerCase());
}
示例2: SecureHttpMethodResponse
import org.apache.commons.httpclient.HostConfiguration; //导入依赖的package包/类
public SecureHttpMethodResponse(HttpMethod method, HostConfiguration hostConfig,
EncryptionUtils encryptionUtils) throws AuthenticationException, IOException
{
super(method);
this.hostConfig = hostConfig;
this.encryptionUtils = encryptionUtils;
if(method.getStatusCode() == HttpStatus.SC_OK)
{
this.decryptedBody = encryptionUtils.decryptResponseBody(method);
// authenticate the response
if(!authenticate())
{
throw new AuthenticationException(method);
}
}
}
示例3: clone
import org.apache.commons.httpclient.HostConfiguration; //导入依赖的package包/类
@Override
public HttpConnector clone() throws CloneNotSupportedException {
HttpConnector clonedObject = (HttpConnector) super.clone();
clonedObject.httpStateListeners = new EventListenerList();
clonedObject.sUrl = "";
clonedObject.handleCookie = true;
clonedObject.httpParameters = new XMLVector<XMLVector<String>>();
clonedObject.postQuery = "";
clonedObject.certificateManager = new CertificateManager();
clonedObject.hostConfiguration = new HostConfiguration();
clonedObject.givenAuthPassword = null;
clonedObject.givenAuthUser = null;
return clonedObject;
}
示例4: getMaxConnectionsPerHost
import org.apache.commons.httpclient.HostConfiguration; //导入依赖的package包/类
/**
* Gets the maximum number of connections to be used for a particular host config. If
* the value has not been specified for the given host the default value will be
* returned.
*
* @param hostConfiguration The host config.
* @return The maximum number of connections to be used for the given host config.
*
* @see #MAX_HOST_CONNECTIONS
*/
public int getMaxConnectionsPerHost(HostConfiguration hostConfiguration) {
Map m = (Map) getParameter(MAX_HOST_CONNECTIONS);
if (m == null) {
// MAX_HOST_CONNECTIONS have not been configured, using the default value
return MultiThreadedHttpConnectionManager.DEFAULT_MAX_HOST_CONNECTIONS;
} else {
Integer max = (Integer) m.get(hostConfiguration);
if (max == null && hostConfiguration != HostConfiguration.ANY_HOST_CONFIGURATION) {
// the value has not been configured specifically for this host config,
// use the default value
return getMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION);
} else {
return (
max == null
? MultiThreadedHttpConnectionManager.DEFAULT_MAX_HOST_CONNECTIONS
: max.intValue()
);
}
}
}
示例5: testDefaults
import org.apache.commons.httpclient.HostConfiguration; //导入依赖的package包/类
public void testDefaults() throws IOException {
this.server.setHttpService(new SimpleService());
this.client.getParams().setParameter(HttpMethodParams.USER_AGENT, "test");
HostConfiguration hostconfig = new HostConfiguration();
hostconfig.setHost(
this.server.getLocalAddress(),
this.server.getLocalPort(),
Protocol.getProtocol("http"));
GetMethod httpget = new GetMethod("/miss/");
try {
this.client.executeMethod(hostconfig, httpget);
} finally {
httpget.releaseConnection();
}
assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
assertEquals("test", httpget.getRequestHeader("User-Agent").getValue());
assertEquals("test", httpget.getParams().
getParameter(HttpMethodParams.USER_AGENT));
assertEquals("test", hostconfig.getParams().
getParameter(HttpMethodParams.USER_AGENT));
assertEquals("test", client.getParams().
getParameter(HttpMethodParams.USER_AGENT));
}
示例6: getProtocol
import org.apache.commons.httpclient.HostConfiguration; //导入依赖的package包/类
/**
* Get a Protocol for the given parameters. The default implementation
* selects a protocol based only on the scheme. Subclasses can do fancier
* things, such as select SSL parameters based on the host or port. This
* method must not return null.
*/
protected Protocol getProtocol(HostConfiguration old, String scheme, String host, int port)
{
final Protocol oldProtocol = old.getProtocol();
if (oldProtocol != null) {
final String oldScheme = oldProtocol.getScheme();
if (oldScheme == scheme || (oldScheme != null && oldScheme.equalsIgnoreCase(scheme))) {
// The old protocol has the desired scheme.
return oldProtocol; // Retain it.
}
}
Protocol newProtocol = (scheme != null && scheme.toLowerCase().endsWith("s")) ? httpsProtocol
: httpProtocol;
if (newProtocol == null) {
newProtocol = Protocol.getProtocol(scheme);
}
return newProtocol;
}
示例7: getHostConfiguration
import org.apache.commons.httpclient.HostConfiguration; //导入依赖的package包/类
@Override
protected HostConfiguration getHostConfiguration(HttpClient client,
MessageContext context, URL url) {
Proxy proxy = null;
String httpUser = null;
String httpPassword = null;
String serverUrl = url.getProtocol() + "://" + url.getHost();
TrackerWebServicesClient webServicesClient = TrackerClientManager
.getInstance().getClient(serverUrl);
proxy = webServicesClient.getProxy();
httpUser = webServicesClient.getHttpUser();
httpPassword = webServicesClient.getHttpPassword();
setupHttpClient(client, proxy, url.toString(), httpUser, httpPassword);
return client.getHostConfiguration();
}
示例8: initHttpClient
import org.apache.commons.httpclient.HostConfiguration; //导入依赖的package包/类
protected void initHttpClient() {
if (MockServer.isTestMode()) {
return;
}
HostConfiguration hostConfiguration = new HostConfiguration();
hostConfiguration.setHost(diamondConfigure.getDomainNameList().get(this.domainNamePos.get()),
diamondConfigure.getPort());
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
connectionManager.closeIdleConnections(diamondConfigure.getPollingIntervalTime() * 4000);
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setStaleCheckingEnabled(diamondConfigure.isConnectionStaleCheckingEnabled());
params.setMaxConnectionsPerHost(hostConfiguration, diamondConfigure.getMaxHostConnections());
params.setMaxTotalConnections(diamondConfigure.getMaxTotalConnections());
params.setConnectionTimeout(diamondConfigure.getConnectionTimeout());
// 设置读超时为1分钟,
// [email protected]
params.setSoTimeout(60 * 1000);
connectionManager.setParams(params);
httpClient = new HttpClient(connectionManager);
httpClient.setHostConfiguration(hostConfiguration);
}
示例9: doSSL
import org.apache.commons.httpclient.HostConfiguration; //导入依赖的package包/类
private void doSSL( HttpClient client, HostConfiguration hostConf, String host, int port){
if (hostConf.getProtocol().isSecure()) {
// System.setProperty("javax.net.ssl.trustStore", sslKeystore);
// Protocol sslPprotocol = new Protocol("https", new
// org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory(),
// 443);
// client.getHostConfiguration().setHost(host, 443, sslPprotocol);
try {
ProtocolSocketFactory factory = new InsecureSSLProtocolSocketFactory();
Protocol https = new Protocol("https", factory, port);
Protocol.registerProtocol("https", https);
client.getHostConfiguration().setHost(host, port, https);
} catch (GeneralSecurityException e) {
throw new CoreException(CoreException.SSL, e);
}
}
}
示例10: init
import org.apache.commons.httpclient.HostConfiguration; //导入依赖的package包/类
private synchronized void init() {
client = new HttpClient(new MultiThreadedHttpConnectionManager());
HttpClientParams params = client.getParams();
if (encode != null && !encode.trim().equals("")) {
params.setParameter("http.protocol.content-charset", encode);
params.setContentCharset(encode);
}
if (timeout > 0) {
params.setSoTimeout(timeout);
}
if (null != proxy) {
HostConfiguration hc = new HostConfiguration();
hc.setProxy(proxy.getHost(), proxy.getPort());
client.setHostConfiguration(hc);
client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxy.getUser(), proxy.getPassword()));
}
initialized = true;
}
示例11: executeMethod
import org.apache.commons.httpclient.HostConfiguration; //导入依赖的package包/类
public int executeMethod(HostConfiguration hostconfig, HttpMethod method, HttpState state, boolean addCasTicket)
throws IOException, HttpException {
if (LOG.isDebugEnabled()) {
LOG.debug("executeMethod(HostConfiguration, HttpMethod, HttpState) - entering");
}
try {
if (this.isAddCasTicketParams()) {
HttpClientCAS.addCASTicket(method);
}
} catch (MotuCasException e) {
throw new HttpException(e.notifyException(), e);
}
int returnint = super.executeMethod(hostconfig, method, state);
if (LOG.isDebugEnabled()) {
LOG.debug("executeMethod(HostConfiguration, HttpMethod, HttpState) - exiting");
}
return returnint;
}
示例12: closeThreadLocalConnections
import org.apache.commons.httpclient.HostConfiguration; //导入依赖的package包/类
/**
*
*/
private void closeThreadLocalConnections() {
// Does not need to be synchronised, as all access is from same thread
Map<HostConfiguration, HttpClient> map = httpClients.get();
if ( map != null ) {
for (HttpClient cl : map.values())
{
// Can cause NPE in HttpClient 3.1
//((SimpleHttpConnectionManager)cl.getHttpConnectionManager()).shutdown();// Closes the connection
// Revert to original method:
cl.getHttpConnectionManager().closeIdleConnections(-1000);// Closes the connection
}
map.clear();
}
}
示例13: HTTPNotificationStrategy
import org.apache.commons.httpclient.HostConfiguration; //导入依赖的package包/类
public HTTPNotificationStrategy(PushNotificationConfig config) {
this.config = config;
if (this.config == null) {
throw new InvalidConfigurationException("Properties Cannot be found");
}
endpoint = config.getProperties().get(URL_PROPERTY);
if (endpoint == null || endpoint.isEmpty()) {
throw new InvalidConfigurationException("Property - 'url' cannot be found");
}
try {
this.uri = endpoint;
URL url = new URL(endpoint);
hostConfiguration = new HostConfiguration();
hostConfiguration.setHost(url.getHost(), url.getPort(), url.getProtocol());
this.authorizationHeaderValue = config.getProperties().get(AUTHORIZATION_HEADER_PROPERTY);
executorService = Executors.newFixedThreadPool(1);
httpClient = new HttpClient();
} catch (MalformedURLException e) {
throw new InvalidConfigurationException("Property - 'url' is malformed.", e);
}
}
示例14: applyProxySettings
import org.apache.commons.httpclient.HostConfiguration; //导入依赖的package包/类
private void applyProxySettings() {
String proxyHost = System.getProperty("http.proxyHost");
String proxyPortSt = System.getProperty("http.proxyPort");
int proxyPort = 0;
try {
if (proxyPortSt != null && proxyPortSt.length() > 0) {
proxyPort = Integer.parseInt(proxyPortSt);
}
} catch (Exception e) {
// nothing to do here
}
if (proxyHost != null && proxyHost.length() > 0) {
HostConfiguration hostCfg = getHostConfiguration();
hostCfg.setProxy(proxyHost, proxyPort);
Log_OC.d(TAG, "Proxy settings: " + proxyHost + ":" + proxyPort);
}
}
示例15: sendReport
import org.apache.commons.httpclient.HostConfiguration; //导入依赖的package包/类
public String sendReport(Map<String, String> values) throws IOException {
HttpClient httpClient = new HttpClient();
HostConfiguration hostConfiguration = new HostConfiguration();
if (!StringUtils.isBlank(proxy)) {
hostConfiguration.setProxy(proxy, proxyPort);
if (StringUtils.isNotBlank(user) && StringUtils.isNotBlank(password)) {
httpClient.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password));
}
}
httpClient.setHostConfiguration(hostConfiguration);
PostMethod method = new PostMethod(getSendUrl());
addHttpPostParams(values, method);
int executeMethod = httpClient.executeMethod(method);
LOGGER.info("HTTP result of report send POST: " + executeMethod);
return IOUtils.toString(method.getResponseBodyAsStream());
}