Example usage for java.net URI getFragment

List of usage examples for java.net URI getFragment

Introduction

In this page you can find the example usage for java.net URI getFragment.

Prototype

public String getFragment() 

Source Link

Document

Returns the decoded fragment component of this URI.

Usage

From source file:org.appverse.web.framework.backend.test.util.oauth2.tests.predefined.implicit.Oauth2ImplicitFlowPredefinedTests.java

@Test
public void obtainTokenFromOuth2LoginEndpoint() throws Exception {
    UriComponentsBuilder builder = UriComponentsBuilder
            .fromHttpUrl(authServerBaseUrl + oauth2AuthorizeEndpointPath);
    builder.queryParam("username", getUsername());
    builder.queryParam("password", getPassword());
    builder.queryParam("client_id", getClientId());
    builder.queryParam("response_type", "token");
    builder.queryParam("redirect_uri", "http://anywhere");

    HttpEntity<String> entity = new HttpEntity<>("");
    ResponseEntity<String> result2 = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.POST,
            entity, String.class);

    // This means the user was correctly authenticated, then a redirection was performed to /oauth/authorize to obtain the token.
    // Then the token was sucessfully obtained (authenticating the client properly) and a last redirection was performed to the 
    // redirect_uri with the token after #
    assertEquals(HttpStatus.FOUND, result2.getStatusCode());

    // Obtain the token from redirection URL after #
    URI location = result2.getHeaders().getLocation();
    accessToken = extractToken(location.getFragment().toString());
    assertNotNull(accessToken);//from   w w  w .  j  a  v a2s. c  o  m

    if (!isJwtTokenStore) {
        // Temporarily we can't not apply the default token enhacer adding the authorities if we use a JwtTokenStore
        // TODO: Put again the login endpoint separated for CSRF and return the authorities there

        // Obtain the user credentials from redirection URL after #
        String extractUserAuthorities = extractUserAuthorities(location.getFragment().toString());
        assertNotNull(extractUserAuthorities);
    }
}

From source file:net.oneandone.sushi.fs.webdav.WebdavFilesystem.java

@Override
public WebdavNode node(URI uri, Object extra) throws NodeInstantiationException {
    if (extra != null) {
        throw new NodeInstantiationException(uri, "unexpected extra argument: " + extra);
    }//  www.  ja  v a2 s.c  o m
    if (uri.getFragment() != null) {
        throw new NodeInstantiationException(uri, "unexpected path fragment");
    }
    if (uri.isOpaque()) {
        throw new NodeInstantiationException(uri, "uri is not hierarchical");
    }
    return root(uri).node(getCheckedPath(uri), uri.getRawQuery());
}

From source file:net.bluemix.todo.connector.CloudantServiceInfoCreator.java

@Override
public CloudantServiceInfo createServiceInfo(Map<String, Object> serviceData) {
    Map<String, Object> credentials = (Map<String, Object>) serviceData.get("credentials");
    String id = (String) serviceData.get("name");
    try {//from  ww  w . j a  va2  s.co  m
        URI uri = new URI((String) credentials.get("url"));
        String scheme = uri.getScheme();
        int port = uri.getPort();
        String host = uri.getHost();
        String path = uri.getPath();
        String query = uri.getQuery();
        String fragment = uri.getFragment();
        String url = new URI(scheme, "", host, port, path, query, fragment).toString();
        String[] userInfo = uri.getUserInfo().split(":");
        return new CloudantServiceInfo(id, userInfo[0], userInfo[1], url);
    } catch (URISyntaxException e) {
        return null;
    }
}

From source file:com.microsoft.tfs.core.util.URIUtils.java

/**
 * <p>/*from  ww w. ja  va 2  s.  c o  m*/
 * Ensures that all the components of the {@link URI} are in lower-case.
 * </p>
 *
 * <p>
 * If the specified {@link URI} is opaque, it is returned. Otherwise, a new
 * {@link URI} is returned that is identical to the specified {@link URI}
 * except that the components (scheme, hostname, path) are converted to
 * their lower case equivalents (in a generic locale.)
 * </p>
 *
 * @param uri
 *        a {@link URI} to check (must not be <code>null</code>)
 * @return a {@link URI} as described above (never <code>null</code>)
 */
public static URI toLowerCase(final URI uri) {
    Check.notNull(uri, "uri"); //$NON-NLS-1$

    if (uri.isOpaque()) {
        return uri;
    }

    final String scheme = uri.getScheme() != null ? uri.getScheme().toLowerCase(LocaleUtil.ROOT) : null;
    final String authority = uri.getAuthority() != null ? uri.getAuthority().toLowerCase(LocaleUtil.ROOT)
            : null;
    final String path = uri.getPath() != null ? uri.getPath().toLowerCase(LocaleUtil.ROOT) : null;
    final String query = uri.getQuery() != null ? uri.getQuery().toLowerCase(LocaleUtil.ROOT) : null;
    final String fragment = uri.getFragment() != null ? uri.getFragment().toLowerCase(LocaleUtil.ROOT) : null;

    return newURI(scheme, authority, path, query, fragment);
}

From source file:org.eclipse.orion.server.git.objects.StashPage.java

@PropertyDescription(name = ProtocolConstants.KEY_PREVIOUS_LOCATION)
protected URI getPreviousPageLocation() throws URISyntaxException {
    if (page > 1) {
        URI location = getLocation();
        String query = String.format("page=%d&pageSize=%d", (page - 1), pageSize); //$NON-NLS-1$
        return new URI(location.getScheme(), location.getAuthority(), location.getPath(), query,
                location.getFragment());
    }/*from w  w w . j a v a  2 s .co  m*/

    return null;
}

From source file:org.eclipse.orion.server.git.objects.StashPage.java

@PropertyDescription(name = ProtocolConstants.KEY_NEXT_LOCATION)
protected URI getNextPageLocation() throws URISyntaxException {
    if (hasNextPage()) {
        URI location = getLocation();
        String query = String.format("page=%d&pageSize=%d", (page + 1), pageSize); //$NON-NLS-1$
        return new URI(location.getScheme(), location.getAuthority(), location.getPath(), query,
                location.getFragment());
    }/*from  w  ww  .  j  a  v  a 2s .  com*/

    return null;
}

From source file:fusion.Fusion.java

public static String getFragmentFromUri(final String uri) throws URISyntaxException {
    // par exemple http://localhost/rdf/val1234 -> localhost
    URI u = new URI(uri);
    return u.getFragment();
}

From source file:org.codice.ddf.catalog.content.resource.reader.DerivedContentActionProvider.java

@Override
public <T> List<Action> getActions(T input) {
    if (!canHandle(input)) {
        return Collections.emptyList();
    }//from  ww w  . jav a 2 s.c  o m
    // Expect only 1
    List<Action> resourceActions = resourceActionProvider.getActions(input);
    if (resourceActions.isEmpty()) {
        return Collections.emptyList();
    }

    return ((Metacard) input).getAttribute(Metacard.DERIVED_RESOURCE_URI).getValues().stream().map(value -> {
        try {
            URI uri = new URI(value.toString());
            URIBuilder builder = new URIBuilder(resourceActions.get(0).getUrl().toURI());
            if (StringUtils.equals(uri.getScheme(), ContentItem.CONTENT_SCHEME)) {
                String qualifier = uri.getFragment();

                builder.addParameters(
                        Collections.singletonList(new BasicNameValuePair(ContentItem.QUALIFIER, qualifier)));
                return Optional.of(new ActionImpl(ID, "View " + qualifier, DESCRIPTION_PREFIX + qualifier,
                        builder.build().toURL()));
            } else {
                return Optional.of(new ActionImpl(ID, "View " + uri.toString(),
                        DESCRIPTION_PREFIX + uri.toString(), uri.toURL()));
            }
        } catch (URISyntaxException | MalformedURLException e) {
            LOGGER.debug("Unable to create action URL.", e);
            return Optional.<Action>empty();
        }
    }).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
}

From source file:org.codice.ddf.catalog.content.resource.reader.ContentResourceReader.java

@Override
public Set<String> getOptions(Metacard metacard) {
    if (metacard != null && metacard.getAttribute(Metacard.DERIVED_RESOURCE_DOWNLOAD_URL) != null
            && !CollectionUtils/*w w w . ja  v  a 2  s .  co m*/
                    .isEmpty(metacard.getAttribute(Metacard.DERIVED_RESOURCE_DOWNLOAD_URL).getValues())) {
        Set<String> options = new HashSet<>();
        for (Serializable value : metacard.getAttribute(Metacard.DERIVED_RESOURCE_DOWNLOAD_URL).getValues()) {
            try {
                URI contentUri = new URI((String) value);
                if (ContentItem.CONTENT_SCHEME.equals(contentUri.getScheme())) {
                    if (StringUtils.isNotBlank(contentUri.getFragment())) {
                        options.add(contentUri.getFragment());
                    }
                }
            } catch (URISyntaxException e) {
                // Ignore - nothing to do
            }
        }
        return options;
    }
    return Collections.emptySet();
}