Java Code Examples for javax.ws.rs.core.MultivaluedMap#get()
The following examples show how to use
javax.ws.rs.core.MultivaluedMap#get() .
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: WebAcFilterTest.java From trellis with Apache License 2.0 | 6 votes |
@Test void testFilterResponseWithControl() { final MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>(); final MultivaluedMap<String, String> stringHeaders = new MultivaluedHashMap<>(); stringHeaders.putSingle("Link", "<http://www.w3.org/ns/ldp#BasicContainer>; rel=\"type\""); when(mockResponseContext.getStatusInfo()).thenReturn(OK); when(mockResponseContext.getHeaders()).thenReturn(headers); when(mockResponseContext.getStringHeaders()).thenReturn(stringHeaders); when(mockContext.getProperty(eq(WebAcFilter.SESSION_WEBAC_MODES))) .thenReturn(new AuthorizedModes(effectiveAcl, allModes)); final WebAcFilter filter = new WebAcFilter(); filter.setAccessService(mockWebAcService); assertTrue(headers.isEmpty()); filter.filter(mockContext, mockResponseContext); assertFalse(headers.isEmpty()); final List<Object> links = headers.get("Link"); assertTrue(links.stream().map(Link.class::cast).anyMatch(link -> link.getRels().contains("acl") && "/?ext=acl".equals(link.getUri().toString()))); assertTrue(links.stream().map(Link.class::cast).anyMatch(link -> "/?ext=acl".equals(link.getUri().toString()) && link.getRels().contains(Trellis.effectiveAcl.getIRIString()))); }
Example 2
Source File: ApplyOperation.java From FHIR with Apache License 2.0 | 6 votes |
private String internalCheckAndProcess(FHIRResourceHelpers resourceHelper, MultivaluedMap<String, String> queryParameters, Parameters parameters, String parameter) throws FHIROperationException { String result = null; List<String> qps = queryParameters.get(parameter); if (qps != null) { if (qps.isEmpty() || qps.size() != 1) { throw buildOperationException("Cardinality expectation for $apply operation parameter is 0..1 "); } result = qps.get(0); } if (result == null) { for (Parameter p : parameters.getParameter()) { if (p.getName() != null && p.getName().getValue().compareTo(parameter) == 0) { result = p.getValue().as(com.ibm.fhir.model.type.String.class).getValue(); break; } } } return result; }
Example 3
Source File: ModelInterceptor.java From ameba with MIT License | 6 votes |
/** * /path?filter=p.in(1,2)c.eq('ddd')d.startWith('a')or(f.eq('a')g.startWith(2)) * * @param queryParams uri query params * @param query query * @param manager a {@link InjectionManager} object. * @param <T> a T object. */ public static <T> void applyFilter(MultivaluedMap<String, String> queryParams, SpiQuery<T> query, InjectionManager manager) { List<String> wheres = queryParams.get(FILTER_PARAM_NAME); if (wheres != null && wheres.size() > 0) { EbeanExprInvoker invoker = new EbeanExprInvoker(query, manager); WhereExprApplier<T> applier = WhereExprApplier.create(query.where()); for (String w : wheres) { QueryDSL.invoke( w, invoker, applier ); } } }
Example 4
Source File: RestResponse.java From ats-framework with Apache License 2.0 | 6 votes |
/** * Get the values of a response header. * It returns null if no header is found with the provided name. * * @param name the header name. * It is case-insensitive according to HTTP/1.1 specification (rfc2616#sec4.2) * @return the header values */ @PublicAtsApi public String[] getHeaderValues( String name ) { MultivaluedMap<String, Object> respHeaders = response.getHeaders(); for (String hName : respHeaders.keySet()) { if (hName.equalsIgnoreCase(name)) { List<String> values = new ArrayList<String>(); for (Object valueObject : respHeaders.get(name)) { values.add(valueObject.toString()); } return values.toArray(new String[values.size()]); } } return null; }
Example 5
Source File: TestHttpAccessControl.java From datacollector with Apache License 2.0 | 6 votes |
private void testCORSGetRequest(String userInfoURI) throws Exception { HttpAuthenticationFeature authenticationFeature = HttpAuthenticationFeature.basic("admin", "admin"); Response response = ClientBuilder.newClient() .target(userInfoURI) .register(authenticationFeature) .request() .header("Origin", "http://example.com") .header("Access-Control-Request-Method", "GET") .get(); Assert.assertEquals(200, response.getStatus()); MultivaluedMap<String, Object> responseHeader = response.getHeaders(); List<Object> allowOriginHeader = responseHeader.get(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER); Assert.assertNotNull(allowOriginHeader); Assert.assertEquals(1, allowOriginHeader.size()); Assert.assertEquals("http://example.com", allowOriginHeader.get(0)); }
Example 6
Source File: CustomEntityDecorator.java From secure-data-service with Apache License 2.0 | 5 votes |
@Override public void decorate(EntityBody entity, EntityDefinition definition, MultivaluedMap<String, String> queryParams) { List<String> params = queryParams.get(ParameterConstants.INCLUDE_CUSTOM); final Boolean includeCustomEntity = Boolean.valueOf((params != null) ? params.get(0) : "false"); if (includeCustomEntity) { String entityId = (String) entity.get("id"); EntityBody custom = definition.getService().getCustom(entityId); if (custom != null) { entity.put(ResourceConstants.CUSTOM, custom); } } }
Example 7
Source File: ApplicationHeaderFilter.java From openscoring with GNU Affero General Public License v3.0 | 5 votes |
@Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext){ MultivaluedMap<String, Object> headers = responseContext.getHeaders(); List<Object> applications = headers.get(Headers.APPLICATION); if(applications == null){ applications = new ArrayList<>(); headers.put(Headers.APPLICATION, applications); } applications.add(ApplicationHeaderFilter.nameAndVersion); }
Example 8
Source File: HeaderClientFilter.java From attic-apex-core with Apache License 2.0 | 5 votes |
@Override public ClientResponse handle(ClientRequest clientRequest) throws ClientHandlerException { final MultivaluedMap<String, Object> headers = clientRequest.getHeaders(); List<Object> hcookies = headers.get(COOKIE_HEADER); if (hcookies == null) { hcookies = new ArrayList<>(); } hcookies.addAll(cookies); headers.put(COOKIE_HEADER, hcookies); return getNext().handle(clientRequest); }
Example 9
Source File: WnsNotificationResponse.java From java-wns with BSD 3-Clause "New" or "Revised" License | 5 votes |
public WnsNotificationResponse(String channelUri, int responseCode, MultivaluedMap<String, String> headers) { this.channelUri = channelUri; this.code = responseCode; this.debugTrace = headers.get("X-WNS-Debug-Trace") != null ? headers.get("X-WNS-Debug-Trace").get(0) : null; this.deviceConnectionStatus = headers.get("X-WNS-DeviceConnectionStatus") != null ? headers.get("X-WNS-DeviceConnectionStatus").get(0) : null; this.errorDescription = headers.get("X-WNS-Error-Description") != null ? headers.get("X-WNS-Error-Description").get(0) : null; this.msgID = headers.get("X-WNS-Msg-ID") != null ? headers.get("X-WNS-Msg-ID").get(0) : null; this.notificationStatus = headers.get("X-WNS-Status") != null ? headers.get("X-WNS-Status").get(0) : null; }
Example 10
Source File: AuthorizationEndpointRequestParserProcessor.java From keycloak with Apache License 2.0 | 5 votes |
public static String getClientId(EventBuilder event, KeycloakSession session, MultivaluedMap<String, String> requestParams) { List<String> clientParam = requestParams.get(OIDCLoginProtocol.CLIENT_ID_PARAM); if (clientParam != null && clientParam.size() == 1) { return clientParam.get(0); } else { event.error(Errors.INVALID_REQUEST); throw new ErrorPageException(session, Response.Status.BAD_REQUEST, Messages.INVALID_REQUEST); } }
Example 11
Source File: ApiKeyRequestFilter.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public void filter(ClientRequestContext requestContext) throws IOException { MultivaluedMap<String, Object> headers = requestContext.getHeaders(); String dateStringForAltus = RFC_1123_DATE_TIME.format(OffsetDateTime.now(ZoneOffset.UTC)); if (headers.get("Content-Type") == null) { headers.add("Content-Type", ContentType.APPLICATION_JSON.getMimeType()); } if (headers.get("Content-Type").size() == 0) { throw new BadRequestException("Content-Type header is empty"); } headers.add(X_ALTUS_DATE, dateStringForAltus); headers.add(X_ALTUS_AUTH, authHeader(accessKey, secretKey, requestContext.getMethod(), headers.get("Content-Type").get(0).toString(), requestContext.getUri().toURL().getFile(), dateStringForAltus)); }
Example 12
Source File: TestMicroservice.java From msf4j with Apache License 2.0 | 5 votes |
@POST @Path("/getAllFormItemsXFormUrlEncoded") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public Response getAllFormItemsXFormUrlEncoded(@Context MultivaluedMap formItemMultivaluedMap) { ArrayList names = (ArrayList) formItemMultivaluedMap.get("names"); String type = formItemMultivaluedMap.getFirst("type").toString(); String response = "Type = " + type + " No of names = " + names.size() + " First name = " + names.get(1); return Response.ok().entity(response).build(); }
Example 13
Source File: HttpHeadersImplTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testGetHeaders() throws Exception { Message m = createMessage(createHeaders()); m.put(HttpHeadersImpl.HEADER_SPLIT_PROPERTY, "true"); HttpHeaders h = new HttpHeadersImpl(m); MultivaluedMap<String, String> hs = h.getRequestHeaders(); List<String> acceptValues = hs.get("Accept"); assertEquals(3, acceptValues.size()); assertEquals("text/bar;q=0.6", acceptValues.get(0)); assertEquals("text/*;q=1", acceptValues.get(1)); assertEquals("application/xml", acceptValues.get(2)); assertEquals(hs.getFirst("Content-Type"), "*/*"); }
Example 14
Source File: JAXRSUtils.java From cxf with Apache License 2.0 | 5 votes |
private static void addTemplateVarValues(List<String> values, MultivaluedMap<String, String> params, URITemplate template) { if (template != null) { for (String var : template.getVariables()) { List<String> paramValues = params.get(var); if (paramValues != null) { values.addAll(paramValues); } } } }
Example 15
Source File: BulkDataExportUtil.java From FHIR with Apache License 2.0 | 5 votes |
private static String retrieveOutputFormat(javax.ws.rs.core.UriInfo uriInfo) throws FHIROperationException { // If the parameter isn't passed, use application/fhir+ndjson String value = "application/fhir+ndjson"; MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters(); List<String> qps = queryParameters.get("_outputFormat"); if (qps != null) { if (qps.isEmpty() || qps.size() != 1) { throw buildOperationException( "_outputFormat cardinality expectation for $apply operation parameter is 0..1 ", IssueType.INVALID); } String format = qps.get(0); // We're checking that it's acceptable. if (!BulkDataConstants.EXPORT_FORMATS.contains(format)) { // Workaround for Liberty/CXF replacing "+" with " " MultivaluedMap<String, String> notDecodedQueryParameters = uriInfo.getQueryParameters(false); List<String> notDecodedQps = notDecodedQueryParameters.get("_outputFormat"); format = notDecodedQps.get(0); if (!BulkDataConstants.EXPORT_FORMATS.contains(format)) { throw buildOperationException("Invalid requested format.", IssueType.INVALID); } } } return value; }
Example 16
Source File: FHIRUrlParserTest.java From FHIR with Apache License 2.0 | 5 votes |
@Test(groups = { "server-basic" }) public void testQueryMultipleValues() { FHIRUrlParser parser = new FHIRUrlParser("?var1=1&var1=2&var1=3"); assertEquals("var1=1&var1=2&var1=3", parser.getQuery()); MultivaluedMap<String, String> queryParams = parser.getQueryParameters(); assertNotNull(queryParams); assertEquals(1, queryParams.size()); List<String> var1Values = queryParams.get("var1"); assertNotNull(var1Values); assertEquals(3, var1Values.size()); assertEquals("1", var1Values.get(0)); assertEquals("2", var1Values.get(1)); assertEquals("3", var1Values.get(2)); }
Example 17
Source File: HttpComponentsConnector.java From cyberduck with GNU General Public License v3.0 | 4 votes |
@Override public ClientResponse apply(final ClientRequest clientRequest) throws ProcessingException { final HttpUriRequest request = this.toUriHttpRequest(clientRequest); final Map<String, String> clientHeadersSnapshot = writeOutBoundHeaders(clientRequest.getHeaders(), request); try { final CloseableHttpResponse response; response = client.execute(new HttpHost(request.getURI().getHost(), request.getURI().getPort(), request.getURI().getScheme()), request, new BasicHttpContext(context)); HeaderUtils.checkHeaderChanges(clientHeadersSnapshot, clientRequest.getHeaders(), this.getClass().getName()); final Response.StatusType status = response.getStatusLine().getReasonPhrase() == null ? Statuses.from(response.getStatusLine().getStatusCode()) : Statuses.from(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()); final ClientResponse responseContext = new ClientResponse(status, clientRequest); final List<URI> redirectLocations = context.getRedirectLocations(); if(redirectLocations != null && !redirectLocations.isEmpty()) { responseContext.setResolvedRequestUri(redirectLocations.get(redirectLocations.size() - 1)); } final Header[] respHeaders = response.getAllHeaders(); final MultivaluedMap<String, String> headers = responseContext.getHeaders(); for(final Header header : respHeaders) { final String headerName = header.getName(); List<String> list = headers.get(headerName); if(list == null) { list = new ArrayList<>(); } list.add(header.getValue()); headers.put(headerName, list); } final HttpEntity entity = response.getEntity(); if(entity != null) { if(headers.get(HttpHeaders.CONTENT_LENGTH) == null) { headers.add(HttpHeaders.CONTENT_LENGTH, String.valueOf(entity.getContentLength())); } final Header contentEncoding = entity.getContentEncoding(); if(headers.get(HttpHeaders.CONTENT_ENCODING) == null && contentEncoding != null) { headers.add(HttpHeaders.CONTENT_ENCODING, contentEncoding.getValue()); } } responseContext.setEntityStream(this.toInputStream(response)); return responseContext; } catch(final Exception e) { throw new ProcessingException(e); } }
Example 18
Source File: JaxrsHttpFacade.java From hammock with Apache License 2.0 | 4 votes |
@Override public List<String> getHeaders(String name) { MultivaluedMap<String, String> headers = requestContext.getHeaders(); return (headers == null) ? null : headers.get(name); }
Example 19
Source File: JaxrsHttpFacade.java From keycloak-dropwizard-integration with Apache License 2.0 | 4 votes |
@Override public List<String> getHeaders(String name) { MultivaluedMap<String, String> headers = requestContext.getHeaders(); return (headers == null) ? null : headers.get(name); }
Example 20
Source File: OptionsMethodTest.java From io with Apache License 2.0 | 4 votes |
/** * 認証なしのOPTIONSメソッドがリクエストされた場合にpersoniumで受け付けている全メソッドが返却されること. * @throws URISyntaxException URISyntaxException */ @Test public void 認証なしのOPTIONSメソッドがリクエストされた場合にpersoniumで受け付けている全メソッドが返却されること() throws URISyntaxException { // 被テストオブジェクトを準備 DcCoreContainerFilter containerFilter = new DcCoreContainerFilter(); // ContainerRequiestを準備 WebApplication wa = mock(WebApplication.class); InBoundHeaders headers = new InBoundHeaders(); // X-FORWARDED-* 系のヘッダ設定 String scheme = "https"; String host = "example.org"; headers.add(DcCoreUtils.HttpHeaders.X_FORWARDED_PROTO, scheme); headers.add(DcCoreUtils.HttpHeaders.X_FORWARDED_HOST, host); ContainerRequest request = new ContainerRequest(wa, HttpMethod.OPTIONS, new URI("http://dc1.example.com/hoge"), new URI("http://dc1.example.com/hoge/hoho"), headers, null); // HttpServletRequestのmockを準備 HttpServletRequest mockServletRequest = mock(HttpServletRequest.class); when(mockServletRequest.getRequestURL()).thenReturn(new StringBuffer("http://dc1.example.com")); ServletContext mockServletContext = mock(ServletContext.class); when(mockServletContext.getContextPath()).thenReturn(""); when(mockServletRequest.getServletContext()).thenReturn(mockServletContext); containerFilter.setHttpServletRequest(mockServletRequest); try { containerFilter.filter(request); } catch (WebApplicationException e) { Response response = e.getResponse(); assertEquals(response.getStatus(), HttpStatus.SC_OK); MultivaluedMap<String, Object> meta = response.getMetadata(); List<Object> values = meta.get("Access-Control-Allow-Methods"); assertEquals(values.size(), 1); String value = (String) values.get(0); String[] methods = value.split(","); Map<String, String> masterMethods = new HashMap<String, String>(); masterMethods.put(HttpMethod.OPTIONS, ""); masterMethods.put(HttpMethod.GET, ""); masterMethods.put(HttpMethod.POST, ""); masterMethods.put(HttpMethod.PUT, ""); masterMethods.put(HttpMethod.DELETE, ""); masterMethods.put(HttpMethod.HEAD, ""); masterMethods.put(com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.MERGE, ""); masterMethods.put(com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.MKCOL, ""); masterMethods.put(com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.MOVE, ""); masterMethods.put(com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.PROPFIND, ""); masterMethods.put(com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.PROPPATCH, ""); masterMethods.put(com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.ACL, ""); for (String method : methods) { if (method.trim() == "") { continue; } String m = masterMethods.remove(method.trim()); if (m == null) { fail("Method " + method + " is not defined."); } } if (!masterMethods.isEmpty()) { fail("UnExcpected Error."); } } }