Skip to content

Commit

Permalink
Annotation parser refactor (Azure#193)
Browse files Browse the repository at this point in the history
* Rename classes in RestProxy, inline populateMatrix() function

* Working on proxy details classes

* Rearrange v2 RestProxy classes and add tests

* Fix checkstyle errors

* Pass checkstyle. Extract HttpClient and SerializerAdapter from RestClient for RestProxy

* Updates based on pull request reviews
  • Loading branch information
Dan Schulte authored and jianghaolu committed Aug 16, 2017
1 parent 08e7fda commit 856a8f6
Show file tree
Hide file tree
Showing 18 changed files with 1,106 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface HttpBinService {
String getSecret(@HostParam String vaultBaseUrl, @PathParam("secretName") String secretName);
}

// @AzureHost not yet supported.
// @AzureHost not yet supported.
// @Test
// public void getBytes() throws Exception {
// RestClient client = new RestClient.Builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/

package com.microsoft.rest.v2;

/**
* An EncodedParameter is the result of encoding a query parameter or header name/value pair for a
* HTTP request. It contains the query parameter or header name, plus the query parameter's value or
* header's value.
*/
class EncodedParameter {
private final String name;
private final String encodedValue;

/**
* Create a new EncodedParameter using the provided parameter name and encoded value.
* @param name The name of the new parameter.
* @param encodedValue The encoded value of the new parameter.
*/
EncodedParameter(String name, String encodedValue) {
this.name = name;
this.encodedValue = encodedValue;
}

/**
* Get this parameter's name.
* @return The name of this parameter.
*/
public String name() {
return name;
}

/**
* Get the encoded value for this parameter.
* @return The encoded value for this parameter.
*/
public String encodedValue() {
return encodedValue;
}

/**
* Get whether or not this value equals the provided rhs value.
* @param rhs The value to compare against this value.
* @return Whether or not this value equals the provided rhs value.
*/
@Override
public boolean equals(Object rhs) {
return rhs instanceof EncodedParameter ? equals((EncodedParameter) rhs) : false;
}

/**
* Get whether or not this value equals the provided rhs value.
* @param rhs The value to compare against this value.
* @return Whether or not this value equals the provided rhs value.
*/
public boolean equals(EncodedParameter rhs) {
return rhs != null
&& name.equals(rhs.name)
&& encodedValue.equals(rhs.encodedValue);
}

/**
* Get the unique hash code for this value.
* @return The unique hash code for this value.
*/
@Override
public int hashCode() {
return name.hashCode() ^ encodedValue.hashCode();
}
}
277 changes: 119 additions & 158 deletions client-runtime/src/main/java/com/microsoft/rest/v2/RestProxy.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/

package com.microsoft.rest.v2;

/**
* A Substitution is a value that can be used to replace placeholder values in a URL. Placeholders
* look like: "http://{host}.com/{fileName}.html", where "{host}" and "{fileName}" are the
* placeholders.
*/
class Substitution {
private final String urlParameterName;
private final int methodParameterIndex;
private final boolean shouldEncode;

/**
* Create a new Substitution.
* @param urlParameterName The name that is used between curly quotes as a placeholder in the
* target URL.
* @param methodParameterIndex The index of the parameter in the original interface method where
* the value for the placeholder is.
* @param shouldEncode Whether or not the value from the method's argument should be encoded
* when the substitution is taking place.
*/
Substitution(String urlParameterName, int methodParameterIndex, boolean shouldEncode) {
this.urlParameterName = urlParameterName;
this.methodParameterIndex = methodParameterIndex;
this.shouldEncode = shouldEncode;
}

/**
* Get the placeholder's name.
* @return The name of the placeholder.
*/
public String urlParameterName() {
return urlParameterName;
}

/**
* Get the index of the method parameter where the replacement value is.
* @return The index of the method parameter where the replacement value is.
*/
public int methodParameterIndex() {
return methodParameterIndex;
}

/**
* Get whether or not the replacement value from the method argument needs to be encoded when the
* substitution is taking place.
* @return Whether or not the replacement value from the method argument needs to be encoded
* when the substitution is taking place.
*/
public boolean shouldEncode() {
return shouldEncode;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/

package com.microsoft.rest.v2;

import java.util.HashMap;
import java.util.Map;

/**
* Details that are associated with an interface that is generated from a Swagger specification.
* This is generally used by a proxy implementation of the Swagger interface.
*/
class SwaggerInterfaceProxyDetails {
private final Map<String, SwaggerMethodProxyDetails> methodDetails = new HashMap<>();

/**
* Create and return a SwaggerMethodProxyDetails object that is associated with the provided
* methodName. If a SwaggerMethodProxyDetails object is already associated with the provided
* methodName, then the existing object will be returned.
* @param methodName The name of the method.
* @return The SwaggerMethodProxyDetails object that is associated with the provided methodName.
*/
public SwaggerMethodProxyDetails getMethodProxyDetails(String methodName) {
SwaggerMethodProxyDetails result = methodDetails.get(methodName);
if (result == null) {
result = new SwaggerMethodProxyDetails();
methodDetails.put(methodName, result);
}
return result;
}
}
Loading

0 comments on commit 856a8f6

Please sign in to comment.