@POST public Response postSomething(@QueryParam("name") String name, @Context UriInfo uriInfo, String content) { MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters(); String nameParam = queryParams.getFirst("name"); }
// showing only the relavent code public FindResponse find( @Context UriInfo allUri ) { MultivaluedMap<String, String> mpAllQueParams = allUri.getQueryParameters(); String prop1 = mpAllQueParams.getFirst("prop1"); }
private Map<String, Object> getQueryParameters(final UriInfo info, final String[] params) { final Map<String, Object> result = new HashMap<>(); for (String each : params) { if (!Strings.isNullOrEmpty(info.getQueryParameters().getFirst(each))) { result.put(each, info.getQueryParameters().getFirst(each)); } } return result; } }
private static boolean shouldSummarize(UriInfo uriInfo) { return uriInfo.getQueryParameters().containsKey("summarize"); }
/** Construct an new response initialized with all the incoming query parameters. */ public Response(UriInfo info) { this.requestParameters = new HashMap<String, String>(); if (info == null) { // in tests where there is no HTTP request, just leave the map empty return; } for (Entry<String, List<String>> e : info.getQueryParameters().entrySet()) { // include only the first instance of each query parameter requestParameters.put(e.getKey(), e.getValue().get(0)); } }
@Override public Set<String> resolve(final Annotation[] annotations) { final Set<String> scopes = new HashSet<>(); final List<String> fields = uriInfo.getQueryParameters().get(SELECTABLE_PARAM_NAME); if (fields != null && !fields.isEmpty()) { for (final String field : fields) { scopes.addAll(getScopesForField(field)); } } else { scopes.add(DEFAULT_SCOPE); } return scopes; }
/** * Return {@code true} if generation of full WADL with * {@link org.glassfish.jersey.server.model.ExtendedResource extended resources} is requested. * * @param uriInfo URI info of the request. * @return {@code true} if full detailed WADL should be generated; false otherwise. */ public static boolean isDetailedWadlRequested(UriInfo uriInfo) { final List<String> simple = uriInfo.getQueryParameters().get(DETAILED_WADL_QUERY_PARAM); if (simple != null) { if (simple.size() == 0) { return true; } final String value = simple.get(0).trim(); return value.isEmpty() || value.toUpperCase().equals("TRUE"); } return false; }
/** * Return {@code true} if generation of full WADL with * {@link org.glassfish.jersey.server.model.ExtendedResource extended resources} is requested. * * @param uriInfo URI info of the request. * @return {@code true} if full detailed WADL should be generated; false otherwise. */ public static boolean isDetailedWadlRequested(UriInfo uriInfo) { final List<String> simple = uriInfo.getQueryParameters().get(DETAILED_WADL_QUERY_PARAM); if (simple != null) { if (simple.size() == 0) { return true; } final String value = simple.get(0).trim(); return value.isEmpty() || value.toUpperCase().equals("TRUE"); } return false; }
@POST @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, MIMETYPE_PROTOBUF_IETF}) public Response post(final CellSetModel model, final @Context UriInfo uriInfo) { if (LOG.isTraceEnabled()) { LOG.trace("POST " + uriInfo.getAbsolutePath() + " " + uriInfo.getQueryParameters()); } return update(model, false); }
@PUT @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, MIMETYPE_PROTOBUF_IETF}) public Response put(final CellSetModel model, final @Context UriInfo uriInfo) { if (LOG.isTraceEnabled()) { LOG.trace("PUT " + uriInfo.getAbsolutePath() + " " + uriInfo.getQueryParameters()); } return update(model, true); }
@Override public void filter(ContainerRequestContext rc) { String maybeType = rc.getUriInfo().getQueryParameters().getFirst("type"); if (maybeType != null && maybeType.equals("gpx")) { rc.getHeaders().putSingle(HttpHeaders.ACCEPT, "application/gpx+xml"); } }
@AroundInvoke public Object logMethodEntry(InvocationContext ctx) throws Exception { MultivaluedMap<String, String> params = jaxrsService.getUriInfo().getQueryParameters(); String user = params.getFirst("user"); if (nameService.getName().equals(user)) { return ctx.proceed(); } else { throw new ForbiddenException("Forbidden resource for the user: " + user); } } }
void extract(UriInfo uriInfo, Map<String, List<String>> headers) { List<String> values = uriInfo.getQueryParameters().get(paramName); if (null == values) { return; } values.forEach(token -> { String tokenValue = tokenHandler.extractToken(token); tokenHandler.addHeader(headers, tokenValue); } ); }
@Override public void filter(final ContainerRequestContext requestContext) throws IOException { String credentials = getCredentials(requestContext.getHeaders().getFirst(HttpHeaders.AUTHORIZATION)); // If Authorization header is not used, check query parameter where token can be passed as well if (credentials == null) { credentials = requestContext.getUriInfo().getQueryParameters().getFirst(OAUTH_ACCESS_TOKEN_PARAM); } if (!authenticate(requestContext, credentials, SecurityContext.BASIC_AUTH)) { throw new WebApplicationException(unauthorizedHandler.buildResponse(prefix, realm)); } }
@Override public Set<String> getParameterNames() { HashSet<String> n = new HashSet<String>(); n.addAll(keys(context.getUriInfo().getQueryParameters())); n.addAll(keys(formParams.get())); return n; }
@Override public List<String> getParameterValues(String name) { ArrayList<String> v = new ArrayList<String>(); v.addAll(values(context.getUriInfo().getQueryParameters(), name)); v.addAll(values(formParams.get(), name)); return v; }
public static StringBuilder append(StringBuilder sb, UriInfo uriInfo, HttpHeaders httpHeaders) { sb.append("\n UriInfo:"); sb.append("\n Absolute path : ").append(uriInfo.getAbsolutePath()); sb.append("\n Base URI : ").append(uriInfo.getBaseUri()); sb.append("\n Mathced resources : ").append(uriInfo.getMatchedResources().toString()); sb.append("\n Matched URIs : ").append(uriInfo.getMatchedURIs().toString()); sb.append("\n Path : ").append(uriInfo.getPath()); sb.append("\n Path parameters:\n"); dumpMultivaluedMap(sb, uriInfo.getPathParameters()); sb.append(" Path segments : ").append(uriInfo.getPathSegments().toString()); sb.append("\n Query parameters:\n"); dumpMultivaluedMap(sb, uriInfo.getQueryParameters()); sb.append(" Request URI : ").append(uriInfo.getRequestUri()); sb.append("\n\n HttpHeaders:\n"); dumpMultivaluedMap(sb, httpHeaders.getRequestHeaders()); return sb; }
/** * Returns a JavaScript callback name to wrap the JSON entity into. The callback name is determined from the {@link JSONP} * annotation. * * @param jsonp {@link JSONP} annotation to determine the callback name from. * @return a JavaScript callback name. */ private String getCallbackName(final JSONP jsonp) { String callback = jsonp.callback(); if (!"".equals(jsonp.queryParam())) { final ContainerRequest containerRequest = containerRequestProvider.get(); final UriInfo uriInfo = containerRequest.getUriInfo(); final MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters(); final List<String> queryParameter = queryParameters.get(jsonp.queryParam()); callback = (queryParameter != null && !queryParameter.isEmpty()) ? queryParameter.get(0) : callback; } return callback; }
@GET @Path( PATH_ALL_NODES_LABELED ) public Response getNodesWithLabelAndProperty( @PathParam( "label" ) String labelName, @Context UriInfo uriInfo ) { try { if ( labelName.isEmpty() ) { throw new InvalidArgumentsException( "Empty label name" ); } Map<String, Object> properties = toMap( map( queryParamsToProperties, uriInfo.getQueryParameters().entrySet())); return output.ok( actions.getNodesWithLabel( labelName, properties ) ); } catch ( BadInputException e ) { return output.badRequest( e ); } }
@Test public void toRegisterEntryFromEmptyQueryParameter() throws Exception { UriInfo uriInfo = Mockito.mock(UriInfo.class); when(uriInfo.getQueryParameters()).thenReturn(new MultivaluedHashMap<>()); Optional<RegisterEntry> re = UriInfoParser.toRegisterEntry(uriInfo); assertFalse(re.isPresent()); } }