List of usage examples for org.apache.commons.httpclient HttpMethodBase getParams
@Override
public HttpMethodParams getParams()
From source file:net.bioclipse.opentox.api.HttpMethodHelper.java
public static HttpMethodBase addMethodHeaders(HttpMethodBase method, Map<String, String> extraHeaders) { // set the time out method.getParams().setParameter("http.socket.timeout", new Integer(Activator.TIME_OUT)); // log in on OpenTox if needed... if (Activator.getToken() != null) { method.setRequestHeader("subjectid", Activator.getToken()); }/*from w w w .j av a 2s . com*/ // add other headers if (extraHeaders != null) { for (String header : extraHeaders.keySet()) { method.setRequestHeader(header, extraHeaders.get(header)); } } return method; }
From source file:lucee.commons.net.http.httpclient3.HttpMethodCloner.java
private static void copyHttpMethodBase(HttpMethodBase m, HttpMethodBase copy) { if (m.getHostConfiguration() != null) { copy.setHostConfiguration(new HostConfiguration(m.getHostConfiguration())); }//from w w w .j a v a2 s. com try { copy.setParams((HttpMethodParams) m.getParams().clone()); } catch (CloneNotSupportedException e) { } }
From source file:fr.openwide.talendalfresco.rest.client.ClientCommandBase.java
/** * Can be overriden to tune the default behaviour, * check or build parameters.../*from w w w .j av a2s . c o m*/ * The client should set the params (query string) itself. */ public HttpMethodBase createMethod() throws RestClientException { // instantiating a new method and configuring it HttpMethodBase method; switch (this.getMethodType()) { case POST: //case PUT: method = new PostMethod(); break; case GET: default: method = new GetMethod(); method.setFollowRedirects(true); } method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); //method.setQueryString(params.toArray(new NameValuePair[0])); // done in client //method.getParams().setContentCharset(this.restEncoding); // done in client // set request entity (allow to fill method body for posts) : if (requestEntity != null && method instanceof EntityEnclosingMethod) { ((EntityEnclosingMethod) method).setRequestEntity(requestEntity); } return method; }
From source file:com.owncloud.android.oc_framework.network.webdav.WebdavClient.java
/** * Requests the received method with the received timeout (milliseconds). * // w w w . j av a 2s . c om * Executes the method through the inherited HttpClient.executedMethod(method). * * Sets the socket and connection timeouts only for the method received. * * The timeouts are both in milliseconds; 0 means 'infinite'; < 0 means 'do not change the default' * * @param method HTTP method request. * @param readTimeout Timeout to set for data reception * @param conntionTimout Timeout to set for connection establishment */ public int executeMethod(HttpMethodBase method, int readTimeout, int connectionTimeout) throws HttpException, IOException { int oldSoTimeout = getParams().getSoTimeout(); int oldConnectionTimeout = getHttpConnectionManager().getParams().getConnectionTimeout(); try { if (readTimeout >= 0) { method.getParams().setSoTimeout(readTimeout); // this should be enough... getParams().setSoTimeout(readTimeout); // ... but this looks like necessary for HTTPS } if (connectionTimeout >= 0) { getHttpConnectionManager().getParams().setConnectionTimeout(connectionTimeout); } return executeMethod(method); } finally { getParams().setSoTimeout(oldSoTimeout); getHttpConnectionManager().getParams().setConnectionTimeout(oldConnectionTimeout); } }
From source file:fr.openwide.talendalfresco.rest.client.AlfrescoRestClient.java
public void execute(ClientCommand clientCommand) throws RestClientException { int statusCode = -1; HttpMethodBase method = null; try {/*from w w w . j a v a 2s . c o m*/ // building method (and body entity if any) method = clientCommand.createMethod(); // setting server URL method.setURI(new URI(restCommandUrlPrefix + clientCommand.getName(), false)); method.getParams().setContentCharset(this.restEncoding); // building params (adding ticket) List<NameValuePair> params = clientCommand.getParams(); params.add(new NameValuePair(TICKET_PARAM, ticket)); method.setQueryString(params.toArray(EMPTY_NAME_VALUE_PAIR)); // Execute the method. statusCode = client.executeMethod(method); // checking HTTP status if (statusCode != HttpStatus.SC_OK) { throw new RestClientException("Bad HTTP Status : " + statusCode); } // parsing response XMLEventReader xmlReader = null; try { xmlReader = XmlHelper.createXMLEventReader(method.getResponseBodyAsStream(), this.restEncoding); clientCommand.handleResponse(xmlReader); if (!RestConstants.CODE_OK.equals(clientCommand.getResultCode())) { //String msg = "Business error in command " + clientCommand.toString(); //logger.error(msg, e); throw new RestClientException(clientCommand.getResultMessage(), new RestClientException(clientCommand.getResultError())); } } catch (XMLStreamException e) { String msg = "XML parsing error on response body : "; try { msg += new String(method.getResponseBody()); } catch (IOException ioex) { msg += "[unreadable]"; } ; //logger.error(msg, e); throw new RestClientException(msg, e); } catch (IOException e) { String msg = "IO Error when parsing XML response body : "; //logger.error(msg, e); throw new RestClientException(msg, e); } finally { if (xmlReader != null) { try { xmlReader.close(); } catch (Throwable t) { } } } } catch (RestClientException rcex) { throw rcex; } catch (URIException e) { throw new RestClientException("URI error while executing command " + clientCommand, e); } catch (HttpException e) { throw new RestClientException("HTTP error while executing command " + clientCommand, e); } catch (IOException e) { throw new RestClientException("IO error while executing command " + clientCommand, e); } finally { if (method != null) { method.releaseConnection(); } } }
From source file:com.cubeia.backoffice.operator.client.OperatorServiceClientHTTP.java
private HttpMethodBase prepareMethod(HttpMethodBase method) { method.setRequestHeader("content-type", "application/json;charset=UTF-8;"); // Provide custom retry handler method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(NUMBER_OF_RETRIES, false)); return method; }
From source file:com.datos.vfs.provider.webdav.WebdavFileObject.java
protected void configureMethod(final HttpMethodBase httpMethod) { httpMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, WebdavMethodRetryHandler.getInstance()); }
From source file:com.cerema.cloud2.lib.common.OwnCloudClient.java
/** * Requests the received method with the received timeout (milliseconds). * /*from w ww . ja v a2 s . c om*/ * Executes the method through the inherited HttpClient.executedMethod(method). * * Sets the socket and connection timeouts only for the method received. * * The timeouts are both in milliseconds; 0 means 'infinite'; * < 0 means 'do not change the default' * * @param method HTTP method request. * @param readTimeout Timeout to set for data reception * @param connectionTimeout Timeout to set for connection establishment */ public int executeMethod(HttpMethodBase method, int readTimeout, int connectionTimeout) throws IOException { int oldSoTimeout = getParams().getSoTimeout(); int oldConnectionTimeout = getHttpConnectionManager().getParams().getConnectionTimeout(); try { if (readTimeout >= 0) { method.getParams().setSoTimeout(readTimeout); // this should be enough... getParams().setSoTimeout(readTimeout); // ... but HTTPS needs this } if (connectionTimeout >= 0) { getHttpConnectionManager().getParams().setConnectionTimeout(connectionTimeout); } return executeMethod(method); } finally { getParams().setSoTimeout(oldSoTimeout); getHttpConnectionManager().getParams().setConnectionTimeout(oldConnectionTimeout); } }
From source file:com.owncloud.android.lib.common.OwnCloudClient.java
/** * Requests the received method with the received timeout (milliseconds). * * Executes the method through the inherited HttpClient.executedMethod(method). * * Sets the socket and connection timeouts only for the method received. * * The timeouts are both in milliseconds; 0 means 'infinite'; * < 0 means 'do not change the default' * * @param method HTTP method request. * @param readTimeout Timeout to set for data reception * @param conntionTimout Timeout to set for connection establishment *///w w w .j ava2s . c om public int executeMethod(HttpMethodBase method, int readTimeout, int connectionTimeout) throws HttpException, IOException { int oldSoTimeout = getParams().getSoTimeout(); int oldConnectionTimeout = getHttpConnectionManager().getParams().getConnectionTimeout(); try { if (readTimeout >= 0) { method.getParams().setSoTimeout(readTimeout); // this should be enough... getParams().setSoTimeout(readTimeout); // ... but HTTPS needs this } if (connectionTimeout >= 0) { getHttpConnectionManager().getParams().setConnectionTimeout(connectionTimeout); } return executeMethod(method); } finally { getParams().setSoTimeout(oldSoTimeout); getHttpConnectionManager().getParams().setConnectionTimeout(oldConnectionTimeout); } }
From source file:com.sittinglittleduck.DirBuster.Worker.java
private int makeRequest(HttpMethodBase httpMethod) throws HttpException, IOException, InterruptedException { if (Config.debug) { System.out.println("DEBUG Worker[" + threadId + "]: " + httpMethod.getName() + " : " + url.toString()); }/* w w w. j a va 2 s . c o m*/ // set the custom HTTP headers Vector HTTPheaders = manager.getHTTPHeaders(); for (int a = 0; a < HTTPheaders.size(); a++) { HTTPHeader httpHeader = (HTTPHeader) HTTPheaders.elementAt(a); /* * Host header has to be set in a different way! */ if (httpHeader.getHeader().startsWith("Host")) { httpMethod.getParams().setVirtualHost(httpHeader.getValue()); } else { httpMethod.setRequestHeader(httpHeader.getHeader(), httpHeader.getValue()); } } httpMethod.setFollowRedirects(Config.followRedirects); /* * this code is used to limit the number of request/sec */ if (manager.isLimitRequests()) { while (manager.getTotalDone() / ((System.currentTimeMillis() - manager.getTimestarted()) / 1000.0) > manager .getLimitRequestsTo()) { Thread.sleep(100); } } /* * Send the request */ int code = httpclient.executeMethod(httpMethod); if (Config.debug) { System.out.println("DEBUG Worker[" + threadId + "]: " + code + " " + url.toString()); } return code; }