Java Code Examples for javax.ws.rs.core.MultivaluedMap#containsKey()
The following examples show how to use
javax.ws.rs.core.MultivaluedMap#containsKey() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseEntityService.java From monolith with Apache License 2.0 | 6 votes |
public List<T> getAll(MultivaluedMap<String, String> queryParameters) { final CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); final CriteriaQuery<T> criteriaQuery = criteriaBuilder.createQuery(entityClass); Root<T> root = criteriaQuery.from(entityClass); Predicate[] predicates = extractPredicates(queryParameters, criteriaBuilder, root); criteriaQuery.select(criteriaQuery.getSelection()).where(predicates); criteriaQuery.orderBy(criteriaBuilder.asc(root.get("id"))); TypedQuery<T> query = entityManager.createQuery(criteriaQuery); if (queryParameters.containsKey("first")) { Integer firstRecord = Integer.parseInt(queryParameters.getFirst("first"))-1; query.setFirstResult(firstRecord); } if (queryParameters.containsKey("maxResults")) { Integer maxResults = Integer.parseInt(queryParameters.getFirst("maxResults")); query.setMaxResults(maxResults); } return query.getResultList(); }
Example 2
Source File: RestUtils.java From para with Apache License 2.0 | 6 votes |
private static <P extends ParaObject> List<P> findTermsQuery(MultivaluedMap<String, String> params, Pager pager, String appid, String type) { if (params == null) { return Collections.emptyList(); } String matchAll = paramOrDefault(params, "matchall", "true"); List<String> termsList = params.get("terms"); if (termsList != null) { Map<String, String> terms = new HashMap<>(termsList.size()); for (String termTuple : termsList) { if (!StringUtils.isBlank(termTuple) && termTuple.contains(Config.SEPARATOR)) { String[] split = termTuple.split(Config.SEPARATOR, 2); terms.put(split[0], split[1]); } } if (params.containsKey("count")) { pager.setCount(Para.getSearch().getCount(appid, type, terms)); } else { return Para.getSearch().findTerms(appid, type, terms, Boolean.parseBoolean(matchAll), pager); } } return Collections.emptyList(); }
Example 3
Source File: ShowService.java From monolith with Apache License 2.0 | 6 votes |
@Override protected Predicate[] extractPredicates(MultivaluedMap<String, String> queryParameters, CriteriaBuilder criteriaBuilder, Root<Show> root) { List<Predicate> predicates = new ArrayList<Predicate>(); if (queryParameters.containsKey("venue")) { String venue = queryParameters.getFirst("venue"); predicates.add(criteriaBuilder.equal(root.get("venue").get("id"), venue)); } if (queryParameters.containsKey("event")) { String event = queryParameters.getFirst("event"); predicates.add(criteriaBuilder.equal(root.get("event").get("id"), event)); } return predicates.toArray(new Predicate[]{}); }
Example 4
Source File: DeviceCompleteRequestHandlerSpiImpl.java From java-oauth-server with Apache License 2.0 | 6 votes |
public DeviceCompleteRequestHandlerSpiImpl( MultivaluedMap<String, String> parameters, User user, Date userAuthenticatedAt, String[] acrs) { // Check the result of end-user authentication and authorization. mResult = parameters.containsKey("authorized") ? Result.AUTHORIZED : Result.ACCESS_DENIED; if (mResult != Result.AUTHORIZED) { // The end-user has not authorized the client. return; } // OK. The end-user has successfully authorized the client. // The end-user. mUser = user; // The time at which end-user has been authenticated. mUserAuthenticatedAt = (userAuthenticatedAt == null) ? 0 : userAuthenticatedAt.getTime() / 1000L; // The requested ACRs. mAcrs = acrs; }
Example 5
Source File: ShowService.java From monolith with Apache License 2.0 | 6 votes |
@Override protected Predicate[] extractPredicates(MultivaluedMap<String, String> queryParameters, CriteriaBuilder criteriaBuilder, Root<Show> root) { List<Predicate> predicates = new ArrayList<Predicate>(); if (queryParameters.containsKey("venue")) { String venue = queryParameters.getFirst("venue"); predicates.add(criteriaBuilder.equal(root.get("venue").get("id"), venue)); } if (queryParameters.containsKey("event")) { String event = queryParameters.getFirst("event"); predicates.add(criteriaBuilder.equal(root.get("event").get("id"), event)); } return predicates.toArray(new Predicate[]{}); }
Example 6
Source File: ODataExceptionWrapper.java From cloud-odata-java with Apache License 2.0 | 6 votes |
private ContentType getContentTypeByUriInfo(final UriInfo uriInfo) { ContentType contentType = null; if (uriInfo != null && uriInfo.getQueryParameters() != null) { MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters(); if (queryParameters.containsKey(DOLLAR_FORMAT)) { String contentTypeString = queryParameters.getFirst(DOLLAR_FORMAT); if (DOLLAR_FORMAT_JSON.equals(contentTypeString)) { contentType = ContentType.APPLICATION_JSON; } else { //Any format mentioned in the $format parameter other than json results in an application/xml content type //for error messages due to the OData V2 Specification. contentType = ContentType.APPLICATION_XML; } } } return contentType; }
Example 7
Source File: ODataExceptionMapperImpl.java From cloud-odata-java with Apache License 2.0 | 6 votes |
private ContentType getContentTypeByUriInfo() { ContentType contentType = null; if (uriInfo != null && uriInfo.getQueryParameters() != null) { MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters(); if (queryParameters.containsKey(DOLLAR_FORMAT)) { String contentTypeString = queryParameters.getFirst(DOLLAR_FORMAT); if (DOLLAR_FORMAT_JSON.equals(contentTypeString)) { contentType = ContentType.APPLICATION_JSON; } else { //Any format mentioned in the $format parameter other than json results in an application/xml content type //for error messages due to the OData V2 Specification. contentType = ContentType.APPLICATION_XML; } } } return contentType; }
Example 8
Source File: QueryExecutorBean.java From datawave with Apache License 2.0 | 5 votes |
@POST @Path("/lookupUUID") @Produces({"application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf", "application/x-protostuff"}) @GZIP @GenerateQuerySessionId(cookieBasePath = "/DataWave/Query/") @Interceptors({ResponseInterceptor.class, RequiredInterceptor.class}) @Override @Timed(name = "dw.query.lookupUUIDBatch", absolute = true) public <T> T lookupUUIDBatch(MultivaluedMap<String,String> queryParameters, @Required("httpHeaders") @Context HttpHeaders httpHeaders) { if (!queryParameters.containsKey("uuidPairs")) { throw new BadRequestException(new IllegalArgumentException("uuidPairs missing from query parameters"), new VoidResponse()); } T response; String queryId = null; try { String uuidPairs = queryParameters.getFirst("uuidPairs"); String streaming = queryParameters.getFirst("streaming"); boolean streamingOutput = false; if (!StringUtils.isEmpty(streaming)) { streamingOutput = Boolean.parseBoolean(streaming); } final PostUUIDCriteria criteria = new PostUUIDCriteria(uuidPairs, queryParameters); if (streamingOutput) { criteria.setStreamingOutputHeaders(httpHeaders); } response = this.lookupUUIDUtil.createUUIDQueryAndNext(criteria); if (response instanceof BaseQueryResponse) { queryId = ((BaseQueryResponse) response).getQueryId(); } return response; } finally { if (null != queryId) { asyncClose(queryId); } } }
Example 9
Source File: TopologyResource.java From incubator-heron with Apache License 2.0 | 5 votes |
protected Response updateContainerNumber( String cluster, String role, String environment, String name, MultivaluedMap<String, String> params, String containerNumber) { final List<Pair<String, Object>> keyValues = new ArrayList<>( Arrays.asList( Pair.create(Key.CLUSTER.value(), cluster), Pair.create(Key.ROLE.value(), role), Pair.create(Key.ENVIRON.value(), environment), Pair.create(Key.TOPOLOGY_NAME.value(), name), Pair.create(Keys.PARAM_CONTAINER_NUMBER, containerNumber) ) ); // has a dry run been requested? if (params.containsKey(PARAM_DRY_RUN)) { keyValues.add(Pair.create(Key.DRY_RUN.value(), Boolean.TRUE)); } final Set<Pair<String, Object>> overrides = getUpdateOverrides(params); // apply overrides if they exists if (!overrides.isEmpty()) { keyValues.addAll(overrides); } final Config config = createConfig(keyValues); getActionFactory().createRuntimeAction(config, ActionType.UPDATE).execute(); return Response.ok() .type(MediaType.APPLICATION_JSON) .entity(Utils.createMessage(String.format("%s updated", name))) .build(); }
Example 10
Source File: TableauMessageBodyGenerator.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public void writeTo(DatasetConfig datasetConfig, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { final String hostname; if (httpHeaders.containsKey(WebServer.X_DREMIO_HOSTNAME)) { hostname = (String) httpHeaders.getFirst(WebServer.X_DREMIO_HOSTNAME); } else { hostname = masterNode; } // Change headers to force download and suggest a filename. String fullPath = Joiner.on(".").join(datasetConfig.getFullPathList()); httpHeaders.putSingle(HttpHeaders.CONTENT_DISPOSITION, format("attachment; filename=\"%s.tds\"", fullPath)); try { final XMLStreamWriter xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(entityStream, "UTF-8"); xmlStreamWriter.writeStartDocument("utf-8", "1.0"); writeDatasource(xmlStreamWriter, datasetConfig, hostname, mediaType); xmlStreamWriter.writeEndDocument(); xmlStreamWriter.close(); } catch (XMLStreamException e) { throw UserExceptionMapper.withStatus( UserException.dataWriteError(e) .message("Cannot generate TDS file") .addContext("Details", e.getMessage()), Status.INTERNAL_SERVER_ERROR ).build(logger); } }
Example 11
Source File: CsrfProtectFilter.java From krazo with Apache License 2.0 | 5 votes |
/** * Inject CSRF header if enabled in the application. * * @param requestContext the request context. * @param responseContext the response context. * @throws IOException if a problem occurs writing a response. */ @Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { if (isCsrfEnabled()) { final CsrfToken token = csrfTokenManager.getOrCreateToken(); final MultivaluedMap<String, Object> headers = responseContext.getHeaders(); if (!headers.containsKey(token.getHeaderName())) { headers.putSingle(token.getHeaderName(), token.getValue()); } } }
Example 12
Source File: ContainerSecurityRequestFilter.java From Cheddar with Apache License 2.0 | 5 votes |
private String getValueForHeader(final MultivaluedMap<String, String> headers, final String header) { if (headers.containsKey(header)) { for (final String headerValue : headers.get(header)) { return headerValue; } } return null; }
Example 13
Source File: MailForm.java From mailgun with MIT License | 5 votes |
@Override void prepareSend() { // apply default parameters MultivaluedMap<String, String> parameters = form.asMap(); Map<String, List<String>> def = configuration().defaultParameters(); for (Map.Entry<String, List<String>> entry : def.entrySet()) if (!parameters.containsKey(entry.getKey())) parameters.addAll(entry.getKey(), entry.getValue()); }
Example 14
Source File: TopologyResource.java From incubator-heron with Apache License 2.0 | 5 votes |
protected Response updateComponentParallelism( String cluster, String role, String environment, String name, MultivaluedMap<String, String> params, List<String> components) { final List<Pair<String, Object>> keyValues = new ArrayList<>( Arrays.asList( Pair.create(Key.CLUSTER.value(), cluster), Pair.create(Key.ROLE.value(), role), Pair.create(Key.ENVIRON.value(), environment), Pair.create(Key.TOPOLOGY_NAME.value(), name), Pair.create(Keys.PARAM_COMPONENT_PARALLELISM, String.join(",", components)) ) ); // has a dry run been requested? if (params.containsKey(PARAM_DRY_RUN)) { keyValues.add(Pair.create(Key.DRY_RUN.value(), Boolean.TRUE)); } final Set<Pair<String, Object>> overrides = getUpdateOverrides(params); // apply overrides if they exists if (!overrides.isEmpty()) { keyValues.addAll(overrides); } final Config config = createConfig(keyValues); getActionFactory().createRuntimeAction(config, ActionType.UPDATE).execute(); return Response.ok() .type(MediaType.APPLICATION_JSON) .entity(Utils.createMessage(String.format("%s updated", name))) .build(); }
Example 15
Source File: EventService.java From monolith with Apache License 2.0 | 5 votes |
/** * <p> * We override the method from parent in order to add support for additional search * criteria for events. * </p> * @param queryParameters - the HTTP query parameters received by the endpoint * @param criteriaBuilder - @{link CriteriaBuilder} used by the invoker * @param root @{link Root} used by the invoker * @return */ @Override protected Predicate[] extractPredicates( MultivaluedMap<String, String> queryParameters, CriteriaBuilder criteriaBuilder, Root<Event> root) { List<Predicate> predicates = new ArrayList<Predicate>() ; if (queryParameters.containsKey("category")) { String category = queryParameters.getFirst("category"); predicates.add(criteriaBuilder.equal(root.get("category").get("id"), category)); } return predicates.toArray(new Predicate[]{}); }
Example 16
Source File: SearchContextImpl.java From cxf with Apache License 2.0 | 5 votes |
public String getSearchExpression() { String queryStr = (String)message.get(Message.QUERY_STRING); if (queryStr != null) { if (MessageUtils.getContextualBoolean(message, USE_ALL_QUERY_COMPONENT)) { return queryStr; } boolean encoded = PropertyUtils.isTrue(getKeepEncodedProperty()); MultivaluedMap<String, String> params = JAXRSUtils.getStructuredParams(queryStr, "&", !encoded, false); String customQueryParamName = (String)message.getContextualProperty(CUSTOM_SEARCH_QUERY_PARAM_NAME); if (customQueryParamName != null) { return params.getFirst(customQueryParamName); } if (queryStr.contains(SHORT_SEARCH_QUERY) || queryStr.contains(SEARCH_QUERY)) { if (params.containsKey(SHORT_SEARCH_QUERY)) { return params.getFirst(SHORT_SEARCH_QUERY); } return params.getFirst(SEARCH_QUERY); } else if (MessageUtils.getContextualBoolean(message, USE_PLAIN_QUERY_PARAMETERS)) { return convertPlainQueriesToFiqlExp(params); } } return null; }
Example 17
Source File: QueryExecutorBean.java From datawave with Apache License 2.0 | 4 votes |
@POST @Path("/lookupContentUUID") @Produces({"application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf", "application/x-protostuff"}) @GZIP @GenerateQuerySessionId(cookieBasePath = "/DataWave/Query/") @Interceptors({ResponseInterceptor.class, RequiredInterceptor.class}) @Override @Timed(name = "dw.query.lookupContentUUIDBatch", absolute = true) public <T> T lookupContentByUUIDBatch(MultivaluedMap<String,String> queryParameters, HttpHeaders httpHeaders) { if (!queryParameters.containsKey("uuidPairs")) { throw new BadRequestException(new IllegalArgumentException("uuidPairs missing from query parameters"), new VoidResponse()); } T response = null; String queryId = null; try { String uuidPairs = queryParameters.getFirst("uuidPairs"); String streaming = queryParameters.getFirst("streaming"); boolean streamingOutput = false; if (!StringUtils.isEmpty(streaming)) { streamingOutput = Boolean.parseBoolean(streaming); } // Create the criteria for looking up the respective events, which we need to get the shard IDs and column families // required for the content lookup final PostUUIDCriteria criteria = new PostUUIDCriteria(uuidPairs, queryParameters); // Set the HTTP headers if a streamed response is required if (streamingOutput) { criteria.setStreamingOutputHeaders(httpHeaders); } response = this.lookupUUIDUtil.lookupContentByUUIDs(criteria); if (response instanceof BaseQueryResponse) { queryId = ((BaseQueryResponse) response).getQueryId(); } return response; } finally { if (null != queryId) { asyncClose(queryId); } } }
Example 18
Source File: Forms.java From incubator-heron with Apache License 2.0 | 4 votes |
static String getFirstOrDefault(MultivaluedMap<String, String> params, String key, String defaultValue) { return params.containsKey(key) ? params.getFirst(key) : defaultValue; }
Example 19
Source File: ClientProxyImpl.java From cxf with Apache License 2.0 | 4 votes |
/** * Updates the current state if Client method is invoked, otherwise * does the remote invocation or returns a new proxy if subresource * method is invoked. Can throw an expected exception if ResponseExceptionMapper * is registered */ @Override public Object invoke(Object o, Method m, Object[] params) throws Throwable { checkClosed(); Class<?> declaringClass = m.getDeclaringClass(); if (Client.class == declaringClass || InvocationHandlerAware.class == declaringClass || Object.class == declaringClass || Closeable.class == declaringClass || AutoCloseable.class == declaringClass) { return m.invoke(this, params); } resetResponse(); OperationResourceInfo ori = cri.getMethodDispatcher().getOperationResourceInfo(m); if (ori == null) { if (m.isDefault()) { return invokeDefaultMethod(declaringClass, o, m, params); } reportInvalidResourceMethod(m, "INVALID_RESOURCE_METHOD"); } MultivaluedMap<ParameterType, Parameter> types = getParametersInfo(m, params, ori); List<Parameter> beanParamsList = getParameters(types, ParameterType.BEAN); int bodyIndex = getBodyIndex(types, ori); List<Object> pathParams = getPathParamValues(m, params, types, beanParamsList, ori, bodyIndex); UriBuilder builder = getCurrentBuilder().clone(); if (isRoot) { addNonEmptyPath(builder, ori.getClassResourceInfo().getURITemplate().getValue()); } addNonEmptyPath(builder, ori.getURITemplate().getValue()); handleMatrixes(m, params, types, beanParamsList, builder); handleQueries(m, params, types, beanParamsList, builder); URI uri = builder.buildFromEncoded(pathParams.toArray()).normalize(); MultivaluedMap<String, String> headers = getHeaders(); MultivaluedMap<String, String> paramHeaders = new MetadataMap<>(); handleHeaders(m, params, paramHeaders, beanParamsList, types); handleCookies(m, params, paramHeaders, beanParamsList, types); if (ori.isSubResourceLocator()) { ClassResourceInfo subCri = cri.getSubResource(m.getReturnType(), m.getReturnType()); if (subCri == null) { reportInvalidResourceMethod(m, "INVALID_SUBRESOURCE"); } MultivaluedMap<String, String> subHeaders = paramHeaders; if (inheritHeaders) { subHeaders.putAll(headers); } ClientState newState = getState().newState(uri, subHeaders, getTemplateParametersMap(ori.getURITemplate(), pathParams)); ClientProxyImpl proxyImpl = new ClientProxyImpl(newState, proxyLoader, subCri, false, inheritHeaders); proxyImpl.setConfiguration(getConfiguration()); return JAXRSClientFactory.createProxy(m.getReturnType(), proxyLoader, proxyImpl); } headers.putAll(paramHeaders); getState().setTemplates(getTemplateParametersMap(ori.getURITemplate(), pathParams)); Object body = null; if (bodyIndex != -1) { body = params[bodyIndex]; if (body == null) { bodyIndex = -1; } } else if (types.containsKey(ParameterType.FORM)) { body = handleForm(m, params, types, beanParamsList); } else if (types.containsKey(ParameterType.REQUEST_BODY)) { body = handleMultipart(types, ori, params); } else if (hasFormParams(params, beanParamsList)) { body = handleForm(m, params, types, beanParamsList); } setRequestHeaders(headers, ori, types.containsKey(ParameterType.FORM), body == null ? null : body.getClass(), m.getReturnType()); try { return doChainedInvocation(uri, headers, ori, params, body, bodyIndex, null, null); } finally { resetResponseStateImmediatelyIfNeeded(); } }
Example 20
Source File: StatisticaQuadraturaConverter.java From govpay with GNU General Public License v3.0 | 4 votes |
private static void creaURLDettaglio(it.govpay.model.reportistica.statistiche.StatisticaRendicontazione statistica, UriInfo uriInfo, StatisticaQuadraturaRendicontazione rsModel) { // URL di dettaglio composta da tutti i filtri e da i valori dei gruppi trovati UriBuilder uriBuilder = UriBuilderUtils.getListRendicontazioni(); MultivaluedMap<String, String> parametri = new MultivaluedHashMap<String, String>(); MultivaluedMap<String,String> queryParameters = uriInfo.getQueryParameters(); /* @QueryParam("dataOraFlussoDa") String dataOraFlussoDa, @QueryParam("dataOraFlussoA") String dataOraFlussoA, @QueryParam("dataRendicontazioneDa") String dataRendicontazioneDa, @QueryParam("dataRendicontazioneA") String dataRendicontazioneA, @QueryParam("idFlusso") String idFlusso, @QueryParam("iuv") String iuv, @QueryParam("direzione") List<String> direzione, @QueryParam("divisione") List<String> divisione */ if(statistica.getCodFlusso() != null) { parametri.add("idFlusso", statistica.getCodFlusso()); } else { if(queryParameters.containsKey("idFlusso")) parametri.addAll("idFlusso", queryParameters.get("idFlusso")); } if(statistica.getDirezione() != null) { parametri.add("direzione", statistica.getDirezione()); } else { if(queryParameters.containsKey("direzione")) parametri.addAll("direzione", queryParameters.get("direzione")); } if(statistica.getDivisione() != null) { parametri.add("divisione", statistica.getDivisione()); } else { if(queryParameters.containsKey("divisione")) parametri.addAll("divisione", queryParameters.get("divisione")); } if(queryParameters.containsKey("dataOraFlussoDa")) parametri.addAll("dataOraFlussoDa", queryParameters.get("dataOraFlussoDa")); if(queryParameters.containsKey("dataOraFlussoA")) parametri.addAll("dataOraFlussoA", queryParameters.get("dataOraFlussoA")); if(queryParameters.containsKey("dataRendicontazioneDa")) parametri.addAll("dataRendicontazioneDa", queryParameters.get("dataRendicontazioneDa")); if(queryParameters.containsKey("dataRendicontazioneA")) parametri.addAll("dataRendicontazioneA", queryParameters.get("dataRendicontazioneA")); if(queryParameters.containsKey("iuv")) parametri.addAll("iuv", queryParameters.get("iuv")); // aggiungo tutti i parametri for (String key : parametri.keySet()) { List<String> list = parametri.get(key); uriBuilder = uriBuilder.queryParam(key, list.toArray(new Object[list.size()])); } rsModel.setDettaglio(uriBuilder.build().toString()); }