Example usage for org.apache.http.client.utils URIBuilder build

List of usage examples for org.apache.http.client.utils URIBuilder build

Introduction

In this page you can find the example usage for org.apache.http.client.utils URIBuilder build.

Prototype

public URI build() throws URISyntaxException 

Source Link

Document

Builds a URI instance.

Usage

From source file:com.collective.celos.CelosClient.java

public SlotState getSlotState(WorkflowID workflowID, ScheduledTime scheduledTime) throws Exception {
    URIBuilder uriBuilder = new URIBuilder(address);
    uriBuilder.setPath(uriBuilder.getPath() + SLOT_STATE_PATH);
    uriBuilder.addParameter(ID_PARAM, workflowID.toString());
    uriBuilder.addParameter(TIME_PARAM, scheduledTime.toString());

    HttpGet workflowListGet = new HttpGet(uriBuilder.build());
    HttpResponse getResponse = execute(workflowListGet);
    InputStream content = getResponse.getEntity().getContent();
    return SlotState.fromJSONNode(workflowID, Util.JSON_READER.withType(ObjectNode.class).readValue(content));
}

From source file:com.collective.celos.CelosClient.java

/**
 * Returns the specified register value, or null if not found.
 *///from  ww w  .ja v  a 2  s .  c om
public JsonNode getRegister(BucketID bucket, RegisterKey key) throws Exception {
    URIBuilder uriBuilder = new URIBuilder(address);
    uriBuilder.setPath(uriBuilder.getPath() + REGISTER_PATH);
    uriBuilder.addParameter(BUCKET_PARAM, bucket.toString());
    uriBuilder.addParameter(KEY_PARAM, key.toString());

    HttpResponse res = client.execute(new HttpGet(uriBuilder.build()));
    try {
        switch (res.getStatusLine().getStatusCode()) {
        case HttpServletResponse.SC_NOT_FOUND:
            return null;
        case HttpServletResponse.SC_OK:
            return Util.JSON_READER.readTree(res.getEntity().getContent());
        default:
            throw new Exception(res.getStatusLine().toString());
        }
    } finally {
        EntityUtils.consume(res.getEntity());
    }
}

From source file:org.apache.rya.indexing.smarturi.SmartUriAdapter.java

/**
 * Serializes a map into a URI.//from w  ww . j a va 2  s.c  o m
 * @param subject the {@link RyaURI} subject of the Entity. Identifies the
 * thing that is being represented as an Entity.
 * @param map the {@link Map} of {@link URI}s to {@link Value}s.
 * @return the Smart {@link URI}.
 * @throws SmartUriException
 */
public static URI serializeUri(final RyaURI subject, final Map<URI, Value> map) throws SmartUriException {
    final String subjectData = subject.getData();
    final int fragmentPosition = subjectData.indexOf("#");
    String prefix = subjectData;
    String fragment = null;
    if (fragmentPosition > -1) {
        prefix = subjectData.substring(0, fragmentPosition);
        fragment = subjectData.substring(fragmentPosition + 1, subjectData.length());
    }

    URIBuilder uriBuilder = null;
    try {
        if (fragmentPosition > -1) {
            uriBuilder = new URIBuilder(new java.net.URI("urn://" + fragment));
        } else {
            uriBuilder = new URIBuilder(new java.net.URI(subjectData.replaceFirst(":", "://")));
        }
    } catch (final URISyntaxException e) {
        throw new SmartUriException("Unable to serialize a Smart URI from the provided properties", e);
    }
    final List<NameValuePair> nameValuePairs = new ArrayList<>();

    for (final Entry<URI, Value> entry : map.entrySet()) {
        final URI key = entry.getKey();
        final Value value = entry.getValue();
        nameValuePairs.add(new BasicNameValuePair(key.getLocalName(), value.stringValue()));
    }

    uriBuilder.setParameters(nameValuePairs);

    URI uri = null;
    try {
        if (fragmentPosition > -1) {
            final java.net.URI partialUri = uriBuilder.build();
            final String uriString = StringUtils.removeStart(partialUri.getRawSchemeSpecificPart(), "//");
            final URIBuilder fragmentUriBuilder = new URIBuilder(new java.net.URI(prefix));
            fragmentUriBuilder.setFragment(uriString);
            final String fragmentUriString = fragmentUriBuilder.build().toString();
            uri = new URIImpl(fragmentUriString);
        } else {
            final String uriString = uriBuilder.build().toString();
            uri = new URIImpl(uriString);
        }
    } catch (final URISyntaxException e) {
        throw new SmartUriException("Smart URI could not serialize the property map.", e);
    }

    return uri;
}

From source file:com.sonicle.webtop.core.app.DocEditorManager.java

private URI buildCallbackUrl(String loopbackUrl, String domainPubName, String sessionId, String editingId)
        throws URISyntaxException {
    URIBuilder builder = new URIBuilder(loopbackUrl);
    URIUtils.appendPath(builder, URIUtils.concatPaths(DocEditor.URL, domainPubName, DocEditor.TRACK_PATH));
    if (!StringUtils.isBlank(sessionId))
        builder.addParameter(DocEditor.SESSION_ID_PARAM, sessionId);
    builder.addParameter(DocEditor.EDITING_ID_PARAM, editingId);
    return builder.build();
}

From source file:ching.icecreaming.action.EditAction.java

@Action(value = "edit", results = { @Result(name = "login", location = "edit.jsp"),
        @Result(name = "success", location = "view.jsp"), @Result(name = "error", location = "error.jsp") })
public String execute() throws Exception {
    URL url1 = null;//from  w  w  w.ja v a  2s .c  om
    URI uri1 = null;
    HttpGet httpGet1 = null;
    DefaultHttpClient httpClient1 = new DefaultHttpClient();
    HttpResponse httpResponse1 = null;
    int int1 = 0, int2 = 401;
    String[] array1 = null;
    String string1 = getText("Error") + " %d: %s", result1 = LOGIN;
    byte[] bytes1 = null;
    if (StringUtils.isBlank(timeZone1))
        timeZone1 = portletPreferences.getValue("timeZone", TimeZone.getDefault().getID());
    if (StringUtils.isNotBlank(sid) && StringUtils.isNotBlank(uid) && StringUtils.isNotBlank(pid)) {
        try {
            url1 = new URL(sid);
            URIBuilder uriBuilder = new URIBuilder(sid);
            uriBuilder.setParameter("j_username", uid);
            uriBuilder.setParameter("j_password", pid);
            uriBuilder.setPath(url1.getPath() + "/rest/login");
            uri1 = uriBuilder.build();
            httpGet1 = new HttpGet(uri1);
            httpResponse1 = httpClient1.execute(httpGet1);
            int2 = httpResponse1.getStatusLine().getStatusCode();
        } catch (IOException exception1) {
            exception1.printStackTrace();
        } catch (URISyntaxException exception1) {
            exception1.printStackTrace();
        } finally {
            httpClient1.getConnectionManager().shutdown();
            if (int2 == HttpStatus.SC_OK) {
                sid = new String(Base64.encodeBase64(sid.getBytes()));
                uid = new String(Base64.encodeBase64(uid.getBytes()));
                pid = new String(Base64.encodeBase64(pid.getBytes()));
                urlString = "/";
                wsType = "folder";
                array1 = new String[] { sid, uid, pid, StringUtils.defaultString(alias1) };
                portletPreferences.setValue("urlString", urlString);
                portletPreferences.setValue("wsType", wsType);
                portletPreferences.setValue("timeZone", timeZone1);
                portletPreferences.setValues("server", array1);
                portletPreferences.store();
                result1 = SUCCESS;
            } else {
                array1 = portletPreferences.getValues("server", null);
                if (array1 != null)
                    if (ArrayUtils.isNotEmpty(array1)) {
                        for (int1 = 0; int1 < array1.length; int1++) {
                            switch (int1) {
                            case 0:
                                sid = array1[int1];
                                break;
                            case 1:
                                uid = array1[int1];
                                break;
                            case 2:
                                pid = array1[int1];
                                break;
                            case 3:
                                alias1 = array1[int1];
                                break;
                            default:
                                break;
                            }
                        }
                        sid = new String(Base64.decodeBase64(sid.getBytes()));
                        uid = new String(Base64.decodeBase64(uid.getBytes()));
                        pid = new String(Base64.decodeBase64(pid.getBytes()));
                    }
                addActionError(String.format(string1, int2, getText(Integer.toString(int2))));
            }
        }
    } else {
        array1 = portletPreferences.getValues("server", null);
        if (StringUtils.isBlank(urlString) || StringUtils.isBlank(wsType)) {
            urlString = portletPreferences.getValue("urlString", "/");
            wsType = portletPreferences.getValue("wsType", "folder");
        }
        if (array1 != null) {
            if (ArrayUtils.isNotEmpty(array1)) {
                for (int1 = 0; int1 < array1.length; int1++) {
                    switch (int1) {
                    case 0:
                        sid = array1[int1];
                        break;
                    case 1:
                        uid = array1[int1];
                        break;
                    case 2:
                        pid = array1[int1];
                        break;
                    case 3:
                        alias1 = array1[int1];
                        break;
                    default:
                        break;
                    }
                }
                sid = new String(Base64.decodeBase64(sid.getBytes()));
                uid = new String(Base64.decodeBase64(uid.getBytes()));
                pid = new String(Base64.decodeBase64(pid.getBytes()));
            }
        }
    }
    return result1;
}

From source file:com.kolich.havalo.client.service.HavaloClient.java

public Either<HttpFailure, ObjectList> listObjects(final String... path) {
    // The listing of objects is only successful when the
    // resulting status code is a 200 OK.  Any other status
    // code on the response is failure.
    return new HavaloGsonClosure<ObjectList>(client_, gson_.create(), ObjectList.class, SC_OK) {
        @Override//  ww w  .ja va  2s  . com
        public void before(final HttpRequestBase request) throws Exception {
            final URIBuilder builder = new URIBuilder(request.getURI());
            if (path != null && path.length > 0) {
                builder.addParameter(API_PARAM_STARTSWITH, varargsToPrefixString(path));
            }
            request.setURI(builder.build());
            super.before(request);
        }
    }.get(API_ACTION_REPOSITORY);
}

From source file:com.sonicle.webtop.core.app.DocEditorManager.java

private URI generateUrl(String loopbackUrl, String domainPubName, String sessionId, String editingId)
        throws URISyntaxException {
    URIBuilder builder = new URIBuilder(loopbackUrl);
    URIUtils.appendPath(builder, URIUtils.concatPaths(DocEditor.URL, domainPubName, DocEditor.DOWNLOAD_PATH));
    if (!StringUtils.isBlank(sessionId))
        builder.addParameter(DocEditor.SESSION_ID_PARAM, sessionId);
    builder.addParameter(DocEditor.EDITING_ID_PARAM, editingId);
    return builder.build();
}

From source file:com.rackspacecloud.blueflood.inputs.handlers.HttpAnnotationsEndToEndTest.java

private URI getAnnotationsQueryURI(Map<String, String> parameterMap) throws URISyntaxException {
    URIBuilder builder = new URIBuilder().setScheme("http").setHost("127.0.0.1").setPort(queryPort)
            .setPath("/v2.0/" + tenant_id + "/events/getEvents");

    Set<String> parameters = parameterMap.keySet();
    Iterator<String> setIterator = parameters.iterator();
    while (setIterator.hasNext()) {
        String paramName = setIterator.next();
        builder.setParameter(paramName, parameterMap.get(paramName));
    }//from   w  w  w  . ja  v  a 2s. co  m
    return builder.build();
}

From source file:eu.esdihumboldt.hale.io.geoserver.rest.AbstractResourceManager.java

private URI buildRequestUri(String url, Map<String, String> parameters) throws URISyntaxException {

    URIBuilder uriBuilder = new URIBuilder(url);
    if (parameters != null) {
        parameters.forEach((param, value) -> uriBuilder.addParameter(param, value));
    }// w  w w .j  a  v a2 s . c om

    return uriBuilder.build();
}

From source file:org.apache.james.jmap.methods.integration.cucumber.DownloadStepdefs.java

@When("^\"([^\"]*)\" downloads \"([^\"]*)\" without blobId parameter$")
public void getDownloadWithoutBlobId(String username, String attachmentId) throws Throwable {
    String blobId = blobIdByAttachmentId.get(attachmentId);

    URIBuilder uriBuilder = mainStepdefs.baseUri().setPath("/download/");
    trustForBlobId(blobId, username);// w w  w.  j  av a2s. co  m
    AttachmentAccessTokenKey key = new AttachmentAccessTokenKey(username, blobId);
    uriBuilder.addParameter("access_token", attachmentAccessTokens.get(key).serialize());
    response = Request.Get(uriBuilder.build()).execute().returnResponse();
}