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

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

Introduction

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

Prototype

int SC_ACCEPTED

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

Click Source Link

Document

<tt>202 Accepted</tt> (HTTP/1.0 - RFC 1945)

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 w w. j  a va2  s  .c  o  m*/
        });
        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 ww  . j  av  a2s .  c o m
        });
        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.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:/*from ww  w  .j a  va 2s.com*/
        throw new UnknownResponseException((new Integer(responseCode)).toString());
    }
}

From source file:gobblin.writer.objectstore.ObjectStoreDeleteOperation.java

/**
 * Calls {@link ObjectStoreClient#delete(String, Config)} for the object ot be deleted
 *
 * {@inheritDoc}/*  w w w .  j  a  va 2 s.c o  m*/
 * @see gobblin.writer.objectstore.ObjectStoreOperation#execute(gobblin.writer.objectstore.ObjectStoreClient)
 */
@Override
public DeleteResponse execute(ObjectStoreClient objectStoreClient) throws IOException {
    objectStoreClient.delete(this.objectId, this.deleteConfig);
    return new DeleteResponse(HttpStatus.SC_ACCEPTED);
}

From source file:com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult.java

public void accepted(Localizable message) {
    this.message = message;
    httpCode = HttpStatus.SC_ACCEPTED;
}

From source file:net.bryansaunders.jee6divelog.service.rest.RestApiTest.java

/**
 * Performs a Login Action and returns the Authorization Token.
 * /*w  w  w  . jav a 2s  .c  o m*/
 * @param userName
 *            User Name
 * @param password
 *            User Password
 * @return Authorization Token
 */
protected UserAccount doLogin(final String userName, final String password) {
    final Credentials credentials = new Credentials();
    credentials.setUsername(userName);
    credentials.setPassword(password);

    final UserAccount user = given().contentType(ContentType.JSON).body(credentials).expect()
            .statusCode(HttpStatus.SC_ACCEPTED).when().post(RestApiTest.URL_ROOT + "/security/login/")
            .as(UserAccount.class);

    assertNotNull(user);
    return user;
}

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

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

From source file:eu.eco2clouds.scheduler.bonfire.BFClientSchedulerImpl.java

private String putMethod(String url, String payload, Boolean exception) {
    // Create an instance of HttpClient.
    HttpClient client = getHttpClient();

    logger.debug("Connecting to: " + url);
    // Create a method instance.
    PutMethod method = new PutMethod(url);
    setHeaders(method);//from  www  .  j a va2  s .  c  o m

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));

    String response = "";

    try {
        RequestEntity entity = new StringRequestEntity(payload, SchedulerDictionary.CONTENT_TYPE_BONFIRE_XML,
                "UTF-8");
        method.setRequestEntity(entity);
        // Execute the method.
        int statusCode = client.executeMethod(method);

        if (statusCode != HttpStatus.SC_ACCEPTED) { //TODO test for this case... 
            logger.warn(
                    "get managed experiments information... : " + url + " failed: " + method.getStatusLine());
        } else {
            // Read the response body.
            byte[] responseBody = method.getResponseBody();
            response = new String(responseBody);
        }

    } catch (HttpException e) {
        logger.warn("Fatal protocol violation: " + e.getMessage());
        e.printStackTrace();
        exception = true;
    } catch (IOException e) {
        logger.warn("Fatal transport error: " + e.getMessage());
        e.printStackTrace();
        exception = true;
    } finally {
        // Release the connection.
        method.releaseConnection();
    }

    return response;
}

From source file:com.nokia.helium.diamonds.DiamondsSessionSocket.java

/**
 * Internal method to send data to diamonds.
 * If ignore result is true, then the method will return null, else the message return by the query
 * will be returned./*from  ww  w . j a v a2 s. co  m*/
 * @param message
 * @param ignoreResult
 * @return
 * @throws DiamondsException is thrown in case of message retrieval error, connection error. 
 */
protected synchronized String sendInternal(Message message, boolean ignoreResult) throws DiamondsException {
    URL destURL = url;
    if (buildId != null) {
        try {
            destURL = new URL(url.getProtocol(), url.getHost(), url.getPort(), buildId);
        } catch (MalformedURLException e) {
            throw new DiamondsException("Error generating the url to send the message: " + e.getMessage(), e);
        }
    }
    PostMethod post = new PostMethod(destURL.toExternalForm());
    try {
        File tempFile = streamToTempFile(message.getInputStream());
        tempFile.deleteOnExit();
        messages.add(tempFile);
        post.setRequestEntity(new FileRequestEntity(tempFile, "text/xml"));
    } catch (MessageCreationException e) {
        throw new DiamondsException("Error retrieving the message: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new DiamondsException("Error serializing the message into a temporary file: " + e.getMessage(),
                e);
    }
    try {
        int result = httpClient.executeMethod(post);
        if (result != HttpStatus.SC_OK && result != HttpStatus.SC_ACCEPTED) {
            throw new DiamondsException("Error sending the message: " + post.getStatusLine() + "("
                    + post.getResponseBodyAsString() + ")");
        }
        if (!ignoreResult) {
            return post.getResponseBodyAsString();
        }
    } catch (HttpException e) {
        throw new DiamondsException("Error sending the message: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new DiamondsException("Error sending the message: " + e.getMessage(), e);
    } finally {
        post.releaseConnection();
    }
    return null;
}

From source file:com.owncloud.android.utils.PushUtils.java

private static void deleteRegistrationForAccount(Account account) {
    Context context = MainApp.getAppContext();
    OwnCloudAccount ocAccount = null;//from  w  w  w .  j ava2 s .  co  m
    arbitraryDataProvider = new ArbitraryDataProvider(MainApp.getAppContext().getContentResolver());

    try {
        ocAccount = new OwnCloudAccount(account, context);
        OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount,
                context);

        RemoteOperation unregisterAccountDeviceForNotificationsOperation = new UnregisterAccountDeviceForNotificationsOperation();

        RemoteOperationResult remoteOperationResult = unregisterAccountDeviceForNotificationsOperation
                .execute(mClient);

        if (remoteOperationResult.getHttpCode() == HttpStatus.SC_ACCEPTED) {
            String arbitraryValue;
            if (!TextUtils.isEmpty(arbitraryValue = arbitraryDataProvider.getValue(account, KEY_PUSH))) {
                Gson gson = new Gson();
                PushConfigurationState pushArbitraryData = gson.fromJson(arbitraryValue,
                        PushConfigurationState.class);
                RemoteOperation unregisterAccountDeviceForProxyOperation = new UnregisterAccountDeviceForProxyOperation(
                        context.getResources().getString(R.string.push_server_url),
                        pushArbitraryData.getDeviceIdentifier(),
                        pushArbitraryData.getDeviceIdentifierSignature(), pushArbitraryData.getUserPublicKey());

                remoteOperationResult = unregisterAccountDeviceForProxyOperation.execute(mClient);

                if (remoteOperationResult.isSuccess()) {
                    arbitraryDataProvider.deleteKeyForAccount(account.name, KEY_PUSH);
                }
            }
        }

    } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
        Log_OC.d(TAG, "Failed to find an account");
    } catch (AuthenticatorException e) {
        Log_OC.d(TAG, "Failed via AuthenticatorException");
    } catch (IOException e) {
        Log_OC.d(TAG, "Failed via IOException");
    } catch (OperationCanceledException e) {
        Log_OC.d(TAG, "Failed via OperationCanceledException");
    }
}