List of usage examples for org.apache.http.client.fluent Request connectTimeout
public Request connectTimeout(final int timeout)
From source file:com.qwazr.utils.json.client.JsonClientAbstract.java
/** * {@inheritDoc}/* w w w . j a va 2s .co m*/ */ @Override final public <T> T execute(Request request, Object bodyObject, Integer msTimeOut, TypeReference<T> typeRef, int... expectedCodes) throws IOException { if (logger.isDebugEnabled()) logger.debug(request.toString()); if (msTimeOut == null) msTimeOut = this.timeout; request = setBodyString(request, bodyObject); return executor .execute(request.connectTimeout(msTimeOut).socketTimeout(msTimeOut).addHeader("accept", ContentType.APPLICATION_JSON.toString())) .handleResponse(new JsonHttpResponseHandler.JsonValueTypeRefResponse<T>( ContentType.APPLICATION_JSON, typeRef, expectedCodes)); }
From source file:com.helger.peppol.bdxrclient.BDXRClientReadOnly.java
/** * The main execution routine. Overwrite this method to add additional * properties to the call.//from www. j a v a 2s. co m * * @param aRequest * The request to be executed. Never <code>null</code>. * @return The HTTP execution response. Never <code>null</code>. * @throws IOException * On HTTP error */ @Nonnull @OverrideOnDemand protected Response executeRequest(@Nonnull final Request aRequest) throws IOException { if (m_aProxy != null) aRequest.viaProxy(m_aProxy); return aRequest.connectTimeout(5000).socketTimeout(10000).execute(); }
From source file:com.jaspersoft.ireport.jasperserver.ws.http.JSSCommonsHTTPSender.java
/** * Extracts info from message context.//from w w w .j a v a 2 s. c o m * * @param method * Post method * @param httpClient * The client used for posting * @param msgContext * the message context * @param tmpURL * the url to post to. * * @throws Exception */ private void addContextInfo(Request req, MessageContext msgContext, URL tmpURL) throws Exception { String v = msgContext.getStrProp(MessageContext.HTTP_TRANSPORT_VERSION); if (v != null && v.equals(HTTPConstants.HEADER_PROTOCOL_V10)) req.version(HttpVersion.HTTP_1_0); // optionally set a timeout for the request if (msgContext.getTimeout() != 0) { req.connectTimeout(msgContext.getTimeout()); req.socketTimeout(msgContext.getTimeout()); } // Get SOAPAction, default to "" String action = msgContext.useSOAPAction() ? msgContext.getSOAPActionURI() : ""; if (action == null) action = ""; Message msg = msgContext.getRequestMessage(); if (msg != null) req.addHeader(HTTPConstants.HEADER_CONTENT_TYPE, msg.getContentType(msgContext.getSOAPConstants())); req.addHeader(HTTPConstants.HEADER_SOAP_ACTION, "\"" + action + "\""); req.addHeader(HTTPConstants.HEADER_USER_AGENT, Messages.getMessage("axisUserAgent")); // add compression headers if needed if (msgContext.isPropertyTrue(HTTPConstants.MC_ACCEPT_GZIP)) req.addHeader(HTTPConstants.HEADER_ACCEPT_ENCODING, HTTPConstants.COMPRESSION_GZIP); if (msgContext.isPropertyTrue(HTTPConstants.MC_GZIP_REQUEST)) req.addHeader(HTTPConstants.HEADER_CONTENT_ENCODING, HTTPConstants.COMPRESSION_GZIP); // Transfer MIME headers of SOAPMessage to HTTP headers. MimeHeaders mimeHeaders = msg.getMimeHeaders(); if (mimeHeaders != null) { for (Iterator<?> i = mimeHeaders.getAllHeaders(); i.hasNext();) { MimeHeader mimeHeader = (MimeHeader) i.next(); // HEADER_CONTENT_TYPE and HEADER_SOAP_ACTION are already set. // Let's not duplicate them. String headerName = mimeHeader.getName(); if (headerName.equals(HTTPConstants.HEADER_CONTENT_TYPE) || headerName.equals(HTTPConstants.HEADER_SOAP_ACTION)) continue; req.addHeader(mimeHeader.getName(), mimeHeader.getValue()); } } // process user defined headers for information. Hashtable<?, ?> userHeaderTable = (Hashtable<?, ?>) msgContext.getProperty(HTTPConstants.REQUEST_HEADERS); if (userHeaderTable != null) for (Map.Entry<?, ?> me : userHeaderTable.entrySet()) { Object keyObj = me.getKey(); if (null == keyObj) continue; String key = keyObj.toString().trim(); String value = me.getValue().toString().trim(); if (key.equalsIgnoreCase(HTTPConstants.HEADER_EXPECT) && value.equalsIgnoreCase(HTTPConstants.HEADER_EXPECT_100_Continue)) req.useExpectContinue(); else if (key.equalsIgnoreCase(HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED)) { req.removeHeader(new BasicHeader("Transfer-Encoding", "chunked")); if (Boolean.parseBoolean(value)) ;// req.setHeader("Transfer-Encoding", "chunked"); } else req.addHeader(key, value); } }
From source file:com.qwazr.utils.json.client.JsonClientAbstract.java
/** * {@inheritDoc}// w ww . j a v a 2 s . c o m */ @Override final public <T> T execute(Request request, Object bodyObject, Integer msTimeOut, Class<T> jsonResultClass, int... expectedCodes) throws IOException { if (logger.isDebugEnabled()) logger.debug(request.toString()); if (msTimeOut == null) msTimeOut = this.timeout; request = setBodyString(request, bodyObject); JsonHttpResponseHandler.JsonValueResponse<T> responseHandler = new JsonHttpResponseHandler.JsonValueResponse<T>( ContentType.APPLICATION_JSON, jsonResultClass, expectedCodes); return executor.execute(request.connectTimeout(msTimeOut).socketTimeout(msTimeOut).addHeader("Accept", ContentType.APPLICATION_JSON.toString())).handleResponse(responseHandler); }