Java Code Examples for javax.ws.rs.core.MultivaluedMap#entrySet()

The following examples show how to use javax.ws.rs.core.MultivaluedMap#entrySet() . 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: SchemaRegistryResource.java    From registry with Apache License 2.0 6 votes vote down vote up
private SchemaFieldQuery buildSchemaFieldQuery(MultivaluedMap<String, String> queryParameters) {
    SchemaFieldQuery.Builder builder = new SchemaFieldQuery.Builder();
    for (Map.Entry<String, List<String>> entry : queryParameters.entrySet()) {
        List<String> entryValue = entry.getValue();
        String value = entryValue != null && !entryValue.isEmpty() ? entryValue.get(0) : null;
        if (value != null) {
            if (SchemaFieldInfo.FIELD_NAMESPACE.equals(entry.getKey())) {
                builder.namespace(value);
            } else if (SchemaFieldInfo.NAME.equals(entry.getKey())) {
                builder.name(value);
            } else if (SchemaFieldInfo.TYPE.equals(entry.getKey())) {
                builder.type(value);
            }
        }
    }

    return builder.build();
}
 
Example 2
Source File: RequestDispatcherProvider.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void setRequestParameters(HttpServletRequestFilter request) {
    if (getMessageContext() != null) {
        UriInfo ui = getMessageContext().getUriInfo();
        MultivaluedMap<String, String> params = ui.getPathParameters();
        for (Map.Entry<String, List<String>> entry : params.entrySet()) {
            String value = entry.getValue().get(0);
            int ind = value.indexOf(';');
            if (ind > 0) {
                value = value.substring(0, ind);
            }
            request.setParameter(entry.getKey(), value);
        }

        List<PathSegment> segments = ui.getPathSegments();
        if (!segments.isEmpty()) {
            doSetRequestParameters(request, segments.get(segments.size() - 1).getMatrixParameters());
        }
        doSetRequestParameters(request, ui.getQueryParameters());
        request.setParameter(ABSOLUTE_PATH_PARAMETER, ui.getAbsolutePath().toString());
        request.setParameter(RELATIVE_PATH_PARAMETER, ui.getPath());
        request.setParameter(BASE_PATH_PARAMETER, ui.getBaseUri().toString());
        request.setParameter(WEBAPP_BASE_PATH_PARAMETER, (String)getMessageContext().get("http.base.path"));
    }
}
 
Example 3
Source File: PlainTextExamplesMessageBodyReader.java    From vw-webservice with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public ExamplesIterable readFrom(Class<ExamplesIterable> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {

	if (LOGGER.isDebugEnabled()) if (httpHeaders != null && httpHeaders.size() > 0) {
		LOGGER.debug("Rec'd HTTP headers: ");

		for (Entry<String, List<String>> entry : httpHeaders.entrySet()) {
			LOGGER.debug("{}:{}", entry.getKey(), StringUtils.join(entry.getValue(), ','));
		}
	}

	// TODO:
	// if a content-length has been provided, then use that to read entire
	// string in one go.

	Charset charset = ReaderWriter.getCharset(mediaType);

	LOGGER.debug("Reading examples using charset: {}", charset.displayName());

	StringExampleIterator theIterator = new StringExampleIterator(entityStream, charset);

	// TODO: provide the proper number of examples here
	// setting this to Integer.MAX_VALUE for now to force streaming
	return new ExamplesIterableImpl(Integer.MAX_VALUE, null, theIterator);
}
 
Example 4
Source File: GremlinClient.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
public Response doGetRequest(String auth,
                             MultivaluedMap<String, String> params) {
    WebTarget target = this.webTarget;
    for (Map.Entry<String, List<String>> entry : params.entrySet()) {
        E.checkArgument(entry.getValue().size() == 1,
                        "Invalid query param '%s', can only accept " +
                        "one value, but got %s",
                        entry.getKey(), entry.getValue());
        target = target.queryParam(entry.getKey(), entry.getValue().get(0));
    }
    return target.request()
                 .header(HttpHeaders.AUTHORIZATION, auth)
                 .accept(MediaType.APPLICATION_JSON)
                 .acceptEncoding(CompressInterceptor.GZIP)
                 .get();
}
 
Example 5
Source File: HttpRequestAdapter.java    From jerseyoauth2 with MIT License 6 votes vote down vote up
public HttpRequestAdapter(ContainerRequest containerRequest) {
	this.containerRequest = containerRequest;
	
	MultivaluedMap<String, String> queryParams = containerRequest.getQueryParameters();
	for (Entry<String, List<String>> entry : queryParams.entrySet())
	{
		StringBuffer values = new StringBuffer();
		for (String val : entry.getValue())
		{
			if (values.length()>0) {
				values.append(",");
			}
			values.append(val);
		}
		this.queryParameters.put(entry.getKey(), values.toString());
	}
}
 
Example 6
Source File: RequestUtils.java    From mrgeo with Apache License 2.0 6 votes vote down vote up
public static MultivaluedMap<String, String> replaceParam(String name, List<String> values,
    MultivaluedMap<String, String> params)
{

  MultivaluedStringMap sm = new MultivaluedStringMap(params);

  for (Map.Entry<String, List<String>> es : params.entrySet())
  {
    if (es.getKey().equalsIgnoreCase(name))
    {
      sm.remove(es.getKey());
      break;
    }
  }

  sm.putIfAbsent(name, values);

  return sm;
}
 
Example 7
Source File: TrasformazioniUtils.java    From govpay with GNU General Public License v3.0 6 votes vote down vote up
private static Map<String, String> convertMultiToRegularMap(MultivaluedMap<String, String> m) {
	Map<String, String> map = new HashMap<String, String>();
	if (m == null) {
		return map;
	}
	for (Entry<String, List<String>> entry : m.entrySet()) {
		if(entry.getValue() != null) {
			StringBuilder sb = new StringBuilder();
			for (String s : entry.getValue()) {
				if (sb.length() > 0) {
					sb.append(',');
				}
				sb.append(s);
			}
			map.put(entry.getKey(), sb.toString());
		}
	}
	return map;
}
 
Example 8
Source File: MultipartBuilder.java    From mailgun with MIT License 5 votes vote down vote up
MultipartBuilder(MailBuilder mailBuilder) {
    configuration = mailBuilder.configuration();

    MultivaluedMap<String, String> map = mailBuilder.form().asMap();
    for (Map.Entry<String, List<String>> entry : map.entrySet())
        for (String value : entry.getValue())
            form.field(entry.getKey(), value);
}
 
Example 9
Source File: OperationContextImpl.java    From ldp4j with Apache License 2.0 5 votes vote down vote up
@Override
public Query getQuery() {
	final MultivaluedMap<String,String> queryParameters = this.uriInfo.getQueryParameters();
	final QueryBuilder builder = QueryBuilder.newInstance();
	for(final Entry<String, List<String>> entry:queryParameters.entrySet()) {
		final String parameterName = entry.getKey();
		for(final String rawValue:entry.getValue()) {
			builder.withParameter(parameterName, rawValue);
		}
	}
	return builder.build();
}
 
Example 10
Source File: RawLoggingFilter.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private void printResponseHeaders(StringBuilder b, long id,
		MultivaluedMap<String, String> headers) {
	for (Map.Entry<String, List<String>> e : headers.entrySet()) {
		String header = e.getKey();
		for (String value : e.getValue()) {
			prefixId(b, id).append(RESPONSE_PREFIX).append(header)
					.append(": ").append(value).append("\n");
		}
	}
	prefixId(b, id).append(RESPONSE_PREFIX).append("\n");
}
 
Example 11
Source File: HttpStageUtil.java    From datacollector with Apache License 2.0 5 votes vote down vote up
public static Object getFirstHeaderIgnoreCase(String name, MultivaluedMap<String, Object> headers) {
  for (final Map.Entry<String, List<Object>> headerEntry : headers.entrySet()) {
    if (name.equalsIgnoreCase(headerEntry.getKey())) {
      if (headerEntry.getValue() != null && headerEntry.getValue().size() > 0) {
        return headerEntry.getValue().get(0);
      }
      break;
    }
  }
  return null;
}
 
Example 12
Source File: RequestLogger.java    From qaf with MIT License 5 votes vote down vote up
private void printResponseHeaders(StringBuilder b, long id, MultivaluedMap<String, String> headers) {
	for (Map.Entry<String, List<String>> e : headers.entrySet()) {
		String header = e.getKey();
		for (String value : e.getValue()) {
			prefixId(b, id).append(RESPONSE_PREFIX).append(header).append(": ").append(value).append("\n");
		}
	}
	prefixId(b, id).append(RESPONSE_PREFIX).append("\n");
}
 
Example 13
Source File: LoggingFilter.java    From dubbox with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 14
Source File: ODataExceptionMapperImpl.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private ODataErrorContext createErrorContext(final WebApplicationException exception) {
  ODataErrorContext context = new ODataErrorContext();
  if (uriInfo != null) {
    context.setRequestUri(uriInfo.getRequestUri());
  }
  if (httpHeaders != null && httpHeaders.getRequestHeaders() != null) {
    MultivaluedMap<String, String> requestHeaders = httpHeaders.getRequestHeaders();
    Set<Entry<String, List<String>>> entries = requestHeaders.entrySet();
    for (Entry<String, List<String>> entry : entries) {
      context.putRequestHeader(entry.getKey(), entry.getValue());
    }
  }
  context.setContentType(getContentType().toContentTypeString());
  context.setException(exception);
  context.setErrorCode(null);
  context.setMessage(exception.getMessage());
  context.setLocale(DEFAULT_RESPONSE_LOCALE);
  HttpStatusCodes statusCode = HttpStatusCodes.fromStatusCode(exception.getResponse().getStatus());
  context.setHttpStatus(statusCode);
  if (statusCode == HttpStatusCodes.METHOD_NOT_ALLOWED) {
    // RFC 2616, 5.1.1: " An origin server SHOULD return the status code
    // 405 (Method Not Allowed) if the method is known by the origin server
    // but not allowed for the requested resource, and 501 (Not Implemented)
    // if the method is unrecognized or not implemented by the origin server."
    // Since all recognized methods are handled elsewhere, we unconditionally
    // switch to 501 here for not-allowed exceptions thrown directly from
    // JAX-RS implementations.
    context.setHttpStatus(HttpStatusCodes.NOT_IMPLEMENTED);
    context.setMessage("The request dispatcher does not allow the HTTP method used for the request.");
    context.setLocale(Locale.ENGLISH);
  }
  return context;
}
 
Example 15
Source File: LoggingFilter.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 16
Source File: CatnapMessageBodyWriter.java    From catnap with Apache License 2.0 5 votes vote down vote up
@Override
public void writeTo(Object obj, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
                    MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    //Check to see if Catnap processing has been disabled for this method
    for (Annotation annotation : annotations) {
        if (annotation instanceof CatnapDisabled) {
            RequestUtil.disableCatnap(request);
            break;
        }
    }

    try {
        //Transfer headers onto the response object that will be processed by Catnap
        if (httpHeaders != null) {
            for (Map.Entry<String, List<Object>> entry : httpHeaders.entrySet()) {
                for (Object value : entry.getValue()) {
                    response.addHeader(entry.getKey(), value.toString());
                }
            }
        }

        response.setContentType(getContentType());
        response.setCharacterEncoding(getCharacterEncoding());

        view.render(request, response, obj);
    } catch (Exception e) {
        logger.error("Exception encountered during view rendering!", e);
        throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
    }
}
 
Example 17
Source File: SimpleJsonExamplesMessageBodyReader.java    From vw-webservice with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public ExamplesIterable readFrom(Class<ExamplesIterable> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {

	if (LOGGER.isDebugEnabled()) if (httpHeaders != null && httpHeaders.size() > 0) {
		LOGGER.debug("Rec'd HTTP headers: ");

		for (Entry<String, List<String>> entry : httpHeaders.entrySet()) {
			LOGGER.debug("{}:{}", entry.getKey(), StringUtils.join(entry.getValue(), ','));
		}
	}

	//TODO: hard-coding to GsonJsonExamplesProvider for now
	return new ExamplesIterableImpl(Integer.MAX_VALUE, null, new GsonJsonExamplesProvider().getExamplesFromStream(entityStream));

}
 
Example 18
Source File: LoggingFilter.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 19
Source File: AbstractSignatureOutFilter.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Map<String, List<String>> convertHeaders(MultivaluedMap<String, Object> requestHeaders) {
    Map<String, List<String>> convertedHeaders = new HashMap<>(requestHeaders.size());
    for (Map.Entry<String, List<Object>> entry : requestHeaders.entrySet()) {
        convertedHeaders.put(entry.getKey(),
                             entry.getValue().stream().map(o -> o.toString().trim()).collect(Collectors.toList()));
    }
    return convertedHeaders;
}
 
Example 20
Source File: ResourceServiceImpl.java    From syncope with Apache License 2.0 4 votes vote down vote up
@Override
public PagedConnObjectTOResult searchConnObjects(
        final String key, final String anyTypeKey, final ConnObjectTOQuery query) {

    Filter filter = null;
    Set<String> moreAttrsToGet = Set.of();
    if (StringUtils.isNotBlank(query.getFiql())) {
        try {
            FilterVisitor visitor = new FilterVisitor();
            SearchCondition<SearchBean> sc = searchContext.getCondition(query.getFiql(), SearchBean.class);
            sc.accept(visitor);

            filter = visitor.getQuery();
            moreAttrsToGet = visitor.getAttrs();
        } catch (Exception e) {
            LOG.error("Invalid FIQL expression: {}", query.getFiql(), e);

            SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSearchExpression);
            sce.getElements().add(query.getFiql());
            sce.getElements().add(ExceptionUtils.getRootCauseMessage(e));
            throw sce;
        }
    }

    Pair<SearchResult, List<ConnObjectTO>> list = logic.searchConnObjects(
            filter,
            moreAttrsToGet,
            key,
            anyTypeKey,
            query.getSize(),
            query.getPagedResultsCookie(),
            getOrderByClauses(query.getOrderBy()));

    PagedConnObjectTOResult result = new PagedConnObjectTOResult();
    if (list.getLeft() != null) {
        result.setAllResultsReturned(list.getLeft().isAllResultsReturned());
        result.setPagedResultsCookie(list.getLeft().getPagedResultsCookie());
        result.setRemainingPagedResults(list.getLeft().getRemainingPagedResults());
    }
    result.getResult().addAll(list.getRight());

    UriBuilder builder = uriInfo.getAbsolutePathBuilder();
    MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
    for (Map.Entry<String, List<String>> queryParam : queryParams.entrySet()) {
        builder = builder.queryParam(queryParam.getKey(), queryParam.getValue().toArray());
    }

    if (StringUtils.isNotBlank(result.getPagedResultsCookie())) {
        result.setNext(builder.
                replaceQueryParam(PARAM_CONNID_PAGED_RESULTS_COOKIE, result.getPagedResultsCookie()).
                replaceQueryParam(PARAM_SIZE, query.getSize()).
                build());
    }

    return result;
}