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

@Deprecated
public URI(String original) throws URIException 

Source Link

Document

Construct a URI from the given string.

Usage

From source file:com.limegroup.gnutella.licenses.WeedLicense.java

/** Builds the URI from the given cid & vid. */
public static final URI buildURI(String cid, String vid) {
    try {/* www  . j  a  va2s.c  o m*/
        return new URI((URI + "?" + VID + "=" + vid + "&" + CID + "=" + cid).toCharArray());
    } catch (URIException bad) {
        return null;
    }
}

From source file:com.limegroup.gnutella.licenses.WeedLicenseTest.java

public void testCopy() throws Exception {
    License l = new StubWeedLicense("1", "2", "text");
    assertEquals(null, l.getLicense());/*from  w  w  w. j a  v a 2  s .c o m*/
    assertEquals("http://www.weedshare.com/license/verify_usage_rights.aspx?versionid=2&contentid=1",
            l.getLicenseURI().toString());

    License l2 = l.copy("text3", new URI("http://uri.com".toCharArray()));
    assertEquals(null, l2.getLicense());
    assertEquals("http://uri.com", l2.getLicenseURI().toString());
}

From source file:com.cloud.ucs.manager.UcsHttpClient.java

public String call(String xml) {
    PostMethod post = new PostMethod(url);
    post.setRequestEntity(new StringRequestEntity(xml));
    post.setRequestHeader("Content-type", "text/xml");
    //post.setFollowRedirects(true);
    try {//  w w w  .j  a v  a 2s. com
        int result = client.executeMethod(post);
        if (result == 302) {
            // Handle HTTPS redirect
            // Ideal way might be to configure from add manager API
            // for using either HTTP / HTTPS
            // Allow only one level of redirect
            String redirectLocation;
            Header locationHeader = post.getResponseHeader("location");
            if (locationHeader != null) {
                redirectLocation = locationHeader.getValue();
            } else {
                throw new CloudRuntimeException("Call failed: Bad redirect from UCS Manager");
            }
            post.setURI(new URI(redirectLocation));
            result = client.executeMethod(post);
        }
        // Check for errors
        if (result != 200) {
            throw new CloudRuntimeException("Call failed: " + post.getResponseBodyAsString());
        }
        String res = post.getResponseBodyAsString();
        if (res.contains("errorCode")) {
            String err = String.format("ucs call failed:\nsubmitted doc:%s\nresponse:%s\n", xml, res);
            throw new CloudRuntimeException(err);
        }
        return res;
    } catch (Exception e) {
        throw new CloudRuntimeException(e.getMessage(), e);
    } finally {
        post.releaseConnection();
    }
}

From source file:com.serena.rlc.provider.artifactory.domain.Artifact.java

public static Artifact parseSingle(JSONObject jsonObject) {
    Artifact aObj = null;/*ww w  .j ava  2s .c o m*/
    if (jsonObject != null) {
        aObj = new Artifact((String) getJSONValue(jsonObject, "uri"), (String) jsonObject.get("path"),
                (String) jsonObject.get("downloadUri"));
        aObj.setRepo((String) jsonObject.get("repo"));
        aObj.setCreated((String) jsonObject.get("created"));
        aObj.setCreatedBy((String) jsonObject.get("createdBy"));
        aObj.setLastModified((String) jsonObject.get("lastModified"));
        aObj.setModifiedBy((String) jsonObject.get("modifiedBy"));
        aObj.setLastUpdated((String) jsonObject.get("lastUpdated"));
        aObj.setMimeType((String) jsonObject.get("mimeType"));
        aObj.setSize((String) jsonObject.get("size"));
        try {
            URI uri = new URI((String) getJSONValue(jsonObject, "uri"));
            aObj.setName(uri.getName());
            String[] segments = uri.getPath().split("/");
            aObj.setVersion(segments[segments.length - 2]);
        } catch (URIException ex) {
            logger.error("Error while parsing input JSON - " + (String) getJSONValue(jsonObject, "uri"), ex);
        }
    }
    return aObj;
}

From source file:com.limegroup.gnutella.licenses.LicenseFactory.java

/** Gets a CC license URI from the given license string. */
private static URI getCCLicenseURI(String license) {
    // find where the URL should begin.
    int verifyAt = license.indexOf(CCConstants.URL_INDICATOR);
    if (verifyAt == -1)
        return null;

    int urlStart = verifyAt + CCConstants.URL_INDICATOR.length();
    if (urlStart >= license.length())
        return null;

    String url = license.substring(urlStart).trim();
    URI uri = null;//  w w  w  .ja v a 2  s  .c  om
    try {
        uri = new URI(url.toCharArray());

        // Make sure the scheme is HTTP.
        String scheme = uri.getScheme();
        if (scheme == null || !scheme.equalsIgnoreCase("http"))
            throw new URIException("Invalid scheme: " + scheme);
        // Make sure the scheme has some authority.
        String authority = uri.getAuthority();
        if (authority == null || authority.equals("") || authority.indexOf(' ') != -1)
            throw new URIException("Invalid authority: " + authority);

    } catch (URIException e) {
        uri = null;
        LOG.error("Unable to create URI", e);
    }

    return uri;
}

From source file:de.kapsi.net.daap.DaapRequest.java

/**
 * Creates a DaapRequest from the the requestLine
 *
 * @param requestLine//w ww .j  a  v  a  2 s .  co  m
 * @throw URIException
 */
public DaapRequest(DaapConnection connection, String requestLine) throws URIException {
    this(connection);

    String method = null;
    URI uri = null;
    String protocol = null;

    try {
        StringTokenizer st = new StringTokenizer(requestLine, " ");
        method = st.nextToken();

        try {
            uri = new URI(st.nextToken().toCharArray());
        } catch (URIException err) {
            if (LOG.isErrorEnabled()) {
                LOG.error(err);
            }
        }

        protocol = st.nextToken();
    } catch (NoSuchElementException err) {
        if (LOG.isErrorEnabled()) {
            LOG.error(err);
        }
    }

    this.isServerSideRequest = false;
    this.isUpdateType = false;

    setMethod(method);
    setURI(uri);
    setProtocol(protocol);
}

From source file:com.eviware.soapui.impl.rest.support.handlers.JsonMediaTypeHandlerTest.java

private SubmitContext submitRequest(RestRequest restRequest, String originalPath)
        throws URISyntaxException, URIException, Request.SubmitException {
    SubmitContext submitContext = new WsdlSubmitContext(restRequest);
    HttpRequestBase httpMethod = mock(HttpRequestBase.class);
    submitContext.setProperty(BaseHttpRequestTransport.HTTP_METHOD, httpMethod);
    submitContext.setProperty(BaseHttpRequestTransport.REQUEST_URI, new URI(ENDPOINT + originalPath));
    restRequest.submit(submitContext, false);
    return submitContext;
}

From source file:com.limegroup.gnutella.licenses.CCLicenseTest.java

public void testCopy() throws Exception {
    License l = new StubCCLicense("text1", "");
    assertEquals("text1", l.getLicense());
    assertEquals("http://1.2.3.4/page", l.getLicenseURI().toString());

    License l2 = l.copy("text3", new URI("http://uri.com".toCharArray()));
    assertEquals("text3", l2.getLicense());
    assertEquals("http://uri.com", l2.getLicenseURI().toString());
}

From source file:com.thoughtworks.go.server.controller.PipelineStatusController.java

String getFullContextPath(HttpServletRequest request) throws URIException {
    String contextPath = request.getContextPath();
    StringBuffer url = request.getRequestURL();
    URI uri = new URI(url.toString());
    uri.setPath(contextPath);//from   www . j  a v a2 s  .  c o  m
    return uri.toString();
}

From source file:com.liferay.util.Http.java

public static byte[] URLtoByteArray(String location, Cookie[] cookies, boolean post) throws IOException {

    byte[] byteArray = null;

    HttpMethod method = null;/*from  w  w  w.j  ava  2 s . co  m*/

    try {
        HttpClient client = new HttpClient(new SimpleHttpConnectionManager());

        if (location == null) {
            return byteArray;
        } else if (!location.startsWith(HTTP_WITH_SLASH) && !location.startsWith(HTTPS_WITH_SLASH)) {

            location = HTTP_WITH_SLASH + location;
        }

        HostConfiguration hostConfig = new HostConfiguration();

        hostConfig.setHost(new URI(location));

        if (Validator.isNotNull(PROXY_HOST) && PROXY_PORT > 0) {
            hostConfig.setProxy(PROXY_HOST, PROXY_PORT);
        }

        client.setHostConfiguration(hostConfig);
        client.setConnectionTimeout(5000);
        client.setTimeout(5000);

        if (cookies != null && cookies.length > 0) {
            HttpState state = new HttpState();

            state.addCookies(cookies);
            state.setCookiePolicy(CookiePolicy.COMPATIBILITY);

            client.setState(state);
        }

        if (post) {
            method = new PostMethod(location);
        } else {
            method = new GetMethod(location);
        }

        method.setFollowRedirects(true);

        client.executeMethod(method);

        Header locationHeader = method.getResponseHeader("location");
        if (locationHeader != null) {
            return URLtoByteArray(locationHeader.getValue(), cookies, post);
        }

        InputStream is = method.getResponseBodyAsStream();

        if (is != null) {
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            byte[] bytes = new byte[512];

            for (int i = is.read(bytes, 0, 512); i != -1; i = is.read(bytes, 0, 512)) {

                buffer.write(bytes, 0, i);
            }

            byteArray = buffer.toByteArray();

            is.close();
            buffer.close();
        }

        return byteArray;
    } finally {
        try {
            if (method != null) {
                method.releaseConnection();
            }
        } catch (Exception e) {
            Logger.error(Http.class, e.getMessage(), e);
        }
    }
}