use of com.twinsoft.convertigo.engine.oauth.HttpOAuthConsumer in project convertigo by convertigo.
the class HttpConnector method doExecuteMethod.
protected int doExecuteMethod(final HttpMethod method, Context context) throws ConnectionException, URIException, MalformedURLException {
int statuscode = -1;
// Tells the method to automatically handle authentication.
method.setDoAuthentication(true);
// Tells the method to automatically handle redirection.
method.setFollowRedirects(false);
HttpPool httpPool = ((AbstractHttpTransaction) context.transaction).getHttpPool();
HttpClient httpClient = context.getHttpClient3(httpPool);
try {
// Display the cookies
if (handleCookie) {
Cookie[] cookies = httpState.getCookies();
if (Engine.logBeans.isTraceEnabled())
Engine.logBeans.trace("(HttpConnector) HttpClient request cookies:" + Arrays.asList(cookies).toString());
}
forwardHeader(new HeaderForwarder() {
public void add(String name, String value, String forwardPolicy) {
if (HttpConnector.HTTP_HEADER_FORWARD_POLICY_IGNORE.equals(forwardPolicy)) {
Header exHeader = method.getRequestHeader(name);
if (exHeader != null) {
// Nothing to do
Engine.logEngine.debug("(WebViewer) Forwarding header '" + name + "' has been ignored due to forward policy");
} else {
method.setRequestHeader(name, value);
Engine.logEngine.debug("(WebViewer) Header forwarded and added: " + name + "=" + value);
}
} else if (HttpConnector.HTTP_HEADER_FORWARD_POLICY_REPLACE.equals(forwardPolicy)) {
method.setRequestHeader(name, value);
Engine.logEngine.debug("(WebViewer) Header forwarded and replaced: " + name + "=" + value);
} else if (HttpConnector.HTTP_HEADER_FORWARD_POLICY_MERGE.equals(forwardPolicy)) {
Header exHeader = method.getRequestHeader(name);
if (exHeader != null)
value = exHeader.getValue() + ", " + value;
method.setRequestHeader(name, value);
Engine.logEngine.debug("(WebViewer) Header forwarded and merged: " + name + "=" + value);
}
}
});
// handle oAuthSignatures if any
if (oAuthKey != null && oAuthSecret != null && oAuthToken != null && oAuthTokenSecret != null) {
oAuthConsumer = new HttpOAuthConsumer(oAuthKey, oAuthSecret, hostConfiguration);
oAuthConsumer.setTokenWithSecret(oAuthToken, oAuthTokenSecret);
oAuthConsumer.sign(method);
oAuthConsumer = null;
}
HttpUtils.logCurrentHttpConnection(httpClient, hostConfiguration, httpPool);
hostConfiguration.getParams().setIntParameter(HttpConnectionParams.SO_TIMEOUT, (int) context.requestedObject.getResponseTimeout() * 1000);
hostConfiguration.getParams().setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, (int) context.requestedObject.getResponseTimeout() * 1000);
Engine.logBeans.debug("(HttpConnector) HttpClient: executing method...");
statuscode = httpClient.executeMethod(hostConfiguration, method, httpState);
Engine.logBeans.debug("(HttpConnector) HttpClient: end of method successfull");
// Display the cookies
if (handleCookie) {
Cookie[] cookies = httpState.getCookies();
if (Engine.logBeans.isTraceEnabled())
Engine.logBeans.trace("(HttpConnector) HttpClient response cookies:" + Arrays.asList(cookies).toString());
}
} catch (SocketTimeoutException e) {
throw new ConnectionException("Timeout reached (" + context.requestedObject.getResponseTimeout() + " sec)");
} catch (IOException e) {
if (!context.requestedObject.runningThread.bContinue) {
return statuscode;
}
HttpUtils.logCurrentHttpConnection(httpClient, hostConfiguration, httpPool);
Engine.logBeans.warn("(HttpConnector) HttpClient: connection error to " + sUrl + ": " + e.getMessage());
} catch (OAuthException eee) {
throw new ConnectionException("OAuth Connection error to " + sUrl, eee);
}
return statuscode;
}
Aggregations