Example usage for org.apache.http.client.utils URIUtils createURI

List of usage examples for org.apache.http.client.utils URIUtils createURI

Introduction

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

Prototype

@Deprecated
public static URI createURI(final String scheme, final String host, final int port, final String path,
        final String query, final String fragment) throws URISyntaxException 

Source Link

Document

Constructs a URI using all the parameters.

Usage

From source file:org.craftercms.profile.impl.ProfileRestClientImpl.java

@Override
/*/*from   w w w . j  av a  2  s  .c o  m*/
 * (non-Javadoc)
 * @see org.craftercms.profile.api.ProfileClient#getTenantByName(java.lang.String, java.lang.String)
 */
public Tenant getTenantByName(String appToken, String tenantName) {
    if (log.isDebugEnabled()) {
        log.debug("Getting the tenant: " + tenantName);
    }
    Tenant tenant = null;
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair(ProfileConstants.APP_TOKEN, appToken));
    HttpEntity entity = null;

    try {
        URI uri = URIUtils.createURI(scheme, host, port,
                profileAppPath + "/api/2/tenant/get/" + tenantName + "" + ".json",
                URLEncodedUtils.format(qparams, HTTP.UTF_8), null);
        HttpGet httpget = new HttpGet(uri);

        HttpResponse response = clientService.getHttpClient().execute(httpget);
        entity = response.getEntity();
        if (response.getStatusLine().getStatusCode() == 200) {
            tenant = (Tenant) objectMapper.readValue(entity.getContent(), Tenant.class);
        } else {
            handleErrorStatus(response.getStatusLine(), entity);
        }
    } catch (URISyntaxException e) {
        log.error(e.getMessage(), e);
    } catch (ClientProtocolException e) {
        log.error(e.getMessage(), e);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    } catch (RestException e) {
        log.error(e.getMessage(), e);
    } finally {
        try {
            EntityUtils.consume(entity);
        } catch (IOException e) {
            log.error("Could not consume entity", e);
        }
    }

    return tenant;
}

From source file:org.craftercms.profile.impl.ProfileRestClientImpl.java

@Override
/*//from w ww  .jav a 2  s  . c o m
 * (non-Javadoc)
 * @see org.craftercms.profile.api.ProfileClient#getTenantById(java.lang.String, java.lang.String)
 */
public Tenant getTenantById(String appToken, String tenantName) {
    if (log.isDebugEnabled()) {
        log.debug("Getting a tenant by id: " + tenantName);
    }
    Tenant tenant = null;
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair(ProfileConstants.APP_TOKEN, appToken));
    HttpEntity entity = null;

    try {
        URI uri = URIUtils.createURI(scheme, host, port,
                profileAppPath + "/api/2/tenant/" + tenantName + "/get_id.json",
                URLEncodedUtils.format(qparams, HTTP.UTF_8), null);
        HttpGet httpget = new HttpGet(uri);

        HttpResponse response = clientService.getHttpClient().execute(httpget);
        entity = response.getEntity();
        if (response.getStatusLine().getStatusCode() == 200) {
            tenant = (Tenant) objectMapper.readValue(entity.getContent(), Tenant.class);
        } else {
            handleErrorStatus(response.getStatusLine(), entity);
        }
    } catch (URISyntaxException e) {
        log.error(e.getMessage(), e);
    } catch (ClientProtocolException e) {
        log.error(e.getMessage(), e);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    } catch (RestException e) {
        log.error(e.getMessage(), e);
    } finally {
        try {
            EntityUtils.consume(entity);
        } catch (IOException e) {
            log.error("Could not consume entity", e);
        }
    }

    return tenant;
}

From source file:org.craftercms.profile.impl.ProfileRestClientImpl.java

@Override
/*//  w  w w.j  a  va  2s.  c om
 * (non-Javadoc)
 * @see org.craftercms.profile.api.ProfileClient#getTenantByTicket(java.lang.String, java.lang.String)
 */
public Tenant getTenantByTicket(String appToken, String ticket) {
    if (log.isDebugEnabled()) {
        log.debug("Getting a tenant by a ticket: " + ticket);
    }
    Tenant tenant = null;
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair(ProfileConstants.APP_TOKEN, appToken));
    HttpEntity entity = null;

    try {
        URI uri = URIUtils.createURI(scheme, host, port,
                profileAppPath + "/api/2/tenant/ticket/" + ticket + "" + ".json",
                URLEncodedUtils.format(qparams, HTTP.UTF_8), null);
        HttpGet httpget = new HttpGet(uri);

        HttpResponse response = clientService.getHttpClient().execute(httpget);
        entity = response.getEntity();
        if (response.getStatusLine().getStatusCode() == 200) {
            tenant = (Tenant) objectMapper.readValue(entity.getContent(), Tenant.class);
        } else {
            handleErrorStatus(response.getStatusLine(), entity);
        }
    } catch (URISyntaxException e) {
        log.error(e.getMessage(), e);
    } catch (ClientProtocolException e) {
        log.error(e.getMessage(), e);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    } catch (RestException e) {
        log.error(e.getMessage(), e);
    } finally {
        try {
            EntityUtils.consume(entity);
        } catch (IOException e) {
            log.error("Could not consume entity", e);
        }
    }

    return tenant;
}

From source file:org.craftercms.profile.impl.ProfileRestClientImpl.java

@Override
/*// w w  w  . jav  a 2  s. c o  m
 * (non-Javadoc)
 * @see org.craftercms.profile.api.ProfileClient#exitsTenant(java.lang.String, java.lang.String)
 */
public boolean exitsTenant(String appToken, String tenantName) {
    if (log.isDebugEnabled()) {
        log.debug("Getting if a tenant exists : " + tenantName);
    }
    boolean exist = false;

    HttpEntity entity = null;

    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair(ProfileConstants.APP_TOKEN, appToken));

    try {
        URI uri = URIUtils.createURI(scheme, host, port,
                profileAppPath + "/api/2/tenant/exists/" + tenantName + ".json",
                URLEncodedUtils.format(qparams, HTTP.UTF_8), null);
        HttpGet httpget = new HttpGet(uri);

        HttpResponse response = clientService.getHttpClient().execute(httpget);
        entity = response.getEntity();
        if (response.getStatusLine().getStatusCode() == 200) {
            exist = (Boolean) objectMapper.readValue(entity.getContent(), Boolean.class);
        } else {
            handleErrorStatus(response.getStatusLine(), entity);
        }
    } catch (URISyntaxException e) {
        log.error(e.getMessage(), e);
    } catch (ClientProtocolException e) {
        log.error(e.getMessage(), e);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    } catch (RestException e) {
        log.error(e.getMessage(), e);
    } finally {
        try {
            EntityUtils.consume(entity);
        } catch (IOException e) {
            log.error("Could not consume entity", e);
        }
    }

    return exist;
}

From source file:org.craftercms.profile.impl.ProfileRestClientImpl.java

@Override
/*/*from   w w w .  j a  v a 2s. co m*/
 * (non-Javadoc)
 * @see org.craftercms.profile.api.ProfileClient#getTenantCount(java.lang.String)
 */
public long getTenantCount(String appToken) {
    if (log.isDebugEnabled()) {
        log.debug("Getting tenant count ");
    }
    long count = 0;
    HttpEntity entity = null;

    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair(ProfileConstants.APP_TOKEN, appToken));

    try {
        URI uri = URIUtils.createURI(scheme, host, port, profileAppPath + "/api/2/tenant/" + "count.json",
                URLEncodedUtils.format(qparams, HTTP.UTF_8), null);
        HttpGet httpget = new HttpGet(uri);

        HttpResponse response = clientService.getHttpClient().execute(httpget);
        entity = response.getEntity();
        if (response.getStatusLine().getStatusCode() == 200) {
            count = (Long) objectMapper.readValue(entity.getContent(), Long.class);
        } else {
            handleErrorStatus(response.getStatusLine(), entity);
        }
    } catch (URISyntaxException e) {
        log.error(e.getMessage(), e);
    } catch (ClientProtocolException e) {
        log.error(e.getMessage(), e);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    } catch (RestException e) {
        log.error(e.getMessage(), e);
    } finally {
        try {
            EntityUtils.consume(entity);
        } catch (IOException e) {
            log.error("Could not consume entity", e);
        }
    }

    return count;
}

From source file:org.craftercms.profile.impl.ProfileRestClientImpl.java

@Override
/*/*w  w w  .ja  v a 2  s  .c o m*/
 * (non-Javadoc)
 * @see org.craftercms.profile.api.ProfileClient#getTenantRange(java.lang.String, java.lang.String, java.lang.String,
  * int, int)
 */
public List<Tenant> getTenantRange(String appToken, String sortBy, String sortOrder, int start, int end) {
    if (log.isDebugEnabled()) {
        log.debug("Getting tenant range starting " + start + " ending " + end + " sortBy " + sortBy
                + " sortOrder" + " " + sortOrder);
    }
    List<Tenant> tenants = new ArrayList<Tenant>();
    HttpEntity entity = null;

    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair(ProfileConstants.APP_TOKEN, appToken));
    qparams.add(new BasicNameValuePair("sortBy", sortBy));
    qparams.add(new BasicNameValuePair("sortOrder", sortOrder));
    qparams.add(new BasicNameValuePair("start", String.valueOf(start)));
    qparams.add(new BasicNameValuePair("end", String.valueOf(end)));

    try {
        URI uri = URIUtils.createURI(scheme, host, port, profileAppPath + "/api/2/tenant/range.json",
                URLEncodedUtils.format(qparams, HTTP.UTF_8), null);
        HttpGet httpget = new HttpGet(uri);

        HttpResponse response = clientService.getHttpClient().execute(httpget);
        entity = response.getEntity();
        if (response.getStatusLine().getStatusCode() == 200) {
            tenants = (List<Tenant>) objectMapper.readValue(entity.getContent(), TENANT_LIST_TYPE);

        } else {
            handleErrorStatus(response.getStatusLine(), entity);
        }
    } catch (URISyntaxException e) {
        log.error(e.getMessage(), e);
    } catch (ClientProtocolException e) {
        log.error(e.getMessage(), e);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    } catch (RestException e) {
        log.error(e.getMessage(), e);
    } finally {
        try {
            EntityUtils.consume(entity);
        } catch (IOException e) {
            log.error("Could not consume entity", e);
        }
    }

    return tenants;
}

From source file:org.craftercms.profile.impl.ProfileRestClientImpl.java

@Override
/*/*from  w w w  . j a  v  a  2  s  .c  om*/
 * (non-Javadoc)
 * @see org.craftercms.profile.api.ProfileClient#getAllTenants(java.lang.String)
 */
public List<Tenant> getAllTenants(String appToken) {
    if (log.isDebugEnabled()) {
        log.debug("Getting all tenants ");
    }
    List<Tenant> tenantList = null;
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair(ProfileConstants.APP_TOKEN, appToken));
    HttpEntity entity = null;

    try {
        URI uri = URIUtils.createURI(scheme, host, port,
                profileAppPath + "/api/2/tenant/get_all_tenants" + "" + ".json",
                URLEncodedUtils.format(qparams, HTTP.UTF_8), null);
        HttpGet httpget = new HttpGet(uri);

        HttpResponse response = clientService.getHttpClient().execute(httpget);
        entity = response.getEntity();
        if (response.getStatusLine().getStatusCode() == 200) {
            tenantList = (List<Tenant>) objectMapper.readValue(entity.getContent(), TENANT_LIST_TYPE);
        } else {
            handleErrorStatus(response.getStatusLine(), entity);
        }
    } catch (URISyntaxException e) {
        log.error(e.getMessage(), e);
    } catch (ClientProtocolException e) {
        log.error(e.getMessage(), e);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    } catch (RestException e) {
        log.error(e.getMessage(), e);
    } finally {
        try {
            EntityUtils.consume(entity);
        } catch (IOException e) {
            log.error("Could not consume entity", e);
        }
    }
    return tenantList;
}

From source file:org.craftercms.profile.impl.ProfileRestClientImpl.java

@Override
/*/* w  ww.j a  v a2 s. c  o  m*/
 * (non-Javadoc)
 * @see org.craftercms.profile.api.ProfileClient#getTenantsByRoleName(java.lang.String, java.lang.String)
 */
public List<Tenant> getTenantsByRoleName(String appToken, String roleName) {
    if (log.isDebugEnabled()) {
        log.debug("Getting tenants by role name");
    }
    List<Tenant> tenantList = null;
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair(ProfileConstants.APP_TOKEN, appToken));
    qparams.add(new BasicNameValuePair(ProfileConstants.ROLE_NAME, roleName));
    HttpEntity entity = null;

    try {
        URI uri = URIUtils.createURI(scheme, host, port, profileAppPath + "/api/2/tenant/get/by_role_name.json",
                URLEncodedUtils.format(qparams, HTTP.UTF_8), null);
        HttpGet httpget = new HttpGet(uri);

        HttpResponse response = clientService.getHttpClient().execute(httpget);
        entity = response.getEntity();
        if (response.getStatusLine().getStatusCode() == 200) {
            tenantList = (List<Tenant>) objectMapper.readValue(entity.getContent(), TENANT_LIST_TYPE);
        } else {
            handleErrorStatus(response.getStatusLine(), entity);
        }
    } catch (URISyntaxException e) {
        log.error(e.getMessage(), e);
    } catch (ClientProtocolException e) {
        log.error(e.getMessage(), e);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    } catch (RestException e) {
        log.error(e.getMessage(), e);
    } finally {
        try {
            EntityUtils.consume(entity);
        } catch (IOException e) {
            log.error("Could not consume entity", e);
        }
    }

    return tenantList;
}

From source file:org.craftercms.profile.impl.ProfileRestClientImpl.java

/**
 * ************ SCHEMA SERVICES ***************
 *///from   w  w w  .ja  va 2 s.c  o m

@Override
/*
 * (non-Javadoc)
 * 
 * @see
 * org.craftercms.profile.httpclient.ProfileRestClient#deleteAttributeForSchema
 * (java.lang.String, java.util.String)
 */
public void deleteAttributeForSchema(String appToken, String tenantName, String attributeName) {
    if (log.isDebugEnabled()) {
        log.debug("Deleting an attribute in the tenant: " + tenantName);
    }
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair(ProfileConstants.APP_TOKEN, appToken));
    qparams.add(new BasicNameValuePair(ProfileConstants.TENANT_NAME, tenantName));
    HttpEntity entity = null;

    if (attributeName != null && !attributeName.isEmpty()) {
        qparams.add(new BasicNameValuePair(AttributeConstants.NAME, attributeName));
    }

    try {
        URI uri = URIUtils.createURI(scheme, host, port, profileAppPath + "/api/2/schema/delete_attribute.json",
                URLEncodedUtils.format(qparams, HTTP.UTF_8), null);
        HttpPost httppost = new HttpPost(uri);

        HttpResponse response = clientService.getHttpClient().execute(httppost);

        entity = response.getEntity();
        if (response.getStatusLine().getStatusCode() != 200) {
            handleErrorStatus(response.getStatusLine(), response.getEntity());
        }
    } catch (URISyntaxException e) {
        log.error(e.getMessage(), e);
    } catch (ClientProtocolException e) {
        log.error(e.getMessage(), e);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    } catch (RestException e) {
        log.error(e.getMessage(), e);
    } finally {
        try {
            EntityUtils.consume(entity);
        } catch (IOException e) {
            log.error("Could not consume entity", e);
        }
    }
}

From source file:org.craftercms.profile.impl.ProfileRestClientImpl.java

@Override
/*// ww w .j av a  2s. c  o  m
 * (non-Javadoc)
 * 
 * @see
 * org.craftercms.profile.httpclient.ProfileRestClient#setAttributeForSchema
 * (java.lang.String, org.craftercms.profile.domain.Attribute)
 */
public void setAttributeForSchema(String appToken, String tenantName, Attribute attribute) {
    if (log.isDebugEnabled()) {
        log.debug("Setting an attribute in the tenant: " + tenantName);
    }
    HttpEntity entity = null;
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair(ProfileConstants.APP_TOKEN, appToken));
    qparams.add(new BasicNameValuePair(ProfileConstants.TENANT_NAME, tenantName));
    if (attribute != null) {
        qparams.add(new BasicNameValuePair(AttributeConstants.NAME, attribute.getName()));
        qparams.add(new BasicNameValuePair(AttributeConstants.LABEL, attribute.getLabel()));
        qparams.add(new BasicNameValuePair(AttributeConstants.ORDER, String.valueOf(attribute.getOrder())));
        qparams.add(new BasicNameValuePair(AttributeConstants.TYPE, attribute.getType()));
        qparams.add(new BasicNameValuePair(AttributeConstants.CONSTRAINT, attribute.getConstraint()));
        qparams.add(
                new BasicNameValuePair(AttributeConstants.REQUIRED, String.valueOf(attribute.isRequired())));
    }
    try {
        URI uri = URIUtils.createURI(scheme, host, port,
                profileAppPath + "/api/2/schema/" + "set_attribute" + ".json",
                URLEncodedUtils.format(qparams, HTTP.UTF_8), null);
        HttpPost httppost = new HttpPost(uri);

        HttpResponse response = clientService.getHttpClient().execute(httppost);
        entity = response.getEntity();

        if (response.getStatusLine().getStatusCode() != 200) {
            handleErrorStatus(response.getStatusLine(), response.getEntity());
        }
    } catch (URISyntaxException e) {
        log.error(e.getMessage(), e);
    } catch (ClientProtocolException e) {
        log.error(e.getMessage(), e);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    } catch (RestException e) {
        log.error(e.getMessage(), e);
    } finally {
        try {
            EntityUtils.consume(entity);
        } catch (IOException e) {
            log.error("Could not consume entity", e);
        }
    }
}