List of usage examples for org.apache.http.message BasicStatusLine BasicStatusLine
public BasicStatusLine(ProtocolVersion protocolVersion, int i, String str)
From source file:com.launchkey.sdk.transport.v1.ApacheHttpClientTransportAuthsTest.java
@Test public void testResponseStatusCodeOf401ThrowsExpectedException() throws Exception { expectedException.expect(LaunchKeyException.class); expectedException.expectMessage("Expected Message"); when(response.getStatusLine())//from w w w. j a v a 2s. co m .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 401, "Expected Message")); transport.auths(new AuthsRequest(null, 0L, null, null, 0, 0)); }
From source file:org.esigate.servlet.impl.ResponseCapturingWrapper.java
@Override public void reset() { if (isCommitted()) { throw new IllegalStateException("Response is already committed"); }/* w w w . ja v a 2 s . com*/ httpClientResponse = BasicCloseableHttpResponse .adapt(new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"))); }
From source file:org.finra.herd.tools.common.databridge.DataBridgeWebClientTest.java
@Test public void testGetBusinessObjectDataStorageFilesCreateResponse400Throws() throws Exception { int expectedStatusCode = 400; String expectedReasonPhrase = "testReasonPhrase"; String expectedErrorMessage = "testErrorMessage"; ErrorInformation errorInformation = new ErrorInformation(); errorInformation.setStatusCode(expectedStatusCode); errorInformation.setMessage(expectedErrorMessage); errorInformation.setStatusDescription(expectedReasonPhrase); String requestContent = xmlHelper.objectToXml(errorInformation); CloseableHttpResponse httpResponse = new MockCloseableHttpResponse( new BasicStatusLine(HttpVersion.HTTP_1_1, expectedStatusCode, expectedReasonPhrase), false); httpResponse.setEntity(new StringEntity(requestContent)); try {// w ww .j a v a 2 s. c om dataBridgeWebClient.getBusinessObjectDataStorageFilesCreateResponse(httpResponse); Assert.fail("expected HttpErrorResponseException, but no exception was thrown"); } catch (Exception e) { assertEquals("thrown exception type", HttpErrorResponseException.class, e.getClass()); HttpErrorResponseException httpErrorResponseException = (HttpErrorResponseException) e; assertEquals("httpErrorResponseException responseMessage", expectedErrorMessage, httpErrorResponseException.getResponseMessage()); assertEquals("httpErrorResponseException statusCode", expectedStatusCode, httpErrorResponseException.getStatusCode()); assertEquals("httpErrorResponseException statusDescription", expectedReasonPhrase, httpErrorResponseException.getStatusDescription()); assertEquals("httpErrorResponseException message", "Failed to add storage files", httpErrorResponseException.getMessage()); } }
From source file:com.launchkey.sdk.transport.v1.ApacheHttpClientTransportLogsTest.java
@Test public void testResponseStatusCodeOf500ThrowsExpectedException() throws Exception { expectedException.expect(CommunicationErrorException.class); expectedException.expectMessage("Expected Message"); when(response.getStatusLine())/*from w w w. j a v a2s .c o m*/ .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 500, "Expected Message")); transport.logs(new LogsRequest("Authenticate", true, null, 0L, null, null)); }
From source file:com.launchkey.sdk.transport.v1.ApacheHttpClientTransportPollTest.java
@Test public void testResponseStatusCodeOf400WithMessageCodeOf70403ReturnsNull() throws Exception { when(response.getStatusLine())//from w w w . j ava 2s . co m .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 400, "Status Message")); when(response.getEntity()) .thenReturn(EntityBuilder.create() .setStream(new ByteArrayInputStream( "{\"message_code\": 70403, \"message\": \"Pending response\"}".getBytes("UTF-8"))) .build()); assertNull(transport.poll(new PollRequest(null, 0L, null, null))); }
From source file:com.yozio.android.YozioApiServiceImplTest.java
private HttpResponse createHttpResponse(int status, HttpEntity httpEntity) { StatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, status, ""); BasicHttpResponse httpResponse = new BasicHttpResponse(statusLine); httpResponse.setEntity(httpEntity);/*from w w w .ja v a2 s. c om*/ return httpResponse; }
From source file:com.launchkey.sdk.transport.v1.ApacheHttpClientTransportUsersTest.java
@Test public void testResponseStatusCodeOf400ReturnsHttpValuesWhenBodyNotParseable() throws Exception { expectedException.expect(CommunicationErrorException.class); expectedException.expectMessage("Expected Message"); when(response.getStatusLine())/*from w w w. j a v a 2 s. c o m*/ .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 400, "Expected Message")); when(response.getEntity()).thenReturn(EntityBuilder.create() .setStream(new ByteArrayInputStream("Unparseable".getBytes("UTF-8"))).build()); transport.users(new UsersRequest(null, 0L, null)); }
From source file:com.apigee.sdk.apm.http.impl.client.cache.RequestProtocolCompliance.java
/** * Extract error information about the {@link HttpRequest} telling the * 'caller' that a problem occured.// w w w . java 2 s. c om * * @param errorCheck * What type of error should I get * @return The {@link HttpResponse} that is the error generated */ public HttpResponse getErrorForRequest(RequestProtocolError errorCheck) { switch (errorCheck) { case BODY_BUT_NO_LENGTH_ERROR: return new BasicHttpResponse( new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_LENGTH_REQUIRED, "")); case WEAK_ETAG_AND_RANGE_ERROR: return new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_BAD_REQUEST, "Weak eTag not compatible with byte range")); case WEAK_ETAG_ON_PUTDELETE_METHOD_ERROR: return new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_BAD_REQUEST, "Weak eTag not compatible with PUT or DELETE requests")); case NO_CACHE_DIRECTIVE_WITH_FIELD_NAME: return new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_BAD_REQUEST, "No-Cache directive MUST NOT include a field name")); default: throw new IllegalStateException( "The request was compliant, therefore no error can be generated for it."); } }
From source file:at.deder.ybr.test.server.SimpleHttpServerTest.java
@Test public void testGetPackageNotExisting() throws ProtocolViolationException, IOException { // given//from www. j av a 2 s . c om ServerManifest dummyManifest = MockUtils.getMockManifest(); given(mockHttpClient.execute(Matchers.any(HttpGet.class))).willReturn(mockHttpResponse); given(mockHttpResponse.getEntity()).willReturn(mockHttpEntity); given(mockHttpResponse.getStatusLine()) .willReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK")); given(mockHttpEntity.getContent()) .willReturn(new ByteArrayInputStream(dummyManifest.toString().getBytes("utf-8"))); SimpleHttpServer instance = new SimpleHttpServer("none"); instance.setHttpClient(mockHttpClient); // when RepositoryEntry result = instance.getPackage("com.doesnotexist"); // then then(result).isEqualTo(null); }
From source file:com.launchkey.sdk.transport.v1.ApacheHttpClientTransportLogsTest.java
@Test public void testResponseStatusCodeOf400ReturnsBodyErrorValues() throws Exception { when(response.getStatusLine())//from www . j a va2s . c om .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 400, "Status Message")); when(response.getEntity()) .thenReturn(EntityBuilder.create() .setStream(new ByteArrayInputStream( "{\"message_code\": 70401, \"message\": \"Expected Message\"}".getBytes("UTF-8"))) .build()); expectedException.expect(InvalidRequestException.class); expectedException.expectMessage("Expected Message"); transport.logs(new LogsRequest("Authenticate", true, null, 0L, null, null)); }