Java Code Examples for javax.ws.rs.core.UriBuilder#buildFromMap()

The following examples show how to use javax.ws.rs.core.UriBuilder#buildFromMap() . 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: ApplicationUris.java    From krazo with Apache License 2.0 6 votes vote down vote up
/**
 * @see javax.mvc.MvcContext#uri(String, Map)
 */
public URI get(String identifier, Map<String, Object> params) {
    UriTemplate uriTemplate = getUriTemplate(identifier);
    UriBuilder uriBuilder = UriBuilder.fromUri(uriTemplate.path());
    Map<String, Object> pathParams = new HashMap<>();
    // Everything which is not defined as query- or matrix-param should be a path-param
    params.forEach((key, value) -> {
        if (uriTemplate.queryParams().contains(key)) {
            uriBuilder.queryParam(key, value);
        } else if (uriTemplate.matrixParams().contains(key)) {
            uriBuilder.matrixParam(key, value);
        } else {
            pathParams.put(key, value);
        }
    });
    return uriBuilder.buildFromMap(pathParams);
}
 
Example 2
Source File: ApplicationUris.java    From ozark with Apache License 2.0 6 votes vote down vote up
/**
 * @see javax.mvc.MvcContext#uri(String, Map)
 */
public URI get(String identifier, Map<String, Object> params) {
    UriTemplate uriTemplate = getUriTemplate(identifier);
    UriBuilder uriBuilder = UriBuilder.fromUri(uriTemplate.path());
    Map<String, Object> pathParams = new HashMap<>();
    // Everything which is not defined as query- or matrix-param should be a path-param
    params.forEach((key, value) -> {
        if (uriTemplate.queryParams().contains(key)) {
            uriBuilder.queryParam(key, value);
        } else if (uriTemplate.matrixParams().contains(key)) {
            uriBuilder.matrixParam(key, value);
        } else {
            pathParams.put(key, value);
        }
    });
    return uriBuilder.buildFromMap(pathParams);
}
 
Example 3
Source File: LinkCreator.java    From rest-schemagen with Apache License 2.0 5 votes vote down vote up
private URI mergeUri(URI baseUri, UriBuilder uriBuilder, Map<String, Object> pathParameters) {
    URI uri = uriBuilder.buildFromMap(pathParameters);

    if (baseUri != null) {
        UriBuilder mergedUriBuilder = UriBuilder.fromUri(baseUri);
        mergedUriBuilder.path(uri.getPath());
        mergedUriBuilder.replaceQuery(uri.getQuery());
        return mergedUriBuilder.buildFromMap(pathParameters);
    }

    return uri;
}
 
Example 4
Source File: SamlProtocol.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public Response sendError(AuthenticationSessionModel authSession, Error error) {
    try {
        ClientModel client = authSession.getClient();

        if ("true".equals(authSession.getClientNote(SAML_IDP_INITIATED_LOGIN))) {
            if (error == Error.CANCELLED_BY_USER) {
                UriBuilder builder = RealmsResource.protocolUrl(uriInfo).path(SamlService.class, "idpInitiatedSSO");
                Map<String, String> params = new HashMap<>();
                params.put("realm", realm.getName());
                params.put("protocol", LOGIN_PROTOCOL);
                params.put("client", client.getAttribute(SAML_IDP_INITIATED_SSO_URL_NAME));
                URI redirect = builder.buildFromMap(params);
                return Response.status(302).location(redirect).build();
            } else {
                return ErrorPage.error(session, authSession, Response.Status.BAD_REQUEST, translateErrorToIdpInitiatedErrorMessage(error));
            }
        } else {
            return samlErrorMessage(
              authSession, new SamlClient(client), isPostBinding(authSession),
              authSession.getRedirectUri(), translateErrorToSAMLStatus(error), authSession.getClientNote(GeneralConstants.RELAY_STATE)
            );
        }
    } finally {
        new AuthenticationSessionManager(session).removeAuthenticationSession(realm, authSession, true);
    }
}