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

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

Introduction

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

Prototype

public PostMethod(String paramString) 

Source Link

Usage

From source file:es.carebear.rightmanagement.client.admin.GetAllUsers.java

public User[] getAll(String authName) throws IOException, IllegalArgumentException,
        InternalServerErrorException, BadRequestException, UnauthorizedException, UnknownResponseException {
    PostMethod postMethod = new PostMethod(baseUri + "/client/users/all");
    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<User> ls = new ArrayList<>();
        lc.getContainer().stream().forEach(obj -> {
            Gson gson = new Gson();
            ls.add(gson.fromJson(obj, User.class));
        });/*from  w  w  w .  j a  v  a2s.c o m*/
        return ls.toArray(new User[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:com.sun.syndication.propono.atom.client.GDataAuthStrategy.java

private void init() throws ProponoException {
    try {/* w w  w  .j a  va  2s  . c o m*/
        HttpClient httpClient = new HttpClient();
        PostMethod method = new PostMethod("https://www.google.com/accounts/ClientLogin");
        NameValuePair[] data = { new NameValuePair("Email", email), new NameValuePair("Passwd", password),
                new NameValuePair("accountType", "GOOGLE"), new NameValuePair("service", service),
                new NameValuePair("source", "ROME Propono Atompub Client") };
        method.setRequestBody(data);
        httpClient.executeMethod(method);

        String responseBody = method.getResponseBodyAsString();
        int authIndex = responseBody.indexOf("Auth=");

        authToken = "GoogleLogin auth=" + responseBody.trim().substring(authIndex + 5);

    } catch (Throwable t) {
        t.printStackTrace();
        throw new ProponoException("ERROR obtaining Google authentication string", t);
    }
}

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

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

    switch (responseCode) {
    case HttpStatus.SC_ACCEPTED:
        String response = XMLHelper.fromStreamToXML(postMethod.getResponseBodyAsStream());
        AttributeContainer lc = XMLHelper.fromXML(response, AttributeContainer.class);
        return lc.toArray();
    case HttpStatus.SC_BAD_REQUEST:
        throw new BadRequestException();
    case HttpStatus.SC_UNAUTHORIZED:
        throw new UnauthorizedException();
    default:/*ww w.  j ava2s. c o  m*/
        throw new UnknownResponseException((new Integer(responseCode)).toString());
    }
}

From source file:com.intellij.internal.statistic.connect.StatisticsHttpClientSender.java

@Override
public void send(@NotNull String url, @NotNull String content) throws StatServiceException {
    PostMethod post = null;//from   ww  w  .  ja  v  a  2 s .  c  o  m

    try {
        //HttpConfigurable.getInstance().prepareURL(url);

        HttpClient httpclient = new HttpClient();
        post = new PostMethod(url);

        post.setRequestBody(
                new NameValuePair[] { new NameValuePair("content", content), new NameValuePair("uuid",
                        UpdateChecker.getInstallationUID(PropertiesComponent.getInstance())) });

        httpclient.executeMethod(post);

        if (post.getStatusCode() != HttpStatus.SC_OK) {
            throw new StatServiceException("Error during data sending... Code: " + post.getStatusCode());
        }

        final Header errors = post.getResponseHeader("errors");
        if (errors != null) {
            final String value = errors.getValue();

            throw new StatServiceException("Error during updating statistics "
                    + (!StringUtil.isEmptyOrSpaces(value) ? " : " + value : ""));
        }
    } catch (StatServiceException e) {
        throw e;
    } catch (Exception e) {
        throw new StatServiceException("Error during data sending...", e);
    } finally {
        if (post != null) {
            post.releaseConnection();
        }
    }
}

From source file:es.carebear.rightmanagement.client.admin.GetAllGroups.java

public Group[] getAll(String authName) throws IOException, IllegalArgumentException,
        InternalServerErrorException, BadRequestException, UnauthorizedException, UnknownResponseException {
    PostMethod postMethod = new PostMethod(baseUri + "/client/groups/all");
    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));
        });//w w w .  j  a  va  2  s  . c  om
        return ls.toArray(new Group[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:com.rometools.propono.atom.client.GDataAuthStrategy.java

private void init() throws ProponoException {
    try {// w ww  .  ja  v a2s. c o m
        final HttpClient httpClient = new HttpClient();
        final PostMethod method = new PostMethod("https://www.google.com/accounts/ClientLogin");
        final NameValuePair[] data = { new NameValuePair("Email", email), new NameValuePair("Passwd", password),
                new NameValuePair("accountType", "GOOGLE"), new NameValuePair("service", service),
                new NameValuePair("source", "ROME Propono Atompub Client") };
        method.setRequestBody(data);
        httpClient.executeMethod(method);

        final String responseBody = method.getResponseBodyAsString();
        final int authIndex = responseBody.indexOf("Auth=");

        authToken = "GoogleLogin auth=" + responseBody.trim().substring(authIndex + 5);

    } catch (final Throwable t) {
        t.printStackTrace();
        throw new ProponoException("ERROR obtaining Google authentication string", t);
    }
}

From source file:jsst.core.client.dispatcher.impl.HTTPDispatcher.java

@Override
public HTTPServerResponse dispatch(Method method) throws DispatcherException {
    HttpClient httpClient = new HttpClient();
    PostMethod postMethod = new PostMethod(url);
    postMethod.setParameter(REQUEST_PARAM_CLASS_NAME, method.getDeclaringClass().getCanonicalName());
    postMethod.setParameter(REQUEST_PARAM_METHOD_NAME, method.getName());
    try {/*ww w .j a v  a 2s.  c o m*/
        try {
            httpClient.executeMethod(postMethod);
        } catch (ConnectException ex) {
            throw new DispatcherException("Failed to connect to \"" + url + "\". Seems like server is down");
        }
        return new HTTPServerResponse(url, postMethod.getResponseBodyAsString(), postMethod.getStatusCode());
    } catch (IOException e) {
        throw new DispatcherException("Exception caught while sending request to \"" + url + "\"", e);
    } finally {
        postMethod.releaseConnection();
    }
}

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  ww  . j a va  2  s  . c om*/
        });
        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:com.alibaba.stonelab.toolkit.misc.Misc.java

public static void main(String[] args) throws Exception {
    PostMethod post = new PostMethod(URL_BOOK);
    post.addParameter("__VIEWSTATE", PARAM_VIEWSTATE);
    post.addParameter("__EVENTVALIDATION", PARAM_EVENTVALIDATION);
    post.addParameter("ctl00%24ContentPlaceHolder1%24tb_bookdate", "2010-08-12");
    post.addParameter("ctl00%24ContentPlaceHolder1%24DropDownList1", "10");
    post.addParameter("ctl00%24ContentPlaceHolder1%24DropDownList2", "00");
    post.addParameter("ctl00%24ContentPlaceHolder1%24DropDownList3", "21");
    post.addParameter("ctl00%24ContentPlaceHolder1%24DropDownList4", "00");
    post.addParameter("ctl00%24ContentPlaceHolder1%24rbl_ProjectorSelect", "");
    post.addParameter("ctl00%24ContentPlaceHolder1%24tb_comments", "");
    post.addParameter("ctl00%24ContentPlaceHolder1%24btn_booking", "");
    httpClient.executeMethod(post);//from w  ww.j a  v  a  2 s .com
    System.out.println(post.getResponseBodyAsString());
    post.releaseConnection();
}

From source file:com.zimbra.qa.unittest.TestSoapFault.java

@Test
public void testSoapFaultTraceIpReveal() throws Exception {
    String batchRequestUrl = TestUtil.getSoapUrl() + "BatchRequest";
    String createAppointmentRequestUrl = TestUtil.getSoapUrl() + "createAppointmentRequest";
    String modifyContactRequestUrl = TestUtil.getSoapUrl() + "ModifyContactRequest";
    String noOpRequestUrl = TestUtil.getSoapUrl() + "NoOpRequest";
    String getMiniCalRequestUrl = TestUtil.getSoapUrl() + "GetMiniCalRequest";

    PostMethod batchRequestMethod = new PostMethod(batchRequestUrl);
    HttpClientUtil.executeMethod(batchRequestMethod);
    String response = batchRequestMethod.getResponseBodyAsString();
    Assert.assertFalse("Trace contains ip address.", response.contains(batchRequestUrl));

    PostMethod createAppointmentRequestMethod = new PostMethod(createAppointmentRequestUrl);
    HttpClientUtil.executeMethod(createAppointmentRequestMethod);
    response = createAppointmentRequestMethod.getResponseBodyAsString();
    Assert.assertFalse("Trace contains ip address.", response.contains(createAppointmentRequestUrl));

    PostMethod modifyContactRequestMethod = new PostMethod(modifyContactRequestUrl);
    HttpClientUtil.executeMethod(modifyContactRequestMethod);
    response = modifyContactRequestMethod.getResponseBodyAsString();
    Assert.assertFalse("Trace contains ip address.", response.contains(modifyContactRequestUrl));

    PostMethod noOpRequestMethod = new PostMethod(noOpRequestUrl);
    HttpClientUtil.executeMethod(noOpRequestMethod);
    response = noOpRequestMethod.getResponseBodyAsString();
    Assert.assertFalse("Trace contains ip address.", response.contains(noOpRequestUrl));

    PostMethod getMiniCalRequestMethod = new PostMethod(getMiniCalRequestUrl);
    HttpClientUtil.executeMethod(getMiniCalRequestMethod);
    response = getMiniCalRequestMethod.getResponseBodyAsString();
    Assert.assertFalse("Trace contains ip address.", response.contains(getMiniCalRequestUrl));
}