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

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

Introduction

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

Prototype

int SC_BAD_REQUEST

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

Click Source Link

Document

<tt>400 Bad Request</tt> (HTTP/1.1 - RFC 2616)

Usage

From source file:org.apache.axis2.transport.http.impl.httpclient3.HTTPSenderImpl.java

/**
 * Used to handle the HTTP Response/*from  w  ww  .j av  a 2  s  . c  o m*/
 * 
 * @param msgContext
 *            - The MessageContext of the message
 * @param method
 *            - The HTTP method used
 * @throws IOException
 *             - Thrown in case an exception occurs
 */
protected void handleResponse(MessageContext msgContext, Object httpMethodBase) throws IOException {
    HttpMethodBase method;
    if (httpMethodBase instanceof HttpMethodBase) {
        method = (HttpMethodBase) httpMethodBase;
    } else {
        log.trace("HttpMethodBase expected, but found - " + httpMethodBase);
        return;
    }
    int statusCode = method.getStatusCode();
    HTTPStatusCodeFamily family = getHTTPStatusCodeFamily(statusCode);
    log.trace("Handling response - " + statusCode);
    if (statusCode == HttpStatus.SC_ACCEPTED) {
        /* When an HTTP 202 Accepted code has been received, this will be the case of an execution 
         * of an in-only operation. In such a scenario, the HTTP response headers should be returned,
         * i.e. session cookies. */
        obtainHTTPHeaderInformation(method, msgContext);
        // Since we don't expect any content with a 202 response, we must release the connection
        method.releaseConnection();
    } else if (HTTPStatusCodeFamily.SUCCESSFUL.equals(family)) {
        // Save the HttpMethod so that we can release the connection when cleaning up
        msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
        processResponse(method, msgContext);
    } else if (statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR || statusCode == HttpStatus.SC_BAD_REQUEST) {
        // Save the HttpMethod so that we can release the connection when
        // cleaning up
        msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
        Header contenttypeHeader = method.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
        String value = null;
        if (contenttypeHeader != null) {
            value = contenttypeHeader.getValue();
        }
        OperationContext opContext = msgContext.getOperationContext();
        if (opContext != null) {
            MessageContext inMessageContext = opContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
            if (inMessageContext != null) {
                inMessageContext.setProcessingFault(true);
            }
        }
        if (value != null) {

            processResponse(method, msgContext);
        }

        if (org.apache.axis2.util.Utils.isClientThreadNonBlockingPropertySet(msgContext)) {
            throw new AxisFault(
                    Messages.getMessage("transportError", String.valueOf(statusCode), method.getStatusText()));
        }
    } else {
        // Since we don't process the response, we must release the
        // connection immediately
        method.releaseConnection();
        throw new AxisFault(
                Messages.getMessage("transportError", String.valueOf(statusCode), method.getStatusText()));
    }
}

From source file:org.apache.cocoon.components.source.impl.WebDAVSource.java

/**
 * Initialize the SWCL WebdavResource./*w  w  w . j  a v  a 2 s  .c om*/
 * <p>
 * The action argument specifies a set of properties to load during initialization.
 * Its value is one of WebdavResource.NOACTION, WebdavResource.NAME,
 * WebdavResource.BASIC, WebdavResource.DEFAULT, WebdavResource.ALL.
 * Similarly the depth argument specifies the depth header of the PROPFIND
 * method that is executed upon initialization.
 * </p>
 * <p>
 * The different methods of this Source implementation call this method to
 * initialize the resource using their minimal action and depth requirements.
 * For instance the WebDAVSource.getMimeType() method requires WebdavResource.BASIC
 * properties and a search depth of 0 is sufficient.
 * </p>
 * <p>
 * However it may be that a later call (eg. WebDAVSource.getChildren()) requires more
 * information. In that case the WebdavResource would have to make another call to the Server.
 * It would be more efficient if previous initialization had been done using depth 1 instead.
 * In order give the user more control over this the WebDAVSource can be passed a minimal
 * action and depth using cocoon:webdav-depth and cocoon:webdav-action query string parameters.
 * By default the mimimum action is WebdavResource.BASIC (which loads all the following basic
 * webdav properties: DAV:displayname, DAV:getcontentlength, DAV:getcontenttype DAV:resourcetype,
 * DAV:getlastmodified and DAV:lockdiscovery). The default minimum depth is 1.
 * </p>
 *
 * @param action  the set of propterties the WebdavResource should load.
 * @param depth  the webdav depth.
 * @throws SourceException
 * @throws SourceNotFoundException
 */
private void initResource(int action, int depth) throws SourceException, SourceNotFoundException {
    try {
        boolean update = false;
        if (action != WebdavResource.NOACTION) {
            if (action > this.action) {
                this.action = action;
                update = true;
            } else {
                action = this.action;
            }
        }
        if (depth > this.depth) {
            this.depth = depth;
            update = true;
        } else {
            depth = this.depth;
        }
        if (this.resource == null) {
            this.resource = new WebdavResource(this.url, action, depth);
        } else if (update) {
            this.resource.setProperties(action, depth);
        }
        if (this.action > WebdavResource.NOACTION) {
            if (this.resource.isCollection()) {
                String path = this.url.getPath();
                if (path.charAt(path.length() - 1) != '/') {
                    this.url.setPath(path + "/");
                }
            }
        }
    } catch (HttpException e) {
        if (e.getReasonCode() == HttpStatus.SC_NOT_FOUND) {
            throw new SourceNotFoundException("Not found: " + getSecureURI(), e);
        }
        if (e.getReasonCode() == HttpStatus.SC_BAD_REQUEST) {
            throw new SourceException("Server doesn't appear to understand WebDAV: " + getSecureURI(), e);
        }
        final String msg = "Could not initialize webdav resource at " + getSecureURI() + ". Server responded "
                + e.getReasonCode() + " (" + e.getReason() + ") - " + e.getMessage();
        throw new SourceException(msg, e);
    } catch (IOException e) {
        throw new SourceException("Could not initialize webdav resource", e);
    }
}

From source file:org.apache.falcon.regression.AuthorizationTest.java

/**
 * U2Delete test cases.//from   w w  w.jav a 2s .co m
 */
//disabled since, falcon does not have authorization https://issues.apache
// .org/jira/browse/FALCON-388
@Test(enabled = false)
public void u1SubmitU2DeleteCluster() throws Exception {
    bundles[0].submitClusters(prism);
    final ServiceResponse serviceResponse = prism.getClusterHelper().delete(bundles[0].getClusters().get(0),
            MerlinConstants.USER2_NAME);
    AssertUtil.assertFailedWithStatus(serviceResponse, HttpStatus.SC_BAD_REQUEST,
            "Entity submitted by first user should not be deletable by second user");
}

From source file:org.apache.falcon.regression.AuthorizationTest.java

@Test(enabled = false)
public void u1SubmitU2DeleteProcess() throws Exception {
    bundles[0].submitClusters(prism);//from   w  ww. j ava2s.c  o m
    bundles[0].submitProcess(true);
    final ServiceResponse serviceResponse = prism.getProcessHelper().delete(bundles[0].getProcessData(),
            MerlinConstants.USER2_NAME);
    AssertUtil.assertFailedWithStatus(serviceResponse, HttpStatus.SC_BAD_REQUEST,
            "Entity submitted by first user should not be deletable by second user");
}

From source file:org.apache.falcon.regression.AuthorizationTest.java

@Test(enabled = false)
public void u1SubmitU2DeleteFeed() throws Exception {
    bundles[0].submitClusters(prism);/*  w  w w .j  a  v a  2  s .  com*/
    bundles[0].submitFeed();
    final ServiceResponse serviceResponse = prism.getFeedHelper().delete(bundles[0].getDataSets().get(0),
            MerlinConstants.USER2_NAME);
    AssertUtil.assertFailedWithStatus(serviceResponse, HttpStatus.SC_BAD_REQUEST,
            "Entity submitted by first user should not be deletable by second user");
}

From source file:org.apache.falcon.regression.AuthorizationTest.java

@Test(enabled = false)
public void u1ScheduleU2DeleteProcess() throws Exception {
    //submit, schedule process by U1
    bundles[0].submitFeedsScheduleProcess(prism);
    AssertUtil.checkStatus(clusterOC, EntityType.PROCESS, bundles[0].getProcessData(), Job.Status.RUNNING);
    //try to delete process by U2
    final ServiceResponse serviceResponse = prism.getProcessHelper().delete(bundles[0].getProcessData(),
            MerlinConstants.USER2_NAME);
    AssertUtil.assertFailedWithStatus(serviceResponse, HttpStatus.SC_BAD_REQUEST,
            "Process scheduled by first user should not be deleted by second user");
}

From source file:org.apache.falcon.regression.AuthorizationTest.java

@Test(enabled = false)
public void u1ScheduleU2DeleteFeed() throws Exception {
    String feed = bundles[0].getInputFeedFromBundle();
    //submit, schedule feed by U1
    bundles[0].submitClusters(prism);//from   ww  w .java2s.co  m
    AssertUtil.assertSucceeded(prism.getFeedHelper().submitAndSchedule(feed));
    AssertUtil.checkStatus(clusterOC, EntityType.FEED, feed, Job.Status.RUNNING);
    //delete feed by U2
    final ServiceResponse serviceResponse = prism.getFeedHelper().delete(feed, MerlinConstants.USER2_NAME);
    AssertUtil.assertFailedWithStatus(serviceResponse, HttpStatus.SC_BAD_REQUEST,
            "Feed scheduled by first user should not be deleted by second user");
}

From source file:org.apache.falcon.regression.AuthorizationTest.java

@Test(enabled = false)
public void u1SuspendU2DeleteProcess() throws Exception {
    //submit, schedule, suspend process by U1
    bundles[0].submitFeedsScheduleProcess(prism);
    AssertUtil.checkStatus(clusterOC, EntityType.PROCESS, bundles[0].getProcessData(), Job.Status.RUNNING);
    AssertUtil.assertSucceeded(prism.getProcessHelper().suspend(bundles[0].getProcessData()));
    AssertUtil.checkStatus(clusterOC, EntityType.PROCESS, bundles[0].getProcessData(), Job.Status.SUSPENDED);
    //try to delete process by U2
    final ServiceResponse serviceResponse = prism.getProcessHelper().delete(bundles[0].getProcessData(),
            MerlinConstants.USER2_NAME);
    AssertUtil.assertFailedWithStatus(serviceResponse, HttpStatus.SC_BAD_REQUEST,
            "Process suspended by first user should not be deleted by second user");
}

From source file:org.apache.falcon.regression.AuthorizationTest.java

@Test(enabled = false)
public void u1SuspendU2DeleteFeed() throws Exception {
    String feed = bundles[0].getInputFeedFromBundle();
    //submit, schedule, suspend feed by U1
    bundles[0].submitClusters(prism);/*from  w w w  .  j  a va  2  s .co  m*/
    AssertUtil.assertSucceeded(prism.getFeedHelper().submitAndSchedule(feed));
    AssertUtil.assertSucceeded(prism.getFeedHelper().suspend(feed));
    AssertUtil.checkStatus(clusterOC, EntityType.FEED, feed, Job.Status.SUSPENDED);
    //delete feed by U2
    final ServiceResponse serviceResponse = prism.getFeedHelper().delete(feed, MerlinConstants.USER2_NAME);
    AssertUtil.assertFailedWithStatus(serviceResponse, HttpStatus.SC_BAD_REQUEST,
            "Feed scheduled by first user should not be deleted by second user");
}

From source file:org.apache.falcon.regression.AuthorizationTest.java

/**
 * U2Suspend test cases.// w w w  . java 2 s  . c o m
 */
//disabled since, falcon does not have authorization https://issues.apache
// .org/jira/browse/FALCON-388
@Test(enabled = false)
public void u1ScheduleU2SuspendFeed() throws Exception {
    String feed = bundles[0].getInputFeedFromBundle();
    //submit, schedule by U1
    bundles[0].submitClusters(prism);
    AssertUtil.assertSucceeded(prism.getFeedHelper().submitAndSchedule(feed));
    AssertUtil.checkStatus(clusterOC, EntityType.FEED, feed, Job.Status.RUNNING);
    //try to suspend by U2
    final ServiceResponse serviceResponse = prism.getFeedHelper().suspend(feed, MerlinConstants.USER2_NAME);
    AssertUtil.assertFailedWithStatus(serviceResponse, HttpStatus.SC_BAD_REQUEST,
            "Feed scheduled by first user should not be suspended by second user");
}