List of usage examples for org.apache.commons.httpclient HttpStatus SC_BAD_REQUEST
int SC_BAD_REQUEST
To view the source code for org.apache.commons.httpclient HttpStatus SC_BAD_REQUEST.
Click Source Link
From source file:com.sappenin.eaut.consumer.mappingservice.MappingServiceClientImpl.java
/** * This function communicates with an EAUT Mapping service via an HTTP get, * provides the service an email address, and return the resulting URL, if * found.//from w w w. j a v a 2 s. c o m * * @param pae * @return The URL that the specified Mapping Service indicates is the URL * of the specified email address. * @throws EAUTException */ @Override public String queryMappingService(ParsedEmailAddress pae, String getUrl) throws EAUTException { HttpClient client = new HttpClient(); GetMethod get = new GetMethod(getUrl); get.setFollowRedirects(true); if (log.isDebugEnabled()) log.debug("Performing HTTP GET on: " + getUrl + " ..."); int statusCode; try { statusCode = client.executeMethod(get); if (statusCode != HttpStatus.SC_OK) { if (statusCode == HttpStatus.SC_BAD_REQUEST) throw new EAUTException("The Email Identifier supplied by '" + getUrl + "' is not properly formatted per the EAUT spec and/or RFC2822 (Http Error 400)"); else if (statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR) throw new EAUTException( "The EAUT Mapping Service was unable to complete a mapping request for URL: '" + getUrl + "'. Please try this request again at a later time. (Http Error 500)"); else throw new EAUTException("GET failed on " + getUrl + "(Http Error " + statusCode + ")"); } else { String redirectLocation = get.getURI().toString(); if (redirectLocation != null) { return redirectLocation; } else { // The response is invalid and did not provide the new // location // for the resource. Report an error or possibly handle the // response like a 404 Not Found error. throw new EAUTException("GET failed on " + getUrl + "(Http Error " + statusCode + ")"); } } } catch (EAUTException ee) { throw ee; } catch (HttpException he) { throw new EAUTException(he); } catch (IOException ioe) { throw new EAUTException(ioe); } }
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 w w.j a v a 2 s . 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:com.eviware.soapui.impl.rest.mock.RestMockActionTest.java
@Test public void testDispatchRequestReturnsHttpStatus() throws Exception { mockResponse.setResponseHttpStatus(HttpStatus.SC_BAD_REQUEST); RestMockResult mockResult = mockAction.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:edu.emory.cci.aiw.cvrg.eureka.servlet.LogoutServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { HttpSession session = req.getSession(false); if (session != null) { session.invalidate();/*from w w w . j av a2s . co m*/ } /* * We need to redirect here rather than forward so that * logout.jsp gets a request object without a user. Otherwise, * the button bar will think we're still logged in. */ StringBuilder buf = new StringBuilder(); String casLogoutUrl = webappProperties.getCasLogoutUrl(); buf.append(casLogoutUrl); String awaitingActivation = req.getParameter("awaitingActivation"); boolean aaEmpty = StringUtils.isEmpty(awaitingActivation); if (!aaEmpty && BooleanUtils.toBooleanObject(awaitingActivation) == null) { resp.sendError(HttpStatus.SC_BAD_REQUEST); return; } String notRegistered = req.getParameter("notRegistered"); boolean nrEmpty = StringUtils.isEmpty(notRegistered); if (!nrEmpty && BooleanUtils.toBooleanObject(notRegistered) == null) { resp.sendError(HttpStatus.SC_BAD_REQUEST); return; } if (!aaEmpty || !nrEmpty) { buf.append('?'); } if (!aaEmpty) { buf.append("awaitingActivation=").append(awaitingActivation); } if (!aaEmpty && !nrEmpty) { buf.append('&'); } if (!nrEmpty) { buf.append("notRegistered=").append(notRegistered); } log("URL IS " + buf.toString()); resp.sendRedirect(buf.toString()); }
From source file:com.cloudera.nav.plugin.client.writer.HttpJsonMetadataWriter.java
@Override public void flush() { super.flush(); try {/*from w w w . j ava2 s. c o m*/ // request is not sent until response code is requested if (conn.getResponseCode() >= HttpStatus.SC_BAD_REQUEST) { throw new RuntimeException(String.format("Error writing metadata (code %s): %s", conn.getResponseCode(), conn.getResponseMessage())); } } catch (IOException e) { Throwables.propagate(e); } }
From source file:com.bbva.arq.devops.ae.mirrorgate.jenkins.plugin.utils.RestCall.java
public MirrorGateResponse makeRestCallPost(String url, String jsonString, String user, String password) { MirrorGateResponse response;/*from ww w. ja v a 2 s. c om*/ PostMethod post = new PostMethod(url); try { HttpClient client = getHttpClient(); if (user != null && password != null) { client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password)); post.setDoAuthentication(true); } StringRequestEntity requestEntity = new StringRequestEntity(jsonString, "application/json", "UTF-8"); post.setRequestEntity(requestEntity); int responseCode = client.executeMethod(post); String responseString = post.getResponseBodyAsStream() != null ? getResponseString(post.getResponseBodyAsStream()) : ""; response = new MirrorGateResponse(responseCode, responseString); } catch (IOException e) { LOGGER.log(Level.SEVERE, "MirrorGate: Error posting to MirrorGate", e); response = new MirrorGateResponse(HttpStatus.SC_BAD_REQUEST, ""); } finally { post.releaseConnection(); } return response; }
From source file:com.uber.jenkins.phabricator.conduit.ConduitAPIClientTest.java
@Test(expected = ConduitAPIException.class) public void testBadRequestErrorCode() throws Exception { server.register("/api/foo", TestUtils.makeHttpHandler(HttpStatus.SC_BAD_REQUEST, "nothing")); client = new ConduitAPIClient(getTestServerAddress(), TestUtils.TEST_CONDUIT_TOKEN); client.perform("foo", emptyParams); }
From source file:es.carebear.rightmanagement.client.user.AddAllowedUserId.java
public void AddUser(String authName, String target, String rigthTarget, String rightMask) throws BadRequestException, InternalServerErrorException, IOException, UnknownResponseException { PostMethod postMethod = new PostMethod(baseUri + "/client/users/change/allowed/" + target); postMethod.addParameter("authName", authName); postMethod.addParameter("rigthTarget", rigthTarget); postMethod.addParameter("rightMask", rightMask); int responseCode = httpClient.executeMethod(postMethod); switch (responseCode) { case HttpStatus.SC_OK: break;//from w ww . j a va2 s . co m 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.server.service.result.HttpLocalizedOperationResult.java
public void badRequest(Localizable message) { this.message = message; httpCode = HttpStatus.SC_BAD_REQUEST; }
From source file:com.cloudera.nav.sdk.client.writer.JsonMetadataWriter.java
@Override public void flush() { super.flush(); try {//w w w. j av a 2 s .co m // request is not sent until response code is requested if (conn.getResponseCode() >= HttpStatus.SC_BAD_REQUEST) { // display error message BufferedReader br = new BufferedReader(new InputStreamReader((conn.getErrorStream()))); StringBuilder sb = new StringBuilder(); String responseBody; while ((responseBody = br.readLine()) != null) { sb.append(responseBody); } responseBody = sb.toString(); throw new RuntimeException(String.format("Error writing metadata (code %s): %s %s", conn.getResponseCode(), conn.getResponseMessage(), responseBody)); } lastResult = mapper.readValue(conn.getInputStream(), ResultSet.class); } catch (IOException e) { Throwables.propagate(e); } }