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:es.carebear.rightmanagement.client.group.AddUserToGroup.java

public void AddUser(String executing, String target, String group)
        throws BadRequestException, InternalServerErrorException, IOException, UnknownResponseException {
    PostMethod postMethod = new PostMethod(baseUri + "/client/groups/add/" + target + "/" + group);
    postMethod.addParameter("authName", executing);
    int responseCode = httpClient.executeMethod(postMethod);

    switch (responseCode) {
    case HttpStatus.SC_OK:
        break;/*from  w ww  . ja  va 2  s .c  om*/
    case HttpStatus.SC_BAD_REQUEST:
        throw new BadRequestException();
    case HttpStatus.SC_INTERNAL_SERVER_ERROR:
        throw new InternalServerErrorException();
    case HttpStatus.SC_FORBIDDEN:
        throw new ForbiddenException();
    default:
        throw new UnknownResponseException((new Integer(responseCode)).toString());
    }
}

From source file:com.thoughtworks.go.config.update.ConfigUpdateAjaxResponseTest.java

@Test
public void shouldGetJsonRepresentationForFailure() throws Exception {
    HashMap<String, List<String>> fieldErrors = new HashMap<String, List<String>>();
    fieldErrors.put("field1", Arrays.asList("error 1"));
    fieldErrors.put("field2", Arrays.asList("error 2"));
    ConfigUpdateAjaxResponse response = ConfigUpdateAjaxResponse.failure("id", HttpStatus.SC_BAD_REQUEST,
            "Save failed", fieldErrors, Arrays.asList("global1", "global2"));
    String jsonString = response.toJson();
    assertThat(response.getStatusCode(), is(HttpStatus.SC_BAD_REQUEST));
    assertThat(jsonString, is(//from ww w.  ja  v a 2  s  .  c om
            "{\"fieldErrors\":{\"field2\":[\"error 2\"],\"field1\":[\"error 1\"]},\"globalErrors\":[\"global1\",\"global2\"],\"message\":\"Save failed\",\"isSuccessful\":false,\"subjectIdentifier\":\"id\"}"));
}

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://from w  w w. j av  a2s.  co m
        throw new UnknownResponseException((new Integer(responseCode)).toString());
    }
}

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

public void AddUser(String authName, String target, String rightMask) throws BadRequestException,
        InternalServerErrorException, IOException, UnknownResponseException, UnauthorizedException {
    PostMethod postMethod = new PostMethod(baseUri + "/client/users/change/allowed");
    postMethod.addParameter("authName", authName);
    postMethod.addParameter("target", target);
    postMethod.addParameter("rightMask", rightMask);
    int responseCode = httpClient.executeMethod(postMethod);

    switch (responseCode) {
    case HttpStatus.SC_OK:
        break;/*w  w w .  j  av  a 2 s .co  m*/
    case HttpStatus.SC_BAD_REQUEST:
        throw new BadRequestException();
    case HttpStatus.SC_INTERNAL_SERVER_ERROR:
        throw new InternalServerErrorException();
    case HttpStatus.SC_UNAUTHORIZED:
        throw new UnauthorizedException();
    case HttpStatus.SC_FORBIDDEN:
        throw new ForbiddenException();
    default:
        throw new UnknownResponseException((new Integer(responseCode)).toString());
    }
}

From source file:eionet.gdem.qa.functions.JsonError.java

/**
 * @return default response code
 */
private Integer getDefaultErrorCode() {
    return HttpStatus.SC_BAD_REQUEST;
}

From source file:com.eviware.soapui.impl.wsdl.mock.WsdlMockOperationTest.java

@Test
public void testDispatchRequestReturnsHttpStatus() throws Exception {
    mockResponse.setResponseHttpStatus(HttpStatus.SC_BAD_REQUEST);

    WsdlMockResult mockResult = mockOperation.dispatchRequest(restMockRequest);

    // HttpResponse is the response transferred over the wire.
    // So here we making sure the http status is actually set on the HttpResponse.
    verify(mockResult.getMockRequest().getHttpResponse()).setStatus(HttpStatus.SC_BAD_REQUEST);

    assertThat(mockResult.getMockResponse().getResponseHttpStatus(), is(HttpStatus.SC_BAD_REQUEST));
}

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

public void ChangeAttribute(String userName, String authName, String[] attribute, String[] value)
        throws BadRequestException, InternalServerErrorException, IOException, UnknownResponseException {
    Gson gson = new Gson();
    String attr = gson.toJson(attribute, attribute.getClass());
    String val = gson.toJson(value, value.getClass());

    PostMethod postMethod = new PostMethod(baseUri + "/client/users/change/" + userName);
    postMethod.addParameter("authName", authName);
    postMethod.addParameter("attribute", attr);
    postMethod.addParameter("value", val);

    int responseCode = httpClient.executeMethod(postMethod);

    switch (responseCode) {
    case HttpStatus.SC_OK:
        break;/*from  w w w  .j av  a 2s .  com*/
    case HttpStatus.SC_BAD_REQUEST:
        throw new BadRequestException();
    case HttpStatus.SC_INTERNAL_SERVER_ERROR:
        throw new InternalServerErrorException();
    case HttpStatus.SC_FORBIDDEN:
        throw new ForbiddenException();
    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.ja v  a2s  .  c o m
        throw new UnknownResponseException((new Integer(responseCode)).toString());
    }
}

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  v  a  2s . co 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:net.sourceforge.fenixedu.presentationTier.Action.publico.FileDownload.java

@Override
public ActionForward execute(final ActionMapping mapping, final ActionForm actionForm,
        final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final String oid = request.getParameter("oid");
    final File file = FenixFramework.getDomainObject(oid);
    if (file == null) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        response.getWriter().write(HttpStatus.getStatusText(HttpStatus.SC_BAD_REQUEST));
        response.getWriter().close();/*from w  w  w. j  av  a2  s  .  co  m*/
    } else {
        final Person person = AccessControl.getPerson();
        if (!file.isPrivate() || file.isPersonAllowedToAccess(person)) {
            response.setContentType(file.getContentType());
            response.addHeader("Content-Disposition", "attachment; filename=" + file.getFilename());
            response.setContentLength(file.getSize().intValue());
            final DataOutputStream dos = new DataOutputStream(response.getOutputStream());
            dos.write(file.getContents());
            dos.close();
        } else if (file.isPrivate() && person == null) {
            response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
            response.getWriter().write(HttpStatus.getStatusText(HttpStatus.SC_UNAUTHORIZED));
            response.getWriter().close();
        } else {
            response.setStatus(HttpServletResponse.SC_FORBIDDEN);
            response.getWriter().write(HttpStatus.getStatusText(HttpStatus.SC_FORBIDDEN));
            response.getWriter().close();
        }
    }
    return null;
}