mirror of https://github.com/apache/jclouds.git
added debug to http executor
This commit is contained in:
parent
f459100c75
commit
84004b8986
|
@ -153,8 +153,8 @@ public abstract class BaseHttpCommandExecutorService<Q> implements HttpCommandEx
|
|||
"After filtering, the request has niether chunked encoding nor content length: " + request);
|
||||
logger.debug("Sending request %s: %s", request.hashCode(), request.getRequestLine());
|
||||
wirePayloadIfEnabled(wire, request);
|
||||
nativeRequest = convert(request);
|
||||
utils.logRequest(headerLog, request, ">>");
|
||||
nativeRequest = convert(request);
|
||||
response = invoke(nativeRequest);
|
||||
|
||||
logger.debug("Receiving response %s: %s", request.hashCode(), response.getStatusLine());
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.jclouds.http.internal;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Throwables.propagate;
|
||||
import static com.google.common.collect.Iterables.getLast;
|
||||
|
@ -66,8 +67,9 @@ import org.jclouds.rest.internal.RestAnnotationProcessor;
|
|||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.LinkedHashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableMultimap.Builder;
|
||||
import com.google.common.io.CountingOutputStream;
|
||||
|
||||
/**
|
||||
* Basic implementation of a {@link HttpCommandExecutorService}.
|
||||
|
@ -86,11 +88,11 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
|
|||
|
||||
@Inject
|
||||
public JavaUrlHttpCommandExecutorService(HttpUtils utils,
|
||||
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ExecutorService ioWorkerExecutor,
|
||||
DelegatingRetryHandler retryHandler, IOExceptionRetryHandler ioRetryHandler,
|
||||
DelegatingErrorHandler errorHandler, HttpWire wire, @Named("untrusted") HostnameVerifier verifier,
|
||||
@Named("untrusted") Supplier<SSLContext> untrustedSSLContextProvider) throws SecurityException,
|
||||
NoSuchFieldException {
|
||||
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ExecutorService ioWorkerExecutor,
|
||||
DelegatingRetryHandler retryHandler, IOExceptionRetryHandler ioRetryHandler,
|
||||
DelegatingErrorHandler errorHandler, HttpWire wire, @Named("untrusted") HostnameVerifier verifier,
|
||||
@Named("untrusted") Supplier<SSLContext> untrustedSSLContextProvider) throws SecurityException,
|
||||
NoSuchFieldException {
|
||||
super(utils, ioWorkerExecutor, retryHandler, ioRetryHandler, errorHandler, wire);
|
||||
if (utils.getMaxConnections() > 0)
|
||||
System.setProperty("http.maxConnections", String.valueOf(checkNotNull(utils, "utils").getMaxConnections()));
|
||||
|
@ -102,6 +104,7 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
|
|||
|
||||
@Override
|
||||
protected HttpResponse invoke(HttpURLConnection connection) throws IOException, InterruptedException {
|
||||
HttpResponse.Builder builder = HttpResponse.builder();
|
||||
InputStream in = null;
|
||||
try {
|
||||
in = consumeOnClose(connection.getInputStream());
|
||||
|
@ -113,19 +116,28 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
|
|||
assert false : "should have propagated exception";
|
||||
}
|
||||
|
||||
if (connection.getResponseCode() == 204) {
|
||||
int responseCode = connection.getResponseCode();
|
||||
if (responseCode == 204) {
|
||||
closeQuietly(in);
|
||||
in = null;
|
||||
}
|
||||
Multimap<String, String> headers = LinkedHashMultimap.create();
|
||||
builder.statusCode(responseCode);
|
||||
builder.message(connection.getResponseMessage());
|
||||
|
||||
Builder<String, String> headerBuilder = ImmutableMultimap.<String, String> builder();
|
||||
for (String header : connection.getHeaderFields().keySet()) {
|
||||
headers.putAll(header, connection.getHeaderFields().get(header));
|
||||
// HTTP message comes back as a header without a key
|
||||
if (header != null)
|
||||
headerBuilder.putAll(header, connection.getHeaderFields().get(header));
|
||||
}
|
||||
ImmutableMultimap<String, String> headers = headerBuilder.build();
|
||||
Payload payload = in != null ? Payloads.newInputStreamPayload(in) : null;
|
||||
if (payload != null)
|
||||
if (payload != null) {
|
||||
payload.getContentMetadata().setPropertiesFromHttpHeaders(headers);
|
||||
return new HttpResponse(connection.getResponseCode(), connection.getResponseMessage(), payload,
|
||||
RestAnnotationProcessor.filterOutContentHeaders(headers));
|
||||
builder.payload(payload);
|
||||
}
|
||||
builder.headers(RestAnnotationProcessor.filterOutContentHeaders(headers));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private InputStream bufferAndCloseStream(InputStream inputStream) throws IOException {
|
||||
|
@ -220,14 +232,17 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
|
|||
} else {
|
||||
Long length = checkNotNull(md.getContentLength(), "payload.getContentLength");
|
||||
connection.setRequestProperty(HttpHeaders.CONTENT_LENGTH, length.toString());
|
||||
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6755625
|
||||
checkArgument(length < Integer.MAX_VALUE,
|
||||
"JDK 1.6 does not support >2GB chunks. Use chunked encoding, if possible.");
|
||||
connection.setFixedLengthStreamingMode(length.intValue());
|
||||
}
|
||||
// writeTo will close the output stream
|
||||
CountingOutputStream out = new CountingOutputStream(connection.getOutputStream());
|
||||
try {
|
||||
request.getPayload().writeTo(connection.getOutputStream());
|
||||
request.getPayload().writeTo(out);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
throw new RuntimeException(String.format("error after writing %d/%s bytes to %s", out.getCount(), md
|
||||
.getContentLength(), request.getRequestLine()), e);
|
||||
}
|
||||
} else {
|
||||
connection.setRequestProperty(HttpHeaders.CONTENT_LENGTH, "0");
|
||||
|
|
Loading…
Reference in New Issue