Skip to content

Commit

Permalink
Merge pull request Azure#77 from rpaquay/5280d51e8867042a22800f4f93d2…
Browse files Browse the repository at this point in the history
…b0dd77b941ca

Looks good
  • Loading branch information
loudej committed Nov 19, 2011
2 parents fc5c5a6 + 5280d51 commit d8c76f9
Show file tree
Hide file tree
Showing 14 changed files with 704 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class ServiceException extends Exception {
String errorCode;
String errorMessage;
Map<String, String> errorValues;
String rawResponseBody;

public ServiceException() {
init();
Expand All @@ -38,6 +39,14 @@ private void init() {
errorValues = new HashMap<String, String>();
}

@Override
public String getMessage() {
if (this.rawResponseBody == null)
return super.getMessage();
else
return super.getMessage() + "\nResponse Body: " + this.rawResponseBody;
}

public int getHttpStatusCode() {
return httpStatusCode;
}
Expand Down Expand Up @@ -94,4 +103,11 @@ public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}

public void setRawResponseBody(String body) {
this.rawResponseBody = body;
}

public String getRawResponseBody() {
return rawResponseBody;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.microsoft.windowsazure.services.blob;

import java.util.Map;

import com.microsoft.windowsazure.common.Builder;
import com.microsoft.windowsazure.services.blob.implementation.BlobExceptionProcessor;
import com.microsoft.windowsazure.services.blob.implementation.BlobRestProxy;
import com.microsoft.windowsazure.services.blob.implementation.HttpURLConnectionClient;
import com.microsoft.windowsazure.services.blob.implementation.SharedKeyFilter;
import com.microsoft.windowsazure.services.blob.implementation.SharedKeyLiteFilter;
import com.sun.jersey.api.client.config.ClientConfig;

public class Exports implements Builder.Exports {
public void register(Builder.Registry registry) {
Expand All @@ -12,5 +17,15 @@ public void register(Builder.Registry registry) {
registry.add(BlobExceptionProcessor.class);
registry.add(BlobRestProxy.class);
registry.add(SharedKeyLiteFilter.class);
registry.add(SharedKeyFilter.class);

registry.add(new Builder.Factory<HttpURLConnectionClient>() {
public HttpURLConnectionClient create(String profile, Builder builder, Map<String, Object> properties) {
ClientConfig clientConfig = (ClientConfig) properties.get("ClientConfig");
HttpURLConnectionClient client = HttpURLConnectionClient.create(clientConfig);
//client.addFilter(new LoggingFilter());
return client;
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,23 @@
import com.microsoft.windowsazure.services.blob.models.SetBlobPropertiesResult;
import com.microsoft.windowsazure.services.blob.models.SetContainerMetadataOptions;
import com.microsoft.windowsazure.utils.jersey.ClientFilterAdapter;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.WebResource.Builder;
import com.sun.jersey.core.util.Base64;

public class BlobRestProxy implements BlobContract {
// private static Log log = LogFactory.getLog(BlobRestProxy.class);

private static final String API_VERSION = "2011-08-18";
private final Client channel;
private final HttpURLConnectionClient channel;
private final String accountName;
private final String url;
private final RFC1123DateConverter dateMapper;
private final ServiceFilter[] filters;
private final SharedKeyLiteFilter filter;
private final SharedKeyFilter filter;

@Inject
public BlobRestProxy(Client channel, @Named(BlobConfiguration.ACCOUNT_NAME) String accountName, @Named(BlobConfiguration.URL) String url,
SharedKeyLiteFilter filter) {
public BlobRestProxy(HttpURLConnectionClient channel, @Named(BlobConfiguration.ACCOUNT_NAME) String accountName, @Named(BlobConfiguration.URL) String url,
SharedKeyFilter filter) {

this.channel = channel;
this.accountName = accountName;
Expand All @@ -86,9 +83,10 @@ public BlobRestProxy(Client channel, @Named(BlobConfiguration.ACCOUNT_NAME) Stri
channel.addFilter(filter);
}

public BlobRestProxy(Client channel, ServiceFilter[] filters, String accountName, String url, SharedKeyLiteFilter filter, RFC1123DateConverter dateMapper) {
public BlobRestProxy(HttpURLConnectionClient client, ServiceFilter[] filters, String accountName, String url, SharedKeyFilter filter,
RFC1123DateConverter dateMapper) {

this.channel = channel;
this.channel = client;
this.filters = filters;
this.accountName = accountName;
this.url = url;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.microsoft.windowsazure.services.blob.implementation;

import com.sun.jersey.api.client.ClientRequest;

public interface EntityStreamingListener {
/**
* This method is called just before the entity is streamed to the underlying connection. This is the last chance
* for filters to inspect and modify the headers of the client request if necessary.
*
* @param clientRequest
* The client request
*/
void onBeforeStreamingEntity(ClientRequest clientRequest);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.microsoft.windowsazure.services.blob.implementation;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.config.ClientConfig;

public class HttpURLConnectionClient extends Client {
private final HttpURLConnectionClientHandler rootHandler;

public HttpURLConnectionClient(HttpURLConnectionClientHandler handler, ClientConfig config) {
super(handler, config);
this.rootHandler = handler;
}

public static HttpURLConnectionClient create(ClientConfig config) {
return new HttpURLConnectionClient(new HttpURLConnectionClientHandler(), config);
}

public HttpURLConnectionClientHandler getRootHandler() {
return rootHandler;
}
}
Loading

0 comments on commit d8c76f9

Please sign in to comment.