Java Code Examples for org.apache.cxf.jaxrs.utils.JAXRSUtils#getStructuredParams()

The following examples show how to use org.apache.cxf.jaxrs.utils.JAXRSUtils#getStructuredParams() . 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: AbstractSAML2SPServlet.java    From syncope with Apache License 2.0 6 votes vote down vote up
protected SAML2ReceivedResponseTO extract(
        final String spEntityID,
        final String urlContext,
        final String clientAddress,
        final InputStream response) throws IOException {

    String strForm = IOUtils.toString(response);
    MultivaluedMap<String, String> params = JAXRSUtils.getStructuredParams(strForm, "&", false, false);

    String samlResponse = params.getFirst(SSOConstants.SAML_RESPONSE);
    if (StringUtils.isNotBlank(samlResponse)) {
        samlResponse = URLDecoder.decode(samlResponse, StandardCharsets.UTF_8);
        LOG.debug("Received SAML Response: {}", samlResponse);
    }

    String relayState = params.getFirst(SSOConstants.RELAY_STATE);
    LOG.debug("Received Relay State: {}", relayState);

    SAML2ReceivedResponseTO receivedResponseTO = new SAML2ReceivedResponseTO();
    receivedResponseTO.setSpEntityID(spEntityID);
    receivedResponseTO.setUrlContext(urlContext);
    receivedResponseTO.setSamlResponse(samlResponse);
    receivedResponseTO.setRelayState(relayState);
    return receivedResponseTO;
}
 
Example 2
Source File: FHIRUrlParser.java    From FHIR with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the url string into the path and query parts,
 * then parses the path part into the individual tokens and also parses the query string
 * into individual JAXRS-style parameters.
 * @param urlString
 */
private void parse(String urlString) {
    String[] tokens = urlString.split("\\?");
    if (tokens.length > 0) {
        path = tokens[0];
        pathTokens = path.split("/");
    }
    if (tokens.length > 1) {
        query = tokens[1];
        if (query != null && !query.isEmpty()) {
            JAXRSUtils.getStructuredParams(queryParameters, query, "&", true, false);
        }
    }
}
 
Example 3
Source File: UriBuilderImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void setUriParts(URI uri) {
    if (uri == null) {
        throw new IllegalArgumentException("uri is null");
    }
    String theScheme = uri.getScheme();
    if (theScheme != null) {
        scheme = theScheme;
    }
    String rawPath = uri.getRawPath();
    if (!uri.isOpaque() && schemeSpecificPart == null
            && (theScheme != null || rawPath != null)) {
        port = uri.getPort();
        host = uri.getHost();
        if (rawPath != null) {
            setPathAndMatrix(rawPath);
        }
        String rawQuery = uri.getRawQuery();
        if (rawQuery != null) {
            query = JAXRSUtils.getStructuredParams(rawQuery, "&", false, true);
        }
        userInfo = uri.getUserInfo();
        schemeSpecificPart = null;
    } else {
        schemeSpecificPart = uri.getSchemeSpecificPart();
    }
    if (scheme != null && host == null && port == -1 && userInfo == null
            && CollectionUtils.isEmpty(query)
            && uri.getSchemeSpecificPart() != null
            && !schemeSpecificPartMatchesUriPath(uri)) {
        schemeSpecificPart = uri.getSchemeSpecificPart();
    }
    String theFragment = uri.getFragment();
    if (theFragment != null) {
        fragment = theFragment;
    }
}
 
Example 4
Source File: UriBuilderImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public UriBuilder replaceQuery(String queryValue) throws IllegalArgumentException {
    if (queryValue != null) {
        // workaround to do with a conflicting and confusing requirement where spaces
        // passed as part of replaceQuery are encoded as %20 while those passed as part
        // of quertyParam are encoded as '+'
        queryValue = queryValue.replace(" ", "%20");
    }
    query = JAXRSUtils.getStructuredParams(queryValue, "&", false, true);
    return this;
}
 
Example 5
Source File: UriBuilderImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public UriBuilder uriAsTemplate(String uri) {
    // This can be a start of replacing URI class Parser completely
    // but it can be too complicated, the following code is needed for now
    // to deal with URIs containing template variables.
    int index = uri.indexOf(':');
    if (index != -1) {
        this.scheme = uri.substring(0, index);
        uri = uri.substring(index + 1);
        if (uri.indexOf("//") == 0) {
            uri = uri.substring(2);
            index = uri.indexOf('/');
            if (index != -1) {
                String[] schemePair = uri.substring(0, index).split(":");
                this.host = schemePair[0];
                this.port = schemePair.length == 2 ? Integer.parseInt(schemePair[1]) : -1;

                uri = uri.substring(index);
            }
        }

    }
    String rawQuery = null;
    index = uri.indexOf('?');
    if (index != -1) {
        rawQuery = uri.substring(index + 1);
        uri = uri.substring(0, index);
    }
    setPathAndMatrix(uri);
    if (rawQuery != null) {
        query = JAXRSUtils.getStructuredParams(rawQuery, "&", false, true);
    }

    return this;
}
 
Example 6
Source File: UriInfoImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public MultivaluedMap<String, String> getQueryParameters(boolean decode) {
    MultivaluedMap<String, String> queries = !caseInsensitiveQueries
        ? new MetadataMap<String, String>() : new MetadataMap<String, String>(false, true);
    JAXRSUtils.getStructuredParams(queries, (String)message.get(Message.QUERY_STRING),
                                  "&", decode, decode, queryValueIsCollection);
    return queries;

}
 
Example 7
Source File: UriBuilderImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void compareURIs(URI uri1, URI uri2) {

        assertEquals("Unexpected scheme", uri1.getScheme(), uri2.getScheme());
        assertEquals("Unexpected host", uri1.getHost(), uri2.getHost());
        assertEquals("Unexpected port", uri1.getPort(), uri2.getPort());
        assertEquals("Unexpected path", uri1.getPath(), uri2.getPath());
        assertEquals("Unexpected fragment", uri1.getFragment(), uri2.getFragment());

        MultivaluedMap<String, String> queries1 =
            JAXRSUtils.getStructuredParams(uri1.getRawQuery(), "&", false, false);
        MultivaluedMap<String, String> queries2 =
            JAXRSUtils.getStructuredParams(uri2.getRawQuery(), "&", false, false);
        assertEquals("Unexpected queries", queries1, queries2);
    }
 
Example 8
Source File: SearchContextImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public String getSearchExpression() {

        String queryStr = (String)message.get(Message.QUERY_STRING);
        if (queryStr != null) {
            if (MessageUtils.getContextualBoolean(message, USE_ALL_QUERY_COMPONENT)) {
                return queryStr;
            }
            boolean encoded = PropertyUtils.isTrue(getKeepEncodedProperty());

            MultivaluedMap<String, String> params =
                JAXRSUtils.getStructuredParams(queryStr, "&", !encoded, false);
            String customQueryParamName = (String)message.getContextualProperty(CUSTOM_SEARCH_QUERY_PARAM_NAME);
            if (customQueryParamName != null) {
                return params.getFirst(customQueryParamName);
            }
            if (queryStr.contains(SHORT_SEARCH_QUERY) || queryStr.contains(SEARCH_QUERY)) {
                if (params.containsKey(SHORT_SEARCH_QUERY)) {
                    return params.getFirst(SHORT_SEARCH_QUERY);
                }
                return params.getFirst(SEARCH_QUERY);
            } else if (MessageUtils.getContextualBoolean(message, USE_PLAIN_QUERY_PARAMETERS)) {
                return convertPlainQueriesToFiqlExp(params);
            }
        }
        return null;

    }
 
Example 9
Source File: FedizRedirectBindingFilter.java    From cxf-fediz with Apache License 2.0 5 votes vote down vote up
public void filter(ContainerRequestContext context) {
    Message m = JAXRSUtils.getCurrentMessage();
    FedizContext fedConfig = getFedizContext(m);

    // See if it is a Metadata request
    if (isMetadataRequest(context, fedConfig)) {
        return;
    }

    String httpMethod = context.getMethod();
    MultivaluedMap<String, String> params = null;

    try {
        if (HttpMethod.GET.equals(httpMethod)) {
            params = context.getUriInfo().getQueryParameters();
        } else if (HttpMethod.POST.equals(httpMethod)) {
            String strForm = IOUtils.toString(context.getEntityStream(), "UTF-8");
            params = JAXRSUtils.getStructuredParams(strForm, "&", true, false);
        }
    } catch (Exception ex) {
        LOG.debug(ex.getMessage(), ex);
        throw ExceptionUtils.toInternalServerErrorException(ex, null);
    }

    // See if it is a Logout request first
    if (isLogoutRequest(context, fedConfig, m, params) || isSignoutCleanupRequest(fedConfig, m, params)) {
        return;
    } else if (checkSecurityContext(fedConfig, m, params)) {
        return;
    } else if (isSignInRequired(fedConfig, params)) {
        processSignInRequired(context, fedConfig);
    } else if (isSignInRequest(fedConfig, params)) {
        processSignInRequest(context, fedConfig, m, params);
    } else {
        LOG.error("SignIn parameter is incorrect or not supported");
        throw ExceptionUtils.toBadRequestException(null, null);
    }
}
 
Example 10
Source File: UriBuilderImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public UriBuilder replaceMatrix(String matrixValues) throws IllegalArgumentException {
    String encodedMatrixValues = matrixValues != null ? HttpUtils.pathEncode(matrixValues) : null;
    this.matrix = JAXRSUtils.getStructuredParams(encodedMatrixValues, ";", true, false);
    return this;
}
 
Example 11
Source File: QueryResourceInfoComparator.java    From cxf-fediz with Apache License 2.0 4 votes vote down vote up
/**
 * This method calculates a number indicating a good or bad match between values provided within the request and
 * expected method parameters. A higher number means a better match.
 *
 * @param operation The operation to be rated, based on contained parameterInfo values.
 * @param message A message containing query and header values from user request
 * @return A positive or negative number, indicating a good match between query and method
 */
protected int getMatchingRate(final OperationResourceInfo operation, final Message message) {
    List<Parameter> params = operation.getParameters();
    if (params == null || params.isEmpty()) {
        return 0;
    }

    // Get Request QueryParams
    String query = (String) message.get(Message.QUERY_STRING);
    String path = (String) message.get(Message.REQUEST_URI);
    Map<String, List<String>> qParams = JAXRSUtils.getStructuredParams(query, "&", true, false);
    Map<String, List<String>> mParams = JAXRSUtils.getMatrixParams(path, true);
    // Get Request Headers
    Map<?, ?> qHeader = (java.util.Map<?, ?>) message.get(Message.PROTOCOL_HEADERS);

    int rate = 0;
    for (Parameter p : params) {
        switch (p.getType()) {
        case QUERY:
            if (qParams.containsKey(p.getName())) {
                rate += 2;
            } else if (p.getDefaultValue() == null) {
                rate -= 1;
            }
            break;
        case MATRIX:
            if (mParams.containsKey(p.getName())) {
                rate += 2;
            } else if (p.getDefaultValue() == null) {
                rate -= 1;
            }
            break;
        case HEADER:
            if (qHeader.containsKey(p.getName())) {
                rate += 2;
            } else if (p.getDefaultValue() == null) {
                rate -= 1;
            }
            break;
        default:
            break;
        }
    }
    return rate;
}