本文整理汇总了Java中javax.ws.rs.core.MultivaluedMap.entrySet方法的典型用法代码示例。如果您正苦于以下问题:Java MultivaluedMap.entrySet方法的具体用法?Java MultivaluedMap.entrySet怎么用?Java MultivaluedMap.entrySet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.core.MultivaluedMap
的用法示例。
在下文中一共展示了MultivaluedMap.entrySet方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: urlEncodeMultivaluedParams
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
/**
* Encodes a collection of key-value pairs as a URL encoded string.
*
* @param params The parameters.
* @return The URL encoded string.
*/
public static String urlEncodeMultivaluedParams(final MultivaluedMap<String, String> params) {
if (params == null || params.isEmpty()) {
return "";
}
final StringBuilder b = new StringBuilder();
for (final Entry<String, List<String>> entry : params.entrySet()) {
for (final String value : entry.getValue()) {
if (b.length() > 0) {
b.append("&");
}
b.append(urlEncode(entry.getKey()));
b.append("=");
b.append(urlEncode(value));
}
}
return b.toString();
}
示例2: serializeMultipartForm
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
public static InputStream serializeMultipartForm(final Form form) {
final String boundary = "------Boundary" + UUID.randomUUID().toString();
final StringBuilder b = new StringBuilder();
final MultivaluedMap<String, String> map = form.asMap();
for (final Entry<String, List<String>> entry : map.entrySet()) {
for (final String value : entry.getValue()) {
b.append(boundary);
b.append("\nContent-Disposition: form-data; name=\"");
b.append(entry.getKey());
b.append("\"\n\n");
b.append(value);
b.append("\n");
}
}
b.append(boundary);
return new ByteArrayInputStream(b.toString().getBytes(StandardCharsets.UTF_8));
}
示例3: logHttpHeaders
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
protected void logHttpHeaders(MultivaluedMap<String, String> headers) {
StringBuilder msg = new StringBuilder("The HTTP headers are: \n");
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
msg.append(entry.getKey()).append(": ");
for (int i = 0; i < entry.getValue().size(); i++) {
msg.append(entry.getValue().get(i));
if (i < entry.getValue().size() - 1) {
msg.append(", ");
}
}
msg.append("\n");
}
logger.info(msg.toString());
}
示例4: equalsRequestHeader
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
private boolean equalsRequestHeader(ContainerRequestContext containerRequestContext) {
MultivaluedMap<String, String> requestHeader = containerRequestContext.getHeaders();
MultivaluedMap<String, Object> desiredHeader = endpoint.getHeader().getContent();
if (!StringUtils.isEmpty(desiredHeader)) {
if (!requestHeader.isEmpty()) {
for (Map.Entry<String, List<Object>> map : desiredHeader.entrySet()) {
if (!requestHeader.containsKey(map.getKey()) || !requestHeader.get(map.getKey()).containsAll(map.getValue()))
return false;
}
} else
return false;
}
return true;
}
示例5: getFilterAttributes
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
public Map<String, String> getFilterAttributes() {
if (uriInfo != null) {
MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
for (Map.Entry<String, List<String>> queryParam : queryParams.entrySet()) {
String queryParamAttribute = queryParam.getKey();
if (StringUtils.isBlank(queryParamAttribute) || !queryParamAttribute.startsWith("filter-")) {
continue;
}
queryParamAttribute = queryParamAttribute.substring("filter-".length(), queryParamAttribute.length());
String filterVal = StringUtils.trimToNull(queryParam.getValue().get(0));
if (filterVal != null) {
filterAttributes.put(queryParamAttribute, filterVal);
}
}
}
return filterAttributes;
}
示例6: mapResponse
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
@Override
public Response mapResponse(StatusType status, Object response) {
javax.ws.rs.core.Response jaxrsResponse = (javax.ws.rs.core.Response) response;
Response cseResponse = Response.status(jaxrsResponse.getStatusInfo()).entity(jaxrsResponse.getEntity());
MultivaluedMap<String, Object> headers = jaxrsResponse.getHeaders();
for (Entry<String, List<Object>> entry : headers.entrySet()) {
if (entry.getValue() == null || entry.getValue().isEmpty()) {
continue;
}
cseResponse.getHeaders().addHeader(entry.getKey(), entry.getValue());
}
return cseResponse;
}
示例7: 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;
}
示例8: commitHeaders
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
protected void commitHeaders(ClientInvocation request, HttpRequestBase httpMethod) {
MultivaluedMap<String, String> headers = request.getHeaders().asMap();
for (Map.Entry<String, List<String>> header : headers.entrySet()) {
List<String> values = header.getValue();
for (String value : values) {
// System.out.println(String.format("setting %s = %s", header.getKey(), value));
httpMethod.addHeader(header.getKey(), value);
}
}
}
示例9: getHeaders
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
/**
* Get all response headers.
*
* @return the response headers
*/
@PublicAtsApi
public RestHeader[] getHeaders() {
List<RestHeader> headers = new ArrayList<RestHeader>();
MultivaluedMap<String, Object> respHeaders = response.getHeaders();
for (Entry<String, List<Object>> respHeaderEntry : respHeaders.entrySet()) {
headers.add(RestHeader.constructRESTHeader(respHeaderEntry.getKey(), respHeaderEntry.getValue()));
}
return headers.toArray(new RestHeader[headers.size()]);
}
示例10: filter
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
@Override
public void filter( ClientRequestContext context ) throws IOException {
if (debugLevel == RESTDebugLevel.NONE || debugLevel == RESTDebugLevel.TARGET_URI) {
return;
}
MultivaluedMap<String, Object> reqHeaders = context.getHeaders();
StringBuilder requestMessage = new StringBuilder();
requestMessage.append("Sending the following request: \n");
if ( (debugLevel & RESTDebugLevel.HEADERS) == RESTDebugLevel.HEADERS) {
requestMessage.append(context.getMethod() + " " + context.getUri() + " \n");
for (Entry<String, List<Object>> reqHeaderEntry : reqHeaders.entrySet()) {
requestMessage.append(reqHeaderEntry.getKey() + ": "
+ Arrays.toString(reqHeaderEntry.getValue().toArray()) + " \n");
}
}
if ( (debugLevel & RESTDebugLevel.BODY) == RESTDebugLevel.BODY && context.hasEntity()) {
//log request body
Object entity = context.getEntity();
if (entity instanceof Form) {
requestMessage.append("Body: " + ((Form) entity).asMap());
} else {
requestMessage.append("Body: " + entity.toString());
}
}
log.info(requestMessage);
}
示例11: getParameters
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
private Map<String, Set<String>> getParameters(UriInfo uriInfo) {
MultivaluedMap<String, String> queryParametersMultiMap = uriInfo.getQueryParameters();
Map<String, Set<String>> queryParameters = new HashMap<>();
for (Map.Entry<String, List<String>> queryEntry : queryParametersMultiMap.entrySet()) {
queryParameters.put(queryEntry.getKey(), new LinkedHashSet<>(queryEntry.getValue()));
}
return queryParameters;
}
示例12: setMultivaluedMapParams
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
private static void setMultivaluedMapParams(MultivaluedMap<String,String> params, Run run, String... excluded) throws IOException {
Collection<String> ex = new HashSet<String>(Arrays.asList(excluded));
for (Map.Entry<String,List<String>> e : params.entrySet()) {
String name = e.getKey();
if (ex.contains(name)) {
continue;
}
List<String> values = e.getValue();
if (values.isEmpty()) {
continue;
}
String value = values.get(values.size() - 1);
setParam(run, name, value);
}
}
示例13: rebuildQuery
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
/** Rebuild the URI query with lower case parameter names. */
private static URI rebuildQuery(final URI uri,
final MultivaluedMap<String, String> parameters) {
UriBuilder b = UriBuilder.fromUri(uri).replaceQuery("");
for(Map.Entry<String, List<String>> e : parameters.entrySet()) {
final String key = StringUtils.toLowerCase(e.getKey());
for(String v : e.getValue()) {
b = b.queryParam(key, v);
}
}
return b.build();
}
示例14: toResponse
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
@Override
public Response toResponse(WebApplicationException exception) {
LOGGER.error("WebApplicationException:", exception);
LOGGER.debug("Constructing Error Response for: [{}]", exception.toString());
ErrorResponse errorResponse = new ErrorResponse();
Response exceptionResponse = exception.getResponse();
Response.StatusType statusInfo = exceptionResponse.getStatusInfo();
errorResponse.setCode(statusInfo.getStatusCode());
errorResponse.setStatus(statusInfo.getReasonPhrase());
errorResponse.setMessage(exception.getMessage());
Response.ResponseBuilder responseBuilder = Response.status(statusInfo)
.entity(errorResponse)
.type(MediaType.APPLICATION_JSON);
MultivaluedMap<String, Object> headers = exceptionResponse.getHeaders();
if (headers.size() > 0) {
LOGGER.debug("Adding headers:");
for (Map.Entry<String, List<Object>> entry : headers.entrySet()) {
String headerKey = entry.getKey();
List<Object> headerValues = entry.getValue();
LOGGER.debug(" {} -> {}", headerKey, headerValues);
if (headerValues.size() == 1) {
responseBuilder.header(headerKey, headerValues.get(0));
} else {
responseBuilder.header(headerKey, headerValues);
}
}
}
return responseBuilder.build();
}
开发者ID:durimkryeziu,项目名称:jersey-2.x-webapp-for-servlet-container,代码行数:36,代码来源:WebApplicationExceptionMapper.java