Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #342

Merged
merged 38 commits into from
May 17, 2013
Merged

Dev #342

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1fd4cbd
partial checkin of rebind content key to allow compilation.
Feb 1, 2013
3e47119
update rebind content key.
Feb 6, 2013
0f77e6d
rebind content key working without X509Certificate working.
Feb 8, 2013
861b366
fix the query parameter escape problem.
Mar 4, 2013
73b6643
Merge branch 'dev' of https://github.com/gcheng/azure-sdk-for-java in…
Mar 4, 2013
3b2b413
update rebind content key unit test using X509 Certificate.
Mar 5, 2013
46d50dc
repro of the client side decryption problem.
Mar 13, 2013
7692cdb
add certificate creation algorithm.
Mar 27, 2013
b8e9151
successful running of unit tests.
Apr 8, 2013
40af700
remove the hard coded dependency on certificate.
Apr 8, 2013
97ec64c
Remove un-used code, get unit tests passed.
Apr 9, 2013
7a47f34
Remove unused comments.
Apr 9, 2013
dd2a0d3
address code review feedback.
Apr 9, 2013
44e2421
Merge pull request #13 from gcheng/rebindcontentkey
Apr 9, 2013
5740210
Merge pull request #319 from gcheng/dev
Apr 9, 2013
5e17ffd
allow space in file path for unit test files.
Apr 10, 2013
90b28e1
Merge pull request #30 from gcheng/rebindcontentkey
Apr 11, 2013
f85f1e0
Merge pull request #321 from gcheng/dev
Apr 11, 2013
e745872
ensure the tests can be passed on machines with space in directory name.
Apr 11, 2013
3e44038
Exposing error message body for UniformInterfaceException
Apr 12, 2013
11992bb
Merge pull request #32 from WindowsAzure/dev
Apr 12, 2013
53de17d
Merge pull request #33 from gcheng/dev
Apr 12, 2013
bdc1c7d
Merge pull request #31 from gcheng/bettererror
Apr 12, 2013
6e5475c
Merge pull request #324 from gcheng/dev
Apr 12, 2013
4975d23
fix empty queue scenario.
Apr 19, 2013
2fe266a
Merge pull request #34 from gcheng/emptyQueue
Apr 22, 2013
17f6254
Merge pull request #329 from gcheng/dev
Apr 22, 2013
2dfa49e
fix the getBytes for StatusLine class.
Apr 23, 2013
efe2872
Merge pull request #35 from gcheng/global
Apr 24, 2013
8886e89
Merge pull request #332 from gcheng/dev
Apr 24, 2013
04a1cc6
fix a test failure due to nimbus update.
Apr 29, 2013
d292204
Merge pull request #36 from gcheng/nimbustestfix
Apr 30, 2013
37c0aab
Merge pull request #334 from gcheng/dev
Apr 30, 2013
e62d01a
fix a unit test failure on ci server.
May 10, 2013
40d1b00
fix for issue 314, remove codehaus exception
May 10, 2013
112fde7
Merge pull request #38 from gcheng/codehausbugfix
May 10, 2013
2a3347e
Merge pull request #37 from gcheng/serviceruntimebug
May 10, 2013
4ebe62f
Merge pull request #338 from gcheng/dev
May 10, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions microsoft-azure-api/pom.xml
Original file line number Diff line number Diff line change
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();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ else if (options.isPeekLock()) {
throw new RuntimeException("Unknown ReceiveMode");
}

if (clientResult.getStatus() == 204) {
return null;
}

BrokerProperties brokerProperties;
if (clientResult.getHeaders().containsKey("BrokerProperties")) {
brokerProperties = mapper.fromString(clientResult.getHeaders().getFirst("BrokerProperties"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public RoleEnvironmentData deserialize(InputStream stream) {
}

try {
Thread.sleep(1000);
Thread.sleep(2000);
}
catch (InterruptedException e) {
e.printStackTrace();
Expand Down
Loading