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  ww w .ja  v a 2  s  .com
 * (non-Javadoc)
* 
* @see
* org.craftercms.profile.httpclient.ProfileRestClient#getProfileCount(java
* .lang.String)
*/
public long getProfileCount(String appToken, String tenantName) {
    long count = 0;
    HttpEntity entity = null;

    if (log.isDebugEnabled()) {
        log.debug("Getting the profile count for 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));

    try {
        URI uri = URIUtils.createURI(scheme, host, port, profileAppPath + "/api/2/profile/" + "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

public Profile getProfile(String appToken, String profileId) {
    if (log.isDebugEnabled()) {
        log.debug("Getting a profile by profileId: " + profileId);
    }/*www .  j  a  v a2s.  c o m*/
    Profile profile = new Profile();
    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/profile/" + profileId + "" + ".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) {
            profile = (Profile) objectMapper.readValue(entity.getContent(), Profile.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 profile;
}

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

@Override
/*/*from  w  w w . ja  v a2  s  .c o  m*/
 * (non-Javadoc)
 * 
 * @see
 * org.craftercms.profile.httpclient.ProfileRestClient#getProfileByTicket
 * (java.lang.String, java.lang.String)
 */
public Profile getProfileByTicket(String appToken, String ticket) {
    if (log.isDebugEnabled()) {
        log.debug("Getting a profile by ticket: " + ticket);
    }
    Profile profile = 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/profile/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) {
            profile = (Profile) objectMapper.readValue(entity.getContent(), Profile.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 profile;
}

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

@Override
/*//from  w w  w.  j  a va 2s  . c o m
 * (non-Javadoc)
 * 
 * @see org.craftercms.profile.httpclient.ProfileRestClient#
 * getProfileByTicketWithAttributes(java.lang.String, java.lang.String,
 * java.util.List)
 */
public Profile getProfileByTicketWithAttributes(String appToken, String ticket, List<String> attributes) {
    if (log.isDebugEnabled()) {
        log.debug("Getting the profile by ticket: " + ticket);
    }
    HttpEntity entity = null;
    Profile profile = null;
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair(ProfileConstants.APP_TOKEN, appToken));
    if (attributes != null && attributes.size() > 0) {
        for (String attribute : attributes) {
            qparams.add(new BasicNameValuePair("attributes", attribute));
        }
    }

    try {
        URI uri = URIUtils.createURI(scheme, host, port,
                profileAppPath + "/api/2/profile/ticket/" + ticket + "/with_attributes.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) {
            profile = (Profile) objectMapper.readValue(entity.getContent(), Profile.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 profile;
}

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

@Override
/*//from   w w  w .j a va 2 s .  co  m
 * (non-Javadoc)
 * 
 * @see org.craftercms.profile.httpclient.ProfileRestClient#
 * getProfileByTicketWithAllAttributes(java.lang.String, java.lang.String)
 */
public Profile getProfileByTicketWithAllAttributes(String appToken, String ticket) {
    if (log.isDebugEnabled()) {
        log.debug("Getting a profile with all the attributes by ticket: " + ticket);
    }
    Profile profile = 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/profile/ticket/" + ticket + "/with_all_attributes.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) {
            profile = (Profile) objectMapper.readValue(entity.getContent(), Profile.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 profile;
}

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

@Override
/*/*from  w w  w  .j  a va 2 s  .c  o  m*/
 * (non-Javadoc)
 * 
 * @see
 * org.craftercms.profile.httpclient.ProfileRestClient#getProfileByUsername
 * (java.lang.String, java.lang.String)
 */
public Profile getProfileByUsername(String appToken, String username, String tenantName) {
    if (log.isDebugEnabled()) {
        log.debug("Getting a profile by username: " + username + " and tenantName:" + tenantName);
    }
    Profile profile = null;
    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;

    try {
        URI uri = URIUtils.createURI(scheme, host, port,
                profileAppPath + "/api/2/profile/username/" + username + ".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) {
            profile = (Profile) objectMapper.readValue(entity.getContent(), Profile.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 profile;
}

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

@Override
/*/*from w  ww  .  j a  v a 2  s .  c  o  m*/
 * (non-Javadoc)
 * 
 * @see org.craftercms.profile.httpclient.ProfileRestClient#
 * getProfileByUsernameWithAttributes(java.lang.String, java.lang.String,
 * java.util.List)
 */
public Profile getProfileByUsernameWithAttributes(String appToken, String username, String tenantName,
        List<String> attributes) {
    if (log.isDebugEnabled()) {
        log.debug("Getting a profile by username: " + username + " and tenantName:" + tenantName
                + " with certain" + " attributes " + attributes);
    }
    HttpEntity entity = null;
    Profile profile = null;
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair(ProfileConstants.APP_TOKEN, appToken));
    qparams.add(new BasicNameValuePair(ProfileConstants.TENANT_NAME, tenantName));

    if (attributes != null && attributes.size() > 0) {
        for (String attribute : attributes) {
            qparams.add(new BasicNameValuePair("attributes", attribute));
        }
    }

    try {
        URI uri = URIUtils.createURI(scheme, host, port,
                profileAppPath + "/api/2/profile/username/" + username + "/with_attributes.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) {
            profile = (Profile) objectMapper.readValue(entity.getContent(), Profile.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 profile;
}

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

@Override
/*// w  ww. j a  v a 2  s. c  o  m
 * (non-Javadoc)
 * 
 * @see org.craftercms.profile.httpclient.ProfileRestClient#
 * getProfileByUsernameWithAllAttributes(java.lang.String, java.lang.String)
 */
public Profile getProfileByUsernameWithAllAttributes(String appToken, String username, String tenantName) {
    if (log.isDebugEnabled()) {
        log.debug("Getting a profile by username: " + username + " and tenantName:" + tenantName + " with all "
                + "attributes ");
    }
    HttpEntity entity = null;
    Profile profile = null;
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair(ProfileConstants.APP_TOKEN, appToken));
    qparams.add(new BasicNameValuePair(ProfileConstants.TENANT_NAME, tenantName));

    try {
        URI uri = URIUtils.createURI(scheme, host, port,
                profileAppPath + "/api/2/profile/username/" + username + "/with_all_attributes.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) {
            profile = (Profile) objectMapper.readValue(entity.getContent(), Profile.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 profile;
}

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

@Override
/*//w  w  w .  j ava  2 s .c o  m
 * (non-Javadoc)
 * 
 * @see
 * org.craftercms.profile.httpclient.ProfileRestClient#getProfileWithAttributes
 * (java.lang.String, java.lang.String, java.util.List)
 */
public Profile getProfileWithAttributes(String appToken, String profileId, List<String> attributes) {
    if (log.isDebugEnabled()) {
        log.debug("Getting a profile by profile id: " + profileId + " with certain attributes " + attributes);
    }
    HttpEntity entity = null;
    Profile profile = new Profile();

    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair(ProfileConstants.APP_TOKEN, appToken));
    if (attributes != null) {
        for (String attribute : attributes) {
            qparams.add(new BasicNameValuePair("attributes", attribute));
        }
    }

    try {
        URI uri = URIUtils.createURI(scheme, host, port,
                profileAppPath + "/api/2/profile/" + profileId + "/with_attributes.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) {
            profile = (Profile) objectMapper.readValue(entity.getContent(), Profile.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 profile;
}

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

@Override
/*//from   w  ww.  j a v a 2  s  .c  o  m
 * (non-Javadoc)
 * 
 * @see org.craftercms.profile.httpclient.ProfileRestClient#
 * getProfileWithAllAttributes(java.lang.String, java.lang.String)
 */
public Profile getProfileWithAllAttributes(String appToken, String profileId) {
    if (log.isDebugEnabled()) {
        log.debug("Getting a profile by profile id: " + profileId + " with all the attributes");
    }
    HttpEntity entity = null;
    Profile profile = new Profile();

    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/profile/" + profileId + "/with_all_attributes.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) {
            profile = (Profile) objectMapper.readValue(entity.getContent(), Profile.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 profile;
}