mirror of https://github.com/apache/jclouds.git
Issue 113: signature logger
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2006 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
903254a6f9
commit
5b95c35ca7
|
@ -34,12 +34,14 @@ import javax.inject.Provider;
|
|||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants;
|
||||
import org.jclouds.atmosonline.saas.reference.AtmosStorageHeaders;
|
||||
import org.jclouds.http.HttpException;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpRequestFilter;
|
||||
import org.jclouds.http.HttpUtils;
|
||||
import org.jclouds.http.internal.SignatureWire;
|
||||
import org.jclouds.util.TimeStamp;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
@ -54,14 +56,17 @@ import com.google.common.annotations.VisibleForTesting;
|
|||
@Singleton
|
||||
public class SignRequest implements HttpRequestFilter {
|
||||
|
||||
private final SignatureWire signatureWire;
|
||||
private final String uid;
|
||||
private final byte[] key;
|
||||
private final Provider<String> timeStampProvider;
|
||||
|
||||
@Inject
|
||||
public SignRequest(@Named(AtmosStorageConstants.PROPERTY_EMCSAAS_UID) String uid,
|
||||
public SignRequest(SignatureWire signatureWire,
|
||||
@Named(AtmosStorageConstants.PROPERTY_EMCSAAS_UID) String uid,
|
||||
@Named(AtmosStorageConstants.PROPERTY_EMCSAAS_KEY) String encodedKey,
|
||||
@TimeStamp Provider<String> timeStampProvider) {
|
||||
this.signatureWire = signatureWire;
|
||||
this.uid = uid;
|
||||
this.key = HttpUtils.fromBase64String(encodedKey);
|
||||
this.timeStampProvider = timeStampProvider;
|
||||
|
@ -80,12 +85,16 @@ public class SignRequest implements HttpRequestFilter {
|
|||
appendHttpHeaders(request, buffer);
|
||||
appendCanonicalizedResource(request, buffer);
|
||||
appendCanonicalizedHeaders(request, buffer);
|
||||
if (signatureWire.enabled())
|
||||
signatureWire.output(buffer.toString());
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
private void calculateAndReplaceAuthHeader(HttpRequest request, String toSign)
|
||||
throws HttpException {
|
||||
String signature = signString(toSign);
|
||||
if (signatureWire.enabled())
|
||||
signatureWire.input(IOUtils.toInputStream(signature));
|
||||
request.getHeaders().replaceValues(AtmosStorageHeaders.SIGNATURE,
|
||||
Collections.singletonList(signature));
|
||||
}
|
||||
|
|
|
@ -1,34 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
Copyright (C) 2009 Cloud Conscious, LLC.
|
||||
<info@cloudconscious.com>
|
||||
|
||||
====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
Licensed to the Apache Software Foundation (ASF) under one or
|
||||
more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information regarding
|
||||
copyright ownership. The ASF licenses this file to you under the
|
||||
Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain
|
||||
a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
http://www.apache.org/licenses/LICENSE-2.0 Unless required by
|
||||
applicable law or agreed to in writing, software distributed
|
||||
under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions
|
||||
and limitations under the License.
|
||||
====================================================================
|
||||
|
||||
-->
|
||||
-->
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
|
||||
<!--
|
||||
For more configuration infromation and examples see the Apache Log4j
|
||||
website: http://logging.apache.org/log4j/
|
||||
For more configuration infromation and examples see the Apache
|
||||
Log4j website: http://logging.apache.org/log4j/
|
||||
-->
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
|
||||
debug="false">
|
||||
|
@ -48,9 +46,9 @@
|
|||
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
||||
|
||||
<!--
|
||||
The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
|
||||
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x)
|
||||
%m%n"/>
|
||||
The full pattern: Date MS Priority [Category]
|
||||
(Thread:NDC) Message\n <param name="ConversionPattern"
|
||||
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
|
||||
-->
|
||||
</layout>
|
||||
</appender>
|
||||
|
@ -70,9 +68,9 @@
|
|||
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
||||
|
||||
<!--
|
||||
The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
|
||||
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x)
|
||||
%m%n"/>
|
||||
The full pattern: Date MS Priority [Category]
|
||||
(Thread:NDC) Message\n <param name="ConversionPattern"
|
||||
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
|
||||
-->
|
||||
</layout>
|
||||
</appender>
|
||||
|
@ -104,6 +102,12 @@
|
|||
<appender-ref ref="ASYNCWIRE" />
|
||||
</category>
|
||||
|
||||
<category name="jclouds.signature.wire">
|
||||
<priority value="DEBUG" />
|
||||
<appender-ref ref="ASYNCWIRE" />
|
||||
</category>
|
||||
|
||||
|
||||
<!-- ======================= -->
|
||||
<!-- Setup the Root category -->
|
||||
<!-- ======================= -->
|
||||
|
|
|
@ -36,11 +36,13 @@ import javax.inject.Provider;
|
|||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.jclouds.aws.s3.reference.S3Constants;
|
||||
import org.jclouds.http.HttpException;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpRequestFilter;
|
||||
import org.jclouds.http.HttpUtils;
|
||||
import org.jclouds.http.internal.SignatureWire;
|
||||
import org.jclouds.util.TimeStamp;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
@ -57,14 +59,16 @@ public class RequestAuthorizeSignature implements HttpRequestFilter {
|
|||
private final String[] firstHeadersToSign = new String[] { "Content-MD5",
|
||||
HttpHeaders.CONTENT_TYPE, HttpHeaders.DATE };
|
||||
|
||||
private final SignatureWire signatureWire;
|
||||
private final String accessKey;
|
||||
private final String secretKey;
|
||||
private final Provider<String> timeStampProvider;
|
||||
|
||||
@Inject
|
||||
public RequestAuthorizeSignature(@Named(S3Constants.PROPERTY_AWS_ACCESSKEYID) String accessKey,
|
||||
public RequestAuthorizeSignature(SignatureWire signatureWire, @Named(S3Constants.PROPERTY_AWS_ACCESSKEYID) String accessKey,
|
||||
@Named(S3Constants.PROPERTY_AWS_SECRETACCESSKEY) String secretKey,
|
||||
@TimeStamp Provider<String> timeStampProvider) {
|
||||
this.signatureWire = signatureWire;
|
||||
this.accessKey = accessKey;
|
||||
this.secretKey = secretKey;
|
||||
this.timeStampProvider = timeStampProvider;
|
||||
|
@ -84,12 +88,16 @@ public class RequestAuthorizeSignature implements HttpRequestFilter {
|
|||
appendAmzHeaders(request, buffer);
|
||||
appendBucketName(request, buffer);
|
||||
appendUriPath(request, buffer);
|
||||
if(signatureWire.enabled())
|
||||
signatureWire.output(buffer.toString());
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
private void calculateAndReplaceAuthHeader(HttpRequest request, String toSign)
|
||||
throws HttpException {
|
||||
String signature = signString(toSign);
|
||||
if (signatureWire.enabled())
|
||||
signatureWire.input(IOUtils.toInputStream(signature));
|
||||
request.getHeaders().replaceValues(HttpHeaders.AUTHORIZATION,
|
||||
Collections.singletonList("AWS " + accessKey + ":" + signature));
|
||||
}
|
||||
|
|
|
@ -34,11 +34,13 @@ import javax.inject.Provider;
|
|||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
||||
import org.jclouds.http.HttpException;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpRequestFilter;
|
||||
import org.jclouds.http.HttpUtils;
|
||||
import org.jclouds.http.internal.SignatureWire;
|
||||
import org.jclouds.util.TimeStamp;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
@ -55,15 +57,17 @@ public class SharedKeyAuthentication implements HttpRequestFilter {
|
|||
private final String[] firstHeadersToSign = new String[] { "Content-MD5",
|
||||
HttpHeaders.CONTENT_TYPE, HttpHeaders.DATE };
|
||||
|
||||
private final SignatureWire signatureWire;
|
||||
private final String account;
|
||||
private final byte[] key;
|
||||
private final Provider<String> timeStampProvider;
|
||||
|
||||
@Inject
|
||||
public SharedKeyAuthentication(
|
||||
public SharedKeyAuthentication(SignatureWire signatureWire,
|
||||
@Named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT) String account,
|
||||
@Named(AzureStorageConstants.PROPERTY_AZURESTORAGE_KEY) String encodedKey,
|
||||
@TimeStamp Provider<String> timeStampProvider) {
|
||||
this.signatureWire = signatureWire;
|
||||
this.account = account;
|
||||
this.key = HttpUtils.fromBase64String(encodedKey);
|
||||
this.timeStampProvider = timeStampProvider;
|
||||
|
@ -82,12 +86,16 @@ public class SharedKeyAuthentication implements HttpRequestFilter {
|
|||
appendHttpHeaders(request, buffer);
|
||||
appendCanonicalizedHeaders(request, buffer);
|
||||
appendCanonicalizedResource(request, buffer);
|
||||
if (signatureWire.enabled())
|
||||
signatureWire.output(buffer.toString());
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
private void calculateAndReplaceAuthHeader(HttpRequest request, String toSign)
|
||||
throws HttpException {
|
||||
String signature = signString(toSign);
|
||||
if (signatureWire.enabled())
|
||||
signatureWire.input(IOUtils.toInputStream(signature));
|
||||
request.getHeaders().replaceValues(HttpHeaders.AUTHORIZATION,
|
||||
Collections.singletonList("SharedKey " + account + ":" + signature));
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ public interface HttpConstants {
|
|||
public static final String PROPERTY_HTTP_MAX_REDIRECTS = "jclouds.http.max-redirects";
|
||||
public static final String HTTP_HEADERS_LOGGER = "jclouds.http.headers";
|
||||
public static final String HTTP_WIRE_LOGGER = "jclouds.http.wire";
|
||||
public static final String SIGNATURE_WIRE_LOGGER = "jclouds.signature.wire";
|
||||
|
||||
/**
|
||||
* longest time a single request can take before throwing an exception.
|
||||
|
|
|
@ -54,10 +54,10 @@ public abstract class BaseHttpCommandExecutorService<Q> implements HttpCommandEx
|
|||
@Named(HttpConstants.HTTP_HEADERS_LOGGER)
|
||||
protected Logger headerLog = Logger.NULL;
|
||||
|
||||
private final Wire wire;
|
||||
private final HttpWire wire;
|
||||
|
||||
protected BaseHttpCommandExecutorService(ExecutorService executorService,
|
||||
DelegatingRetryHandler retryHandler, DelegatingErrorHandler errorHandler, Wire wire) {
|
||||
DelegatingRetryHandler retryHandler, DelegatingErrorHandler errorHandler, HttpWire wire) {
|
||||
this.retryHandler = retryHandler;
|
||||
this.errorHandler = errorHandler;
|
||||
this.executorService = executorService;
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.http.internal;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.http.HttpConstants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.logging.internal.Wire;
|
||||
|
||||
/**
|
||||
* Logs data to the wire LOG.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see org.apache.HttpWire.impl.conn.Wire
|
||||
*/
|
||||
public class HttpWire extends Wire {
|
||||
|
||||
@Resource
|
||||
@Named(HttpConstants.HTTP_WIRE_LOGGER)
|
||||
Logger wireLog = Logger.NULL;
|
||||
|
||||
@Inject
|
||||
public HttpWire(ExecutorService exec) {
|
||||
super(exec);
|
||||
}
|
||||
|
||||
public Logger getWireLog() {
|
||||
return wireLog;
|
||||
}
|
||||
|
||||
}
|
|
@ -66,7 +66,7 @@ public class JavaUrlHttpCommandExecutorService extends
|
|||
|
||||
@Inject
|
||||
public JavaUrlHttpCommandExecutorService(ExecutorService executorService,
|
||||
DelegatingRetryHandler retryHandler, DelegatingErrorHandler errorHandler, Wire wire) {
|
||||
DelegatingRetryHandler retryHandler, DelegatingErrorHandler errorHandler, HttpWire wire) {
|
||||
super(executorService, retryHandler, errorHandler, wire);
|
||||
sslMap = Maps.newHashMap();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.http.internal;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.http.HttpConstants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.logging.internal.Wire;
|
||||
|
||||
/**
|
||||
* Logs data to the wire LOG.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see org.apache.HttpWire.impl.conn.Wire
|
||||
*/
|
||||
public class SignatureWire extends Wire {
|
||||
|
||||
@Resource
|
||||
@Named(HttpConstants.SIGNATURE_WIRE_LOGGER)
|
||||
Logger wireLog = Logger.NULL;
|
||||
|
||||
@Inject
|
||||
public SignatureWire(ExecutorService exec) {
|
||||
super(exec);
|
||||
}
|
||||
|
||||
public Logger getWireLog() {
|
||||
return wireLog;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
|
@ -21,7 +21,7 @@
|
|||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.http.internal;
|
||||
package org.jclouds.logging.internal;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
|
@ -37,34 +37,28 @@ import java.util.concurrent.ExecutorService;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.io.input.TeeInputStream;
|
||||
import org.jclouds.concurrent.SingleThreaded;
|
||||
import org.jclouds.http.HttpConstants;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
/**
|
||||
* Logs data to the wire LOG.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see org.apache.http.impl.conn.Wire
|
||||
* @see org.apache.HttpWire.impl.conn.Wire
|
||||
*/
|
||||
public class Wire {
|
||||
public abstract class Wire {
|
||||
|
||||
@Resource
|
||||
@Named(HttpConstants.HTTP_WIRE_LOGGER)
|
||||
protected Logger wireLog = Logger.NULL;
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final ExecutorService exec;
|
||||
protected final ExecutorService exec;
|
||||
|
||||
@Inject
|
||||
public Wire(ExecutorService exec) {
|
||||
this.exec = checkNotNull(exec, "executor");
|
||||
}
|
||||
protected abstract Logger getWireLog();
|
||||
|
||||
private void wire(String header, InputStream instream) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
|
@ -77,7 +71,7 @@ public class Wire {
|
|||
buffer.append("[\\n]\"");
|
||||
buffer.insert(0, "\"");
|
||||
buffer.insert(0, header);
|
||||
wireLog.debug(buffer.toString());
|
||||
getWireLog().debug(buffer.toString());
|
||||
buffer.setLength(0);
|
||||
} else if ((ch < 32) || (ch > 127)) {
|
||||
buffer.append("[0x");
|
||||
|
@ -91,7 +85,7 @@ public class Wire {
|
|||
buffer.append('\"');
|
||||
buffer.insert(0, '\"');
|
||||
buffer.insert(0, header);
|
||||
wireLog.debug(buffer.toString());
|
||||
getWireLog().debug(buffer.toString());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error(e, "Error tapping line");
|
||||
|
@ -99,7 +93,7 @@ public class Wire {
|
|||
}
|
||||
|
||||
public boolean enabled() {
|
||||
return wireLog.isDebugEnabled();
|
||||
return getWireLog().isDebugEnabled();
|
||||
}
|
||||
|
||||
public InputStream copy(final String header, InputStream instream) {
|
||||
|
@ -141,7 +135,7 @@ public class Wire {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T output(T data) {
|
||||
checkNotNull(data, "data must be set before calling generateETag()");
|
||||
checkNotNull(data, "data");
|
||||
if (data instanceof InputStream) {
|
||||
if (exec.getClass().isAnnotationPresent(SingleThreaded.class))
|
||||
return (T) copy(">> ", (InputStream) data);
|
|
@ -39,7 +39,7 @@ import org.jclouds.http.TransformingHttpCommandExecutorServiceImpl;
|
|||
import org.jclouds.http.TransformingHttpCommandImpl;
|
||||
import org.jclouds.http.functions.ReturnStringIf200;
|
||||
import org.jclouds.http.internal.JavaUrlHttpCommandExecutorService;
|
||||
import org.jclouds.http.internal.Wire;
|
||||
import org.jclouds.http.internal.HttpWire;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.logging.Logger.LoggerFactory;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
|
@ -93,7 +93,7 @@ public class BackoffLimitedRetryHandlerTest {
|
|||
void setupExecutorService() throws Exception {
|
||||
ExecutorService execService = Executors.newCachedThreadPool();
|
||||
JavaUrlHttpCommandExecutorService httpService = new JavaUrlHttpCommandExecutorService(
|
||||
execService, new DelegatingRetryHandler(), new DelegatingErrorHandler(), new Wire(
|
||||
execService, new DelegatingRetryHandler(), new DelegatingErrorHandler(), new HttpWire(
|
||||
Executors.newCachedThreadPool()));
|
||||
executorService = new TransformingHttpCommandExecutorServiceImpl(httpService, execService,
|
||||
new LoggerFactory() {
|
||||
|
|
|
@ -40,6 +40,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import org.apache.commons.io.IOUtils;
|
||||
import org.jclouds.concurrent.WithinThreadExecutorService;
|
||||
import org.jclouds.http.HttpUtils;
|
||||
import org.jclouds.http.internal.HttpWire;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -61,7 +62,7 @@ public class WireLiveTest {
|
|||
}
|
||||
|
||||
public Void call() throws Exception {
|
||||
Wire wire = setUp();
|
||||
HttpWire wire = setUp();
|
||||
InputStream in = wire.input(fromServer);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
IOUtils.copy(in, out);
|
||||
|
@ -69,7 +70,7 @@ public class WireLiveTest {
|
|||
Thread.sleep(100);
|
||||
assertEquals(HttpUtils.toHexString(compare), checkNotNull(sysHttpStreamMd5,
|
||||
sysHttpStreamMd5));
|
||||
assertEquals(((BufferLogger) wire.wireLog).buff.toString().getBytes().length, 3331484);
|
||||
assertEquals(((BufferLogger) wire.getWireLog()).buff.toString().getBytes().length, 3331484);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -125,19 +126,19 @@ public class WireLiveTest {
|
|||
|
||||
}
|
||||
|
||||
public static Wire setUp() throws Exception {
|
||||
public static HttpWire setUp() throws Exception {
|
||||
ExecutorService service = Executors.newCachedThreadPool();
|
||||
BufferLogger bufferLogger = new BufferLogger();
|
||||
Wire wire = new Wire(service);
|
||||
wire.wireLog = bufferLogger;
|
||||
HttpWire wire = new HttpWire(service);
|
||||
wire.wireLog = (bufferLogger);
|
||||
return wire;
|
||||
}
|
||||
|
||||
public Wire setUpSynch() throws Exception {
|
||||
public HttpWire setUpSynch() throws Exception {
|
||||
ExecutorService service = new WithinThreadExecutorService();
|
||||
BufferLogger bufferLogger = new BufferLogger();
|
||||
Wire wire = new Wire(service);
|
||||
wire.wireLog = bufferLogger;
|
||||
HttpWire wire = new HttpWire(service);
|
||||
wire.wireLog = (bufferLogger);
|
||||
return wire;
|
||||
}
|
||||
|
||||
|
@ -145,12 +146,12 @@ public class WireLiveTest {
|
|||
public void testRemoteInputInputStream() throws Exception {
|
||||
URL url = new URL(checkNotNull(sysHttpStreamUrl, "sysHttpStreamUrl"));
|
||||
URLConnection connection = url.openConnection();
|
||||
Wire wire = setUp();
|
||||
HttpWire wire = setUp();
|
||||
InputStream in = wire.input(connection.getInputStream());
|
||||
byte[] compare = HttpUtils.md5(in);
|
||||
Thread.sleep(100);
|
||||
assertEquals(HttpUtils.toHexString(compare), checkNotNull(sysHttpStreamMd5, sysHttpStreamMd5));
|
||||
assertEquals(((BufferLogger) wire.wireLog).buff.toString().getBytes().length, 3331484);
|
||||
assertEquals(((BufferLogger) wire.getWireLog()).buff.toString().getBytes().length, 3331484);
|
||||
}
|
||||
|
||||
@Test(groups = "live")
|
||||
|
@ -166,12 +167,12 @@ public class WireLiveTest {
|
|||
public void testRemoteInputInputStreamSynch() throws Exception {
|
||||
URL url = new URL(checkNotNull(sysHttpStreamUrl, "sysHttpStreamUrl"));
|
||||
URLConnection connection = url.openConnection();
|
||||
Wire wire = setUpSynch();
|
||||
HttpWire wire = setUpSynch();
|
||||
InputStream in = wire.input(connection.getInputStream());
|
||||
byte[] compare = HttpUtils.md5(in);
|
||||
Thread.sleep(100);
|
||||
assertEquals(HttpUtils.toHexString(compare), checkNotNull(sysHttpStreamMd5, sysHttpStreamMd5));
|
||||
assertEquals(((BufferLogger) wire.wireLog).buff.toString().getBytes().length, 3331484);
|
||||
assertEquals(((BufferLogger) wire.getWireLog()).buff.toString().getBytes().length, 3331484);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import java.util.concurrent.ExecutorService;
|
|||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.jclouds.concurrent.WithinThreadExecutorService;
|
||||
import org.jclouds.http.internal.HttpWire;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -93,57 +94,57 @@ public class WireTest {
|
|||
|
||||
}
|
||||
|
||||
public Wire setUp() throws Exception {
|
||||
public HttpWire setUp() throws Exception {
|
||||
ExecutorService service = Executors.newCachedThreadPool();
|
||||
BufferLogger bufferLogger = new BufferLogger();
|
||||
Wire wire = new Wire(service);
|
||||
wire.wireLog = bufferLogger;
|
||||
HttpWire wire = new HttpWire(service);
|
||||
wire.wireLog = (bufferLogger);
|
||||
return wire;
|
||||
}
|
||||
|
||||
public Wire setUpSynch() throws Exception {
|
||||
public HttpWire setUpSynch() throws Exception {
|
||||
ExecutorService service = new WithinThreadExecutorService();
|
||||
BufferLogger bufferLogger = new BufferLogger();
|
||||
Wire wire = new Wire(service);
|
||||
wire.wireLog = bufferLogger;
|
||||
HttpWire wire = new HttpWire(service);
|
||||
wire.wireLog = (bufferLogger);
|
||||
return wire;
|
||||
}
|
||||
|
||||
public void testInputInputStream() throws Exception {
|
||||
Wire wire = setUp();
|
||||
HttpWire wire = setUp();
|
||||
InputStream in = wire.input(new ByteArrayInputStream("foo".getBytes()));
|
||||
String compare = Utils.toStringAndClose(in);
|
||||
Thread.sleep(100);
|
||||
assertEquals(compare, "foo");
|
||||
assertEquals(((BufferLogger) wire.wireLog).buff.toString(), "<< \"foo\"");
|
||||
assertEquals(((BufferLogger) wire.getWireLog()).buff.toString(), "<< \"foo\"");
|
||||
}
|
||||
|
||||
public void testInputInputStreamSynch() throws Exception {
|
||||
Wire wire = setUpSynch();
|
||||
HttpWire wire = setUpSynch();
|
||||
InputStream in = wire.input(new ByteArrayInputStream("foo".getBytes()));
|
||||
String compare = Utils.toStringAndClose(in);
|
||||
assertEquals(compare, "foo");
|
||||
assertEquals(((BufferLogger) wire.wireLog).buff.toString(), "<< \"foo\"");
|
||||
assertEquals(((BufferLogger) wire.getWireLog()).buff.toString(), "<< \"foo\"");
|
||||
}
|
||||
|
||||
public void testOutputInputStream() throws Exception {
|
||||
Wire wire = setUp();
|
||||
HttpWire wire = setUp();
|
||||
InputStream in = wire.output(new ByteArrayInputStream("foo".getBytes()));
|
||||
String compare = Utils.toStringAndClose(in);
|
||||
Thread.sleep(100);
|
||||
assertEquals(compare, "foo");
|
||||
assertEquals(((BufferLogger) wire.wireLog).buff.toString(), ">> \"foo\"");
|
||||
assertEquals(((BufferLogger) wire.getWireLog()).buff.toString(), ">> \"foo\"");
|
||||
}
|
||||
|
||||
public void testOutputBytes() throws Exception {
|
||||
Wire wire = setUp();
|
||||
HttpWire wire = setUp();
|
||||
wire.output("foo".getBytes());
|
||||
assertEquals(((BufferLogger) wire.wireLog).buff.toString(), ">> \"foo\"");
|
||||
assertEquals(((BufferLogger) wire.getWireLog()).buff.toString(), ">> \"foo\"");
|
||||
}
|
||||
|
||||
public void testOutputString() throws Exception {
|
||||
Wire wire = setUp();
|
||||
HttpWire wire = setUp();
|
||||
wire.output("foo");
|
||||
assertEquals(((BufferLogger) wire.wireLog).buff.toString(), ">> \"foo\"");
|
||||
assertEquals(((BufferLogger) wire.getWireLog()).buff.toString(), ">> \"foo\"");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ import org.jclouds.http.HttpResponse;
|
|||
import org.jclouds.http.handlers.DelegatingErrorHandler;
|
||||
import org.jclouds.http.handlers.DelegatingRetryHandler;
|
||||
import org.jclouds.http.internal.BaseHttpCommandExecutorService;
|
||||
import org.jclouds.http.internal.Wire;
|
||||
import org.jclouds.http.internal.HttpWire;
|
||||
|
||||
import com.google.appengine.api.urlfetch.FetchOptions;
|
||||
import com.google.appengine.api.urlfetch.HTTPHeader;
|
||||
|
@ -68,7 +68,7 @@ public class GaeHttpCommandExecutorService extends BaseHttpCommandExecutorServic
|
|||
@Inject
|
||||
public GaeHttpCommandExecutorService(URLFetchService urlFetchService,
|
||||
ExecutorService executorService, DelegatingRetryHandler retryHandler,
|
||||
DelegatingErrorHandler errorHandler, Wire wire) {
|
||||
DelegatingErrorHandler errorHandler, HttpWire wire) {
|
||||
super(executorService, retryHandler, errorHandler, wire);
|
||||
this.urlFetchService = urlFetchService;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ import org.jclouds.http.HttpRequest;
|
|||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.handlers.DelegatingErrorHandler;
|
||||
import org.jclouds.http.handlers.DelegatingRetryHandler;
|
||||
import org.jclouds.http.internal.Wire;
|
||||
import org.jclouds.http.internal.HttpWire;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Parameters;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -71,7 +71,7 @@ public class GaeHttpCommandExecutorServiceTest {
|
|||
endPoint = URI.create("http://localhost:80/foo");
|
||||
client = new GaeHttpCommandExecutorService(createNiceMock(URLFetchService.class),
|
||||
createNiceMock(ExecutorService.class), createNiceMock(DelegatingRetryHandler.class),
|
||||
createNiceMock(DelegatingErrorHandler.class), createNiceMock(Wire.class));
|
||||
createNiceMock(DelegatingErrorHandler.class), createNiceMock(HttpWire.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -45,7 +45,7 @@ import org.jclouds.http.HttpRequestFilter;
|
|||
import org.jclouds.http.handlers.DelegatingErrorHandler;
|
||||
import org.jclouds.http.handlers.DelegatingRetryHandler;
|
||||
import org.jclouds.http.httpnio.util.NioHttpUtils;
|
||||
import org.jclouds.http.internal.Wire;
|
||||
import org.jclouds.http.internal.HttpWire;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
/**
|
||||
|
@ -57,7 +57,7 @@ public class NioHttpCommandExecutionHandler implements NHttpRequestExecutionHand
|
|||
private final ConsumingNHttpEntityFactory entityFactory;
|
||||
private final DelegatingRetryHandler retryHandler;
|
||||
private final DelegatingErrorHandler errorHandler;
|
||||
private final Wire wire;
|
||||
private final HttpWire wire;
|
||||
|
||||
/**
|
||||
* inputOnly: nothing is taken from this queue.
|
||||
|
@ -73,7 +73,7 @@ public class NioHttpCommandExecutionHandler implements NHttpRequestExecutionHand
|
|||
@Inject
|
||||
public NioHttpCommandExecutionHandler(ConsumingNHttpEntityFactory entityFactory,
|
||||
BlockingQueue<HttpCommandRendezvous<?>> resubmitQueue,
|
||||
DelegatingRetryHandler retryHandler, DelegatingErrorHandler errorHandler, Wire wire) {
|
||||
DelegatingRetryHandler retryHandler, DelegatingErrorHandler errorHandler, HttpWire wire) {
|
||||
this.entityFactory = entityFactory;
|
||||
this.resubmitQueue = resubmitQueue;
|
||||
this.retryHandler = retryHandler;
|
||||
|
|
Loading…
Reference in New Issue