Skip to content

Commit

Permalink
Merge pull request Azure#351 from WindowsAzure/release
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
xuezhai committed May 30, 2013
2 parents ecf2f64 + b095b91 commit d039ddd
Show file tree
Hide file tree
Showing 31 changed files with 3,014 additions and 222 deletions.
10 changes: 10 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
2013.05.27 Version 0.4.3
* Added support for updating existing Queue/Topic/Subscription for Service Bus
* Added support for message lock renewal to support long running message processing for Service Bus
* Added new properties to Queue/Topic/Subscription/Rule for Service Bus
* Added support for rebinding content key for Media Services

2013.04.16 Version 0.4.2
* Fixed a bunch of GB18030 encoding issues
* Fixed a service bus issue when the locale is not UTC

2013.03.12 Version 0.4.1
* Added "Azure-SDK-For-Java/<version>" To User-Agent HTTP header
* Added connection string support for Service Bus
Expand Down
55 changes: 33 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
#Windows Azure SDK for Java

This SDK allows you to build Windows Azure applications in Java that allow
you to take advantage of Azure scalable cloud computing resources: table and blob
storage, messaging through Service Bus.

For documentation please see the [Windows Azure Java Developer Center](http://www.windowsazure.com/en-us/develop/java/)
This project provides a client library in Java that makes it easy to consume Windows Azure services. For documentation please see the [Windows Azure Java Developer Center](http://www.windowsazure.com/en-us/develop/java/).

#Features
* Blob
* Create/Read/Update/Delete Blobs
* Queue
* Create/Delete Queues
* Insert/Peek Queue Messages
* Advanced Queue Operations
* Media Services
* Upload Media Files to Media Services
* Change the encoding on uploaded Media Services
* Provide streaming or download access to uploaded/transformed Media Files

* Storage
* Blob
* Create/Read/Update/Delete containers
* Create/Read/Update/Delete blobs
* Queue
* Create/Delete Queues
* Insert/Peek Queue Messages
* Advanced Queue Operations
* Table
* Create/Read/Update/Delete tables
* Create/Read/Update/Delete entities
* Batch operation
* Service Bus
* Use either the Queue or Topic/Subscription Model
* Queues
* Create/Read/Update/Delete queues
* Send/Receive/Unlock/Delete messages
* Renew message lock
* Topics
* Create/Read/Update/Delete topics
* Create/Read/Update/Delete subscriptions
* Create/Read/Update/Delete rules
* Send/Receive/Unlock/Delete messages
* Renew message lock
* Media Services
* Create/Read/Update/Delete access policies
* Create/Read/Update/Delete asset files
* Create/Read/Update/Delete assets
* Create/Read/Update/Delete/Rebind content keys
* Create/Read/Update/Cancel/Delete jobs
* Service Runtime
* Retrieve information about the state of your Azure Compute instances
* Table
* Manage Tables
* Table Entity Operations
* Entity Group Transactions (Batch)
* Retrieve information about the state of your Azure Compute instances


#Getting Started

Expand All @@ -45,7 +56,7 @@ within your project you can also have them installed by the Java package manager
<dependency>
<groupId>com.microsoft.windowsazure</groupId>
<artifactId>microsoft-windowsazure-api</artifactId>
<version>0.4.2</version>
<version>0.4.3</version>
</dependency>

##Minimum Requirements
Expand Down
8 changes: 7 additions & 1 deletion microsoft-azure-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.windowsazure</groupId>
<artifactId>microsoft-windowsazure-api</artifactId>
<version>0.4.2</version>
<version>0.4.3</version>
<packaging>jar</packaging>

<name>Microsoft Windows Azure Client API</name>
Expand Down Expand Up @@ -104,6 +104,12 @@
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk16</artifactId>
<version>1.46</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,29 @@
import com.sun.jersey.api.client.WebResource.Builder;

public class PipelineHelpers {

private static String createErrorMessage(ClientResponse clientResponse) {
clientResponse.bufferEntity();
String errorMessage = clientResponse.toString();
if (clientResponse.hasEntity()) {
errorMessage = errorMessage + " " + clientResponse.getEntity(String.class);
}
return errorMessage;
}

public static void ThrowIfNotSuccess(ClientResponse clientResponse) {
int statusCode = clientResponse.getStatus();

if ((statusCode < 200) || (statusCode >= 300)) {
throw new UniformInterfaceException(clientResponse);
String errorMessage = createErrorMessage(clientResponse);
throw new UniformInterfaceException(errorMessage, clientResponse);
}
}

public static void ThrowIfError(ClientResponse clientResponse) {
if (clientResponse.getStatus() >= 400) {
throw new UniformInterfaceException(clientResponse);
String errorMessage = createErrorMessage(clientResponse);
throw new UniformInterfaceException(errorMessage, clientResponse);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public <T> T action(EntityTypeActionOperation<T> entityTypeActionOperation) thro
.queryParams(entityTypeActionOperation.getQueryParameters())
.accept(entityTypeActionOperation.getAcceptType()).accept(MediaType.APPLICATION_XML_TYPE)
.entity(entityTypeActionOperation.getRequestContents(), MediaType.APPLICATION_XML_TYPE);

ClientResponse clientResponse = webResource.method(entityTypeActionOperation.getVerb(), ClientResponse.class);
return entityTypeActionOperation.processTypeResponse(clientResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public URI getBaseURI() {

public URI getRedirectedURI(URI originalURI) {
UriBuilder uriBuilder = UriBuilder.fromUri(baseURI).path(originalURI.getPath());
String queryString = originalURI.getQuery();
String queryString = originalURI.getRawQuery();

if (queryString != null && !queryString.isEmpty()) {
uriBuilder.replaceQuery(queryString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static StatusLine create(DataSource dataSource) {

private static void expect(Reader reader, String string) {
try {
byte[] byteArray = string.getBytes();
byte[] byteArray = string.getBytes("UTF-8");
int ch;
for (int i = 0; i < string.length(); i++) {
ch = reader.read();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,20 @@ public ContentKeyRestType createContentKeyRestType() {
}

/**
* Create an instance of {@link AssetFileType}
* Create an instance of {@link AssetFileType}.
*
* @return a new AssetFileType instance.
*/
public AssetFileType createAssetFileType() {
return new AssetFileType();
}

/**
* Creates an instance of (@link RebindContentKeyType).
*
* @return the rebind content key type instance.
*/
public RebindContentKeyType createRebindContentKeyType() {
return new RebindContentKeyType();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* 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.media.implementation.content;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;

/**
* The Class RebindContentKeyType.
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "RebindContentKey", namespace = Constants.ODATA_DATA_NS)
public class RebindContentKeyType implements MediaServiceDTO {

/** The rebind content key. */
@XmlValue
String rebindContentKey;

/**
* Gets the content key.
*
* @return the content key
*/
public String getContentKey() {
return rebindContentKey;
}

/**
* Sets the content key.
*
* @param rebindContentKey
* the new content key
*/
public void setContentKey(String rebindContentKey) {
this.rebindContentKey = rebindContentKey;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,30 @@

package com.microsoft.windowsazure.services.media.models;

import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.InvalidParameterException;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;

import com.microsoft.windowsazure.services.core.utils.pipeline.PipelineHelpers;
import com.microsoft.windowsazure.services.media.entityoperations.DefaultDeleteOperation;
import com.microsoft.windowsazure.services.media.entityoperations.DefaultEntityTypeActionOperation;
import com.microsoft.windowsazure.services.media.entityoperations.DefaultGetOperation;
import com.microsoft.windowsazure.services.media.entityoperations.DefaultListOperation;
import com.microsoft.windowsazure.services.media.entityoperations.EntityCreateOperation;
import com.microsoft.windowsazure.services.media.entityoperations.EntityDeleteOperation;
import com.microsoft.windowsazure.services.media.entityoperations.EntityGetOperation;
import com.microsoft.windowsazure.services.media.entityoperations.EntityOperationSingleResultBase;
import com.microsoft.windowsazure.services.media.entityoperations.EntityTypeActionOperation;
import com.microsoft.windowsazure.services.media.implementation.content.ContentKeyRestType;
import com.microsoft.windowsazure.services.media.implementation.content.RebindContentKeyType;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.GenericType;

/**
Expand Down Expand Up @@ -213,4 +229,82 @@ public static EntityDeleteOperation delete(String contentKeyId) {
return new DefaultDeleteOperation(ENTITY_SET, contentKeyId);
}

/**
* Rebind content key with specified content key and X509 Certificate.
*
* @param contentKeyId
* the content key id
* @param x509Certificate
* the x509 certificate
* @return the entity action operation
*/
public static EntityTypeActionOperation<String> rebind(String contentKeyId, String x509Certificate) {
return new RebindContentKeyActionOperation(contentKeyId, x509Certificate);
}

/**
* Rebind content key with specified content key Id.
*
* @param contentKeyId
* the content key id
* @return the entity action operation
*/
public static EntityTypeActionOperation<String> rebind(String contentKeyId) {
return rebind(contentKeyId, "");
}

private static class RebindContentKeyActionOperation extends DefaultEntityTypeActionOperation<String> {
private final JAXBContext jaxbContext;

private final Unmarshaller unmarshaller;

public RebindContentKeyActionOperation(String contentKeyId, String x509Certificate) {
super("RebindContentKey");

String escapedContentKeyId;
try {
escapedContentKeyId = URLEncoder.encode(contentKeyId, "UTF-8");
}
catch (UnsupportedEncodingException e) {
throw new InvalidParameterException("UTF-8 encoding is not supported.");
}
this.addQueryParameter("x509Certificate", "'" + x509Certificate + "'");
this.addQueryParameter("id", "'" + escapedContentKeyId + "'");

try {
jaxbContext = JAXBContext.newInstance(RebindContentKeyType.class);
}
catch (JAXBException e) {
throw new RuntimeException(e);
}

try {
unmarshaller = jaxbContext.createUnmarshaller();
}
catch (JAXBException e) {
throw new RuntimeException(e);
}
}

@Override
public String processTypeResponse(ClientResponse clientResponse) {
PipelineHelpers.ThrowIfNotSuccess(clientResponse);
RebindContentKeyType rebindContentKeyType = parseResponse(clientResponse);
return rebindContentKeyType.getContentKey();
}

private RebindContentKeyType parseResponse(ClientResponse clientResponse) {
InputStream inputStream = clientResponse.getEntityInputStream();
JAXBElement<RebindContentKeyType> rebindContentKeyTypeJaxbElement;
try {
rebindContentKeyTypeJaxbElement = unmarshaller.unmarshal(new StreamSource(inputStream),
RebindContentKeyType.class);
}
catch (JAXBException e) {
throw new RuntimeException(e);
}
return rebindContentKeyTypeJaxbElement.getValue();
}

}
}
Loading

0 comments on commit d039ddd

Please sign in to comment.