/** * Construct a new listener defining the generic type of the response to * receive. * * @param genericType the generic type of the response. */ public TypeListener(GenericType<T> genericType) { this.type = genericType.getRawClass(); this.genericType = genericType; }
@Override public <T> T getEntity(Type type) throws Exception { return bcr.getEntity(new GenericType<T>(type)); } }
/** * Constructs a new generic type, supplying the generic type * information and derving the class. * * @param genericType the generic type. * @throws IllegalArgumentException if genericType * is null or is neither an instance of Class or ParameterizedType whose raw * type is not an instance of Class. */ public GenericType(Type genericType) { if (genericType == null) { throw new IllegalArgumentException("Type must not be null"); } this.t = genericType; this.c = getClass(this.t); }
/** * Get the entity of the response. * <p> * If the entity is not an instance of Closeable then this response * is closed (you cannot read it more than once, any subsequent * call will produce {@link ClientHandlerException}). * * @param <T> the type of the response. * @param gt the generic type of the entity. * @return an instance of the type represented by the generic type. * * @throws ClientHandlerException if there is an error processing the response. * @throws UniformInterfaceException if the response status is 204 (No Content). */ public <T> T getEntity(GenericType<T> gt) throws ClientHandlerException, UniformInterfaceException { return getEntity(gt.getRawClass(), gt.getType()); }
/** * Get the entity of the response. * <p> * If the entity is not an instance of Closeable then this response * is closed (you cannot read it more than once, any subsequent * call will produce {@link ClientHandlerException}). * * @param <T> the type of the response. * @param gt the generic type of the entity. * @return an instance of the type represented by the generic type. * * @throws ClientHandlerException if there is an error processing the response. * @throws UniformInterfaceException if the response status is 204 (No Content). */ public <T> T getEntity(GenericType<T> gt) throws ClientHandlerException, UniformInterfaceException { return getEntity(gt.getRawClass(), gt.getType()); }
/** * Construct a new listener defining the generic type of the response to * receive. * * @param genericType the generic type of the response. */ public TypeListener(GenericType<T> genericType) { this.type = genericType.getRawClass(); this.genericType = genericType; }
protected <T> T callAPIWithResource(API api, WebResource resource, Object requestObject, Class<T> responseType) throws AtlasServiceException { GenericType<T> genericType = null; if (responseType != null) { genericType = new GenericType<>(responseType); } return callAPIWithResource(api, resource, requestObject, genericType); }
/** * Constructs a new generic type, supplying the generic type * information and derving the class. * * @param genericType the generic type. * @throws IllegalArgumentException if genericType * is null or is neither an instance of Class or ParameterizedType whose raw * type is not an instance of Class. */ public GenericType(Type genericType) { if (genericType == null) { throw new IllegalArgumentException("Type must not be null"); } this.t = genericType; this.c = getClass(this.t); }
protected T get(ClientResponse response) { if (gt.getRawClass() == ClientResponse.class) return gt.getRawClass().cast(response); if (response.getStatus() < 300) return response.getEntity(gt); throw new UniformInterfaceException(response, request.getPropertyAsFeature(ClientConfig.PROPERTY_BUFFER_RESPONSE_ENTITY_ON_EXCEPTION, true)); } };
protected <T> T callAPIWithResource(API api, WebResource resource, Object requestObject, Class<T> responseType) throws AtlasServiceException { GenericType<T> genericType = null; if (responseType != null) { genericType = new GenericType<>(responseType); } return callAPIWithResource(api, resource, requestObject, genericType); }
/** * Constructs a new generic type, deriving the generic type and class from * type parameter. Note that this constructor is protected, users should create * a (usually anonymous) subclass as shown above. * */ protected GenericType() { Type superclass = getClass().getGenericSuperclass(); if (!(superclass instanceof ParameterizedType)) { throw new RuntimeException("Missing type parameter."); } ParameterizedType parameterized = (ParameterizedType) superclass; this.t = parameterized.getActualTypeArguments()[0]; this.c = getClass(this.t); }
protected T get(ClientResponse response) { if (gt.getRawClass() == ClientResponse.class) return gt.getRawClass().cast(response); if (response.getStatus() < 300) return response.getEntity(gt); throw new UniformInterfaceException(response, request.getPropertyAsFeature(ClientConfig.PROPERTY_BUFFER_RESPONSE_ENTITY_ON_EXCEPTION, true)); } };
protected <T> T callAPIWithResource(APIInfo api, WebResource resource, Object requestObject, Class<T> responseType) throws AtlasServiceException { GenericType<T> genericType = null; if (responseType != null) { genericType = new GenericType<>(responseType); } return callAPIWithResource(api, resource, requestObject, genericType); }
/** * Constructs a new generic type, deriving the generic type and class from * type parameter. Note that this constructor is protected, users should create * a (usually anonymous) subclass as shown above. * */ protected GenericType() { Type superclass = getClass().getGenericSuperclass(); if (!(superclass instanceof ParameterizedType)) { throw new RuntimeException("Missing type parameter."); } ParameterizedType parameterized = (ParameterizedType) superclass; this.t = parameterized.getActualTypeArguments()[0]; this.c = getClass(this.t); }
private <T> T handle(GenericType<T> gt, ClientRequest ro) throws UniformInterfaceException, ClientHandlerException { setProperties(ro); ClientResponse r = getHeadHandler().handle(ro); if (gt.getRawClass() == ClientResponse.class) return gt.getRawClass().cast(r); if (r.getStatus() < 300) return r.getEntity(gt); throw new UniformInterfaceException(r, ro.getPropertyAsFeature(ClientConfig.PROPERTY_BUFFER_RESPONSE_ENTITY_ON_EXCEPTION, true)); }
@Override public <T> T getEntity(TypeToken<T> type) throws Exception { return bcr.getEntity(new GenericType<T>(type.getType())); }
private <T> T handle(GenericType<T> gt, ClientRequest ro) throws UniformInterfaceException, ClientHandlerException { setProperties(ro); ClientResponse r = getHeadHandler().handle(ro); if (gt.getRawClass() == ClientResponse.class) return gt.getRawClass().cast(r); if (r.getStatus() < 300) return r.getEntity(gt); throw new UniformInterfaceException(r, ro.getPropertyAsFeature(ClientConfig.PROPERTY_BUFFER_RESPONSE_ENTITY_ON_EXCEPTION, true)); }
if (responseType.getRawClass().equals(ObjectNode.class)) { String stringEntity = clientResponse.getEntity(String.class); try {
if(api.getProduces().equals(MediaType.APPLICATION_OCTET_STREAM)) { return (T) clientResponse.getEntityInputStream(); } else if (responseType.getRawClass().equals(ObjectNode.class)) { String stringEntity = clientResponse.getEntity(String.class); try {
if (responseType.getRawClass() == JSONObject.class) { String stringEntity = clientResponse.getEntity(String.class); try {