当前位置: 首页>>代码示例>>Java>>正文


Java MultivaluedMap.get方法代码示例

本文整理汇总了Java中javax.ws.rs.core.MultivaluedMap.get方法的典型用法代码示例。如果您正苦于以下问题:Java MultivaluedMap.get方法的具体用法?Java MultivaluedMap.get怎么用?Java MultivaluedMap.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.ws.rs.core.MultivaluedMap的用法示例。


在下文中一共展示了MultivaluedMap.get方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getHeaderValues

import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:25,代码来源:RestResponse.java

示例2: getQueryParameterValue

import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
/**
 * Get a URI query parameter value by name
 * @param queryParameters URI query parameters
 * @param name Parameter name
 * @return Parameter value, or <code>null</code> if not found
 */
public static Optional<String> getQueryParameterValue(MultivaluedMap<String, String> queryParameters, String name) {
	if (name != null) {
		if (queryParameters != null && queryParameters.containsKey(name)) {
			List<String> values = queryParameters.get(name);
			if (values != null && !values.isEmpty()) {
				if (values.size() == 1) {
					return Optional.ofNullable(values.get(0));
				} else {
					StringBuilder sb = new StringBuilder();
					for (String value : values) {
						if (sb.length() > 0) {
							sb.append(',');
						}
						sb.append(value);
					}
					return Optional.of(sb.toString());
				}
			}
		}
	}
	return Optional.empty();
}
 
开发者ID:holon-platform,项目名称:holon-jaxrs,代码行数:29,代码来源:RequestUtils.java

示例3: executeQuery

import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
@GET
@javax.ws.rs.Path("/commands/{commandName}/query")
@Consumes(MediaType.MEDIA_TYPE_WILDCARD)
@Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN})
public Response executeQuery(@Context UriInfo uriInfo,
                             @PathParam("commandName") String commandName,
                             @Context HttpHeaders headers)
        throws Exception {
    validateCommand(commandName);
    String stepIndex = null;
    MultivaluedMap<String, String> parameters = uriInfo.getQueryParameters();
    List<String> stepValues = parameters.get("stepIndex");
    if (stepValues != null && !stepValues.isEmpty()) {
        stepIndex = stepValues.get(0);
    }
    if (stepIndex == null) {
        stepIndex = "0";
    }
    final JsonBuilder jsonBuilder = new JsonBuilder().createJson(Integer.valueOf(stepIndex));
    for (Map.Entry<String, List<String>> entry : parameters.entrySet()) {
        String key = entry.getKey();
        if (!"stepIndex".equals(key)) {
            jsonBuilder.addInput(key, entry.getValue());
        }
    }

    final Response response = executeCommandJson(jsonBuilder.build(), commandName, headers);
    if (response.getEntity() instanceof JsonObject) {
        JsonObject responseEntity = (JsonObject) response.getEntity();
        String error = ((JsonObject) responseEntity.getJsonArray("messages").get(0)).getString("description");
        return Response.status(Status.PRECONDITION_FAILED).entity(unwrapJsonObjects(error)).build();
    }
    return response;
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:35,代码来源:LaunchResource.java

示例4: assertHasHeaderValue

import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
/**
 * Assert the specified header name has the specified value.
 */
protected void assertHasHeaderValue(String name, String value) {
	MultivaluedMap<String, String> headers = getLastReceivedHeaders();
	Assert.assertNotNull(headers);

	List<String> values = headers.get(name);
	Assert.assertNotNull(values);

	Assert.assertTrue(values.contains(value));
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:13,代码来源:AbstractClientTest.java

示例5: logHeaders

import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
private static void logHeaders(StringBuilder sb, int id, char prefix, MultivaluedMap<String, String> headers, HttpRequest actual) {
    Set<String> keys = new TreeSet(headers.keySet());
    for (String key : keys) {
        List<String> entries = headers.get(key);
        sb.append(id).append(' ').append(prefix).append(' ')
                .append(key).append(": ").append(entries.size() == 1 ? entries.get(0) : entries).append('\n');
        if (actual != null) {
            actual.putHeader(key, entries);
        }
    }
}
 
开发者ID:intuit,项目名称:karate,代码行数:12,代码来源:LoggingInterceptor.java

示例6: assertHeader

import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
private void assertHeader(MultivaluedMap<String, Object> headers, String headerName, String... headerValues) {
	assertThat(headers, hasKey(headerName));
	final List<Object> values = headers.get(headerName);
	assertThat(values, hasSize(headerValues.length));
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:6,代码来源:JerseyApplicationTest.java

示例7: apply

import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:52,代码来源:HttpComponentsConnector.java

示例8: filter

import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) {
    Method method = resourceInfo.getResourceMethod();
    if (!method.isAnnotationPresent(PermitAll.class)) {

        if (method.isAnnotationPresent(DenyAll.class)) {
            requestContext.abortWith(ACCESS_FORBIDDEN);
            return;
        }

        //Get request headers
        final MultivaluedMap<String, String> headers = requestContext.getHeaders();
        //Fetch authorization header
        final List<String> authorization = headers.get(AUTHORIZATION_PROPERTY);

        //If no authorization information present; block access
        if (authorization == null || authorization.isEmpty()) {
            requestContext.abortWith(ACCESS_DENIED);
            return;
        }

        //Get encoded username and password
        final String encodedUserPassword = authorization.get(0).replaceFirst(AUTHENTICATION_SCHEME + " ", "");

        //Decode username and password
        String usernameAndPassword = new String(Base64.decode(encodedUserPassword.getBytes()));
        ;

        //Split username and password tokens
        final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");
        final String username = tokenizer.nextToken();
        final String password = tokenizer.nextToken();

        //Verify user access
        if (method.isAnnotationPresent(RolesAllowed.class)) {
            RolesAllowed rolesAnnotation = method.getAnnotation(RolesAllowed.class);
            Set<String> rolesSet = new HashSet<String>(Arrays.asList(rolesAnnotation.value()));

            //Is user valid?
            if (!isUserAllowed(username, password, rolesSet)) {
                requestContext.abortWith(ACCESS_DENIED);
                return;
            }
        }
    }
}
 
开发者ID:faizan-ali,项目名称:full-javaee-app,代码行数:47,代码来源:AuthenticationFilter.java

示例9: PersoniumCoreContainerFilter

import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
/**
 * 認証なしのOPTIONSメソッドがリクエストされた場合にpersoniumで受け付けている全メソッドが返却されること.
 * @throws URISyntaxException URISyntaxException
 */
@Test
public void 認証なしのOPTIONSメソッドがリクエストされた場合にpersoniumで受け付けている全メソッドが返却されること() throws URISyntaxException {
    // 被テストオブジェクトを準備
    PersoniumCoreContainerFilter containerFilter = new PersoniumCoreContainerFilter();
    // ContainerRequiestを準備
    WebApplication wa = mock(WebApplication.class);
    InBoundHeaders headers = new InBoundHeaders();
    // X-FORWARDED-* 系のヘッダ設定
    String scheme = "https";
    String host = "example.org";
    headers.add(PersoniumCoreUtils.HttpHeaders.X_FORWARDED_PROTO, scheme);
    headers.add(PersoniumCoreUtils.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(io.personium.common.utils.PersoniumCoreUtils.HttpMethod.MERGE, "");
        masterMethods.put(io.personium.common.utils.PersoniumCoreUtils.HttpMethod.MKCOL, "");
        masterMethods.put(io.personium.common.utils.PersoniumCoreUtils.HttpMethod.MOVE, "");
        masterMethods.put(io.personium.common.utils.PersoniumCoreUtils.HttpMethod.PROPFIND, "");
        masterMethods.put(io.personium.common.utils.PersoniumCoreUtils.HttpMethod.PROPPATCH, "");
        masterMethods.put(io.personium.common.utils.PersoniumCoreUtils.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.");
        }
    }
}
 
开发者ID:personium,项目名称:personium-core,代码行数:65,代码来源:OptionsMethodTest.java

示例10: get

import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
@GET
@Produces({ MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, MIMETYPE_PROTOBUF_IETF })
public Response get(final @Context UriInfo uriInfo) {
  MultivaluedMap<String, String> params = uriInfo.getQueryParameters();

  servlet.getMetrics().incrementRequests(1);
  try {
    CellSetModel model = new CellSetModel();
    for (String rk : params.get(ROW_KEYS_PARAM_NAME)) {
      RowSpec rowSpec = new RowSpec(rk);

      if (this.versions != null) {
        rowSpec.setMaxVersions(this.versions);
      }
      ResultGenerator generator =
        ResultGenerator.fromRowSpec(this.tableResource.getName(), rowSpec, null,
          !params.containsKey(NOCACHE_PARAM_NAME));
      Cell value = null;
      RowModel rowModel = new RowModel(rk);
      if (generator.hasNext()) {
        while ((value = generator.next()) != null) {
          rowModel.addCell(new CellModel(CellUtil.cloneFamily(value), CellUtil
              .cloneQualifier(value), value.getTimestamp(), CellUtil.cloneValue(value)));
        }
        model.addRow(rowModel);
      } else {
        LOG.trace("The row : " + rk + " not found in the table.");
      }
    }

    if (model.getRows().size() == 0) {
    //If no rows found.
      servlet.getMetrics().incrementFailedGetRequests(1);
      return Response.status(Response.Status.NOT_FOUND)
          .type(MIMETYPE_TEXT).entity("No rows found." + CRLF)
          .build();
    } else {
      servlet.getMetrics().incrementSucessfulGetRequests(1);
      return Response.ok(model).build();
    }
  } catch (Exception e) {
    servlet.getMetrics().incrementFailedGetRequests(1);
    return processException(e);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:46,代码来源:MultiRowResource.java


注:本文中的javax.ws.rs.core.MultivaluedMap.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。