if (validatedResponse != null) throw new NoLogWebApplicationException(validatedResponse.status(Response.Status.NOT_MODIFIED).cacheControl(cc).header(HttpHeaders.ETAG, etag).build());
@Override public Response toResponse(NoLogWebApplicationException exception) { return getDefaultBuilder(exception, Response.Status.fromStatusCode( exception.getResponse().getStatus()), determineBestMediaType()).build(); }
private static Void throwErrorForbidden(String botId, Integer version, IllegalAccessException e) { String message = "Bot deployment is currently in progress! (botId=%s , version=%s)"; message = String.format(message, botId, version); log.error(message, e); throw new NoLogWebApplicationException(new Throwable(message), Response.Status.FORBIDDEN); }
@Override public String viewHtml(String path) { try { return resourceFileManager.getResourceAsString("html", "chat.html"); } catch (IResourceFileManager.NotFoundException e) { throw new NoLogWebApplicationException(Response.Status.NOT_FOUND); } }
@Override public Response getBotZipArchive(String botFilename) { try { String zipFilePath = FileUtilities.buildPath(tmpPath.toString(), botFilename); return Response.ok(new BufferedInputStream(new FileInputStream(zipFilePath))).build(); } catch (FileNotFoundException e) { throw new NoLogWebApplicationException(Response.Status.NOT_FOUND); } }
@Override public void write(OutputStream outputStream) throws IOException, WebApplicationException { try { final RDFWriter writer = Rio.createWriter(format, outputStream); sparqlService.createServiceDescription(writer, request.getRequestURL().toString(), isUpdate); } catch (RDFHandlerException e) { log.warn("Could not send SpaqlServiceDescription", e); throw new NoLogWebApplicationException(e, Response.serverError().entity(e).build()); } } };
@Override public void write(OutputStream outputStream) throws IOException, WebApplicationException { try { final RDFWriter writer = Rio.createWriter(format, outputStream); sparqlService.createServiceDescription(writer, request.getRequestURL().toString(), isUpdate); } catch (RDFHandlerException e) { log.warn("Could not send SpaqlServiceDescription", e); throw new NoLogWebApplicationException(e, Response.serverError().entity(e).build()); } } };
@Override public Response getBinary(String path) { try { String extension = path.contains(".") ? path.substring(path.lastIndexOf(".") + 1) : null; InputStream fileStream = resourceFileManager.getResourceAsInputStream(path); if (fileStream != null) { return Response.ok(fileStream).type(contentTypeProvider.getContentTypeByExtension(extension)).build(); } else { throw new NotFoundException(); } } catch (IResourceFileManager.NotFoundException e) { throw new NoLogWebApplicationException(Response.Status.NOT_FOUND); } } }
@Override public void deleteTestCase(String id) { try { testCaseStore.delete(id, 0); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e); } catch (IResourceStore.ResourceModifiedException e) { log.debug(e.getLocalizedMessage(), e); throw new NoLogWebApplicationException(Response.Status.CONFLICT); } catch (IResourceStore.ResourceNotFoundException e) { log.debug(e.getLocalizedMessage(), e); throw new NoLogWebApplicationException(Response.Status.NOT_FOUND); } } }
@Override public TestCase readTestCase(String id) { try { return testCaseStore.read(id, 0); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e); } catch (IResourceStore.ResourceNotFoundException e) { throw new NoLogWebApplicationException(Response.Status.NOT_FOUND); } }
@Override public Group readGroup(String groupId) { try { return groupStore.readGroup(groupId); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(); } catch (IResourceStore.ResourceNotFoundException e) { throw new NoLogWebApplicationException(Response.Status.NOT_FOUND); } }
@Override public String viewHtml(String path) { try { path = preparePath(path); String htmlString = resourceFileManager.getResourceAsString("html", path); htmlString = htmlString.replace("<EDDI-VERSION/>", runtime.getVersion()); return htmlString; } catch (IResourceFileManager.NotFoundException e) { throw new NoLogWebApplicationException(Response.Status.NOT_FOUND); } }
@Override public User readUser(String userId) { try { return userStore.readUser(userId); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(); } catch (IResourceStore.ResourceNotFoundException e) { throw new NoLogWebApplicationException(Response.Status.NOT_FOUND); } }
@Override public URI updateTestCase(String id, TestCase testCase) { try { testCaseStore.update(id, 0, testCase); return RestUtilities.createURI(resourceURI, id, versionQueryParam, 0); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e); } catch (IResourceStore.ResourceNotFoundException e) { log.debug(e.getLocalizedMessage(), e); throw new NoLogWebApplicationException(Response.Status.NOT_FOUND); } catch (IResourceStore.ResourceModifiedException e) { log.debug(e.getLocalizedMessage(), e); throw new NoLogWebApplicationException(Response.Status.CONFLICT); } }
@Override public Permissions readPermissions(String resourceId) { try { return permissionStore.readFilteredPermissions(resourceId); } catch (IResourceStore.ResourceStoreException e) { throw new InternalServerErrorException(e.getLocalizedMessage(), e); } catch (IResourceStore.ResourceNotFoundException e) { throw new NoLogWebApplicationException(Response.Status.NOT_FOUND); } }
@Override public URI searchUser(String username) { try { String id = userStore.searchUser(username); return RestUtilities.createURI(resourceURI, id); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(); } catch (IResourceStore.ResourceNotFoundException e) { throw new NoLogWebApplicationException(Response.Status.NOT_FOUND); } }
@Override public ConversationState getConversationState(Deployment.Environment environment, String conversationId) { RuntimeUtilities.checkNotNull(environment, "environment"); RuntimeUtilities.checkNotNull(conversationId, "conversationId"); ConversationState conversationState = conversationStateCache.get(conversationId); if (conversationState == null) { conversationState = conversationMemoryStore.getConversationState(conversationId); cacheConversationState(conversationId, conversationState); } if (conversationState == null) { String message = "No conversation found! (conversationId=%s)"; message = String.format(message, conversationId); throw new NoLogWebApplicationException(new Throwable(message), Response.Status.NOT_FOUND); } return conversationState; }
@Override public void write(OutputStream output) throws IOException, WebApplicationException { try { final RepositoryConnection outputConn = sesameService.getConnection(); try { outputConn.begin(); ldpService.exportResource(outputConn, resource, output, format, preference); outputConn.commit(); } catch (RDFHandlerException e) { outputConn.rollback(); throw new NoLogWebApplicationException(e, createResponse(Response.status(Response.Status.INTERNAL_SERVER_ERROR)).entity(e.getMessage()).build()); } catch (final Throwable t) { outputConn.rollback(); throw t; } finally { outputConn.close(); } } catch (RepositoryException e) { throw new WebApplicationException(e, createResponse(Response.status(Response.Status.INTERNAL_SERVER_ERROR)).entity(e).build()); } } };
@Override public SimpleConversationMemorySnapshot readConversation(Deployment.Environment environment, String botId, String conversationId, Boolean returnDetailed, Boolean returnCurrentStepOnly, List<String> returningFields) { RuntimeUtilities.checkNotNull(environment, "environment"); RuntimeUtilities.checkNotNull(botId, "botId"); RuntimeUtilities.checkNotNull(conversationId, "conversationId"); try { var conversationMemorySnapshot = conversationMemoryStore.loadConversationMemorySnapshot(conversationId); if (!botId.equals(conversationMemorySnapshot.getBotId())) { String message = "conversationId: '%s' does not belong to bot with conversationId: '%s'. " + "(provided botId='%s', botId in ConversationMemory='%s')"; message = String.format(message, conversationId, botId, botId, conversationMemorySnapshot.getBotId()); throw new IllegalAccessException(message); } return getSimpleConversationMemorySnapshot(conversationMemorySnapshot, returnDetailed, returnCurrentStepOnly, returningFields); } catch (ResourceStoreException | IllegalAccessException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e.getLocalizedMessage(), e); } catch (ResourceNotFoundException e) { throw new NoLogWebApplicationException(Response.Status.NOT_FOUND); } }
public static NoLogWebApplicationException createConflictException(String containerUri, IResourceStore.IResourceId currentId) { URI resourceUri = RestUtilities.createURI(containerUri, currentId.getId(), versionQueryParam, currentId.getVersion()); ResponseBuilderImpl builder = new ResponseBuilderImpl(); builder.status(Response.Status.CONFLICT); builder.entity(resourceUri.toString()); builder.type(MediaType.TEXT_PLAIN); return new NoLogWebApplicationException(builder.build()); }