public Object extractEntity(ClientRequestContext context, Object... args) { EntityTypeFactory factory = null; try { factory = entityTypeFactory.newInstance(); } catch (InstantiationException e) { throw context.getClientResponse().createResponseFailure(Messages.MESSAGES.couldNotCreateEntityFactory(entityTypeFactory.getClass().getName())); } catch (IllegalAccessException e) { throw ((BaseClientResponse<?>)context.getClientResponse()) .createResponseFailure(Messages.MESSAGES.couldNotCreateEntityFactoryMessage(entityTypeFactory.getClass().getName(), e.getMessage())); } context.getClientResponse().setReturnType( factory.getEntityType(((BaseClientResponse<?>) context.getClientResponse()).getStatus(), ((BaseClientResponse<?>) context.getClientResponse()).getMetadata())); return context.getClientResponse(); } };
public Object extractEntity(ClientRequestContext context, Object... args) { EntityTypeFactory factory = null; try { factory = entityTypeFactory.newInstance(); } catch (InstantiationException e) { throw context.getClientResponse().createResponseFailure(Messages.MESSAGES.couldNotCreateEntityFactory(entityTypeFactory.getClass().getName())); } catch (IllegalAccessException e) { throw ((BaseClientResponse<?>)context.getClientResponse()) .createResponseFailure(Messages.MESSAGES.couldNotCreateEntityFactoryMessage(entityTypeFactory.getClass().getName(), e.getMessage())); } context.getClientResponse().setReturnType( factory.getEntityType(((BaseClientResponse<?>) context.getClientResponse()).getStatus(), ((BaseClientResponse<?>) context.getClientResponse()).getMetadata())); return context.getClientResponse(); } };
@SuppressWarnings("deprecation") public static <T> Response copyResponseAndClose(Response source, Class<T> type) { int status = -1; Headers<Object> headers = new Headers<Object>(); Object entity = null; try { status = source.getStatus(); if (source instanceof org.jboss.resteasy.client.core.BaseClientResponse) headers.putAll(((org.jboss.resteasy.client.core.BaseClientResponse<?>)source).getMetadata()); if (source instanceof org.jboss.resteasy.client.ClientResponse) { entity = ((org.jboss.resteasy.client.ClientResponse<?>)source).getEntity(type); } else { entity = source.getEntity(); } return new BuiltResponsePreservingError(status, headers, entity, new Annotation[0], null); } catch (Exception e) { Exceptions.propagateIfFatal(e); return new BuiltResponsePreservingError(status, headers, entity, new Annotation[0], e); } finally { if (source instanceof org.jboss.resteasy.client.core.BaseClientResponse) ((org.jboss.resteasy.client.core.BaseClientResponse<?>)source).close(); } }
@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 }