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

/**
 * Gets the list of Groups- Role mapping for a tenant
 *
 * @param appToken   Current application token
 * @param tenantName used to get the Group - Role mapping list
 * @return//from   ww w .j  a v  a  2 s  .c o m
 */
public List<GroupRole> getGroupRoleMappingByTenant(String appToken, String tenantName) {
    HttpEntity entity = null;
    List<GroupRole> groupRole = new ArrayList<GroupRole>();
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair(ProfileConstants.APP_TOKEN, appToken));
    qparams.add(new BasicNameValuePair(GroupConstants.TENANT_NAME, tenantName));
    try {
        URI uri = URIUtils.createURI(scheme, host, port, profileAppPath + "/api/2/group/get_all_tenant.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) {
            groupRole = (List<GroupRole>) objectMapper.readValue(entity.getContent(), GROUP_ROLE_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 groupRole;
}

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

public GroupRole getGroupRoleMapping(String appToken, String groupId) {
    HttpEntity entity = null;//from w ww  . j  a  va2s.c  o m
    GroupRole groupRole = null;
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair(ProfileConstants.APP_TOKEN, appToken));
    qparams.add(new BasicNameValuePair(GroupConstants.ID, groupId));
    try {
        URI uri = URIUtils.createURI(scheme, host, port, profileAppPath + "/api/2/group/get_item.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) {
            groupRole = (GroupRole) objectMapper.readValue(entity.getContent(), GroupRole.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 groupRole;
}

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

/**
 * CHANGING PASSWORD **/*  w w  w. j  av  a  2s .c o m*/
 */

public Profile resetPassword(String appToken, String token, String newPassword) {
    HttpEntity entity = null;
    Profile profile = new Profile();
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair(ProfileConstants.APP_TOKEN, appToken));
    qparams.add(new BasicNameValuePair(PasswordChangeConstants.TOKEN, token));
    qparams.add(new BasicNameValuePair(PasswordChangeConstants.NEW_PASSWORD, newPassword));

    try {
        URI uri = URIUtils.createURI(scheme, host, port, profileAppPath + "/api/2/password/reset-password.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) {
            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);
        throw new PasswordException(formatPasswordErrorMessage(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

public Profile forgotPassword(String appToken, String changePasswordUrl, String tenantName, String username)
        throws PasswordException {
    HttpEntity entity = null;/*from   w  ww  .  j  a  v a  2s .c  o m*/
    Profile profile = null;

    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair(ProfileConstants.APP_TOKEN, appToken));
    qparams.add(new BasicNameValuePair(PasswordChangeConstants.CHANGE_PASSWORD_URL, changePasswordUrl));
    qparams.add(new BasicNameValuePair(ProfileConstants.TENANT_NAME, tenantName));
    qparams.add(new BasicNameValuePair(PasswordChangeConstants.USERNAME, username));
    try {
        URI uri = URIUtils.createURI(scheme, host, port,
                profileAppPath + "/api/2/password/forgot-password.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) {
            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);
        throw new PasswordException(formatPasswordErrorMessage(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

/************************************SUBSCRITIONS*******************************/

@Override/*  w w w .  ja va 2s .  co  m*/
public Subscriptions setSubscriptions(String appToken, String profileId, Subscriptions subscriptions) {
    if (log.isDebugEnabled()) {
        log.debug("Adding a new subscription: " + profileId);
    }
    HttpEntity entity = null;
    Subscriptions subscriptionsResponse = 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/profile/subscriptions/" + profileId + ".json",
                URLEncodedUtils.format(qparams, HTTP.UTF_8), null);
        HttpPost httppost = new HttpPost(uri);
        String test = this.objectMapper.writeValueAsString(subscriptions);
        StringEntity input = new StringEntity(test);
        input.setContentType("application/json");
        httppost.setEntity(input);

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

        entity = response.getEntity();
        if (response.getStatusLine().getStatusCode() == 200) {
            subscriptionsResponse = (Subscriptions) objectMapper.readValue(entity.getContent(),
                    Subscriptions.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);
        throw new PasswordException(formatPasswordErrorMessage(e.getMessage()), e);
    } finally {
        try {
            EntityUtils.consume(entity);
        } catch (IOException e) {
            log.error("Could not consume entity", e);
        }
    }
    return subscriptionsResponse;
}

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

@Override
public Profile addSubscription(String appToken, String profileId, String targetId, String targetDescription,
        String targetUrl) {/*  w w w .jav  a2s .  co  m*/
    if (log.isDebugEnabled()) {
        log.debug("Adding a new subscription: " + profileId);
    }
    HttpEntity entity = null;
    Profile profile = new Profile();
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair(ProfileConstants.APP_TOKEN, appToken));
    qparams.add(new BasicNameValuePair(ProfileConstants.TARGET_ID, targetId));

    qparams.add(new BasicNameValuePair(ProfileConstants.TARGET_DESCRIPTION, targetDescription));
    qparams.add(new BasicNameValuePair(ProfileConstants.TARGET_URL, targetUrl));

    try {
        URI uri = URIUtils.createURI(scheme, host, port,
                profileAppPath + "/api/2/profile/subscribe/" + profileId + ".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) {
            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);
        throw new PasswordException(formatPasswordErrorMessage(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
public Profile createOrUpdateSubscription(String appToken, String profileId, String targetId,
        String targetDescription, String targetUrl) {
    if (log.isDebugEnabled()) {
        log.debug("Creating or updating a subscription: " + profileId);
    }/*from  w ww.  j a v  a  2  s. c  o  m*/
    HttpEntity entity = null;
    Profile profile = new Profile();
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair(ProfileConstants.APP_TOKEN, appToken));
    qparams.add(new BasicNameValuePair(ProfileConstants.TARGET_ID, targetId));

    qparams.add(new BasicNameValuePair(ProfileConstants.TARGET_DESCRIPTION, targetDescription));
    qparams.add(new BasicNameValuePair(ProfileConstants.TARGET_URL, targetUrl));

    try {
        URI uri = URIUtils.createURI(scheme, host, port,
                profileAppPath + "/api/2/profile/subscription/create-update/" + profileId + ".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) {
            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);
        throw new PasswordException(formatPasswordErrorMessage(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
public Profile updateSubscription(String appToken, String profileId, String targetId, String targetDescription,
        String targetUrl) {/* w w  w. j a v  a  2 s.c o m*/
    if (log.isDebugEnabled()) {
        log.debug("Updating a subscription in: " + profileId);
    }
    HttpEntity entity = null;
    Profile profile = new Profile();
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair(ProfileConstants.APP_TOKEN, appToken));
    qparams.add(new BasicNameValuePair(ProfileConstants.TARGET_ID, targetId));

    qparams.add(new BasicNameValuePair(ProfileConstants.TARGET_DESCRIPTION, targetDescription));
    qparams.add(new BasicNameValuePair(ProfileConstants.TARGET_URL, targetUrl));

    try {
        URI uri = URIUtils.createURI(scheme, host, port,
                profileAppPath + "/api/2/profile/subscription/update/" + profileId + ".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) {
            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);
        throw new PasswordException(formatPasswordErrorMessage(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
public Profile removeSubscription(String appToken, String profileId, String targetId) {
    if (log.isDebugEnabled()) {
        log.debug("Removing a subscription from: " + profileId);
    }/*www .  j  av  a2s.c  om*/
    HttpEntity entity = null;
    Profile profile = new Profile();
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair(ProfileConstants.APP_TOKEN, appToken));
    qparams.add(new BasicNameValuePair(ProfileConstants.TARGET_ID, targetId));

    try {
        URI uri = URIUtils.createURI(scheme, host, port,
                profileAppPath + "/api/2/profile/unsubscribe/" + profileId + ".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) {
            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);
        throw new PasswordException(formatPasswordErrorMessage(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
public Subscriptions getSubscriptions(String appToken, String profileId) {

    if (log.isDebugEnabled()) {
        log.debug("Getting subscription list for: " + profileId);
    }//from  w  w w  .  j  av a  2s. com
    Subscriptions subscriptions = 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/subscriptions/" + 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) {
            subscriptions = (Subscriptions) objectMapper.readValue(entity.getContent(), Subscriptions.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 subscriptions;

}