JaxrsResourceMethodParameters params = resourceMethod.getParameters();
// construct path using @PathParams and @MatrixParams
String path = resourceMethod.getPath();
ContextualStatementBuilder pathValue = Stmt.loadLiteral(path);
for (String pathParamName : JaxrsResourceMethodParameters.getPathParameterNames(path)) {
pathValue = pathValue.invoke("replace", "{" + pathParamName + "}",
encodePath(marshal(params.getPathParameter(pathParamName))));
}
if (params.getMatrixParameters() != null) {
for (String matrixParamName : params.getMatrixParameters().keySet()) {
pathValue = pathValue.invoke("concat", ";" + matrixParamName + "=")
.invoke("concat", encodePath(marshal(params.getMatrixParameter(matrixParamName))));
}
}
ContextualStatementBuilder urlBuilder = Stmt.loadVariable("url").invoke(APPEND, pathValue);
// construct query using @QueryParams
if (params.getQueryParameters() != null) {
urlBuilder = urlBuilder.invoke(APPEND, "?");
int i = 0;
for (String queryParamName : params.getQueryParameters().keySet()) {
for (Parameter queryParam : params.getQueryParameters(queryParamName)) {
if (i++ > 0)
urlBuilder = urlBuilder.invoke(APPEND, "&");
urlBuilder = urlBuilder.invoke(APPEND, queryParamName).invoke(APPEND, "=")
.invoke(APPEND, encodeQuery(marshal(queryParam)));
}
}
}