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

The following examples show how to use javax.ws.rs.core.MultivaluedMap#putAll() . 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: AuditBeanTest.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Test
public void restCallTest() {
    MultivaluedMap<String,String> mvMapParams = new MultivaluedMapImpl<>();
    mvMapParams.putAll(params);
    auditBean.auditRest(mvMapParams);
    
    AuditParameters expected = new AuditParameters();
    expected.validate(mvMapParams);
    
    AuditParameters actual = new AuditParameters();
    actual.validate(AuditParameters.parseMessage(auditor.params));
    
    assertEquals(expected.getUserDn(), actual.getUserDn());
    assertEquals(expected.getQuery(), actual.getQuery());
    assertEquals(expected.getSelectors(), actual.getSelectors());
    assertEquals(expected.getAuths(), actual.getAuths());
    assertEquals(expected.getAuditType(), actual.getAuditType());
    assertEquals(expected.getColviz(), actual.getColviz());
}
 
Example 2
Source File: ApplicationResource.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
protected MultivaluedMap<String, String> getRequestParameters() {
    final MultivaluedMap<String, String> entity = new MultivaluedMapImpl();

    // get the form that jersey processed and use it if it exists (only exist for requests with a body and application form urlencoded
    final Form form = (Form) httpContext.getProperties().get(FormDispatchProvider.FORM_PROPERTY);
    if (form == null) {
        for (final Map.Entry<String, String[]> entry : httpServletRequest.getParameterMap().entrySet()) {
            if (entry.getValue() == null) {
                entity.add(entry.getKey(), null);
            } else {
                for (final String aValue : entry.getValue()) {
                    entity.add(entry.getKey(), aValue);
                }
            }
        }
    } else {
        entity.putAll(form);
    }

    return entity;
}
 
Example 3
Source File: ParaClient.java    From para with Apache License 2.0 6 votes vote down vote up
/**
 * Searches for objects that have properties matching some given values. A terms query.
 * @param <P> type of the object
 * @param type the type of object to search for. See {@link com.erudika.para.core.ParaObject#getType()}
 * @param terms a map of fields (property names) to terms (property values)
 * @param matchAll match all terms. If true - AND search, if false - OR search
 * @param pager a {@link com.erudika.para.utils.Pager}
 * @return a list of objects found
 */
public <P extends ParaObject> List<P> findTerms(String type, Map<String, ?> terms, boolean matchAll,
		Pager... pager) {
	if (terms == null) {
		return Collections.emptyList();
	}
	MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
	params.putSingle("matchall", Boolean.toString(matchAll));
	LinkedList<String> list = new LinkedList<>();
	for (Map.Entry<String, ? extends Object> term : terms.entrySet()) {
		String key = term.getKey();
		Object value = term.getValue();
		if (value != null) {
			list.add(key.concat(Config.SEPARATOR).concat(value.toString()));
		}
	}
	if (!terms.isEmpty()) {
		params.put("terms", list);
	}
	params.putSingle(Config._TYPE, type);
	params.putAll(pagerToParams(pager));
	return getItems(find("terms", params), pager);
}
 
Example 4
Source File: DefaultUUIDModificationRequest.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public MultivaluedMap<String,String> toMap() {
    MultivaluedMap<String,String> p = new MultivaluedMapImpl<String,String>();
    p.putAll(super.toMap());
    if (this.events != null) {
        for (ModificationEvent e : events) {
            p.add("Events", e.toString());
        }
    }
    return p;
}
 
Example 5
Source File: ParaClient.java    From para with Apache License 2.0 5 votes vote down vote up
/**
 * Returns all child objects linked to this object.
 * @param <P> the type of children
 * @param type2 the type of children to look for
 * @param field the field name to use as filter
 * @param term the field value to use as filter
 * @param obj the object to execute this method on
 * @param pager a {@link com.erudika.para.utils.Pager}
 * @return a list of {@link ParaObject} in a one-to-many relationship with this object
 */
@SuppressWarnings("unchecked")
public <P extends ParaObject> List<P> getChildren(ParaObject obj, String type2, String field, String term,
		Pager... pager) {
	if (obj == null || obj.getId() == null || type2 == null) {
		return Collections.emptyList();
	}
	MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
	params.putSingle("childrenonly", "true");
	params.putSingle("field", field);
	params.putSingle("term", term);
	params.putAll(pagerToParams(pager));
	String url = Utils.formatMessage("{0}/links/{1}", obj.getObjectURI(), Utils.urlEncode(type2));
	return getItems((Map<String, Object>) getEntity(invokeGet(url, params), Map.class), pager);
}
 
Example 6
Source File: ParaClient.java    From para with Apache License 2.0 5 votes vote down vote up
/**
 * Returns all child objects linked to this object.
 * @param <P> the type of children
 * @param type2 the type of children to look for
 * @param obj the object to execute this method on
 * @param pager a {@link com.erudika.para.utils.Pager}
 * @return a list of {@link ParaObject} in a one-to-many relationship with this object
 */
@SuppressWarnings("unchecked")
public <P extends ParaObject> List<P> getChildren(ParaObject obj, String type2, Pager... pager) {
	if (obj == null || obj.getId() == null || type2 == null) {
		return Collections.emptyList();
	}
	MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
	params.putSingle("childrenonly", "true");
	params.putAll(pagerToParams(pager));
	String url = Utils.formatMessage("{0}/links/{1}", obj.getObjectURI(), Utils.urlEncode(type2));
	return getItems((Map<String, Object>) getEntity(invokeGet(url, params), Map.class), pager);
}
 
Example 7
Source File: ParaClient.java    From para with Apache License 2.0 5 votes vote down vote up
/**
 * Searches through all linked objects in many-to-many relationships.
 * @param <P> type of linked objects
 * @param type2 type of linked objects to search for
 * @param obj the object to execute this method on
 * @param pager a {@link com.erudika.para.utils.Pager}
 * @param field the name of the field to target (within a nested field "nstd")
 * @param query a query string
 * @return a list of linked objects matching the search query
 */
@SuppressWarnings("unchecked")
public <P extends ParaObject> List<P> findLinkedObjects(ParaObject obj, String type2, String field,
		String query, Pager... pager) {
	if (obj == null || obj.getId() == null || type2 == null) {
		return Collections.emptyList();
	}
	MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
	params.putSingle("field", field);
	params.putSingle("q", (query == null) ? "*" : query);
	params.putAll(pagerToParams(pager));
	String url = Utils.formatMessage("{0}/links/{1}", obj.getObjectURI(), Utils.urlEncode(type2));
	return getItems((Map<String, Object>) getEntity(invokeGet(url, params), Map.class), pager);
}
 
Example 8
Source File: CrossOriginResourceSharingFilter.java    From cxf with Apache License 2.0 5 votes vote down vote up
private OperationResourceInfo findPreflightMethod(
    Map<ClassResourceInfo, MultivaluedMap<String, String>> matchedResources,
                                                  String requestUri,
                                                  String httpMethod,
                                                  MultivaluedMap<String, String> values,
                                                  Message m) {
    final String contentType = MediaType.WILDCARD;
    final MediaType acceptType = MediaType.WILDCARD_TYPE;
    OperationResourceInfo ori = JAXRSUtils.findTargetMethod(matchedResources,
                                m, httpMethod, values,
                                contentType,
                                Collections.singletonList(acceptType),
                                false,
                                false);
    if (ori == null) {
        return null;
    }
    if (ori.isSubResourceLocator()) {
        Class<?> cls = ori.getMethodToInvoke().getReturnType();
        ClassResourceInfo subcri = ori.getClassResourceInfo().getSubResource(cls, cls);
        if (subcri == null) {
            return null;
        }
        MultivaluedMap<String, String> newValues = new MetadataMap<>();
        newValues.putAll(values);
        return findPreflightMethod(Collections.singletonMap(subcri, newValues),
                                   values.getFirst(URITemplate.FINAL_MATCH_GROUP),
                                   httpMethod,
                                   newValues,
                                   m);
    }
    return ori;
}
 
Example 9
Source File: JAXRSInvoker.java    From cxf with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected MultivaluedMap<String, String> getTemplateValues(Message msg) {
    MultivaluedMap<String, String> values = new MetadataMap<>();
    MultivaluedMap<String, String> oldValues =
        (MultivaluedMap<String, String>)msg.get(URITemplate.TEMPLATE_PARAMETERS);
    if (oldValues != null) {
        values.putAll(oldValues);
    }
    return values;
}
 
Example 10
Source File: ClusterCatalogResource.java    From streamline with Apache License 2.0 5 votes vote down vote up
/**
 * List ALL clusters or the ones matching specific query params.
 */
@GET
@Path("/clusters")
@Timed
public Response listClusters(@Context UriInfo uriInfo, @Context SecurityContext securityContext) {
    List<QueryParam> queryParams = new ArrayList<>();
    MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
    Collection<Cluster> clusters;
    Boolean detail = false;

    if (params.isEmpty()) {
        clusters = environmentService.listClusters();
    } else {
        MultivaluedMap<String, String> copiedParams = new MultivaluedHashMap<>();
        copiedParams.putAll(params);
        List<String> detailOption = copiedParams.remove("detail");
        if (detailOption != null && !detailOption.isEmpty()) {
            detail = BooleanUtils.toBooleanObject(detailOption.get(0));
        }

        queryParams = WSUtils.buildQueryParameters(copiedParams);
        clusters = environmentService.listClusters(queryParams);
    }

    if (clusters != null) {
        boolean servicePoolUser = SecurityUtil.hasRole(authorizer, securityContext, Roles.ROLE_SERVICE_POOL_USER);
        if (servicePoolUser) {
            LOG.debug("Returning all service pools since user has role: {}", Roles.ROLE_SERVICE_POOL_USER);
        } else {
            clusters = SecurityUtil.filter(authorizer, securityContext, NAMESPACE, clusters, READ);
        }
        return buildClustersGetResponse(clusters, detail);
    }

    throw EntityNotFoundException.byFilter(queryParams.toString());
}
 
Example 11
Source File: NamespaceCatalogResource.java    From streamline with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/namespaces")
@Timed
public Response listNamespaces(@Context UriInfo uriInfo,
                               @Context SecurityContext securityContext) {
  List<QueryParam> queryParams = new ArrayList<>();
  MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
  Collection<Namespace> namespaces;
  Boolean detail = false;

  if (params.isEmpty()) {
    namespaces = environmentService.listNamespaces();
  } else {
    MultivaluedMap<String, String> copiedParams = new MultivaluedHashMap<>();
    copiedParams.putAll(params);
    List<String> detailOption = copiedParams.remove("detail");
    if (detailOption != null && !detailOption.isEmpty()) {
      detail = BooleanUtils.toBooleanObject(detailOption.get(0));
    }

    queryParams = WSUtils.buildQueryParameters(copiedParams);
    namespaces = environmentService.listNamespaces(queryParams);
  }
  if (namespaces != null) {
    boolean environmentUser = SecurityUtil.hasRole(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_USER);
    if (environmentUser) {
      LOG.debug("Returning all environments since user has role: {}", Roles.ROLE_ENVIRONMENT_USER);
    } else {
      namespaces = SecurityUtil.filter(authorizer, securityContext, Namespace.NAMESPACE, namespaces, READ);
    }
    return buildNamespacesGetResponse(namespaces, detail);
  }

  throw EntityNotFoundException.byFilter(queryParams.toString());
}
 
Example 12
Source File: HmacAuthInterceptor.java    From gazpachoquest with GNU General Public License v3.0 5 votes vote down vote up
public void addHeader(Message message, String name, String value) {
    HttpHeaders requestHeaders = new HttpHeadersImpl(message);
    MultivaluedMap<String, String> newHeaders = new MetadataMap<String, String>();
    newHeaders.putAll(requestHeaders.getRequestHeaders());
    newHeaders.put(name, Arrays.asList(value));
    message.put(Message.PROTOCOL_HEADERS, newHeaders);
}
 
Example 13
Source File: AbstractClient.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public MultivaluedMap<String, String> getHeaders() {
    MultivaluedMap<String, String> map = new MetadataMap<>(false, true);
    map.putAll(state.getRequestHeaders());
    return map;
}
 
Example 14
Source File: OidcRpAuthenticationFilter.java    From cxf with Apache License 2.0 5 votes vote down vote up
private MultivaluedMap<String, String> toRequestState(ContainerRequestContext rc) {
    MultivaluedMap<String, String> requestState = new MetadataMap<>();
    requestState.putAll(rc.getUriInfo().getQueryParameters(true));
    if (MediaType.APPLICATION_FORM_URLENCODED_TYPE.isCompatible(rc.getMediaType())) {
        String body = FormUtils.readBody(rc.getEntityStream(), StandardCharsets.UTF_8.name());
        FormUtils.populateMapFromString(requestState, JAXRSUtils.getCurrentMessage(), body,
                                        StandardCharsets.UTF_8.name(), true);
        rc.setEntityStream(new ByteArrayInputStream(StringUtils.toBytesUTF8(body)));

    }
    return requestState;
}
 
Example 15
Source File: ClientProxyImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * 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 16
Source File: ParaClient.java    From para with Apache License 2.0 3 votes vote down vote up
/**
 * Search for {@link com.erudika.para.core.Address} objects in a radius of X km from a given point.
 * @param <P> type of the object
 * @param type the type of object to search for. See {@link com.erudika.para.core.ParaObject#getType()}
 * @param query the query string
 * @param radius the radius of the search circle
 * @param lat latitude
 * @param lng longitude
 * @param pager a {@link com.erudika.para.utils.Pager}
 * @return a list of objects found
 */
public <P extends ParaObject> List<P> findNearby(String type, String query, int radius, double lat, double lng,
		Pager... pager) {
	MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
	params.putSingle("latlng", lat + "," + lng);
	params.putSingle("radius", Integer.toString(radius));
	params.putSingle("q", query);
	params.putSingle(Config._TYPE, type);
	params.putAll(pagerToParams(pager));
	return getItems(find("nearby", params), pager);
}
 
Example 17
Source File: ParaClient.java    From para with Apache License 2.0 3 votes vote down vote up
/**
 * Simple query string search. This is the basic search method.
 * @param <P> type of the object
 * @param type the type of object to search for. See {@link com.erudika.para.core.ParaObject#getType()}
 * @param query the query string
 * @param pager a {@link com.erudika.para.utils.Pager}
 * @return a list of objects found
 */
public <P extends ParaObject> List<P> findQuery(String type, String query, Pager... pager) {
	MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
	params.putSingle("q", query);
	params.putSingle(Config._TYPE, type);
	params.putAll(pagerToParams(pager));
	return getItems(find("", params), pager);
}
 
Example 18
Source File: ParaClient.java    From para with Apache License 2.0 3 votes vote down vote up
/**
 * Searches within a nested field. The objects of the given type must contain a nested field "nstd".
 * @param <P> type of the object
 * @param type the type of object to search for. See {@link com.erudika.para.core.ParaObject#getType()}
 * @param field the name of the field to target (within a nested field "nstd")
 * @param query the query string
 * @param pager a {@link com.erudika.para.utils.Pager}
 * @return a list of objects found
 */
public <P extends ParaObject> List<P> findNestedQuery(String type, String field, String query, Pager... pager) {
	MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
	params.putSingle("q", query);
	params.putSingle("field", field);
	params.putSingle(Config._TYPE, type);
	params.putAll(pagerToParams(pager));
	return getItems(find("nested", params), pager);
}
 
Example 19
Source File: ParaClient.java    From para with Apache License 2.0 3 votes vote down vote up
/**
 * Searches for objects tagged with one or more tags.
 * @param <P> type of the object
 * @param type the type of object to search for. See {@link com.erudika.para.core.ParaObject#getType()}
 * @param tags the list of tags
 * @param pager a {@link com.erudika.para.utils.Pager}
 * @return a list of objects found
 */
public <P extends ParaObject> List<P> findTagged(String type, String[] tags, Pager... pager) {
	MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
	params.put("tags", tags == null ? null : Arrays.asList(tags));
	params.putSingle(Config._TYPE, type);
	params.putAll(pagerToParams(pager));
	return getItems(find("tagged", params), pager);
}
 
Example 20
Source File: ParaClient.java    From para with Apache License 2.0 3 votes vote down vote up
/**
 * Searches for objects that have a property with a value matching a wildcard query.
 * @param <P> type of the object
 * @param type the type of object to search for. See {@link com.erudika.para.core.ParaObject#getType()}
 * @param field the property name of an object
 * @param wildcard wildcard query string. For example "cat*".
 * @param pager a {@link com.erudika.para.utils.Pager}
 * @return a list of objects found
 */
public <P extends ParaObject> List<P> findWildcard(String type, String field, String wildcard, Pager... pager) {
	MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
	params.putSingle("field", field);
	params.putSingle("q", wildcard);
	params.putSingle(Config._TYPE, type);
	params.putAll(pagerToParams(pager));
	return getItems(find("wildcard", params), pager);
}