use of org.apache.commons.httpclient.HttpClient in project pinpoint by naver.
the class HttpClientIT method test.
@Test
public void test() throws Exception {
HttpClient client = new HttpClient();
client.getParams().setConnectionManagerTimeout(CONNECTION_TIMEOUT);
client.getParams().setSoTimeout(SO_TIMEOUT);
GetMethod method = new GetMethod("http://google.com");
// Provide custom retry handler is necessary
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
method.setQueryString(new NameValuePair[] { new NameValuePair("key2", "value2") });
try {
// Execute the method.
client.executeMethod(method);
} catch (Exception ignored) {
} finally {
method.releaseConnection();
}
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache();
}
use of org.apache.commons.httpclient.HttpClient in project openhab1-addons by openhab.
the class KM200Comm method sendDataToService.
/**
* This function does the SEND http communication to the device
*
*/
public Integer sendDataToService(String service, byte[] data) {
// Create an instance of HttpClient.
Integer rCode = null;
if (client == null) {
client = new HttpClient();
}
synchronized (client) {
// Create a method instance.
PostMethod method = new PostMethod("http://" + device.getIP4Address() + service);
// Provide custom retry handler is necessary
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
// Set the right header
method.setRequestHeader("Accept", "application/json");
method.addRequestHeader("User-Agent", "TeleHeater/2.2.3");
method.setRequestEntity(new ByteArrayRequestEntity(data));
try {
rCode = client.executeMethod(method);
} catch (Exception e) {
logger.error("Failed to send data {}", e);
} finally {
// Release the connection.
method.releaseConnection();
}
return rCode;
}
}
use of org.apache.commons.httpclient.HttpClient in project tdi-studio-se by Talend.
the class WSDLLocatorImpl method createHttpClient.
private HttpClient createHttpClient() {
HttpClient httpClient = new HttpClient();
if (configuration.getProxyServer() != null) {
HostConfiguration hostConfiguration = new HostConfiguration();
hostConfiguration.setProxy(configuration.getProxyServer(), configuration.getProxyPort());
httpClient.setHostConfiguration(hostConfiguration);
}
if (configuration.getUsername() != null) {
Credentials credentials = new UsernamePasswordCredentials(configuration.getUsername(), configuration.getPassword());
httpClient.getState().setCredentials(AuthScope.ANY, credentials);
}
if (configuration.getProxyUsername() != null) {
Credentials credentials = new UsernamePasswordCredentials(configuration.getProxyUsername(), configuration.getProxyPassword());
httpClient.getState().setProxyCredentials(AuthScope.ANY, credentials);
httpClient.getHostConfiguration().setProxy(configuration.getProxyServer(), configuration.getProxyPort());
}
return httpClient;
}
use of org.apache.commons.httpclient.HttpClient in project tdi-studio-se by Talend.
the class SpagoBITalendEngineClient_0_5_0 method deployJob.
/*
* (non-Javadoc)
*
* @see
* it.eng.spagobi.engines.talend.client.ISpagoBITalendEngineClient#deployJob(it.eng.spagobi.engines.talend.client
* .JobDeploymentDescriptor, java.io.File)
*/
public boolean deployJob(JobDeploymentDescriptor jobDeploymentDescriptor, File executableJobFiles) throws EngineUnavailableException, AuthenticationFailedException, ServiceInvocationFailedException {
HttpClient client;
PostMethod method;
File deploymentDescriptorFile;
boolean result = false;
client = new HttpClient();
method = new PostMethod(getServiceUrl(JOB_UPLOAD_SERVICE));
deploymentDescriptorFile = null;
try {
//$NON-NLS-1$ //$NON-NLS-2$
deploymentDescriptorFile = File.createTempFile("deploymentDescriptor", ".xml");
FileWriter writer = new FileWriter(deploymentDescriptorFile);
writer.write(jobDeploymentDescriptor.toXml());
writer.flush();
writer.close();
Part[] parts = { new FilePart(executableJobFiles.getName(), executableJobFiles), //$NON-NLS-1$
new FilePart("deploymentDescriptor", deploymentDescriptorFile) };
method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams()));
client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
int status = client.executeMethod(method);
if (status == HttpStatus.SC_OK) {
if (//$NON-NLS-1$
method.getResponseBodyAsString().equalsIgnoreCase("OK"))
result = true;
} else {
throw new ServiceInvocationFailedException(Messages.getString("SpagoBITalendEngineClient_0_5_0.serviceExcFailed") + JOB_UPLOAD_SERVICE, //$NON-NLS-1$
method.getStatusLine().toString(), method.getResponseBodyAsString());
}
} catch (HttpException e) {
//$NON-NLS-1$
throw new EngineUnavailableException(Messages.getString("SpagoBITalendEngineClient_0_5_0.protocolViolation") + e.getMessage());
} catch (IOException e) {
//$NON-NLS-1$
throw new EngineUnavailableException(Messages.getString("SpagoBITalendEngineClient_0_5_0.transportError") + e.getMessage());
} finally {
method.releaseConnection();
if (deploymentDescriptorFile != null)
deploymentDescriptorFile.delete();
}
return result;
}
use of org.apache.commons.httpclient.HttpClient in project tdi-studio-se by Talend.
the class MDMTransactionClient method getSessionID.
public static String getSessionID(String url, String username, String password) throws IOException {
HttpClient client = new HttpClient();
client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
client.getParams().setAuthenticationPreemptive(true);
GetMethod get = new GetMethod(url);
get.setDoAuthentication(true);
String sessionID;
try {
client.executeMethod(get);
sessionID = parseSessionID(get);
} catch (HttpException e) {
throw e;
} catch (IOException e) {
throw e;
} finally {
get.releaseConnection();
}
return sessionID;
}
Aggregations