Example usage for org.apache.commons.httpclient HttpStatus SC_CREATED

List of usage examples for org.apache.commons.httpclient HttpStatus SC_CREATED

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpStatus SC_CREATED.

Prototype

int SC_CREATED

To view the source code for org.apache.commons.httpclient HttpStatus SC_CREATED.

Click Source Link

Document

<tt>201 Created</tt> (HTTP/1.0 - RFC 1945)

Usage

From source file:alluxio.util.network.HttpUtils.java

/**
 * Uses the post method to send a url with arguments by http, this method can call RESTful Api.
 *
 * @param url the http url/*from   ww w  .  ja  va  2s.co m*/
 * @param timeout milliseconds to wait for the server to respond before giving up
 * @param processInputStream the response body stream processor
 */
public static void post(String url, Integer timeout, IProcessInputStream processInputStream)
        throws IOException {
    Preconditions.checkNotNull(timeout, "timeout");
    Preconditions.checkNotNull(processInputStream, "processInputStream");
    PostMethod postMethod = new PostMethod(url);
    try {
        HttpClient httpClient = new HttpClient();
        httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(timeout);
        httpClient.getHttpConnectionManager().getParams().setSoTimeout(timeout);
        int statusCode = httpClient.executeMethod(postMethod);
        if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED) {
            InputStream inputStream = postMethod.getResponseBodyAsStream();
            processInputStream.process(inputStream);
        } else {
            throw new IOException("Failed to perform POST request. Status code: " + statusCode);
        }
    } finally {
        postMethod.releaseConnection();
    }
}

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

public User register(String username, String password) throws BadRequestException, InternalServerErrorException,
        IOException, UnauthorizedException, UnknownResponseException {
    PostMethod postMethod = new PostMethod(baseUri + "/client/users/register/" + username);
    postMethod.addParameter("password", password);
    int responseCode = httpClient.executeMethod(postMethod);

    switch (responseCode) {
    case HttpStatus.SC_CREATED:
        String response = postMethod.getResponseBodyAsString();
        return XMLHelper.fromXML(response, User.class);
    case HttpStatus.SC_BAD_REQUEST:
        throw new BadRequestException();
    case HttpStatus.SC_INTERNAL_SERVER_ERROR:
        throw new InternalServerErrorException();
    default:/*w  w w  . j a  v  a 2 s.c o m*/
        throw new UnknownResponseException((new Integer(responseCode)).toString());
    }
}

From source file:com.bbva.arq.devops.ae.mirrorgate.jenkins.plugin.service.DefaultMirrorGateService.java

@Override
public MirrorGateResponse publishBuildData(BuildDTO request) {
    try {/*ww  w. j av  a2  s  . c om*/
        MirrorGateResponse callResponse = buildRestCall().makeRestCallPost(
                MirrorGateUtils.getMirrorGateAPIUrl() + "/api/builds",
                MirrorGateUtils.convertObjectToJson(request), MirrorGateUtils.getMirrorGateUser(),
                MirrorGateUtils.getMirrorGatePassword());

        if (callResponse.getResponseCode() != HttpStatus.SC_CREATED) {
            LOG.log(Level.SEVERE, "MirrorGate: Build Publisher post may have failed. Response: {0}",
                    callResponse.getResponseCode());
        }
        return callResponse;
    } catch (IOException e) {
        LOG.log(Level.SEVERE, "MirrorGate: Error posting to mirrorGate", e);
        return new MirrorGateResponse(HttpStatus.SC_CONFLICT, "");
    }
}

From source file:net.sf.sail.webapp.dao.sds.impl.SdsCurnitUpdateCommandHttpRestImpl.java

/**
 * @see net.sf.sail.webapp.dao.sds.SdsCommand#generateRequest()
 *//*  w w  w.j  av  a2 s  . com*/
public HttpPutRequest generateRequest() {
    final SdsCurnit sdsCurnit = this.getSdsCurnit();
    final String bodyData = "<curnit><name>" + sdsCurnit.getName() + "</name><url>" + sdsCurnit.getUrl()
            + "</url></curnit>";
    final String url = "/curnit/" + sdsCurnit.getSdsObjectId().toString();
    return new HttpPutRequest(REQUEST_HEADERS_CONTENT, bodyData, url, HttpStatus.SC_CREATED);
}

From source file:net.sf.sail.webapp.dao.sds.impl.SdsJnlpUpdateCommandHttpRestImpl.java

/**
 * @see net.sf.sail.webapp.dao.sds.SdsCommand#generateRequest()
 *//*from  ww  w.  ja va  2  s .  c om*/
@SuppressWarnings("unchecked")
public HttpPutRequest generateRequest() {
    final SdsJnlp sdsJnlp = this.getSdsJnlp();
    final String bodyData = "<jnlp><name>" + sdsJnlp.getName() + "</name><url>" + sdsJnlp.getUrl()
            + "</url></jnlp>";
    final String url = "/jnlp/" + sdsJnlp.getSdsObjectId();
    return new HttpPutRequest(REQUEST_HEADERS_CONTENT, bodyData, url, HttpStatus.SC_CREATED);
}

From source file:net.sf.sail.webapp.dao.sds.impl.SdsJnlpCreateCommandHttpRestImpl.java

/**
 * @see net.sf.sail.webapp.dao.sds.SdsCommand#generateRequest()
 *//*from www.  java 2  s  . c  o  m*/
@SuppressWarnings("unchecked")
public HttpPostRequest generateRequest() {
    final SdsJnlp sdsJnlp = this.getSdsJnlp();
    final String bodyData = "<jnlp><name>" + sdsJnlp.getName() + "</name><url>" + sdsJnlp.getUrl()
            + "</url></jnlp>";
    final String url = "/jnlp";
    return new HttpPostRequest(REQUEST_HEADERS_CONTENT, EMPTY_STRING_MAP, bodyData, url, HttpStatus.SC_CREATED);
}

From source file:net.sf.sail.webapp.dao.sds.impl.SdsUserCreateCommandHttpRestImpl.java

/**
 * @see net.sf.sail.webapp.dao.sds.SdsCommand#generateRequest()
 *///from   w  ww .j  av a  2 s . co m
public HttpPostRequest generateRequest() {
    final SdsUser sdsUser = this.getSdsUser();
    final String bodyData = "<user><first-name>" + sdsUser.getFirstName() + "</first-name><last-name>"
            + sdsUser.getLastName() + "</last-name></user>";

    final String url = "/sail_user";

    return new HttpPostRequest(REQUEST_HEADERS_CONTENT, EMPTY_STRING_MAP, bodyData, url, HttpStatus.SC_CREATED);
}

From source file:net.sf.sail.webapp.dao.sds.impl.SdsUserUpdateCommandHttpRestImpl.java

/**
 * @see net.sf.sail.webapp.dao.sds.SdsCommand#generateRequest()
 *//*from w w w  . j ava2  s .c  om*/
public HttpPutRequest generateRequest() {
    final SdsUser sdsUser = this.getSdsUser();
    final String bodyData = "<user><first-name>" + sdsUser.getFirstName() + "</first-name><last-name>"
            + sdsUser.getLastName() + "</last-name></user>";

    final String url = "/sail_user/" + sdsUser.getSdsObjectId();

    return new HttpPutRequest(REQUEST_HEADERS_CONTENT, bodyData, url, HttpStatus.SC_CREATED);
}

From source file:net.sf.sail.webapp.dao.sds.impl.SdsCurnitCreateCommandHttpRestImpl.java

/**
 * @see net.sf.sail.webapp.dao.sds.SdsCommand#generateRequest()
 *//*from  ww w .  j a  va 2  s  .c om*/
public HttpPostRequest generateRequest() {
    final SdsCurnit sdsCurnit = this.getSdsCurnit();
    final String bodyData = "<curnit><name>" + sdsCurnit.getName() + "</name><url>" + sdsCurnit.getUrl()
            + "</url></curnit>";
    final String url = "/curnit";
    return new HttpPostRequest(REQUEST_HEADERS_CONTENT, EMPTY_STRING_MAP, bodyData, url, HttpStatus.SC_CREATED);
}

From source file:net.sf.sail.webapp.dao.sds.impl.SdsOfferingUpdateCommandHttpRestImpl.java

/**
 * @see net.sf.sail.webapp.dao.sds.SdsCommand#generateRequest()
 *///from  w w  w.j a  v  a  2 s.com
@SuppressWarnings("unchecked")
public HttpPutRequest generateRequest() {
    final SdsOffering sdsOffering = this.getSdsOffering();
    final String bodyData = "<offering><name>" + sdsOffering.getName() + "</name><curnit-id>"
            + sdsOffering.getSdsCurnit().getSdsObjectId() + "</curnit-id><jnlp-id>"
            + sdsOffering.getSdsJnlp().getSdsObjectId() + "</jnlp-id></offering>";
    final String url = "/offering/" + sdsOffering.getSdsObjectId();
    return new HttpPutRequest(REQUEST_HEADERS_CONTENT, bodyData, url, HttpStatus.SC_CREATED);
}