use of javax.ws.rs.QueryParam in project jersey by jersey.
the class InjectLinkFieldDescriptor method extractQueryParams.
private static CharSequence extractQueryParams(AnnotatedMethod method) throws SecurityException {
// append query parameters
StringBuilder querySubString = new StringBuilder();
int parameterIndex = 0;
for (Annotation[] paramAnns : method.getParameterAnnotations()) {
for (Annotation ann : paramAnns) {
if (ann.annotationType() == QueryParam.class) {
querySubString.append(((QueryParam) ann).value());
querySubString.append(',');
}
if (ann.annotationType() == BeanParam.class) {
Class<?> beanParamType = method.getParameterTypes()[parameterIndex];
Field[] fields = beanParamType.getFields();
for (Field field : fields) {
QueryParam queryParam = field.getAnnotation(QueryParam.class);
if (queryParam != null) {
querySubString.append(queryParam.value());
querySubString.append(',');
}
}
Method[] beanMethods = beanParamType.getMethods();
for (Method beanMethod : beanMethods) {
QueryParam queryParam = beanMethod.getAnnotation(QueryParam.class);
if (queryParam != null) {
querySubString.append(queryParam.value());
querySubString.append(',');
}
}
}
}
parameterIndex++;
}
CharSequence result = "";
if (querySubString.length() > 0) {
result = querySubString.subSequence(0, querySubString.length() - 1);
}
return result;
}
use of javax.ws.rs.QueryParam in project helios by spotify.
the class HostsResource method list.
/**
* Returns the list of hostnames of known hosts/agents.
* @return The list of hostnames.
*/
@GET
@Produces(APPLICATION_JSON)
@Timed
@ExceptionMetered
public List<String> list(@QueryParam("namePattern") final String namePattern, @QueryParam("selector") final List<String> hostSelectors) {
List<String> hosts = model.listHosts();
if (namePattern != null) {
final Predicate<String> matchesPattern = Pattern.compile(namePattern).asPredicate();
hosts = hosts.stream().filter(matchesPattern).collect(Collectors.toList());
}
if (!hostSelectors.isEmpty()) {
// check that all supplied selectors are parseable/valid
final List<HostSelector> selectors = hostSelectors.stream().map(selectorStr -> {
final HostSelector parsed = HostSelector.parse(selectorStr);
if (parsed == null) {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity("Invalid host selector: " + selectorStr).build());
}
return parsed;
}).collect(Collectors.toList());
final Map<String, Map<String, String>> hostsAndLabels = getLabels(hosts);
final HostMatcher matcher = new HostMatcher(hostsAndLabels);
hosts = matcher.getMatchingHosts(selectors);
}
return hosts;
}
use of javax.ws.rs.QueryParam in project keywhiz by square.
the class AutomationGroupResource method getGroupByName.
/**
* Retrieve Group by a specified name, or all Groups if no name given
*
* @param name the name of the Group to retrieve, if provided
* @excludeParams automationClient
* @optionalParams name
* @description Returns a single Group or a set of all Groups
* @responseMessage 200 Found and retrieved Group(s)
* @responseMessage 404 Group with given name not found (if name provided)
*/
@Timed
@ExceptionMetered
@GET
public Response getGroupByName(@Auth AutomationClient automationClient, @QueryParam("name") Optional<String> name) {
if (name.isPresent()) {
Group group = groupDAO.getGroup(name.get()).orElseThrow(NotFoundException::new);
ImmutableList<Client> clients = ImmutableList.copyOf(aclDAO.getClientsFor(group));
ImmutableList<SanitizedSecret> sanitizedSecrets = ImmutableList.copyOf(aclDAO.getSanitizedSecretsFor(group));
return Response.ok().entity(GroupDetailResponse.fromGroup(group, sanitizedSecrets, clients)).build();
}
ImmutableList<SanitizedSecret> emptySecrets = ImmutableList.of();
ImmutableList<Client> emptyClients = ImmutableList.of();
List<GroupDetailResponse> groups = groupDAO.getGroups().stream().map((g) -> GroupDetailResponse.fromGroup(g, emptySecrets, emptyClients)).collect(toList());
return Response.ok().entity(groups).build();
}
use of javax.ws.rs.QueryParam in project keywhiz by square.
the class AutomationClientResource method findClient.
/**
* Retrieve Client by a specified name, or all Clients if no name given
*
* @param name the name of the Client to retrieve, if provided
* @excludeParams automationClient
* @optionalParams name
* @description Returns a single Client or a set of all Clients
* @responseMessage 200 Found and retrieved Client(s)
* @responseMessage 404 Client with given name not found (if name provided)
*/
@Timed
@ExceptionMetered
@GET
public Response findClient(@Auth AutomationClient automationClient, @QueryParam("name") Optional<String> name) {
logger.info("Automation ({}) - Looking up a name {}", automationClient.getName(), name);
if (name.isPresent()) {
Client client = clientDAO.getClient(name.get()).orElseThrow(NotFoundException::new);
ImmutableList<Group> groups = ImmutableList.copyOf(aclDAO.getGroupsFor(client));
return Response.ok().entity(ClientDetailResponse.fromClient(client, groups, ImmutableList.of())).build();
}
List<ClientDetailResponse> clients = clientDAO.getClients().stream().map(c -> ClientDetailResponse.fromClient(c, ImmutableList.copyOf(aclDAO.getGroupsFor(c)), ImmutableList.of())).collect(toList());
return Response.ok().entity(clients).build();
}
use of javax.ws.rs.QueryParam in project japid42 by branaway.
the class RouterMethod method extractArguments.
public Object[] extractArguments(play.mvc.Http.RequestHeader r) {
String path = r.path();
if (path.endsWith(withExtension))
path = path.substring(0, path.lastIndexOf(withExtension));
List<RegMatch> rootParamValueMatches = RegMatch.findAllMatchesIn(valueExtractionPattern, path);
List<String> rootParamValues = new ArrayList<String>();
for (RegMatch rm : rootParamValueMatches) {
rootParamValues.addAll(rm.subgroups);
}
if (rootParamValues.size() != paramSpecList.size()) {
throw new RuntimeException("param spec number does not match that from URI capturing. Spec contains: " + paramSpecList.size() + " while the URI contains: " + rootParamValues.size() + ". The route entry is: " + this.toString());
}
Map<String, Object> args = new java.util.HashMap<String, Object>();
int c = 0;
for (ParamSpec paramSpec : paramSpecList) {
String name = paramSpec.name;
String value = rootParamValues.get(c++);
if (!paramSpec.formatPattern.matcher(value).matches()) {
throw new IllegalArgumentException("format mismatch for : (" + name + ")" + value + ". The route entry is: " + this.toString());
}
Class<?> type = paramSpec.type;
Object val = convertArgType(c, name, value, type);
args.put(name, val);
}
//
Object[] argValues = new Object[0];
List<Object> argVals = new ArrayList<Object>();
Annotation[][] annos = meth.getParameterAnnotations();
c = 0;
int pos = 0;
for (Annotation[] ans : annos) {
PathParam pathParam = null;
QueryParam queryParam = null;
for (Annotation an : ans) {
if (an instanceof PathParam)
pathParam = (PathParam) an;
else if (an instanceof QueryParam)
queryParam = (QueryParam) an;
}
if (pathParam != null) {
Object v = args.get(pathParam.value());
if (v != null)
argVals.add(v);
else
throw new IllegalArgumentException("can not find annotation value for argument " + pathParam.value() + "in " + meth.getDeclaringClass() + "#" + meth);
} else if (queryParam != null) {
String name = queryParam.value();
// XXX should this
String queryString = r.getQueryString(name);
// be of
// String[]?
argVals.add(convertArgType(c, name, queryString, meth.getParameterTypes()[c]));
} else if (autoRouting) {
Object v = args.get("_" + pos++);
if (v != null)
argVals.add(v);
else
throw new IllegalArgumentException("can not find value for param No. " + c + " in " + meth.getDeclaringClass() + "#" + meth);
} else
throw new IllegalArgumentException("can not find how to map the value for an argument for method:" + meth.getDeclaringClass() + "#" + meth + ". The parameter position is(0-based): " + c);
c++;
}
argValues = argVals.toArray(argValues);
return argValues;
}
Aggregations