response = ((ResponseProcessingException) cause).getResponse(); } else if (cause instanceof WebApplicationException) { response = ((WebApplicationException) cause).getResponse();
@Override public ClientResponse invoke() { Providers current = pushProvidersContext(); try { ClientRequestContextImpl requestContext = new ClientRequestContextImpl(this); ClientResponse aborted = filterRequest(requestContext); // spec requires that aborted response go through filter/interceptor chains. ClientResponse response = (aborted != null) ? aborted : (ClientResponse)client.httpEngine().invoke(this); return filterResponse(requestContext, response); } catch (ResponseProcessingException e) { if (e.getResponse() != null) { e.getResponse().close(); } throw e; } finally { popProvidersContext(current); } }
public static void printErrorMessage(Throwable throwable) { final Throwable cause = throwable.getCause(); if (cause == null) { System.out.println("cause = " + cause); //noinspection Duplicates } else if (cause instanceof ResponseProcessingException) { final ResponseProcessingException responseProcessingException = (ResponseProcessingException) cause; final Response response = responseProcessingException.getResponse(); final String s1 = response.readEntity(String.class); java.lang.System.out.println("s1 = " + s1); } else { throwable.printStackTrace(); } }
public Project get() { try { return webResource() .get(Project.class); } catch (ResponseProcessingException rpe) { if (rpe.getResponse().getStatus() == 404) { return null; } throw rpe; } }
public @Nullable Account get(String username) { try { return webResource(username) .get(Account.class); } catch (ResponseProcessingException e) { if (e.getResponse().getStatusInfo().equals(Response.Status.NOT_FOUND)) { return null; } else { throw e; } } }
public @Nullable Account get(String username) { try { return webResource(username) .get(Account.class); } catch (ResponseProcessingException e) { if (e.getResponse().getStatusInfo().equals(Response.Status.NOT_FOUND)) { return null; } else { throw e; } } }
public Project get() { try { return webResource() .get(Project.class); } catch (ResponseProcessingException rpe) { if (rpe.getResponse().getStatus() == 404) { return null; } throw rpe; } }
protected Object interceptorChainCompleted() throws Exception { try { return method.invoke(target, args); } catch (InvocationTargetException e) { if (e.getCause() instanceof ResponseProcessingException) { ResponseProcessingException rpe = (ResponseProcessingException) e.getCause(); // Note that the default client engine leverages a single connection // MP FT: we need to close the response otherwise we would not be able to retry if the method returns javax.ws.rs.core.Response rpe.getResponse().close(); Throwable cause = rpe.getCause(); if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } } throw e; } }
protected Object interceptorChainCompleted() throws Exception { try { return method.invoke(target, args); } catch (InvocationTargetException e) { if (e.getCause() instanceof ResponseProcessingException) { ResponseProcessingException rpe = (ResponseProcessingException) e.getCause(); // Note that the default client engine leverages a single connection // MP FT: we need to close the response otherwise we would not be able to retry if the method returns javax.ws.rs.core.Response rpe.getResponse().close(); Throwable cause = rpe.getCause(); if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } } throw e; } }
/** * Try to get the file types from the server (if server is new enough), otherwise use * compiled-in values (as older versions of the client did). * @param client * @return */ public List<FileTypeInfo> fileTypeInfoList(FileResourceClient client) { try { return client.fileTypeInfoList(); } catch (ResponseProcessingException e) { if (e.getResponse().getStatus() == 404) { log.info("Detected old Zanata Server; using hard-coded file types."); // probably running against an old Zanata Server return fileTypeInfoListWorkaround(); } throw e; } }
/** * Try to get the file types from the server (if server is new enough), otherwise use * compiled-in values (as older versions of the client did). * @param client * @return */ public List<FileTypeInfo> fileTypeInfoList(FileResourceClient client) { try { return client.fileTypeInfoList(); } catch (ResponseProcessingException e) { if (e.getResponse().getStatus() == 404) { log.info("Detected old Zanata Server; using hard-coded file types."); // probably running against an old Zanata Server return fileTypeInfoListWorkaround(); } throw e; } }
@Override public final void processTrial(Trial trial) { if (uploadUri.isPresent()) { WebTarget resource = client.target(uploadUri.get()); if (apiKey.isPresent()) { resource = resource.queryParam("key", apiKey.get().toString()); } boolean threw = true; try { // TODO(gak): make the json part happen automagically resource.request(MediaType.APPLICATION_JSON).post(Entity.<String>json(gson.toJson(ImmutableList.of(trial)))); // only set the run id if a result has been successfully uploaded runId = Optional.of(trial.run().id()); threw = false; } catch (ResponseProcessingException e) { logUploadFailure(trial, e); logger.fine("Failed upload response: " + e.getResponse().getStatus()); } catch (ProcessingException e) { logUploadFailure(trial, e); } finally { failure |= threw; } } }
private void fail(Throwable throwable) { if (throwable.getClass().isInstance(WebApplicationException.class)) { final WebApplicationException cast = WebApplicationException.class.cast(throwable); final Response response = cast.getResponse(); if (shouldHandleError(response)) { handleError(response); } } else if (throwable.getClass().isInstance(ResponseProcessingException.class)) { final ResponseProcessingException cast = ResponseProcessingException.class.cast(throwable); final Response response = cast.getResponse(); if (shouldHandleError(response)) { handleError(response); } } else { exchange.setException(throwable); } }
private void fail(Throwable throwable) { if (throwable.getClass().isInstance(WebApplicationException.class)) { final WebApplicationException cast = WebApplicationException.class.cast(throwable); final Response response = cast.getResponse(); if (shouldHandleError(response)) { handleError(response); } } else if (throwable.getClass().isInstance(ResponseProcessingException.class)) { final ResponseProcessingException cast = ResponseProcessingException.class.cast(throwable); final Response response = cast.getResponse(); if (shouldHandleError(response)) { handleError(response); } } else { exchange.setException(throwable); } }
public Resource getResource(String docId, Set<String> extensions) { Client client = factory.getClient(); WebTarget webResource = getBaseServiceResource(client) .path("resource") .queryParam("docId", docId) .queryParam("ext", extensions.toArray()); try { return webResource.request(MediaType.APPLICATION_XML_TYPE) .get(Resource.class); } catch (ResponseProcessingException e) { if (RestUtil.isNotFound(e.getResponse())) { // fallback to old endpoint String idNoSlash = RestUtil.convertToDocumentURIId(docId); webResource = getBaseServiceResource(client) .path("r") .path(idNoSlash) .queryParam("ext", extensions.toArray()); return webResource.request(MediaType.APPLICATION_XML_TYPE) .get(Resource.class); } throw e; } }
public Resource getResource(String docId, Set<String> extensions) { Client client = factory.getClient(); WebTarget webResource = getBaseServiceResource(client) .path("resource") .queryParam("docId", docId) .queryParam("ext", extensions.toArray()); try { return webResource.request(MediaType.APPLICATION_XML_TYPE) .get(Resource.class); } catch (ResponseProcessingException e) { if (RestUtil.isNotFound(e.getResponse())) { // fallback to old endpoint String idNoSlash = RestUtil.convertToDocumentURIId(docId); webResource = getBaseServiceResource(client) .path("r") .path(idNoSlash) .queryParam("ext", extensions.toArray()); return webResource.request(MediaType.APPLICATION_XML_TYPE) .get(Resource.class); } throw e; } }
public String deleteResource(String docId) { Client client = factory.getClient(); WebTarget webResource = getBaseServiceResource(client); try { return webResource.path("resource").queryParam("docId", docId) .request().delete(String.class); } catch (ResponseProcessingException e) { if (RestUtil.isNotFound(e.getResponse())) { String idNoSlash = RestUtil.convertToDocumentURIId(docId); return webResource.path("r").path(idNoSlash).request() .delete(String.class); } throw e; } } }
public String deleteResource(String docId) { Client client = factory.getClient(); WebTarget webResource = getBaseServiceResource(client); try { return webResource.path("resource").queryParam("docId", docId) .request().delete(String.class); } catch (ResponseProcessingException e) { if (RestUtil.isNotFound(e.getResponse())) { String idNoSlash = RestUtil.convertToDocumentURIId(docId); return webResource.path("r").path(idNoSlash).request() .delete(String.class); } throw e; } } }
@Override public ProcessStatus startSourceDocCreationOrUpdateWithDocId( String projectSlug, String iterationSlug, Resource resource, Set<String> extensions, String docId) { Client client = factory.getClient(); WebTarget webResource = client.target(baseUri) .path(AsynchronousProcessResource.SERVICE_PATH) .path("projects").path("p").path(projectSlug) .path("iterations").path("i").path(iterationSlug) .path("resource"); try { Response response = webResource .queryParam("docId", docId) .queryParam("ext", extensions.toArray()) .request(MediaType.APPLICATION_XML_TYPE) .put(Entity.xml(resource)); response.bufferEntity(); return response.readEntity(ProcessStatus.class); } catch (ResponseProcessingException e) { if (RestUtil.isNotFound(e.getResponse())) { // fallback to old endpoint String idNoSlash = RestUtil.convertToDocumentURIId(docId); return startSourceDocCreationOrUpdate(idNoSlash, projectSlug, iterationSlug, resource, extensions, false); } throw e; } }
@Override public ClientResponse invoke() { Providers current = pushProvidersContext(); try { ClientRequestContextImpl requestContext = new ClientRequestContextImpl(this); ClientResponse aborted = filterRequest(requestContext); // spec requires that aborted response go through filter/interceptor chains. ClientResponse response = (aborted != null) ? aborted : client.httpEngine().invoke(this); return filterResponse(requestContext, response); } catch (ResponseProcessingException e) { if (e.getResponse() != null) { e.getResponse().close(); } throw e; } finally { popProvidersContext(current); } }