public ClientResponse httpMethod(String httpMethod) throws Exception { this.httpMethod = httpMethod; return execute(); }
public ClientResponse httpMethod(String httpMethod) throws Exception { this.httpMethod = httpMethod; return execute(); }
public RestfulResponse<JsonRepresentation> execute() { try { if (!args.isEmpty()) { clientRequestConfigurer.configureArgs(args); } final ClientRequest clientRequest = clientRequestConfigurer.getClientRequest(); final Response response = clientRequest.execute(); // this is a bit hacky @SuppressWarnings("unchecked") final BaseClientResponse<String> restEasyResponse = (BaseClientResponse<String>) response; restEasyResponse.setReturnType(String.class); return RestfulResponse.ofT(response); } catch (final Exception ex) { throw new RuntimeException(ex); } }
public RestfulResponse<JsonRepresentation> execute() { try { if (!args.isEmpty()) { clientRequestConfigurer.configureArgs(args); } final Response response = clientRequestConfigurer.getClientRequest().execute(); // this is a bit hacky @SuppressWarnings("unchecked") final BaseClientResponse<String> restEasyResponse = (BaseClientResponse<String>) response; restEasyResponse.setReturnType(String.class); return RestfulResponse.ofT(response); } catch (final Exception ex) { throw new RuntimeException(ex); } }
@Test public void bioViaJson() throws Exception{ String jsonBodyRequest = "{\n" + " \"id\": \"303021\",\n" + " \"names\": [\n" + " {\n" + " \"firstName\": \"You First\",\n" + " \"lastName\": \"Me Last\"\n" + " }\n" + " ]\n" + "}"; givenThat(WireMock.get(urlEqualTo("/identitymanagement-services/identitymanagement-services/person/internalHandle/person_id_009/biographics/default")) .willReturn(aResponse() .withStatus(200) .withHeader("Content-Type", APPLICATION_JSON) .withBody(jsonBodyRequest))); ApacheHttpClientExecutor httpClientExecutor = new ApacheHttpClientExecutor(); ClientRequest clientExecutor = httpClientExecutor.createRequest("http://localhost:9073/identitymanagement-services/identitymanagement-services/person/internalHandle/person_id_009/biographics/default"); clientExecutor.setHttpMethod("GET"); ClientResponse serverResponse = clientExecutor.execute(); final String respBodyAsString = (String)serverResponse.getEntity(String.class); JSONAssert.assertEquals(jsonBodyRequest, respBodyAsString, true); System.out.println("### bio response from mapping: \n" + respBodyAsString); } }
@Ignore("TODO") @Test public void follow_get() throws Exception { final LinkRepresentation link = jsonRepresentation.getLink("aLink"); final String href = link.getHref(); // when context.checking(new Expectations() { { one(mockExecutor).createRequest(with(any(UriBuilderImpl.class))); will(returnValue(mockClientRequest)); one(mockExecutor).execute(mockClientRequest); will(returnValue(mockClientResponse)); one(mockClientRequest).accept(MediaType.APPLICATION_JSON_TYPE); atLeast(1).of(mockClientRequest).setHttpMethod("GET"); allowing(mockClientRequest).getHttpMethod(); will(returnValue("GET")); one(mockClientRequest).execute(); will(returnValue(mockClientResponse)); one(mockClientResponse).setReturnType(String.class); allowing(mockClientResponse); final MultiValueMap result = new MultiValueMap(); result.put("Content-Type", "application/json"); allowing(mockClientResponse).getMetadata(); will(returnValue(result)); } }); final RestfulResponse<JsonRepresentation> response = client.follow(link); // then }