Example usage for java.net URI toString

List of usage examples for java.net URI toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns the content of this URI as a string.

Usage

From source file:org.jasig.portlet.calendar.adapter.exchange.AutodiscoverRedirectStrategy.java

private boolean matchesPatternSet(URI uri, List<Pattern> patterns) {
    for (Pattern pattern : patterns) {
        Matcher matcher = pattern.matcher(uri.toString());
        if (matcher.matches()) {
            return true;
        }/*from   w ww.  j a v a  2  s . c  o  m*/
    }
    return false;
}

From source file:com.microsoft.exchange.autodiscover.AutodiscoverRedirectStrategy.java

/**
* Overrides behavior to follow redirects for POST messages, AND to have the redirect be a POST.  Behavior of
* <code>DefaultRedirectStrategy</code> is to use a GET for the redirect (though against spec this is the
* de-facto standard, see http://www.mail-archive.com/httpclient-users@hc.apache.org/msg06327.html and
* http://www.alanflavell.org.uk/www/post-redirect.html).
*
* For our application, we want to follow the redirect for a 302 as long as it is to a safe location and
* have the redirect be a POST.//from ww  w .j  av a  2 s  . c o  m
*
* This code is modified from http-components' http-client 4.2.5.  Since we only use POST the code for the
* other HTTP methods has been removed to simplify this method.
*
* @param request Http request
* @param response Http response
* @param context Http context
* @return Request to issue to the redirected location
* @throws ProtocolException protocol exception
*/
@Override
public HttpUriRequest getRedirect(final HttpRequest request, final HttpResponse response,
        final HttpContext context) throws ProtocolException {
    URI uri = getLocationURI(request, response, context);
    log.info("Following redirect to " + uri.toString());
    String method = request.getRequestLine().getMethod();
    int status = response.getStatusLine().getStatusCode();

    // Insure location is safe
    if (matchesPatternSet(uri, unsafeUriPatterns)) {
        log.warn("Not following to URI {} - matches a configured unsafe URI pattern " + uri.toString());
        throw new ExchangeWebServicesRuntimeException(
                "Autodiscover redirected to unsafe URI " + uri.toString());
    }

    if (!matchesPatternSet(uri, uriRequirementPatterns) && uriRequirementPatterns.size() > 0) {
        log.warn("Not following to URI {} - URI does not match a required URI pattern " + uri.toString());
        throw new ExchangeWebServicesRuntimeException(
                "Autodiscover redirected to URI not matching required pattern. URI=" + uri.toString());
    }

    // Follow forwards for 301 and 302 in addition to 307, to validate the redirect location,
    // and to use a POST method.
    if (status == HttpStatus.SC_TEMPORARY_REDIRECT || status == HttpStatus.SC_MOVED_PERMANENTLY
            || status == HttpStatus.SC_MOVED_TEMPORARILY) {
        if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) {
            return copyEntity(new HttpPost(uri), request);
        }
    }

    // Should not get here, but return sensible value just in case.  A GET will likely fail.
    return new HttpGet(uri);
}

From source file:com.github.ukase.toolkit.WrappedUserAgentCallback.java

private String resolveUri(URI resolvingUri) {
    URI baseURI = transformUri(getBaseURL());
    if (baseURI == null) {
        return resolvingUri.toString();
    }//from  w w  w.j  a  v  a  2 s . c om
    return baseURI.resolve(resolvingUri).toString();
}

From source file:com.bah.lucene.hdfs.SoftlinkHdfsDirectory.java

private void createLinkForNewFile(String name, URI uri) throws IOException, UnsupportedEncodingException {
    String uriStr = uri.toString();
    Path linkPath = createLinkPath(name);
    FSDataOutputStream outputStream = _fileSystem.create(linkPath, false);
    outputStream.write(uriStr.getBytes(UTF_8));
    outputStream.close();/*from   w  ww .  j ava  2  s .  co  m*/
}

From source file:com.github.brandtg.pantopod.crawler.DbiBasedCrawlingEventHandler.java

@Override
protected void markError(URI url, int errorCode) throws IOException {
    try (Handle handle = dbi.open()) {
        handle.execute("INSERT INTO `pantopod_crawler` (`url`, `error`) VALUES (?, ?)", url.toString(),
                errorCode);/*from   w  ww . j a v  a 2s.  c o m*/
    } catch (Exception e) {
        LOG.error("Could not mark error {}", url, e);
    }
}

From source file:com.diversityarrays.dalclient.DalUtil.java

/**
 * Execute the provided request using the client and allow the handler to process the response.
 * Before returning the result from the handler, ensure that the response has been closed.
 * If the <code>elapsedTime</code> parameter is supplied then return the number of milliseconds
 * spent in the <code>client.execute()</code> method call.
 * @param client/*w  w  w  . ja  v  a 2s . co m*/
 * @param request
 * @param handler
 * @param elapsedTimeMillis if non-null it will receive the elapsed time of the actual time spent in the <code>client.execute()</code> method
 * @return the result provided by the handler
 * @throws IOException
 */
static public <T> T doHttp(DalCloseableHttpClient client, DalRequest request, DalResponseHandler<T> handler,
        Long[] elapsedTimeMillis) throws IOException {
    T result = null;

    DalCloseableHttpResponse response = null;
    try {
        if (DEBUG) {
            URI uri = request.getURI();
            System.err.println(DalUtil.class.getSimpleName() + ".doHttp: " + uri.toString()); //$NON-NLS-1$
            System.err.println("  --- Headers ---"); //$NON-NLS-1$
            for (DalHeader h : request.getAllHeaders()) {
                System.err.println("\t" + h.getName() + ":\t" + h.getValue()); //$NON-NLS-1$ //$NON-NLS-2$
            }
        }
        long startMillis = System.currentTimeMillis();
        response = client.execute(request);
        if (elapsedTimeMillis != null) {
            elapsedTimeMillis[0] = System.currentTimeMillis() - startMillis;
        }
        result = handler.handleResponse(response);
    } finally {
        if (response != null) {
            try {
                response.close();
            } catch (IOException ignore) {
            }
        }
    }

    return result;
}

From source file:edu.wisc.ws.client.support.DestinationOverridingWebServiceTemplate.java

@Override
public String getDefaultUri() {
    final DestinationProvider destinationProvider = this.getDestinationProvider();
    if (destinationProvider != null) {
        final URI uri = destinationProvider.getDestination();
        if (uri == null) {
            return null;
        }/*from   w  w  w . j  a  v a 2s .c om*/

        if (portOverride == null) {
            return uri.toString();
        }

        final URI overridenUri;
        try {
            overridenUri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), portOverride,
                    uri.getPath(), uri.getQuery(), uri.getFragment());
        } catch (URISyntaxException e) {
            this.logger.error("Could not override port on URI " + uri + " to " + portOverride, e);
            return uri.toString();
        }

        return overridenUri.toString();
    }

    return null;
}

From source file:jails.http.client.CommonsClientHttpRequestFactory.java

public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
    HttpMethodBase commonsHttpMethod = createCommonsHttpMethod(httpMethod, uri.toString());
    postProcessCommonsHttpMethod(commonsHttpMethod);
    return new CommonsClientHttpRequest(getHttpClient(), commonsHttpMethod);
}

From source file:net.sourceforge.dita4publishers.impl.ditabos.DitaBoundedObjectSetImpl.java

public BosMember constructBosMember(BosMember member, URI targetUri) throws BosException {
    String key = targetUri.toString();
    if (this.getMember(key) != null) {
        BosMember cand = this.getMember(key);
        return cand;
    }//from w  w  w.ja v  a2  s  .  c om
    NonXmlBosMember newMember = new NonXmlBosMemberImpl(this, targetUri);
    return newMember;
}

From source file:de.hft.GA.GA.java

private URI addEntry(ListOfPostedRecords listOfPR) {

    // create location of new resource
    URI location = uriInfo.getAbsolutePathBuilder().path("" + index).build();

    index++;/*from w  w  w  .  j  ava 2s .  c  o m*/
    // set location as href
    listOfPR.setHref(location.toString());

    // return new location
    return location;
}