Example usage for org.apache.commons.httpclient URI URI

List of usage examples for org.apache.commons.httpclient URI URI

Introduction

In this page you can find the example usage for org.apache.commons.httpclient URI URI.

Prototype

public URI(String scheme, String host, String path, String fragment) throws URIException 

Source Link

Document

Construct a general URI from the given components.

Usage

From source file:org.eclipsetrader.yahoojapanfx.internal.core.Util.java

/**
 * Builds the http method for historycal prices download.
 *
 * @return the method.// w  w  w.j  ava2  s.  com
 */
public static HttpMethod getPrepareHistoryFeedMethod(IFeedIdentifier identifier) throws URIException {
    String symbol = getSymbol(identifier).toLowerCase();

    String prefix = "/chart/";
    String suffix = symbol.substring(0, 3) + "_" + symbol.substring(3, 6) + ".html";
    URI uri = new URI("http", historyFeedHost, prefix + suffix, "");

    GetMethod method = new GetMethod();
    method.setURI(uri);
    setCommonRequestHeaders(method);
    method.setFollowRedirects(true);
    //        try {
    //            System.out.println(method.getURI().toString());
    //        } catch (URIException e) {
    //            e.printStackTrace();
    //        }

    return method;
}

From source file:org.eclipsetrader.yahoojapanfx.internal.core.Util.java

/**
 * Builds the http method for historycal prices download.
 *
 * @return the method.//w w w  .  j  a v  a  2s  .  c o  m
 */
public static HttpMethod getHistoryFeedMethod(IFeedIdentifier identifier, String period, String c)
        throws URIException {
    String symbol = getSymbol(identifier).toLowerCase();

    String prefix = "/chart/history.json";
    String suffix = "?period=" + period + "&position=" + symbol + "&c=" + c;
    URI uri = new URI("http", historyFeedHost, prefix + suffix, "");

    GetMethod method = new GetMethod();
    method.setURI(uri);
    setCommonRequestHeaders(method);
    method.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    method.setRequestHeader("Referer",
            "http://fx.yahoo.co.jp/chart/" + symbol.substring(0, 3) + "_" + symbol.substring(3, 6) + ".html");
    method.setFollowRedirects(true);
    //        try {
    //            System.out.println(method.getURI().toString());
    //        } catch (URIException e) {
    //            e.printStackTrace();
    //        }

    return method;
}

From source file:org.parosproxy.paros.core.scanner.VariantURLPath.java

/**
 * Encode the parameter value for a correct URL introduction
 * @param value the value that need to be encoded
 * @return the Encoded value// ww  w . j a v  a2  s. c om
 */
private String getEscapedValue(String value) {
    if (value != null) {
        try {
            return (new URI(null, null, value, null)).toString();

        } catch (URIException ex) {
        }
    }

    return "";
}

From source file:org.springframework.security.saml.websso.ArtifactResolutionProfileImplTest.java

/**
 * Verifies that hostConfiguration can be loaded when HttpClient has no defaults.
 *///from   w  w w . j a  v  a 2s  . c  om
@Test
public void testHostConfigurationNoDefaults() throws Exception {
    HttpClient client = new HttpClient();
    ArtifactResolutionProfileImpl artifactResolutionProfile = new ArtifactResolutionProfileImpl(client);
    URI uri = new URI("http", "test", "/artifact", null);
    HostConfiguration hostConfiguration = artifactResolutionProfile.getHostConfiguration(uri, null);
    assertNotNull(hostConfiguration);
    assertEquals("test", hostConfiguration.getHost());
}

From source file:org.springframework.security.saml.websso.ArtifactResolutionProfileImplTest.java

/**
 * Verifies that hostConfiguration is correctly cloned when HttpClient contains defaults.
 *//*  w w  w. j  av  a  2s.c  o m*/
@Test
public void testHostConfigurationWithDefaults() throws Exception {

    // Client object with default settings
    HttpClient client = new HttpClient();
    HostConfiguration defaultConfiguration = new HostConfiguration();
    defaultConfiguration.setProxy("testProxy", 8000);
    defaultConfiguration.getParams().setParameter("testParam", "testValue");
    client.setHostConfiguration(defaultConfiguration);

    ArtifactResolutionProfileImpl artifactResolutionProfile = new ArtifactResolutionProfileImpl(client);
    URI uri = new URI("http", "test", "/artifact", null);
    HostConfiguration hostConfiguration = artifactResolutionProfile.getHostConfiguration(uri, null);

    // Verify that settings were cloned
    assertNotNull(hostConfiguration);
    assertEquals("test", hostConfiguration.getHost());
    assertEquals("testProxy", hostConfiguration.getProxyHost());
    assertEquals(8000, hostConfiguration.getProxyPort());
    assertEquals("testValue", hostConfiguration.getParams().getParameter("testParam"));

    // Make sure default object and newly created configuration are independent
    defaultConfiguration.setProxyHost(null);
    assertEquals("testProxy", hostConfiguration.getProxyHost());
    assertEquals(8000, hostConfiguration.getProxyPort());

}

From source file:org.zaproxy.zap.extension.accessControl.widgets.SiteTree.java

public SiteTreeNode addPath(Context context, URI uri, String method, Collection<String> urlParameters,
        Collection<String> formParameters, String contentType) {
    SiteTreeNode parent = this.root;
    SiteTreeNode leaf = null;//from w  w  w.ja v  a2  s.  c om
    String pathSegment = "";
    URI pathSegmentUri;

    try {

        URI hostUri = new URI(uri.getScheme(), null, uri.getHost(), uri.getPort());
        String hostname = UriUtils.getHostName(uri);

        // add host
        parent = findOrAddPathSegmentNode(parent, hostname, hostUri);

        ParameterParser paramParser = context.getUrlParamParser();
        List<String> path = paramParser.getTreePath(uri);
        for (int i = 0; i < path.size(); i++) {
            pathSegment = path.get(i);
            if (pathSegment != null && !pathSegment.equals("")) {
                if (i == path.size() - 1) {
                    String leafName = UriUtils.getLeafNodeRepresentation(pathSegment, method, urlParameters,
                            formParameters, contentType);
                    leaf = findOrAddPathSegmentNode(parent, leafName, uri);
                } else {
                    pathSegmentUri = new URI(hostUri, paramParser.getAncestorPath(uri, i + 1), false);
                    parent = findOrAddPathSegmentNode(parent, pathSegment, pathSegmentUri);
                }
            }
        }
        // If no leaf found, which means the parent was really the leaf. This happens, for
        // example, when first adding a node for the top-level node, without any path elements
        if (leaf == null) {
            leaf = parent;
        }

    } catch (Exception e) {
        // ZAP: Added error
        log.error("Exception adding " + uri.toString() + " " + e.getMessage(), e);
    }

    return leaf;
}

From source file:org.zaproxy.zap.extension.pscanrules.CSRFCountermeasuresUnitTest.java

private HttpMessage createScopedMessage(boolean isInScope) throws URIException {
    HttpMessage newMsg = new HttpMessage() {
        @Override//from  ww w . j  a va2  s. c  o  m
        public boolean isInScope() {
            return isInScope;
        }
    };
    newMsg.getRequestHeader().setURI(new URI("http://", "localhost", "/", ""));
    newMsg.setResponseBody("<html><head></head><body>"
            + "<form name=\"someName\" data-no-csrf><input type=\"text\" name=\"name\"/><input type=\"submit\"/></form>"
            + "</body></html>");
    return newMsg;
}

From source file:org.zaproxy.zap.extension.sse.BaseEventStreamTest.java

protected HttpMessage getMockHttpMessage() throws URIException {
    HistoryReference mockHistoryRef = Mockito.mock(HistoryReference.class);

    HttpRequestHeader mockReqHeader = Mockito.mock(HttpRequestHeader.class);
    when(mockReqHeader.getURI()).thenReturn(new URI("http", "example.com", "/", ""));

    HttpMessage mockMessage = Mockito.mock(HttpMessage.class);
    when(mockMessage.getHistoryRef()).thenReturn(mockHistoryRef);
    when(mockMessage.getRequestHeader()).thenReturn(mockReqHeader);

    return mockMessage;
}

From source file:org.zaproxy.zap.testutils.WebSocketTestUtils.java

public URI getServertUrl() throws URIException {
    return new URI(webSocketTestServer.isSecure() ? "https" : "http", null, webSocketTestServer.getHostname(),
            webSocketTestServer.getListeningPort());
}