Skip to content

Commit

Permalink
Merge pull request Azure#24 from gcheng/RefactorUrlEncoding
Browse files Browse the repository at this point in the history
refactor url encoding logic.
  • Loading branch information
Albert Cheng committed Oct 10, 2012
2 parents 7021a19 + 1614370 commit 24591c6
Showing 1 changed file with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ private WebResource getResource(String entityType, String entityId) throws Servi
return getResource(entityPath);
}

private <T> T mergeRequest(String path, java.lang.Class<T> c, java.lang.Object requestEntity) {
WebResource resource = getResource(path);
private <T> T mergeRequest(String entityType, String entityId, java.lang.Class<T> c, java.lang.Object requestEntity)
throws ServiceException {
WebResource resource = getResource(entityType, entityId);
WebResource.Builder builder = resource.getRequestBuilder();
builder = builder.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML)
.header("X-HTTP-Method", "MERGE");
Expand Down Expand Up @@ -218,14 +219,7 @@ public List<AssetInfo> listAssets() {
*/
@Override
public void updateAsset(String assetId, UpdateAssetOptions updateAssetOptions) throws ServiceException {
String escapedAssetId = null;
try {
escapedAssetId = URLEncoder.encode(assetId, "UTF-8");
}
catch (UnsupportedEncodingException e) {
throw new ServiceException(e);
}
String assetPath = String.format("Assets(\'%s\')", escapedAssetId);

AssetType updatedAssetType = new AssetType();
updatedAssetType.setAlternateId(updateAssetOptions.getAlternateId());
updatedAssetType.setName(updateAssetOptions.getName());
Expand All @@ -237,7 +231,7 @@ public void updateAsset(String assetId, UpdateAssetOptions updateAssetOptions) t
updatedAssetType.setState(updateAssetOptions.getState().getCode());
}

ClientResponse clientResponse = mergeRequest(assetPath, ClientResponse.class, updatedAssetType);
ClientResponse clientResponse = mergeRequest("Assets", assetId, ClientResponse.class, updatedAssetType);
PipelineHelpers.ThrowIfNotSuccess(clientResponse);
}

Expand Down

0 comments on commit 24591c6

Please sign in to comment.