@Test public void shouldMakePostRequest() { httpMethod = "POST"; contentType = CONTENT_TYPE; Answer<Void> postAnswer = new Answer<Void>() { @Override public Void answer(InvocationOnMock invocationOnMock) throws Throwable { ByteArrayOutputStream os = (ByteArrayOutputStream) invocationOnMock.getArguments()[0]; os.write("some post data".getBytes()); return null; } }; when(mockCallContext.getRequestUUID()).thenReturn(new RequestUUIDImpl()); when(mockMessage.getHeaderMap()).thenReturn(Collections.<String, Object>emptyMap()); doAnswer(postAnswer).when(mockMarshaller).marshall(any(ByteArrayOutputStream.class), anyObject(), anyString(), eq(true)); Object result = factory.create(uri, httpMethod, mockMessage, mockMarshaller, contentType, mockCallContext, mockTimeConstraints); assertSame(httpRequest, result); assertEquals(5, headers.size()); assertHeadersContains(headers, ACCEPT, contentType); assertHeadersContains(headers, USER_AGENT, CougarRequestFactory.USER_AGENT_HEADER); assertHeadersContains(headers, "X-REQUEST-UUID"); assertHeadersContains(headers, "X-RequestTime"); assertHeadersContains(headers, "X-RequestTimeout", "0"); assertEquals("some post data", postEntity); }
public HR create(final String uri, final String httpMethod, final Message message, final Marshaller marshaller, final String contentType, final ClientCallContext ctx, final TimeConstraints timeConstraints) { final HR httpRequest = createRequest(httpMethod, uri); if ("POST".equalsIgnoreCase(httpMethod)) { addPostEntity(httpRequest, createPostEntity(message, marshaller), contentType); } List<Header> coreHeaders = constructRequestHeaders(message, contentType, timeConstraints); contextEmission.emit(ctx, httpRequest, coreHeaders); addHeaders(httpRequest, coreHeaders); return httpRequest; }
CougarRequestFactory { public HR create(final String uri, final String httpMethod, final Message message, final Marshaller marshaller, final String contentType, final ClientCallContext ctx, final TimeConstraints timeConstraints) { final HR httpRequest = createRequest(httpMethod, uri); if ("POST".equalsIgnoreCase(httpMethod)) { addPostEntity(httpRequest, createPostEntity(message, marshaller), contentType); } List<Header> coreHeaders = constructRequestHeaders(message, contentType, timeConstraints); contextEmission.emit(ctx, httpRequest, coreHeaders); addHeaders(httpRequest, coreHeaders); return httpRequest; } }
CougarRequestFactory { public HR create(final String uri, final String httpMethod, final Message message, final Marshaller marshaller, final String contentType, final ClientCallContext ctx, final TimeConstraints timeConstraints) { final HR httpRequest = createRequest(httpMethod, uri); if ("POST".equalsIgnoreCase(httpMethod)) { addPostEntity(httpRequest, createPostEntity(message, marshaller), contentType); } List<Header> coreHeaders = constructRequestHeaders(message, contentType, timeConstraints); contextEmission.emit(ctx, httpRequest, coreHeaders); addHeaders(httpRequest, coreHeaders); return httpRequest; } CougarRequestFactory(ContextEmitter<HR,List<Header>> contextEmission); }
CougarRequestFactory { public HR create(final String uri, final String httpMethod, final Message message, final Marshaller marshaller, final String contentType, final ClientCallContext ctx, final TimeConstraints timeConstraints) { final HR httpRequest = createRequest(httpMethod, uri); if ("POST".equalsIgnoreCase(httpMethod)) { addPostEntity(httpRequest, createPostEntity(message, marshaller), contentType); } List<Header> coreHeaders = constructRequestHeaders(message, contentType, timeConstraints); contextEmission.emit(ctx, httpRequest, coreHeaders); addHeaders(httpRequest, coreHeaders); return httpRequest; } CougarRequestFactory(ContextEmitter<HR,List<Header>> contextEmission); HR create(final String uri, final String httpMethod, final Message message,
                              final Marshaller marshaller, final String contentType, final ClientCallContext ctx, final TimeConstraints timeConstraints); void setGzipCompressionEnabled(boolean gzipCompressionEnabled); }
CougarRequestFactory { public HR create(final String uri, final String httpMethod, final Message message, final Marshaller marshaller, final String contentType, final ClientCallContext ctx, final TimeConstraints timeConstraints) { final HR httpRequest = createRequest(httpMethod, uri); if ("POST".equalsIgnoreCase(httpMethod)) { addPostEntity(httpRequest, createPostEntity(message, marshaller), contentType); } List<Header> coreHeaders = constructRequestHeaders(message, contentType, timeConstraints); contextEmission.emit(ctx, httpRequest, coreHeaders); addHeaders(httpRequest, coreHeaders); return httpRequest; } CougarRequestFactory(ContextEmitter<HR,List<Header>> contextEmission); HR create(final String uri, final String httpMethod, final Message message,
                              final Marshaller marshaller, final String contentType, final ClientCallContext ctx, final TimeConstraints timeConstraints); void setGzipCompressionEnabled(boolean gzipCompressionEnabled);  }