String expectedResponseFromJasperServer = "....."; ClientRequest request = mock(ClientRequest.class); ClientResponse<String> response = mock(ClientResponse.class); when(request.get(String.class)).thenReturn(response); when(response.getEntity()).thenReturn(expectedResponseFromJasperServer);
/** * @see org.jboss.resteasy.client.ClientRequest#get() */ @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public ClientResponse get() throws Exception { ClientResponse response = super.get(); handlePotentialServerError(response); return response; }
/** * @see org.jboss.resteasy.client.ClientRequest#get(java.lang.Class) */ @Override public <T> ClientResponse<T> get(Class<T> returnType) throws Exception { ClientResponse<T> response = super.get(returnType); handlePotentialServerError(response); return response; }
/** * @see org.jboss.resteasy.client.ClientRequest#get() */ @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public ClientResponse get() throws Exception { ClientResponse response = super.get(); handlePotentialServerError(response); return response; }
/** * @see org.jboss.resteasy.client.ClientRequest#get(Class) */ @Override public <T> ClientResponse<T> get(Class<T> returnType) throws Exception { ClientResponse<T> response = super.get(returnType); handlePotentialServerError(response); return response; }
//(...imports...) import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.impl.client.DefaultHttpClient; import org.jboss.resteasy.client.ClientRequest; import org.jboss.resteasy.client.ClientResponse; import org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor; //(...code...) private static final String ENDPOINT = "the_rest_endpoint_here"; String username = "<user_name>"; String password = "<password>"; DefaultHttpClient client = new DefaultHttpClient(); client.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); ApacheHttpClient4Executor executer = new ApacheHttpClient4Executor(client); ClientRequest req = new ClientRequest(ENDPOINT, executer); ClientResponse<String> res = req.get(String.class); System.out.println(res.getEntity()); res.close();
/** * Templates the returned ClientResponse for easy access to returned entity * * @param returnType * @param <T> * @return * @throws Exception */ public <T> ClientResponse<T> get(Class<T> returnType) throws Exception { BaseClientResponse response = (BaseClientResponse) get(); response.setReturnType(returnType); return response; }
/** * Templates the returned ClientResponse for easy access to returned entity * * @param returnType * @param <T> * @return * @throws Exception */ public <T> ClientResponse<T> get(Class<T> returnType) throws Exception { BaseClientResponse response = (BaseClientResponse) get(); response.setReturnType(returnType); return response; }
public <T> ClientResponse<T> get(Class<T> returnType, Type genericType) throws Exception { BaseClientResponse response = (BaseClientResponse) get(); response.setReturnType(returnType); response.setGenericReturnType(genericType); return response; }
public <T> ClientResponse<T> get(Class<T> returnType, Type genericType) throws Exception { BaseClientResponse response = (BaseClientResponse) get(); response.setReturnType(returnType); response.setGenericReturnType(genericType); return response; }
public ClientResponse<String> get(String url, MediaType mediaType) throws Exception { ClientRequest request = new ClientRequest(url); request.accept(mediaType); ClientResponse<String> response = request.get(String.class); return response; }
public <T> ClientResponse<T> get(GenericType type) throws Exception { BaseClientResponse response = (BaseClientResponse) get(); response.setReturnType(type.getType()); response.setGenericReturnType(type.getGenericType()); return response; }
public <T> T get(String uriTemplate, Class<T> type, Object... params) throws Exception { return createRequest(uriTemplate).followRedirects(true).pathParameters( params).get(type).getEntity(); }
public <T> T get(String uriTemplate, Class<T> type, Object... params) throws Exception { return createRequest(uriTemplate).followRedirects(true).pathParameters( params).get(type).getEntity(); }
public <T> ClientResponse<T> get(GenericType type) throws Exception { BaseClientResponse response = (BaseClientResponse) get(); response.setReturnType(type.getType()); response.setGenericReturnType(type.getGenericType()); return response; }
/** * Tries to automatically unmarshal to target type. * * @param returnType * @param <T> * @return * @throws Exception */ public <T> T getTarget(Class<T> returnType) throws Exception { BaseClientResponse<T> response = (BaseClientResponse<T>) get(returnType); if (response.getStatus() == 204) return null; if (response.getStatus() != 200) throw new ClientResponseFailure(response); T obj = response.getEntity(); if (obj instanceof InputStream) { response.setWasReleased(true); } return obj; }
clientRequest.setHttpMethod(HttpMethod.GET); ClientResponse<String> clientResponse = clientRequest.get(String.class); int status = clientResponse.getStatus();
/** * Tries to automatically unmarshal to target type. * * @param returnType * @param <T> * @return * @throws Exception */ public <T> T getTarget(Class<T> returnType) throws Exception { BaseClientResponse<T> response = (BaseClientResponse<T>) get(returnType); if (response.getStatus() == 204) return null; if (response.getStatus() != 200) throw new ClientResponseFailure(response); T obj = response.getEntity(); if (obj instanceof InputStream) { response.setWasReleased(true); } return obj; }
clientResponse1 = clientRequest.get(String.class); int status = clientResponse1.getStatus();
clientResponse = clientRequest.get(String.class);