Permalink
Browse files

Merge pull request #85 from gcheng/betteraction

DCR of action to expose two types of action API
  • Loading branch information...
2 parents 1a1717e + fd3b016 commit 9f0b32fc951596ff542756723c9f0ae216b4a2b9 Albert Cheng committed Jan 9, 2013
@@ -30,6 +30,7 @@
import com.microsoft.windowsazure.services.media.implementation.entities.EntityDeleteOperation;
import com.microsoft.windowsazure.services.media.implementation.entities.EntityGetOperation;
import com.microsoft.windowsazure.services.media.implementation.entities.EntityListOperation;
+import com.microsoft.windowsazure.services.media.implementation.entities.EntityTypeActionOperation;
import com.microsoft.windowsazure.services.media.implementation.entities.EntityUpdateOperation;
import com.microsoft.windowsazure.services.media.models.ListResult;
import com.microsoft.windowsazure.services.media.models.LocatorInfo;
@@ -176,9 +177,25 @@ public void delete(EntityDeleteOperation deleter) throws ServiceException {
* @see com.microsoft.windowsazure.services.media.implementation.entities.EntityContract#action(com.microsoft.windowsazure.services.media.implementation.entities.EntityActionOperation)
*/
@Override
- public Object action(EntityActionOperation action) throws ServiceException {
+ public void action(EntityActionOperation entityActionOperation) throws ServiceException {
try {
- return service.action(action);
+ service.action(entityActionOperation);
+ }
+ catch (UniformInterfaceException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ catch (ClientHandlerException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.implementation.entities.EntityContract#action(com.microsoft.windowsazure.services.media.implementation.entities.EntityTypeActionOperation)
+ */
+ @Override
+ public <T> T action(EntityTypeActionOperation<T> entityTypeActionOperation) throws ServiceException {
+ try {
+ return service.action(entityTypeActionOperation);
}
catch (UniformInterfaceException e) {
throw processCatch(new ServiceException(e));
@@ -27,6 +27,8 @@
* Generic implementation of Delete operation usable by most entities.
*/
public class DefaultActionOperation implements EntityActionOperation {
+
+ /** The proxy data. */
private EntityProxyData proxyData;
/** The name. */
@@ -39,7 +41,7 @@
private MediaType acceptType = MediaType.APPLICATION_ATOM_XML_TYPE;
/** The query parameters. */
- protected final MultivaluedMap<String, String> queryParameters;
+ protected MultivaluedMap<String, String> queryParameters;
/**
* The default action operation.
@@ -68,7 +70,7 @@ public void setProxyData(EntityProxyData proxyData) {
}
/**
- * Get the current proxy data
+ * Get the current proxy data.
*
* @return the proxy data
*/
@@ -116,6 +118,7 @@ public MediaType getContentType() {
* the content type
* @return the default action operation
*/
+ @Override
public DefaultActionOperation setContentType(MediaType contentType) {
this.contentType = contentType;
return this;
@@ -142,15 +145,6 @@ public DefaultActionOperation setAcceptType(MediaType acceptType) {
}
/* (non-Javadoc)
- * @see com.microsoft.windowsazure.services.media.implementation.entities.EntityActionOperation#processResponse(com.sun.jersey.api.client.ClientResponse)
- */
- @Override
- public Object processResponse(ClientResponse clientResponse) {
- PipelineHelpers.ThrowIfNotSuccess(clientResponse);
- return null;
- }
-
- /* (non-Javadoc)
* @see com.microsoft.windowsazure.services.media.implementation.entities.EntityActionOperation#getVerb()
*/
@Override
@@ -166,8 +160,13 @@ public Object getRequestContents() {
return null;
}
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.implementation.entities.EntityOperation#processResponse(java.lang.Object)
+ */
@Override
public Object processResponse(Object rawResponse) throws ServiceException {
+ PipelineHelpers.ThrowIfNotSuccess((ClientResponse) rawResponse);
return rawResponse;
}
+
}
@@ -0,0 +1,165 @@
+/**
+ * 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.entities;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+
+import com.microsoft.windowsazure.services.core.ServiceException;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+
+/**
+ * The Class DefaultTypeActionOperation.
+ *
+ * @param <T>
+ * the generic type
+ */
+public class DefaultEntityTypeActionOperation<T> implements EntityTypeActionOperation<T> {
+
+ /** The name. */
+ private String name;
+
+ /** The content type. */
+ private MediaType contentType = MediaType.APPLICATION_ATOM_XML_TYPE;
+
+ /** The accept type. */
+ private MediaType acceptType = MediaType.APPLICATION_ATOM_XML_TYPE;
+
+ /** The query parameters. */
+ private final MultivaluedMap<String, String> queryParameters;
+
+ /** The proxy data. */
+ protected EntityProxyData proxyData;
+
+ /**
+ * Instantiates a new default type action operation.
+ *
+ * @param name
+ * the name
+ */
+ public DefaultEntityTypeActionOperation(String name) {
+ this();
+ this.name = name;
+ }
+
+ /**
+ * Instantiates a new default type action operation.
+ */
+ public DefaultEntityTypeActionOperation() {
+ this.queryParameters = new MultivaluedMapImpl();
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.implementation.entities.EntityTypeActionOperation#processTypeResponse(com.sun.jersey.api.client.ClientResponse)
+ */
+ @Override
+ public T processTypeResponse(ClientResponse clientResponse) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.implementation.entities.EntityTypeActionOperation#getQueryParameters()
+ */
+ @Override
+ public MultivaluedMap<String, String> getQueryParameters() {
+ return this.queryParameters;
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.implementation.entities.EntityTypeActionOperation#getVerb()
+ */
+ @Override
+ public String getVerb() {
+ return "GET";
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.implementation.entities.EntityTypeActionOperation#getRequestContents()
+ */
+ @Override
+ public Object getRequestContents() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.implementation.entities.EntityOperation#setProxyData(com.microsoft.windowsazure.services.media.implementation.entities.EntityProxyData)
+ */
+ @Override
+ public void setProxyData(EntityProxyData proxyData) {
+ this.proxyData = proxyData;
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.implementation.entities.EntityOperation#getUri()
+ */
+ @Override
+ public String getUri() {
+ return this.name;
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.implementation.entities.EntityOperation#getContentType()
+ */
+ @Override
+ public MediaType getContentType() {
+ return this.contentType;
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.implementation.entities.EntityOperation#getAcceptType()
+ */
+ @Override
+ public MediaType getAcceptType() {
+ return this.acceptType;
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.implementation.entities.EntityOperation#processResponse(java.lang.Object)
+ */
+ @Override
+ public Object processResponse(Object rawResponse) throws ServiceException {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.implementation.entities.EntityTypeActionOperation#addQueryParameter(java.lang.String, java.lang.String)
+ */
+ @Override
+ public DefaultEntityTypeActionOperation<T> addQueryParameter(String key, String value) {
+ this.queryParameters.add(key, value);
+ return this;
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.implementation.entities.EntityTypeActionOperation#setContentType(javax.ws.rs.core.MediaType)
+ */
+ @Override
+ public EntityTypeActionOperation<T> setContentType(MediaType contentType) {
+ this.contentType = contentType;
+ return this;
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.implementation.entities.EntityTypeActionOperation#setAcceptType(javax.ws.rs.core.MediaType)
+ */
+ @Override
+ public EntityTypeActionOperation<T> setAcceptType(MediaType acceptType) {
+ this.acceptType = acceptType;
+ return this;
+ }
+
+}
@@ -15,10 +15,9 @@
package com.microsoft.windowsazure.services.media.implementation.entities;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
-import com.sun.jersey.api.client.ClientResponse;
-
/**
* Action operation for Entities.
*/
@@ -43,15 +42,6 @@
EntityActionOperation addQueryParameter(String key, String value);
/**
- * Process response.
- *
- * @param clientResponse
- * the client response
- * @return the object
- */
- Object processResponse(ClientResponse clientResponse);
-
- /**
* Gets the verb.
*
* @return the verb
@@ -65,4 +55,13 @@
*/
Object getRequestContents();
+ /**
+ * Sets the content type.
+ *
+ * @param contentType
+ * the content type
+ * @return the default action operation
+ */
+ EntityActionOperation setContentType(MediaType contentType);
+
}
Oops, something went wrong.

0 comments on commit 9f0b32f

Please sign in to comment.