Example usage for org.apache.commons.httpclient.methods PostMethod addParameter

List of usage examples for org.apache.commons.httpclient.methods PostMethod addParameter

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods PostMethod addParameter.

Prototype

public void addParameter(String paramString1, String paramString2) throws IllegalArgumentException 

Source Link

Usage

From source file:es.carebear.rightmanagement.client.user.GetAllUsersWithAccess.java

public String[] getUsers(String authName) throws BadRequestException, InternalServerErrorException, IOException,
        UnauthorizedException, UnknownResponseException {
    PostMethod postMethod = new PostMethod(baseUri + "/client/users/all/withAccess");
    postMethod.addParameter("authName", authName);
    int responseCode = httpClient.executeMethod(postMethod);

    switch (responseCode) {
    case HttpStatus.SC_ACCEPTED:
        String response = XMLHelper.fromStreamToXML(postMethod.getResponseBodyAsStream());
        StringListContainer lc = XMLHelper.fromXML(response, StringListContainer.class);
        List<String> ls = new ArrayList<>();
        lc.getContainer().stream().forEach(obj -> {
            Gson gson = new Gson();
            ls.add(obj);//from   w  ww. j  av a 2s  . com
        });
        return ls.toArray(new String[ls.size()]);
    case HttpStatus.SC_BAD_REQUEST:
        throw new BadRequestException();
    case HttpStatus.SC_UNAUTHORIZED:
        throw new UnauthorizedException();
    default:
        throw new UnknownResponseException((new Integer(responseCode)).toString());
    }
}

From source file:es.carebear.rightmanagement.client.user.GetAllRightsOnUsers.java

public String[] getRights(String authName)
        throws BadRequestException, InternalServerErrorException, IOException, UnknownResponseException {
    PostMethod postMethod = new PostMethod(baseUri + "/client/users/all/withRigthOnUser");
    postMethod.addParameter("authName", authName);
    int responseCode = httpClient.executeMethod(postMethod);

    switch (responseCode) {
    case HttpStatus.SC_ACCEPTED:
        String response = XMLHelper.fromStreamToXML(postMethod.getResponseBodyAsStream());
        StringListContainer lc = XMLHelper.fromXML(response, StringListContainer.class);
        List<String> ls = new ArrayList<>();
        lc.getContainer().stream().forEach(obj -> {
            Gson gson = new Gson();
            ls.add(obj);//from  w  w  w  . j  a  va 2 s. c  om
        });
        return ls.toArray(new String[ls.size()]);
    case HttpStatus.SC_BAD_REQUEST:
        throw new BadRequestException();
    default:
        throw new UnknownResponseException((new Integer(responseCode)).toString());
    }
}

From source file:es.carebear.rightmanagement.client.group.GetUserlistGroup.java

public String[] GetUserlist(String targetGroup, String authName)
        throws IOException, UnauthorizedException, BadRequestException, UnknownResponseException {
    PostMethod postMethod = new PostMethod(baseUri + "/client/groups/users/" + targetGroup);
    postMethod.addParameter("authName", authName);
    int responseCode = httpClient.executeMethod(postMethod);

    switch (responseCode) {
    case HttpStatus.SC_ACCEPTED:
        String response = XMLHelper.fromStreamToXML(postMethod.getResponseBodyAsStream());
        StringListContainer lc = XMLHelper.fromXML(response, StringListContainer.class);
        List<String> ls = new ArrayList<>();
        lc.getContainer().stream().forEach(obj -> {
            ls.add(obj);/*from   ww  w. j a va2  s. co  m*/
        });
        return ls.toArray(new String[ls.size()]);
    case HttpStatus.SC_FORBIDDEN:
        throw new UnauthorizedException();
    case HttpStatus.SC_BAD_REQUEST:
        throw new BadRequestException();
    default:
        throw new UnknownResponseException((new Integer(responseCode)).toString());
    }
}

From source file:es.carebear.rightmanagement.client.user.ChangeAttributeUser.java

public void ChangeAttribute(String userName, String authName, String[] attribute, String[] value)
        throws BadRequestException, InternalServerErrorException, IOException, UnknownResponseException {
    Gson gson = new Gson();
    String attr = gson.toJson(attribute, attribute.getClass());
    String val = gson.toJson(value, value.getClass());

    PostMethod postMethod = new PostMethod(baseUri + "/client/users/change/" + userName);
    postMethod.addParameter("authName", authName);
    postMethod.addParameter("attribute", attr);
    postMethod.addParameter("value", val);

    int responseCode = httpClient.executeMethod(postMethod);

    switch (responseCode) {
    case HttpStatus.SC_OK:
        break;/* ww  w.ja va  2  s  . c  om*/
    case HttpStatus.SC_BAD_REQUEST:
        throw new BadRequestException();
    case HttpStatus.SC_INTERNAL_SERVER_ERROR:
        throw new InternalServerErrorException();
    case HttpStatus.SC_FORBIDDEN:
        throw new ForbiddenException();
    default:
        throw new UnknownResponseException((new Integer(responseCode)).toString());
    }
}

From source file:es.carebear.rightmanagement.client.group.GetOwnRightsOnGroups.java

public String[] getRights(String userName, String authName) throws IOException, IllegalArgumentException,
        InternalServerErrorException, BadRequestException, UnauthorizedException, UnknownResponseException {
    PostMethod postMethod = new PostMethod(baseUri + "/client/groups/all/rights/" + authName);
    postMethod.addParameter("authName", authName);
    int responseCode = httpClient.executeMethod(postMethod);
    switch (responseCode) {
    case HttpStatus.SC_ACCEPTED:
        String response = XMLHelper.fromStreamToXML(postMethod.getResponseBodyAsStream());
        StringListContainer lc = XMLHelper.fromXML(response, StringListContainer.class);
        List<String> ls = new ArrayList<>();
        lc.getContainer().stream().forEach(obj -> {
            ls.add(obj);/*from   w  w w .java  2 s.  c  o m*/
        });
        return ls.toArray(new String[ls.size()]);
    case HttpStatus.SC_INTERNAL_SERVER_ERROR:
        throw new InternalServerErrorException();
    case HttpStatus.SC_UNAUTHORIZED:
        throw new UnauthorizedException();
    case HttpStatus.SC_BAD_REQUEST:
        throw new BadRequestException();
    default:
        throw new UnknownResponseException((new Integer(responseCode)).toString());
    }
}

From source file:es.carebear.rightmanagement.client.group.GrantGroupRight.java

public void GrantRight(String groupName, String targetName, String authName, String rightMask)
        throws IOException, UnauthorizedException, BadRequestException, UnknownResponseException,
        InternalServerErrorException {//from  w  w w.j  a va  2s. co m
    PostMethod postMethod = new PostMethod(baseUri + "/client/groups/grant/" + groupName + "/" + targetName);
    postMethod.addParameter("authName", authName);
    postMethod.addParameter("rightMask", rightMask);
    int responseCode = httpClient.executeMethod(postMethod);

    switch (responseCode) {
    case HttpStatus.SC_OK:
        break;
    case HttpStatus.SC_FORBIDDEN:
        throw new UnauthorizedException();
    case HttpStatus.SC_BAD_REQUEST:
        throw new BadRequestException();
    case HttpStatus.SC_INTERNAL_SERVER_ERROR:
        throw new InternalServerErrorException();
    default:
        throw new UnknownResponseException((new Integer(responseCode)).toString());
    }
}

From source file:edu.northwestern.bioinformatics.studycalendar.security.plugin.websso.direct.DirectLoginHttpFacade.java

/**
 * Select the specified credential provider.  This is the first step of the authentication
 * process./*from   ww w  . j av  a 2  s .co  m*/
 *
 * @return the page content so that the collaborating code can select an authentication service URL
 * @see LoginFormReader
 */
public String selectCredentialProvider(String credentialProvider) throws IOException {
    this.dorianName = credentialProvider;
    log.trace("POSTing to {} to obtain authentication service URLs for {}", getLoginUrl(), credentialProvider);

    PostMethod post = createLoginPostMethod();
    post.addParameter(EVENT_ID_PARAMETER, "selectDorian");
    post.addParameter(CREDENTIAL_PROVIDER_PARAMETER, this.dorianName);
    post.addParameter(LOGIN_TICKET_PARAMETER, this.lt);

    return doIntermediatePost(post);
}

From source file:es.carebear.rightmanagement.client.group.GetGroupListOfUser.java

public ArrayList<Group> getGroups(String authName, String userName) throws IOException, UnauthorizedException,
        BadRequestException, UnknownResponseException, ClassNotFoundException {
    PostMethod postMethod = new PostMethod(baseUri + "/client/groups/all/" + userName);
    postMethod.addParameter("authName", authName);
    int responseCode = httpClient.executeMethod(postMethod);

    switch (responseCode) {
    case HttpStatus.SC_ACCEPTED:
        String response = XMLHelper.fromStreamToXML(postMethod.getResponseBodyAsStream());

        StringListContainer lc = XMLHelper.fromXML(response, StringListContainer.class);
        List<Group> ls = new ArrayList<>();
        lc.getContainer().stream().forEach(obj -> {
            Gson gson = new Gson();
            ls.add(gson.fromJson(obj, Group.class));
        });/*from  w  ww  .  ja va 2s. c  o m*/
        return (ArrayList<Group>) ls;
    case HttpStatus.SC_FORBIDDEN:
        throw new UnauthorizedException();
    case HttpStatus.SC_BAD_REQUEST:
        throw new BadRequestException();
    default:
        throw new UnknownResponseException((new Integer(responseCode)).toString());
    }
}

From source file:es.carebear.rightmanagement.client.user.AddAllowedUserId.java

public void AddUser(String authName, String target, String rightMask) throws BadRequestException,
        InternalServerErrorException, IOException, UnknownResponseException, UnauthorizedException {
    PostMethod postMethod = new PostMethod(baseUri + "/client/users/change/allowed");
    postMethod.addParameter("authName", authName);
    postMethod.addParameter("target", target);
    postMethod.addParameter("rightMask", rightMask);
    int responseCode = httpClient.executeMethod(postMethod);

    switch (responseCode) {
    case HttpStatus.SC_OK:
        break;/*  w w w  . java  2 s. c om*/
    case HttpStatus.SC_BAD_REQUEST:
        throw new BadRequestException();
    case HttpStatus.SC_INTERNAL_SERVER_ERROR:
        throw new InternalServerErrorException();
    case HttpStatus.SC_UNAUTHORIZED:
        throw new UnauthorizedException();
    case HttpStatus.SC_FORBIDDEN:
        throw new ForbiddenException();
    default:
        throw new UnknownResponseException((new Integer(responseCode)).toString());
    }
}

From source file:com.thoughtworks.go.util.TimeReportingUtil.java

public void report() throws IOException {
    long difference = new Date().getTime() - begin.getTime();
    HttpClient httpClient = new HttpClient();
    HttpService.HttpClientFactory factory = new HttpService.HttpClientFactory(httpClient);
    PostMethod post = factory.createPost("http://host:3000/properties");
    post.addParameter("property[key]", key);
    post.addParameter("property[value]", String.valueOf(difference));
    try {//w w  w  .  ja  va 2  s .  c o  m
        httpClient.executeMethod(post);
    } finally {
        begin = null;
    }
    if (shouldThrowUp()) {
        if (post.getStatusCode() != HttpStatus.SC_OK) {
            throw new RuntimeException(
                    String.format("[Error] Posting [Key: %s] [Value: %s] failed.with status code %s", key,
                            difference, post.getStatusCode()));
        }
    }
}