diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/Exports.java index 57a7cd87cc5f9..7dfef8f100dbd 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/Exports.java @@ -20,6 +20,7 @@ import com.microsoft.windowsazure.services.blob.implementation.SharedKeyFilter; import com.microsoft.windowsazure.services.blob.implementation.SharedKeyLiteFilter; import com.microsoft.windowsazure.services.core.Builder; +import com.microsoft.windowsazure.services.core.UserAgentFilter; public class Exports implements Builder.Exports { @Override @@ -30,5 +31,6 @@ public void register(Builder.Registry registry) { registry.add(SharedKeyLiteFilter.class); registry.add(SharedKeyFilter.class); registry.add(ISO8601DateConverter.class); + registry.add(UserAgentFilter.class); } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobRestProxy.java index bb628ea9d72fc..ed87b549f79be 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobRestProxy.java @@ -22,26 +22,29 @@ import com.microsoft.windowsazure.services.blob.BlobConfiguration; import com.microsoft.windowsazure.services.blob.BlobContract; import com.microsoft.windowsazure.services.core.ServiceFilter; +import com.microsoft.windowsazure.services.core.UserAgentFilter; import com.microsoft.windowsazure.services.core.utils.pipeline.HttpURLConnectionClient; import com.sun.jersey.api.client.Client; public class BlobRestProxy extends BlobOperationRestProxy implements BlobContract { - private final SharedKeyFilter filter; + private final SharedKeyFilter sharedKeyFilter; @Inject public BlobRestProxy(HttpURLConnectionClient channel, @Named(BlobConfiguration.ACCOUNT_NAME) String accountName, - @Named(BlobConfiguration.URI) String url, SharedKeyFilter filter) { + @Named(BlobConfiguration.URI) String url, SharedKeyFilter sharedKeyFilter, UserAgentFilter userAgentFilter) { super(channel, accountName, url); - this.filter = filter; - channel.addFilter(filter); + this.sharedKeyFilter = sharedKeyFilter; + + channel.addFilter(sharedKeyFilter); + channel.addFilter(userAgentFilter); } public BlobRestProxy(Client client, ServiceFilter[] filters, String accountName, String url, - SharedKeyFilter filter, RFC1123DateConverter dateMapper) { + SharedKeyFilter sharedKeyFilter, RFC1123DateConverter dateMapper) { super(client, filters, accountName, url, dateMapper); - this.filter = filter; + this.sharedKeyFilter = sharedKeyFilter; } @Override @@ -49,6 +52,7 @@ public BlobContract withFilter(ServiceFilter filter) { ServiceFilter[] currentFilters = getFilters(); ServiceFilter[] newFilters = Arrays.copyOf(currentFilters, currentFilters.length + 1); newFilters[currentFilters.length] = filter; - return new BlobRestProxy(getChannel(), newFilters, getAccountName(), getUrl(), this.filter, getDateMapper()); + return new BlobRestProxy(getChannel(), newFilters, getAccountName(), getUrl(), this.sharedKeyFilter, + getDateMapper()); } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/UserAgentFilter.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/UserAgentFilter.java new file mode 100644 index 0000000000000..871c5074325bd --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/UserAgentFilter.java @@ -0,0 +1,104 @@ +/** + * Copyright Microsoft Corporation + * + * Licensed 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 com.microsoft.windowsazure.services.core; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import com.sun.jersey.api.client.ClientHandlerException; +import com.sun.jersey.api.client.ClientRequest; +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.filter.ClientFilter; + +/** + * The Class UserAgentFilter. + */ +public class UserAgentFilter extends ClientFilter { + + /** The azure sdk product token. */ + private static String azureSDKProductToken; + + /** + * Instantiates a new user agent filter. + */ + public UserAgentFilter() { + if ((azureSDKProductToken == null) || azureSDKProductToken.isEmpty()) { + azureSDKProductToken = createAzureSDKProductToken(); + } + + } + + /* (non-Javadoc) + * @see com.sun.jersey.api.client.filter.ClientFilter#handle(com.sun.jersey.api.client.ClientRequest) + */ + @Override + public ClientResponse handle(ClientRequest clientRequest) throws ClientHandlerException { + String userAgent; + + if (clientRequest.getHeaders().containsKey("User-Agent")) { + String currentUserAgent = (String) clientRequest.getHeaders().getFirst("User-Agent"); + userAgent = azureSDKProductToken + " " + currentUserAgent; + clientRequest.getHeaders().remove("User-Agent"); + } + else { + userAgent = azureSDKProductToken; + } + + clientRequest.getHeaders().add("User-Agent", userAgent); + + return this.getNext().handle(clientRequest); + } + + /** + * Creates the azure sdk product token. + * + * @return the string + */ + private String createAzureSDKProductToken() { + String version = getVersionFromResources(); + String productToken; + if ((version != null) && (!version.isEmpty())) { + productToken = "Azure-SDK-For-Java/" + version; + } + else { + productToken = "Azure-SDK-For-Java"; + } + + return productToken; + } + + /** + * Gets the version of the SDK from resources. + * + * @return the version from resources + */ + private String getVersionFromResources() { + String version; + Properties properties = new Properties(); + try { + InputStream inputStream = getClass().getClassLoader().getResourceAsStream( + "META-INF/maven/com.microsoft.windowsazure/microsoft-windowsazure-api/pom.properties"); + properties.load(inputStream); + version = properties.getProperty("version"); + inputStream.close(); + } + catch (IOException e) { + version = ""; + } + + return version; + } +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java index dfd199c90b9bc..f2c6e3afbc287 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java @@ -20,6 +20,7 @@ import javax.xml.parsers.ParserConfigurationException; import com.microsoft.windowsazure.services.core.Builder; +import com.microsoft.windowsazure.services.core.UserAgentFilter; import com.microsoft.windowsazure.services.media.implementation.MediaContentProvider; import com.microsoft.windowsazure.services.media.implementation.MediaExceptionProcessor; import com.microsoft.windowsazure.services.media.implementation.MediaRestProxy; @@ -50,6 +51,7 @@ public void register(Builder.Registry registry) { registry.add(ResourceLocationManager.class); registry.add(RedirectFilter.class); registry.add(VersionHeadersFilter.class); + registry.add(UserAgentFilter.class); registry.alter(ClientConfig.class, new Builder.Alteration() { @SuppressWarnings("rawtypes") diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaRestProxy.java index cb8480f28920b..aa756c90f0c83 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaRestProxy.java @@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory; import com.microsoft.windowsazure.services.core.ServiceFilter; +import com.microsoft.windowsazure.services.core.UserAgentFilter; import com.microsoft.windowsazure.services.core.utils.pipeline.ClientConfigSettings; import com.microsoft.windowsazure.services.media.MediaContract; import com.microsoft.windowsazure.services.media.WritableBlobContainerContract; @@ -58,13 +59,16 @@ public class MediaRestProxy extends EntityRestProxy implements MediaContract { * the redirect filter * @param versionHeadersFilter * the version headers filter + * @param userAgentFilter + * the user agent filter * @param clientConfigSettings * Currently configured HTTP client settings * */ @Inject public MediaRestProxy(Client channel, OAuthFilter authFilter, RedirectFilter redirectFilter, - VersionHeadersFilter versionHeadersFilter, ClientConfigSettings clientConfigSettings) { + VersionHeadersFilter versionHeadersFilter, UserAgentFilter userAgentFilter, + ClientConfigSettings clientConfigSettings) { super(channel, new ServiceFilter[0]); this.clientConfigSettings = clientConfigSettings; @@ -72,6 +76,7 @@ public MediaRestProxy(Client channel, OAuthFilter authFilter, RedirectFilter red channel.addFilter(redirectFilter); channel.addFilter(authFilter); channel.addFilter(versionHeadersFilter); + channel.addFilter(userAgentFilter); } /** diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthRestProxy.java index be98df7af3807..77bc0ce745896 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthRestProxy.java @@ -28,6 +28,7 @@ import org.codehaus.jackson.type.TypeReference; import com.microsoft.windowsazure.services.core.ServiceException; +import com.microsoft.windowsazure.services.core.UserAgentFilter; import com.microsoft.windowsazure.services.core.utils.ServiceExceptionFactory; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; @@ -46,8 +47,9 @@ public class OAuthRestProxy implements OAuthContract { static Log log = LogFactory.getLog(OAuthContract.class); @Inject - public OAuthRestProxy(Client channel) { + public OAuthRestProxy(Client channel, UserAgentFilter userAgentFilter) { this.channel = channel; + channel.addFilter(userAgentFilter); } /** diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/Exports.java index 3d57a69f82c7a..3be2f2909feee 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/Exports.java @@ -2,19 +2,20 @@ * Copyright Microsoft Corporation * * Licensed 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 + * 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. + * 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 com.microsoft.windowsazure.services.queue; import com.microsoft.windowsazure.services.core.Builder; +import com.microsoft.windowsazure.services.core.UserAgentFilter; import com.microsoft.windowsazure.services.queue.implementation.QueueExceptionProcessor; import com.microsoft.windowsazure.services.queue.implementation.QueueRestProxy; import com.microsoft.windowsazure.services.queue.implementation.SharedKeyFilter; @@ -28,5 +29,6 @@ public void register(Builder.Registry registry) { registry.add(QueueRestProxy.class); registry.add(SharedKeyLiteFilter.class); registry.add(SharedKeyFilter.class); + registry.add(UserAgentFilter.class); } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/implementation/QueueRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/implementation/QueueRestProxy.java index 4b038a023b20d..5f3c663c37db3 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/implementation/QueueRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/implementation/QueueRestProxy.java @@ -2,15 +2,15 @@ * Copyright Microsoft Corporation * * Licensed 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 + * 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. + * 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 com.microsoft.windowsazure.services.queue.implementation; @@ -24,6 +24,7 @@ import com.microsoft.windowsazure.services.blob.implementation.RFC1123DateConverter; import com.microsoft.windowsazure.services.core.ServiceException; import com.microsoft.windowsazure.services.core.ServiceFilter; +import com.microsoft.windowsazure.services.core.UserAgentFilter; import com.microsoft.windowsazure.services.core.utils.pipeline.ClientFilterAdapter; import com.microsoft.windowsazure.services.core.utils.pipeline.HttpURLConnectionClient; import com.microsoft.windowsazure.services.core.utils.pipeline.PipelineHelpers; @@ -55,19 +56,20 @@ public class QueueRestProxy implements QueueContract { private final String url; private final RFC1123DateConverter dateMapper; private final ServiceFilter[] filters; - private final SharedKeyFilter filter; + private final SharedKeyFilter sharedKeyFilter; @Inject public QueueRestProxy(HttpURLConnectionClient channel, @Named(QueueConfiguration.ACCOUNT_NAME) String accountName, - @Named(QueueConfiguration.URI) String url, SharedKeyFilter filter) { + @Named(QueueConfiguration.URI) String url, SharedKeyFilter sharedKeyFilter, UserAgentFilter userAgentFilter) { this.channel = channel; this.accountName = accountName; this.url = url; - this.filter = filter; + this.sharedKeyFilter = sharedKeyFilter; this.dateMapper = new RFC1123DateConverter(); this.filters = new ServiceFilter[0]; - channel.addFilter(filter); + channel.addFilter(sharedKeyFilter); + channel.addFilter(userAgentFilter); } public QueueRestProxy(HttpURLConnectionClient channel, ServiceFilter[] filters, String accountName, String url, @@ -77,14 +79,15 @@ public QueueRestProxy(HttpURLConnectionClient channel, ServiceFilter[] filters, this.filters = filters; this.accountName = accountName; this.url = url; - this.filter = filter; + this.sharedKeyFilter = filter; this.dateMapper = dateMapper; } + @Override public QueueContract withFilter(ServiceFilter filter) { ServiceFilter[] newFilters = Arrays.copyOf(filters, filters.length + 1); newFilters[filters.length] = filter; - return new QueueRestProxy(this.channel, newFilters, this.accountName, this.url, this.filter, this.dateMapper); + return new QueueRestProxy(this.channel, newFilters, this.accountName, this.url, this.sharedKeyFilter, this.dateMapper); } private void ThrowIfError(ClientResponse r) { @@ -117,10 +120,12 @@ private WebResource getResource(QueueServiceOptions options) { return webResource; } + @Override public GetServicePropertiesResult getServiceProperties() throws ServiceException { return getServiceProperties(new QueueServiceOptions()); } + @Override public GetServicePropertiesResult getServiceProperties(QueueServiceOptions options) throws ServiceException { WebResource webResource = getResource(options).path("/").queryParam("resType", "service") .queryParam("comp", "properties"); @@ -132,10 +137,12 @@ public GetServicePropertiesResult getServiceProperties(QueueServiceOptions optio return result; } + @Override public void setServiceProperties(ServiceProperties serviceProperties) throws ServiceException { setServiceProperties(serviceProperties, new QueueServiceOptions()); } + @Override public void setServiceProperties(ServiceProperties serviceProperties, QueueServiceOptions options) throws ServiceException { WebResource webResource = getResource(options).path("/").queryParam("resType", "service") @@ -146,11 +153,13 @@ public void setServiceProperties(ServiceProperties serviceProperties, QueueServi builder.put(serviceProperties); } + @Override public void createQueue(String queue) throws ServiceException { createQueue(queue, new CreateQueueOptions()); } + @Override public void createQueue(String queue, CreateQueueOptions options) throws ServiceException { if (queue == null) throw new NullPointerException(); @@ -163,10 +172,12 @@ public void createQueue(String queue, CreateQueueOptions options) throws Service builder.put(); } + @Override public void deleteQueue(String queue) throws ServiceException { deleteQueue(queue, new QueueServiceOptions()); } + @Override public void deleteQueue(String queue, QueueServiceOptions options) throws ServiceException { if (queue == null) throw new NullPointerException(); @@ -178,10 +189,12 @@ public void deleteQueue(String queue, QueueServiceOptions options) throws Servic builder.delete(); } + @Override public ListQueuesResult listQueues() throws ServiceException { return listQueues(new ListQueuesOptions()); } + @Override public ListQueuesResult listQueues(ListQueuesOptions options) throws ServiceException { WebResource webResource = getResource(options).path("/").queryParam("comp", "list"); webResource = addOptionalQueryParam(webResource, "prefix", options.getPrefix()); @@ -196,10 +209,12 @@ public ListQueuesResult listQueues(ListQueuesOptions options) throws ServiceExce return builder.get(ListQueuesResult.class); } + @Override public GetQueueMetadataResult getQueueMetadata(String queue) throws ServiceException { return getQueueMetadata(queue, new QueueServiceOptions()); } + @Override public GetQueueMetadataResult getQueueMetadata(String queue, QueueServiceOptions options) throws ServiceException { if (queue == null) throw new NullPointerException(); @@ -219,10 +234,12 @@ public GetQueueMetadataResult getQueueMetadata(String queue, QueueServiceOptions return result; } + @Override public void setQueueMetadata(String queue, HashMap metadata) throws ServiceException { setQueueMetadata(queue, metadata, new QueueServiceOptions()); } + @Override public void setQueueMetadata(String queue, HashMap metadata, QueueServiceOptions options) throws ServiceException { if (queue == null) @@ -236,10 +253,12 @@ public void setQueueMetadata(String queue, HashMap metadata, Que builder.put(); } + @Override public void createMessage(String queue, String messageText) throws ServiceException { createMessage(queue, messageText, new CreateMessageOptions()); } + @Override public void createMessage(String queue, String messageText, CreateMessageOptions options) throws ServiceException { if (queue == null) throw new NullPointerException(); @@ -256,12 +275,14 @@ public void createMessage(String queue, String messageText, CreateMessageOptions builder.post(queueMessage); } + @Override public UpdateMessageResult updateMessage(String queue, String messageId, String popReceipt, String messageText, int visibilityTimeoutInSeconds) throws ServiceException { return updateMessage(queue, messageId, popReceipt, messageText, visibilityTimeoutInSeconds, new QueueServiceOptions()); } + @Override public UpdateMessageResult updateMessage(String queue, String messageId, String popReceipt, String messageText, int visibilityTimeoutInSeconds, QueueServiceOptions options) throws ServiceException { if (queue == null) @@ -287,10 +308,12 @@ public UpdateMessageResult updateMessage(String queue, String messageId, String return result; } + @Override public ListMessagesResult listMessages(String queue) throws ServiceException { return listMessages(queue, new ListMessagesOptions()); } + @Override public ListMessagesResult listMessages(String queue, ListMessagesOptions options) throws ServiceException { if (queue == null) throw new NullPointerException(); @@ -304,10 +327,12 @@ public ListMessagesResult listMessages(String queue, ListMessagesOptions options return builder.get(ListMessagesResult.class); } + @Override public PeekMessagesResult peekMessages(String queue) throws ServiceException { return peekMessages(queue, new PeekMessagesOptions()); } + @Override public PeekMessagesResult peekMessages(String queue, PeekMessagesOptions options) throws ServiceException { if (queue == null) throw new NullPointerException(); @@ -320,10 +345,12 @@ public PeekMessagesResult peekMessages(String queue, PeekMessagesOptions options return builder.get(PeekMessagesResult.class); } + @Override public void deleteMessage(String queue, String messageId, String popReceipt) throws ServiceException { deleteMessage(queue, messageId, popReceipt, new QueueServiceOptions()); } + @Override public void deleteMessage(String queue, String messageId, String popReceipt, QueueServiceOptions options) throws ServiceException { if (queue == null) @@ -339,10 +366,12 @@ public void deleteMessage(String queue, String messageId, String popReceipt, Que builder.delete(); } + @Override public void clearMessages(String queue) throws ServiceException { clearMessages(queue, new QueueServiceOptions()); } + @Override public void clearMessages(String queue, QueueServiceOptions options) throws ServiceException { if (queue == null) throw new NullPointerException(); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Exports.java index b335a9f9106f7..d0466bb31cb75 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Exports.java @@ -2,21 +2,22 @@ * Copyright Microsoft Corporation * * Licensed 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 + * 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. + * 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 com.microsoft.windowsazure.services.serviceBus; import java.util.Map; import com.microsoft.windowsazure.services.core.Builder; +import com.microsoft.windowsazure.services.core.UserAgentFilter; import com.microsoft.windowsazure.services.serviceBus.implementation.BrokerPropertiesMapper; import com.microsoft.windowsazure.services.serviceBus.implementation.EntryModelProvider; import com.microsoft.windowsazure.services.serviceBus.implementation.MarshallerProvider; @@ -33,6 +34,7 @@ public void register(Builder.Registry registry) { registry.add(ServiceBusContract.class, ServiceBusExceptionProcessor.class); registry.add(ServiceBusExceptionProcessor.class); registry.add(ServiceBusRestProxy.class); + registry.add(UserAgentFilter.class); // alter jersey client config for serviceBus registry.alter(ClientConfig.class, new Builder.Alteration() { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/BrokerProperties.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/BrokerProperties.java index 2db84273def96..826ea46fd63ec 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/BrokerProperties.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/BrokerProperties.java @@ -2,15 +2,15 @@ * Copyright Microsoft Corporation * * Licensed 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 + * 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. + * 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 com.microsoft.windowsazure.services.serviceBus.implementation; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusRestProxy.java index b2007513afb2f..d73991edb30bf 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusRestProxy.java @@ -29,6 +29,7 @@ import com.microsoft.windowsazure.services.core.ServiceException; import com.microsoft.windowsazure.services.core.ServiceFilter; +import com.microsoft.windowsazure.services.core.UserAgentFilter; import com.microsoft.windowsazure.services.core.utils.pipeline.ClientFilterAdapter; import com.microsoft.windowsazure.services.serviceBus.ServiceBusContract; import com.microsoft.windowsazure.services.serviceBus.models.AbstractListOptions; @@ -74,7 +75,7 @@ public class ServiceBusRestProxy implements ServiceBusContract { @Inject public ServiceBusRestProxy(Client channel, @Named("serviceBus") WrapFilter authFilter, - @Named("serviceBus.uri") String uri, BrokerPropertiesMapper mapper) { + @Named("serviceBus.uri") String uri, BrokerPropertiesMapper mapper, UserAgentFilter userAgentFilter) { this.channel = channel; this.filters = new ServiceFilter[0]; @@ -82,6 +83,7 @@ public ServiceBusRestProxy(Client channel, @Named("serviceBus") WrapFilter authF this.mapper = mapper; this.customPropertiesMapper = new CustomPropertiesMapper(); channel.addFilter(authFilter); + channel.addFilter(userAgentFilter); } public ServiceBusRestProxy(Client channel, ServiceFilter[] filters, String uri, BrokerPropertiesMapper mapper) { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/WrapRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/WrapRestProxy.java index ec124f718c2a7..3de13aea1d265 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/WrapRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/WrapRestProxy.java @@ -2,15 +2,15 @@ * Copyright Microsoft Corporation * * Licensed 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 + * 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. + * 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 com.microsoft.windowsazure.services.serviceBus.implementation; @@ -21,6 +21,7 @@ import org.apache.commons.logging.LogFactory; import com.microsoft.windowsazure.services.core.ServiceException; +import com.microsoft.windowsazure.services.core.UserAgentFilter; import com.microsoft.windowsazure.services.core.utils.ServiceExceptionFactory; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.UniformInterfaceException; @@ -32,10 +33,12 @@ public class WrapRestProxy implements WrapContract { static Log log = LogFactory.getLog(WrapContract.class); @Inject - public WrapRestProxy(Client channel) { + public WrapRestProxy(Client channel, UserAgentFilter userAgentFilter) { this.channel = channel; + this.channel.addFilter(userAgentFilter); } + @Override public WrapAccessTokenResult wrapAccessToken(String uri, String name, String password, String scope) throws ServiceException { Form requestForm = new Form(); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/Exports.java index 39fea9c07eb1b..485104a66a291 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/Exports.java @@ -15,6 +15,7 @@ package com.microsoft.windowsazure.services.table; import com.microsoft.windowsazure.services.core.Builder; +import com.microsoft.windowsazure.services.core.UserAgentFilter; import com.microsoft.windowsazure.services.table.implementation.AtomReaderWriter; import com.microsoft.windowsazure.services.table.implementation.DefaultEdmValueConterter; import com.microsoft.windowsazure.services.table.implementation.DefaultXMLStreamFactory; @@ -39,5 +40,6 @@ public void register(Builder.Registry registry) { registry.add(MimeReaderWriter.class); registry.add(HttpReaderWriter.class); registry.add(EdmValueConverter.class, DefaultEdmValueConterter.class); + registry.add(UserAgentFilter.class); } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/TableRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/TableRestProxy.java index 72379bb2582bd..043032a474ab3 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/TableRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/TableRestProxy.java @@ -43,6 +43,7 @@ import com.microsoft.windowsazure.services.blob.implementation.RFC1123DateConverter; import com.microsoft.windowsazure.services.core.ServiceException; import com.microsoft.windowsazure.services.core.ServiceFilter; +import com.microsoft.windowsazure.services.core.UserAgentFilter; import com.microsoft.windowsazure.services.core.utils.CommaStringBuilder; import com.microsoft.windowsazure.services.core.utils.DateFactory; import com.microsoft.windowsazure.services.core.utils.ServiceExceptionFactory; @@ -107,8 +108,9 @@ public class TableRestProxy implements TableContract { @Inject public TableRestProxy(HttpURLConnectionClient channel, @Named(TableConfiguration.URI) String url, - SharedKeyFilter filter, DateFactory dateFactory, ISO8601DateConverter iso8601DateConverter, - AtomReaderWriter atomReaderWriter, MimeReaderWriter mimeReaderWriter, HttpReaderWriter httpReaderWriter) { + SharedKeyFilter filter, UserAgentFilter userAgentFilter, DateFactory dateFactory, + ISO8601DateConverter iso8601DateConverter, AtomReaderWriter atomReaderWriter, + MimeReaderWriter mimeReaderWriter, HttpReaderWriter httpReaderWriter) { this.channel = channel; this.url = url; @@ -121,6 +123,7 @@ public TableRestProxy(HttpURLConnectionClient channel, @Named(TableConfiguration this.mimeReaderWriter = mimeReaderWriter; this.httpReaderWriter = httpReaderWriter; channel.addFilter(filter); + channel.addFilter(userAgentFilter); } public TableRestProxy(HttpURLConnectionClient channel, ServiceFilter[] filters, String url, SharedKeyFilter filter, diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/OAuthRestProxyIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/OAuthRestProxyIntegrationTest.java index f559ba17d5a6f..472b1a6ddfbf0 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/OAuthRestProxyIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/OAuthRestProxyIntegrationTest.java @@ -20,6 +20,7 @@ import org.junit.Test; +import com.microsoft.windowsazure.services.core.UserAgentFilter; import com.microsoft.windowsazure.services.media.IntegrationTestBase; import com.microsoft.windowsazure.services.media.MediaConfiguration; import com.sun.jersey.api.client.Client; @@ -28,7 +29,7 @@ public class OAuthRestProxyIntegrationTest extends IntegrationTestBase { @Test public void serviceCanBeCalledToCreateAccessToken() throws Exception { // Arrange - OAuthContract oAuthContract = new OAuthRestProxy(config.create(Client.class)); + OAuthContract oAuthContract = new OAuthRestProxy(config.create(Client.class), new UserAgentFilter()); // Act URI oAuthUri = new URI((String) config.getProperty(MediaConfiguration.OAUTH_URI)); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java index 580a8909fec5e..3fc50cae73e71 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java @@ -23,6 +23,7 @@ import org.junit.Assert; import org.junit.Test; +import com.microsoft.windowsazure.services.core.UserAgentFilter; import com.microsoft.windowsazure.services.core.utils.DefaultDateFactory; import com.microsoft.windowsazure.services.media.IntegrationTestBase; import com.microsoft.windowsazure.services.media.MediaConfiguration; @@ -72,7 +73,7 @@ public void canBuildJerseyClientToCreateAnAssetWhichIsProperlyDeserialized() thr } private OAuthContract createOAuthContract() { - return new OAuthRestProxy(Client.create()); + return new OAuthRestProxy(Client.create(), new UserAgentFilter()); } private OAuthTokenManager createTokenManager() throws URISyntaxException { diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/implementation/WrapRestProxyIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/implementation/WrapRestProxyIntegrationTest.java index 016de94febc64..7033d388c392b 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/implementation/WrapRestProxyIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/implementation/WrapRestProxyIntegrationTest.java @@ -2,15 +2,15 @@ * Copyright Microsoft Corporation * * Licensed 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 + * 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. + * 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 com.microsoft.windowsazure.services.serviceBus.implementation; @@ -21,6 +21,7 @@ import org.junit.Test; import com.microsoft.windowsazure.services.core.Configuration; +import com.microsoft.windowsazure.services.core.UserAgentFilter; import com.microsoft.windowsazure.services.serviceBus.ServiceBusConfiguration; import com.sun.jersey.api.client.Client; @@ -33,7 +34,7 @@ public void serviceCanBeCalledToCreateAccessToken() throws Exception { overrideWithEnv(config, ServiceBusConfiguration.WRAP_URI); overrideWithEnv(config, ServiceBusConfiguration.WRAP_NAME); overrideWithEnv(config, ServiceBusConfiguration.WRAP_PASSWORD); - WrapContract contract = new WrapRestProxy(config.create(Client.class)); + WrapContract contract = new WrapRestProxy(config.create(Client.class), new UserAgentFilter()); // Act String serviceBusUri = (String) config.getProperty(ServiceBusConfiguration.URI);