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

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

Introduction

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

Prototype

public String getPath() 

Source Link

Usage

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

/**
 * Deletes the specified register value.
 *//*from   w w  w.  j a  va  2 s  . c o  m*/
public void deleteRegister(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());
    executeDelete(uriBuilder.build());
}

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

public Set<WorkflowID> getWorkflowList() throws Exception {
    URIBuilder uriBuilder = new URIBuilder(address);
    uriBuilder.setPath(uriBuilder.getPath() + WORKFLOW_LIST_PATH);

    HttpGet workflowListGet = new HttpGet(uriBuilder.build());
    HttpResponse getResponse = execute(workflowListGet);
    InputStream content = getResponse.getEntity().getContent();
    return parseWorkflowIdsList(content);
}

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

public void iterateScheduler(ScheduledTime scheduledTime, Set<WorkflowID> workflowIDs) throws Exception {
    URIBuilder uriBuilder = new URIBuilder(address);
    uriBuilder.setPath(uriBuilder.getPath() + SCHEDULER_PATH);
    if (!workflowIDs.isEmpty()) {
        uriBuilder.addParameter(IDS_PARAM, StringUtils.join(workflowIDs, ","));
    }//from  w w w.  j  a v  a2  s.c  o m
    uriBuilder.addParameter(TIME_PARAM, timeFormatter.formatPretty(scheduledTime));
    executePost(uriBuilder.build());
}

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

/**
 * Sets the specified register value./*from www.java2 s . c o m*/
 */
public void putRegister(BucketID bucket, RegisterKey key, JsonNode value) 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());
    executePut(uriBuilder.build(),
            new StringEntity(Util.JSON_WRITER.writeValueAsString(value), StandardCharsets.UTF_8));
}

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

public List<RegisterKey> getRegisterKeys(BucketID bucket, String prefix) throws Exception {
    URIBuilder uriBuilder = new URIBuilder(address);
    uriBuilder.setPath(uriBuilder.getPath() + LIST_REGISTER_KEYS_PATH);
    uriBuilder.addParameter(BUCKET_PARAM, bucket.toString());
    if (!StringUtils.isEmpty(prefix)) {
        uriBuilder.addParameter(PREFIX_PARAM, prefix);
    }//w ww  .j  a v  a 2 s  .  c o  m
    InputStream contentStream = execute(new HttpGet(uriBuilder.build())).getEntity().getContent();
    return parseKeyList(contentStream);
}

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:uk.org.openeyes.oink.itest.adapters.ITFacadeToProxy.java

@Test
public void testGetPractitioners() throws Exception {
    String facadeUri = (String) facadeProps.get("facade.uri");

    URIBuilder builder = new URIBuilder(facadeUri);
    URI uri = builder.setPath(builder.getPath() + "/Practitioner")
            .setParameter("_profile", "http://openeyes.org.uk/fhir/1.7.0/profile/Practitioner/Gp").build();

    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpGet httpGet = new HttpGet(uri);
    httpGet.addHeader("Accept", "application/json+fhir; charset=UTF-8");
    CloseableHttpResponse response1 = httpclient.execute(httpGet);

    assertEquals(200, response1.getStatusLine().getStatusCode());
    String json = null;//from w w w  .j a v  a  2 s . c  o  m
    try {
        HttpEntity entity1 = response1.getEntity();
        json = EntityUtils.toString(entity1);
    } finally {
        response1.close();
    }

    assertNotNull(json);

    BundleParser conv = new BundleParser();
    AtomFeed response = conv.fromJsonOrXml(json);

    assertNotEquals(0, response.getEntryList().size());
}

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

public WorkflowStatus getWorkflowStatus(WorkflowID workflowID, ScheduledTime startTime, ScheduledTime endTime)
        throws Exception {

    URIBuilder uriBuilder = new URIBuilder(address);
    uriBuilder.setPath(uriBuilder.getPath() + WORKFLOW_SLOTS_PATH);
    if (endTime != null) {
        uriBuilder.addParameter(END_TIME_PARAM, timeFormatter.formatPretty(endTime));
    }/*from w  ww  . jav a  2s .c o  m*/
    if (startTime != null) {
        uriBuilder.addParameter(START_TIME_PARAM, timeFormatter.formatPretty(startTime));
    }
    uriBuilder.addParameter(ID_PARAM, workflowID.toString());
    URI uri = uriBuilder.build();

    HttpGet workflowListGet = new HttpGet(uri);
    HttpResponse getResponse = execute(workflowListGet);
    InputStream content = getResponse.getEntity().getContent();
    return parseWorkflowStatus(workflowID, content);
}

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

/**
 * Returns the specified register value, or null if not found.
 *///from ww w .  jav a  2 s.co m
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:uk.org.openeyes.oink.itest.adapters.ITFacadeToProxy.java

@Test
public void testCreateAndDeletePractitioners() throws Exception {
    String facadeUri = (String) facadeProps.get("facade.uri");

    URIBuilder builder = new URIBuilder(facadeUri);
    URI uri = builder.setPath(builder.getPath() + "/Practitioner")
            .setParameter("_profile", "http://openeyes.org.uk/fhir/1.7.0/profile/Practitioner/Gp").build();

    System.out.println(uri.toString());

    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpPost httpPost = new HttpPost(uri);
    httpPost.addHeader("Accept", "application/json+fhir; charset=UTF-8");
    httpPost.addHeader("Category",
            "http://openeyes.org.uk/fhir/1.7.0/profile/Practitioner/Gp; scheme=\"http://hl7.org/fhir/tag/profile\"; label=\"\"");
    httpPost.addHeader("Content-Type", "application/json+fhir");
    InputStream is = getClass().getResourceAsStream("/example-messages/fhir/practitioner.json");

    StringWriter writer = new StringWriter();
    IOUtils.copy(is, writer);/*w w w .j  a v a  2 s . c  o m*/
    String theString = writer.toString();

    StringEntity isEntity = new StringEntity(theString);

    httpPost.setEntity(isEntity);

    CloseableHttpResponse response1 = httpclient.execute(httpPost);

    assertEquals(201, response1.getStatusLine().getStatusCode());

    // Note location header is the real end-server location not the facade
    // e.g. http://192.168.1.100/api/Practitioner/gp-4/_history/1401366763
    String locationHeader = response1.getHeaders("Location")[0].getValue();
    assertNotNull(locationHeader);

    String resourceId = extractResourceIdFromUri(locationHeader);
    assertNotNull(resourceId);

    URIBuilder builder2 = new URIBuilder(facadeUri);
    URI uri2 = builder2.setPath(builder2.getPath() + "/Practitioner/" + resourceId)
            .setParameter("_profile", "http://openeyes.org.uk/fhir/1.7.0/profile/Practitioner/Gp").build();

    HttpDelete httpDelete = new HttpDelete(uri2);
    CloseableHttpResponse response2 = httpclient.execute(httpDelete);
    assertEquals(204, response2.getStatusLine().getStatusCode());
}