Skip to content

Commit

Permalink
Merge pull request #369 from WindowsAzure/dev
Browse files Browse the repository at this point in the history
Prepare 0.4.4 release.
  • Loading branch information
Albert Cheng committed Jun 25, 2013
2 parents b095b91 + 3413c7d commit 663f72a
Show file tree
Hide file tree
Showing 17 changed files with 745 additions and 135 deletions.
117 changes: 57 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ To get the source code of the SDK via git just type:
To get the binaries of this library as distributed by Microsoft, ready for use
within your project you can also have them installed by the Java package manager Maven.

<dependency>
<groupId>com.microsoft.windowsazure</groupId>
<artifactId>microsoft-windowsazure-api</artifactId>
<version>0.4.3</version>
</dependency>
```xml
<dependency>
<groupId>com.microsoft.windowsazure</groupId>
<artifactId>microsoft-windowsazure-api</artifactId>
<version>0.4.2</version>
</dependency>
```

##Minimum Requirements

Expand All @@ -72,67 +74,62 @@ account. To host your Java code in Windows Azure, you additionally need to down
the full Windows Azure SDK for Java - which includes packaging, emulation, and
deployment tools.

##Code Samples
##Code Sample

The following is a quick example on how to set up a Azure blob using the API
and uploading a file to it. For additional information on using the client libraries to access Azure services see the How To guides listed [here](http://www.windowsazure.com/en-us/develop/java/).

```java
import java.io.*;

import com.microsoft.windowsazure.services.core.storage.*;
import com.microsoft.windowsazure.services.blob.client.*;

public class BlobSample {
public static final String storageConnectionString =
"DefaultEndpointsProtocol=http;"
+ "AccountName=your_account_name;"
+ "AccountKey= your_account_key";

public static void main(String[] args) {
try {
CloudStorageAccount account;
CloudBlobClient serviceClient;
CloudBlobContainer container;
CloudBlockBlob blob;

account = CloudStorageAccount.parse(storageConnectionString);
serviceClient = account.createCloudBlobClient();
// Container name must be lower case.
container = serviceClient.getContainerReference("blobsample");
container.createIfNotExist();

// Set anonymous access on the container.
BlobContainerPermissions containerPermissions;
containerPermissions = new BlobContainerPermissions();
container.uploadPermissions(containerPermissions);

// Upload an image file.
blob = container.getBlockBlobReference("image1.jpg");
File fileReference = new File("c:\\myimages\\image1.jpg");
blob.upload(new FileInputStream(fileReference), fileReference.length());
} catch (FileNotFoundException fileNotFoundException) {
System.out.print("FileNotFoundException encountered: ");
System.out.println(fileNotFoundException.getMessage());
System.exit(-1);
} catch (StorageException storageException) {
System.out.print("StorageException encountered: ");
System.out.println(storageException.getMessage());
System.exit(-1);
} catch (Exception e) {
System.out.print("Exception encountered: ");
System.out.println(e.getMessage());
System.exit(-1);
}

import com.microsoft.windowsazure.services.core.storage.*;
import com.microsoft.windowsazure.services.blob.client.*;

public class BlobSample {
public static final String storageConnectionString =
"DefaultEndpointsProtocol=http;" +
"AccountName=your_account_name;" +
"AccountKey= your_account_name";

public static void main(String[] args)
{
try
{
CloudStorageAccount account;
CloudBlobClient serviceClient;
CloudBlobContainer container;
CloudBlockBlob blob;
account = CloudStorageAccount.parse(storageConnectionString);
serviceClient = account.createCloudBlobClient();
// Container name must be lower case.
container = serviceClient.getContainerReference("blobsample");
container.createIfNotExist();
// Set anonymous access on the container.
BlobContainerPermissions containerPermissions;
containerPermissions = new BlobContainerPermissions();

// Upload an image file.
blob = container.getBlockBlobReference("image1.jpg");
File fileReference = new File ("c:\\myimages\\image1.jpg");
blob.upload(new FileInputStream(fileReference), fileReference.length());
}
catch (FileNotFoundException fileNotFoundException)
{
System.out.print("FileNotFoundException encountered: ");
System.out.println(fileNotFoundException.getMessage());
System.exit(-1);
}
catch (StorageException storageException)
{
System.out.print("StorageException encountered: ");
System.out.println(storageException.getMessage());
System.exit(-1);
}
catch (Exception e)
{
System.out.print("Exception encountered: ");
System.out.println(e.getMessage());
System.exit(-1);
}

}
}

}
```

#Need Help?

Expand Down
8 changes: 5 additions & 3 deletions microsoft-azure-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.0</version>
<version>0.8.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
Expand All @@ -154,16 +154,18 @@
</executions>
<configuration>
<extension>true</extension>
<debug>true</debug>
<verbose>true</verbose>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.0</version>
<version>0.6.4</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.0</version>
<version>0.6.4</version>
</plugin>
</plugins>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ ReceiveSubscriptionMessageResult receiveSubscriptionMessage(String topicPath, St
/**
* Creates a queue.
*
* @param queue
* A <code>Queue</code> object that represents the queue to create.
* @param queueInfo
* A <code>QueueInfo</code> object that represents the queue to create.
* @return A <code>CreateQueueResult</code> object that represents the result.
* @throws ServiceException
* If a service exception is encountered.
*/
CreateQueueResult createQueue(QueueInfo queue) throws ServiceException;
CreateQueueResult createQueue(QueueInfo queueInfo) throws ServiceException;

/**
* Deletes a queue.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* 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.
Expand All @@ -15,29 +15,30 @@

package com.microsoft.windowsazure.services.serviceBus.implementation;

import com.microsoft.windowsazure.services.core.utils.ConnectionStringSyntaxException;

import java.net.URI;
import java.net.URISyntaxException;

import com.microsoft.windowsazure.services.core.utils.ConnectionStringSyntaxException;

/**
* Class that encapsulates all the various settings needed
* to connect to Service Bus, provided via either a
* connection string or via separate configuration variables.
* <p/>
* The connection string is looked for first, falling back
* to separate config values if not found.
* The connection string is looked for first, falling back to separate config values if not found.
*/
class ServiceBusConnectionSettings {
private String uri;
private String wrapUri;
private String wrapName;
private String wrapPassword;

public ServiceBusConnectionSettings(String connectionString, String uri, String wrapUri, String wrapName, String wrapPassword) throws ConnectionStringSyntaxException, URISyntaxException {
public ServiceBusConnectionSettings(String connectionString, String uri, String wrapUri, String wrapName,
String wrapPassword) throws ConnectionStringSyntaxException, URISyntaxException {
if (connectionString != null) {
parseConnectionString(connectionString);
} else {
}
else {
this.uri = uri;
this.wrapUri = wrapUri;
this.wrapName = wrapName;
Expand All @@ -61,7 +62,8 @@ public String getWrapPassword() {
return wrapPassword;
}

private boolean parseConnectionString(String connectionString) throws URISyntaxException, ConnectionStringSyntaxException {
private boolean parseConnectionString(String connectionString) throws URISyntaxException,
ConnectionStringSyntaxException {
ServiceBusConnectionString cs = new ServiceBusConnectionString(connectionString);
setUri(cs);
setWrapUri(cs);
Expand All @@ -79,8 +81,9 @@ private void setWrapUri(ServiceBusConnectionString connectionString) throws URIS
URI hostUri = new URI(uri);
String namespace = hostUri.getHost().split("\\.")[0];
wrapUri = "https://" + namespace + "-sb.accesscontrol.windows.net/WRAPv0.9";
} else {
wrapUri = connectionString.getStsEndpoint();
}
else {
wrapUri = connectionString.getStsEndpoint().replaceAll("\\/$", "") + "/WRAPv0.9";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,13 @@ public void deleteMessage(BrokeredMessage message) throws ServiceException {
}

@Override
public CreateQueueResult createQueue(QueueInfo entry) throws ServiceException {
return new CreateQueueResult(getResource().path(entry.getPath())
.type("application/atom+xml;type=entry;charset=utf-8").put(QueueInfo.class, entry));
public CreateQueueResult createQueue(QueueInfo queueInfo) throws ServiceException {
Builder webResourceBuilder = getResource().path(queueInfo.getPath()).type(
"application/atom+xml;type=entry;charset=utf-8");
if ((queueInfo.getForwardTo() != null) && !queueInfo.getForwardTo().isEmpty()) {
webResourceBuilder.header("ServiceBusSupplementaryAuthorization", queueInfo.getForwardTo());
}
return new CreateQueueResult(webResourceBuilder.put(QueueInfo.class, queueInfo));
}

@Override
Expand All @@ -296,8 +300,12 @@ public ListQueuesResult listQueues(ListQueuesOptions options) throws ServiceExce

@Override
public QueueInfo updateQueue(QueueInfo queueInfo) throws ServiceException {
return getResource().path(queueInfo.getPath()).type("application/atom+xml;type=entry;charset=utf-8")
.header("If-Match", "*").put(QueueInfo.class, queueInfo);
Builder webResourceBuilder = getResource().path(queueInfo.getPath())
.type("application/atom+xml;type=entry;charset=utf-8").header("If-Match", "*");
if ((queueInfo.getForwardTo() != null) && !queueInfo.getForwardTo().isEmpty()) {
webResourceBuilder.header("ServiceBusSupplementaryAuthorization", queueInfo.getForwardTo());
}
return webResourceBuilder.put(QueueInfo.class, queueInfo);
}

private WebResource listOptions(AbstractListOptions<?> options, WebResource path) {
Expand All @@ -307,6 +315,9 @@ private WebResource listOptions(AbstractListOptions<?> options, WebResource path
if (options.getSkip() != null) {
path = path.queryParam("$skip", options.getSkip().toString());
}
if (options.getFilter() != null) {
path = path.queryParam("$filter", options.getFilter());
}
return path;
}

Expand Down Expand Up @@ -345,10 +356,14 @@ public TopicInfo updateTopic(TopicInfo topicInfo) throws ServiceException {
}

@Override
public CreateSubscriptionResult createSubscription(String topicPath, SubscriptionInfo subscription) {
return new CreateSubscriptionResult(getResource().path(topicPath).path("subscriptions")
.path(subscription.getName()).type("application/atom+xml;type=entry;charset=utf-8")
.put(SubscriptionInfo.class, subscription));
public CreateSubscriptionResult createSubscription(String topicPath, SubscriptionInfo subscriptionInfo) {
Builder webResourceBuilder = getResource().path(topicPath).path("subscriptions")
.path(subscriptionInfo.getName()).type("application/atom+xml;type=entry;charset=utf-8");
if ((subscriptionInfo.getForwardTo() != null) && (!subscriptionInfo.getForwardTo().isEmpty())) {
webResourceBuilder.header("ServiceBusSupplementaryAuthorization", subscriptionInfo.getForwardTo());

}
return new CreateSubscriptionResult(webResourceBuilder.put(SubscriptionInfo.class, subscriptionInfo));
}

@Override
Expand Down Expand Up @@ -377,9 +392,13 @@ public ListSubscriptionsResult listSubscriptions(String topicPath, ListSubscript
@Override
public SubscriptionInfo updateSubscription(String topicName, SubscriptionInfo subscriptionInfo)
throws ServiceException {
return getResource().path(topicName).path("subscriptions").path(subscriptionInfo.getName())
.type("application/atom+xml;type=entry;charset=utf-8").header("If-Match", "*")
.put(SubscriptionInfo.class, subscriptionInfo);
Builder webResourceBuilder = getResource().path(topicName).path("subscriptions")
.path(subscriptionInfo.getName()).type("application/atom+xml;type=entry;charset=utf-8")
.header("If-Match", "*");
if ((subscriptionInfo.getForwardTo() != null) && !subscriptionInfo.getForwardTo().isEmpty()) {
webResourceBuilder.header("ServiceBusSupplementaryAuthorization", subscriptionInfo.getForwardTo());
}
return webResourceBuilder.put(SubscriptionInfo.class, subscriptionInfo);
}

@Override
Expand Down
Loading

0 comments on commit 663f72a

Please sign in to comment.