Example usage for java.net URL toString

List of usage examples for java.net URL toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Constructs a string representation of this URL .

Usage

From source file:com.samebug.clients.search.api.client.SamebugClient.java

public @NotNull ClientResponse<SearchHistory> getSearchHistory() {
    final URL url = urlBuilder.history();
    HttpGet request = new HttpGet(url.toString());

    return rawClient.execute(request, new HandleAuthenticatedJsonRequest<SearchHistory>(SearchHistory.class));
}

From source file:com.samebug.clients.search.api.client.SamebugClient.java

public @NotNull ClientResponse<MarkResponse> postMark(@NotNull final Integer searchId,
        @NotNull final Integer solutionId) {
    final URL url = urlBuilder.mark();
    HttpPost post = new HttpPost(url.toString());
    List<BasicNameValuePair> form = Arrays.asList(new BasicNameValuePair("solution", solutionId.toString()),
            new BasicNameValuePair("search", searchId.toString()));
    post.setEntity(new UrlEncodedFormEntity(form, Consts.UTF_8));

    return rawClient.execute(post, new HandleAuthenticatedJsonRequest<MarkResponse>(MarkResponse.class));
}

From source file:com.ewgvip.buyer.android.volley.toolbox.HurlStack.java

/**
 * Create an {@link HttpURLConnection} for the specified {@code url}.
 *//*from  w ww.  ja  va 2 s. c  om*/
protected HttpURLConnection createConnection(URL url) throws IOException {
    if (url.toString().contains("https")) {
        //??
        HTTPSTrustManager.allowAllSSL();
    }
    return (HttpURLConnection) url.openConnection();
}

From source file:net.javacoding.jspider.extension.rule.IncreasingRule.java

/**
 *
 *
 * @param context/*w ww  .  j  a v a  2 s  .c o  m*/
 * @param currentSite
 * @param url
 * @return
 */
@Override
public Decision apply(SpiderContext context, Site currentSite, URL url) {
    URL orgin = url;
    Object[] pts = null;
    if (map.containsKey(url.toString())) {
        // remove !
        pts = map.remove(url.toString());
        orgin = (URL) pts[0];
    } else {
        String path = url.getPath();
        if (this.queryEnable) {
            if (url.getQuery() != null) {
                path += "?" + url.getQuery();
            }
        }
        Matcher mt = pattern.matcher(path);
        if (mt.matches()) {
            orgin = url;
            int size = mt.groupCount();
            pts = new Object[size + 2];
            pts[0] = url;
            for (int i = 1; i <= size; i++) {
                pts[i] = mt.group(i);
            }
        }
    }
    if (pts != null) {
        URL find = this.getNexturl(pts, orgin);
        if (find != null) {
            log.debug("Increasing page " + find);
            map.put(find.toString(), pts);
            context.getAgent().registerEvent(orgin, new URLFoundEvent(context, orgin, find));
        }
    }
    return new DecisionInternal(DecisionInternal.RULE_ACCEPT);
}

From source file:org.seedstack.w20.internal.W20BridgeIT.java

@Test
@RunAsClient//from  ww  w .j a  v  a 2s .c  o  m
public void fragment_ignore(@ArquillianResource URL baseUrl) throws IOException {
    String response = given().auth().basic("ThePoltergeist", "bouh").expect().statusCode(200).when()
            .get(baseUrl.toString() + "seed-w20/application/configuration").getBody().asString();
    assertThat(getFragment(response, baseUrl.getPath() + "seed-w20/seed-w20.w20.json").isIgnore()).isFalse();
    assertThat(getFragment(response, baseUrl.getPath() + "ignored-fragment.w20.json")).isNull();
    assertThat(getFragment(response, "ignored-external-fragment.w20.json").isIgnore()).isTrue();
}

From source file:org.seedstack.w20.internal.W20BridgeIT.java

@Test
@RunAsClient//from  ww  w  . ja v  a 2s  .  c  om
public void fragment_optional(@ArquillianResource URL baseUrl) throws IOException {
    String response = given().auth().basic("ThePoltergeist", "bouh").expect().statusCode(200).when()
            .get(baseUrl.toString() + "seed-w20/application/configuration").getBody().asString();
    assertThat(getFragment(response, baseUrl.getPath() + "seed-w20/seed-w20.w20.json").isOptional()).isFalse();
    assertThat(getFragment(response, baseUrl.getPath() + "optional-fragment.w20.json").isOptional()).isTrue();
    assertThat(getFragment(response, "optional-external-fragment.w20.json").isOptional()).isTrue();
}

From source file:com.cladonia.xngreditor.URLUtilities.java

/**
 * Convert the given url to a location relative to the current machine, ie: 
 * file: is missing./*from   w  ww.j ava  2 s  . co  m*/
 * 
 * @param url the url string to be converted.
 * 
 * @return a new file or null if the string does not describe a file.
 */
public static String toRelativeString(URL url) {
    String location = null;

    if (url != null) {
        location = url.toString();

        if (url.getProtocol().equals("file")) {
            location = location.substring(6, location.length());
        }
    }

    return location;
}

From source file:com.netflix.config.util.ConfigurationUtils.java

public static AbstractConfiguration getConfigFromPropertiesFile(URL startingUrl, Set<String> loaded,
        String... nextLoadKeys) throws FileNotFoundException {
    if (loaded.contains(startingUrl.toExternalForm())) {
        logger.warn(startingUrl + " is already loaded");
        return null;
    }/*from ww  w.j a  v  a 2 s . co m*/
    PropertiesConfiguration propConfig = null;
    try {
        propConfig = new OverridingPropertiesConfiguration(startingUrl);
        logger.info("Loaded properties file " + startingUrl);
    } catch (ConfigurationException e) {
        Throwable cause = e.getCause();
        if (cause instanceof FileNotFoundException) {
            throw (FileNotFoundException) cause;
        } else {
            throw new RuntimeException(e);
        }
    }

    if (nextLoadKeys == null) {
        return propConfig;
    }
    String urlString = startingUrl.toExternalForm();
    String base = urlString.substring(0, urlString.lastIndexOf("/"));
    loaded.add(startingUrl.toString());
    loadFromPropertiesFile(propConfig, base, loaded, nextLoadKeys);
    return propConfig;
}

From source file:cn.ctyun.amazonaws.internal.EC2MetadataClient.java

/**
 * Connects to the metadata service to read the specified resource and
 * returns the text contents.//w ww .  ja  v  a2 s .c  o  m
 *
 * @param resourcePath
 *            The resource
 *
 * @return The text payload returned from the Amazon EC2 Instance Metadata
 *         service for the specified resource path.
 *
 * @throws IOException
 *             If any problems were encountered while connecting to metadata
 *             service for the requested resource path.
 * @throws AmazonClientException
 *             If the requested metadata service is not found.
 */
public String readResource(String resourcePath) throws IOException, AmazonClientException {
    URL url = getEc2MetadataServiceUrlForResource(resourcePath);
    log.debug("Connecting to EC2 instance metadata service at URL: " + url.toString());

    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setConnectTimeout(1000 * 2);
    connection.setRequestMethod("GET");
    connection.setDoOutput(true);
    connection.connect();

    return readResponse(connection);
}

From source file:org.apache.cxf.fediz.service.idp.STSPortFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    Assert.isTrue(applicationContext != null, "Application context must not be null");
    STSAuthenticationProvider authProvider = authenticationProvider;
    if (authProvider == null) {
        authProvider = applicationContext.getBean(STSAuthenticationProvider.class);
    }/*from ww w.ja va2 s .  c om*/
    Assert.isTrue(authProvider != null, "STSAuthenticationProvider must be configured");

    //Only update the port if HTTPS is used, otherwise ignored (like retrieving the WADL over HTTP)
    if (!isPortSet && request.isSecure()) {
        try {
            URL url = new URL(authProvider.getWsdlLocation());
            if (url.getPort() == 0) {
                URL updatedUrl = new URL(url.getProtocol(), url.getHost(), request.getLocalPort(),
                        url.getFile());
                setSTSWsdlUrl(authProvider, updatedUrl.toString());
                LOG.info("STSAuthenticationProvider.wsdlLocation set to " + updatedUrl.toString());
            } else {
                setSTSWsdlUrl(authProvider, url.toString());
            }
        } catch (MalformedURLException e) {
            LOG.error("Invalid Url '" + authProvider.getWsdlLocation() + "': " + e.getMessage());
        }
    }

    chain.doFilter(request, response);
}