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:com.owncloud.android.operations.CommentFileOperation.java

private boolean isSuccess(int status) {
    return status == HttpStatus.SC_CREATED;
}

From source file:com.kagilum.plugins.icescrum.IceScrumSession.java

public boolean sendBuildStatut(JSONObject build) throws UnsupportedEncodingException {
    PostMethod method = new PostMethod(settings.getUrl() + "/ws/p/" + settings.getPkey() + "/build");
    StringRequestEntity requestEntity = new StringRequestEntity(build.toString(), "application/json", "UTF-8");
    method.setRequestEntity(requestEntity);
    return executeMethod(method, HttpStatus.SC_CREATED);
}

From source file:com.bbva.arq.devops.ae.mirrorgate.jenkins.plugin.listener.MirrorGateListenerHelper.java

private void sendBuildExtraData(BuildBuilder builder, TaskListener listener) {
    List<String> extraUrl = MirrorGateUtils.getURLList();

    extraUrl.forEach(u -> {/*from ww w  .j  a  v a  2  s .  c  o  m*/
        MirrorGateResponse response = getMirrorGateService()
                .sendBuildDataToExtraEndpoints(builder.getBuildData(), u);

        String msg = "POST to " + u + " succeeded!";
        Level level = Level.FINE;
        if (response.getResponseCode() != HttpStatus.SC_CREATED) {
            msg = "POST to " + u + " failed with code: " + response.getResponseCode();
            level = Level.WARNING;
        }

        if (listener != null && level == Level.FINE) {
            listener.getLogger().println(msg);
        }
        LOG.log(level, msg);
    });
}

From source file:ke.go.moh.oec.adt.Daemon.java

private static boolean sendMessage(String url, String filename) {
    int returnStatus = HttpStatus.SC_CREATED;
    HttpClient httpclient = new HttpClient();
    HttpConnectionManager connectionManager = httpclient.getHttpConnectionManager();
    connectionManager.getParams().setSoTimeout(120000);

    PostMethod httpPost = new PostMethod(url);

    RequestEntity requestEntity;// w  w  w .ja v a  2s .co m
    try {
        FileInputStream message = new FileInputStream(filename);
        Base64InputStream message64 = new Base64InputStream(message, true, -1, null);
        requestEntity = new InputStreamRequestEntity(message64, "application/octet-stream");
    } catch (FileNotFoundException e) {
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "File not found.", e);
        return false;
    }
    httpPost.setRequestEntity(requestEntity);
    try {
        httpclient.executeMethod(httpPost);
        returnStatus = httpPost.getStatusCode();
    } catch (SocketTimeoutException e) {
        returnStatus = HttpStatus.SC_REQUEST_TIMEOUT;
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "Request timed out.  Not retrying.", e);
    } catch (HttpException e) {
        returnStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "HTTP exception.  Not retrying.", e);
    } catch (ConnectException e) {
        returnStatus = HttpStatus.SC_SERVICE_UNAVAILABLE;
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "Service unavailable.  Not retrying.", e);
    } catch (UnknownHostException e) {
        returnStatus = HttpStatus.SC_NOT_FOUND;
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "Not found.  Not retrying.", e);
    } catch (IOException e) {
        returnStatus = HttpStatus.SC_GATEWAY_TIMEOUT;
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "IO exception.  Not retrying.", e);
    } finally {
        httpPost.releaseConnection();
    }
    return returnStatus == HttpStatus.SC_OK;
}

From source file:com.cerema.cloud2.lib.resources.files.UploadRemoteFileOperation.java

public boolean isSuccess(int status) {
    return ((status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED
            || status == HttpStatus.SC_NO_CONTENT));
}

From source file:fedora.test.integration.TestLargeDatastreams.java

private String upload() throws Exception {
    String url = fedoraClient.getUploadURL();
    EntityEnclosingMethod httpMethod = new PostMethod(url);
    httpMethod.setDoAuthentication(true);
    httpMethod.getParams().setParameter("Connection", "Keep-Alive");
    httpMethod.setContentChunked(true);/*from   w  ww .j a va 2s . c o m*/
    Part[] parts = { new FilePart("file", new SizedPartSource()) };
    httpMethod.setRequestEntity(new MultipartRequestEntity(parts, httpMethod.getParams()));
    HttpClient client = fedoraClient.getHttpClient();
    try {

        int status = client.executeMethod(httpMethod);
        String response = new String(httpMethod.getResponseBody());

        if (status != HttpStatus.SC_CREATED) {
            throw new IOException("Upload failed: " + HttpStatus.getStatusText(status) + ": "
                    + replaceNewlines(response, " "));
        } else {
            response = response.replaceAll("\r", "").replaceAll("\n", "");
            return response;
        }
    } finally {
        httpMethod.releaseConnection();
    }
}

From source file:com.serena.rlc.provider.jenkins.client.JenkinsClient.java

/**
 * Send a POST and returns the Location header which contains the url to the queued item
 *
 * @param jenkinsUrl//from   www .  java2s  . com
 * @param postPath
 * @param postData
 * @return Response body
 * @throws JenkinsClientException
 */
public String processBuildPost(String jenkinsUrl, String postPath, String postData)
        throws JenkinsClientException {
    String uri = createUrl(jenkinsUrl, postPath);

    logger.debug("Start executing Jenkins POST request to url=\"{}\" with payload={}", uri);

    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpPost postRequest = new HttpPost(uri);

    if (getJenkinsUsername() != null && !StringUtils.isEmpty(getJenkinsUsername())) {
        UsernamePasswordCredentials creds = new UsernamePasswordCredentials(getJenkinsUsername(),
                getJenkinsPassword());
        postRequest.addHeader(BasicScheme.authenticate(creds, "US-ASCII", false));
    }

    postRequest.addHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
    postRequest.addHeader(HttpHeaders.ACCEPT, "application/json");
    String result = "";

    List<NameValuePair> params = new ArrayList<>();
    params.add(new BasicNameValuePair("json", postData));

    try {

        postRequest.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

        HttpResponse response = httpClient.execute(postRequest);
        if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK
                && response.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED) {
            throw createHttpError(response);
        }

        result = response.getFirstHeader("Location").getValue();

        logger.debug("End executing Jenkins POST request to url=\"{}\" and receive this result={}", uri,
                result);

    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        throw new JenkinsClientException("Server not available", e);
    } finally {
        httpClient.getConnectionManager().shutdown();
    }

    return result;
}

From source file:com.tribune.uiautomation.testscripts.Photo.java

public boolean create() throws JSONException {
    checkValidStateForCreate();//ww  w.  j ava2s  .  c  o m

    PostMethod post = new PostMethod(constructCreateUrl());

    try {
        setRequestHeaders(post);
        setParameters(post);

        HttpClient client = new HttpClient();
        int status = client.executeMethod(post);

        log.debug("Photo Service create return status: " + post.getStatusLine());
        if (status == HttpStatus.SC_CREATED) {
            processResponse(this, post.getResponseBodyAsStream());
            persisted = true;
            return true;
        }
    } catch (HttpException e) {
        log.fatal("Fatal protocol violation: " + e.getMessage(), e);
    } catch (IOException e) {
        log.fatal("Fatal transport error: " + e.getMessage(), e);
    } finally {
        // Release the connection.
        post.releaseConnection();
    }

    return false;
}

From source file:com.unicauca.braim.http.HttpBraimClient.java

public Session POST_Session(String user_id, String access_token) throws IOException {
    Session session = null;//from   w ww . jav  a 2s . c o m
    Gson gson = new Gson();

    String data = "?session[user_id]=" + user_id;
    String token_data = "&braim_token=" + access_token;

    PostMethod method = new PostMethod(api_url + "/api/v1/sessions");
    method.addParameter("session[user_id]", user_id);
    method.addParameter("braim_token", access_token);
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));

    int statusCode = client.executeMethod(method);
    if (statusCode != HttpStatus.SC_CREATED) {
        System.err.println("Method failed: " + method.getStatusLine());
        throw new IOException("The session was not being created");
    }

    byte[] responseBody = method.getResponseBody();
    String response = new String(responseBody, "UTF-8");
    session = gson.fromJson(response, Session.class);
    System.out.println("new session of" + session.getUser_id() + "was created");

    return session;
}

From source file:com.owncloud.android.lib.resources.notifications.RegisterAccountDeviceForNotificationsOperation.java

private boolean isSuccess(int status) {
    return (status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED);
}