@Test public void should_retrieve_exception_when_bad_dsl_request_for_select_single() throws Exception { JsonNode fromString = JsonHandler.getFromString("{\n" + " \"$roots\": [],\n" + " \"$query\": [\n" + " {\n" + " \"exists\": {\n" + " \"Title\": \"assemblée\"\n" + " },\n" + " \"$depth\": 20\n" + " },\n" + " {\n" + " \"exists\": {\n" + " },\n" + " \"$depth\": 20\n" + " }\n" + " ],\n" + " \"$filter\": {\n" + " \"$orderby\": {\n" + " \"TransactedDate\": 1\n" + " }\n" + " }\n" + "}"); ContainerRequestContext containerRequestContext = spy(ContainerRequestContext.class); when(containerRequestContext.getEntityStream()).thenReturn(JsonHandler.writeToInpustream(fromString)); final DslScannerFilter dslScannerFilter = new DslScannerFilter(DslSchema.SELECT_SINGLE); dslScannerFilter.filter(containerRequestContext); }
@Override public void filter(ContainerRequestContext requestContext) throws IOException { try { final InputStream bodyInputStream = requestContext.getEntityStream(); final ByteArrayOutputStream bout = new ByteArrayOutputStream(); StreamUtils.copy(bodyInputStream, bout); switch (this.dslSchema) { case SELECT_MULTIPLE: selectMultipleSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case SELECT_SINGLE: selectSingleSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case BATCH_PROCESSING: batchProcessingQuerySchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case GET_BY_ID: getByIdSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case UPDATE_BY_ID: updateByIdSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case RECLASSIFICATION_QUERY: updateQueryReclassificationSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case MASS_UPDATE: massUpdateSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; default: requestContext.abortWith( VitamCodeHelper.toVitamError(VitamCode.GLOBAL_INTERNAL_SERVER_ERROR, "Dsl schema is not valid.") .toResponse()); } requestContext.setEntityStream(new ByteArrayInputStream(bout.toByteArray())); } catch (ValidationException e) { LOGGER.warn(e); requestContext.abortWith( e.getVitamError().toResponse()); } catch (InvalidParseOperationException e) { LOGGER.warn(e); requestContext.abortWith( VitamCodeHelper.toVitamError(VitamCode.GLOBAL_INTERNAL_SERVER_ERROR, "Can not read Dsl query").toResponse()); } }
DslScannerFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws IOException { try { final InputStream bodyInputStream = requestContext.getEntityStream(); final ByteArrayOutputStream bout = new ByteArrayOutputStream(); StreamUtils.copy(bodyInputStream, bout); switch (this.dslSchema) { case SELECT_MULTIPLE: selectMultipleSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case SELECT_SINGLE: selectSingleSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case BATCH_PROCESSING: batchProcessingQuerySchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case GET_BY_ID: getByIdSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case UPDATE_BY_ID: updateByIdSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case RECLASSIFICATION_QUERY: updateQueryReclassificationSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case MASS_UPDATE: massUpdateSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; default: requestContext.abortWith( VitamCodeHelper.toVitamError(VitamCode.GLOBAL_INTERNAL_SERVER_ERROR, "Dsl schema is not valid.") .toResponse()); } requestContext.setEntityStream(new ByteArrayInputStream(bout.toByteArray())); } catch (ValidationException e) { LOGGER.warn(e); requestContext.abortWith( e.getVitamError().toResponse()); } catch (InvalidParseOperationException e) { LOGGER.warn(e); requestContext.abortWith( VitamCodeHelper.toVitamError(VitamCode.GLOBAL_INTERNAL_SERVER_ERROR, "Can not read Dsl query").toResponse()); } } }
DslScannerFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws IOException { try { final InputStream bodyInputStream = requestContext.getEntityStream(); final ByteArrayOutputStream bout = new ByteArrayOutputStream(); StreamUtils.copy(bodyInputStream, bout); switch (this.dslSchema) { case SELECT_MULTIPLE: selectMultipleSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case SELECT_SINGLE: selectSingleSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case BATCH_PROCESSING: batchProcessingQuerySchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case GET_BY_ID: getByIdSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case UPDATE_BY_ID: updateByIdSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case RECLASSIFICATION_QUERY: updateQueryReclassificationSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case MASS_UPDATE: massUpdateSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; default: requestContext.abortWith( VitamCodeHelper.toVitamError(VitamCode.GLOBAL_INTERNAL_SERVER_ERROR, "Dsl schema is not valid.") .toResponse()); } requestContext.setEntityStream(new ByteArrayInputStream(bout.toByteArray())); } catch (ValidationException e) { LOGGER.warn(e); requestContext.abortWith( e.getVitamError().toResponse()); } catch (InvalidParseOperationException e) { LOGGER.warn(e); requestContext.abortWith( VitamCodeHelper.toVitamError(VitamCode.GLOBAL_INTERNAL_SERVER_ERROR, "Can not read Dsl query").toResponse()); } } DslScannerFilter(DslSchema dslSchema); }
DslScannerFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws IOException { try { final InputStream bodyInputStream = requestContext.getEntityStream(); final ByteArrayOutputStream bout = new ByteArrayOutputStream(); StreamUtils.copy(bodyInputStream, bout); switch (this.dslSchema) { case SELECT_MULTIPLE: selectMultipleSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case SELECT_SINGLE: selectSingleSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case BATCH_PROCESSING: batchProcessingQuerySchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case GET_BY_ID: getByIdSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case UPDATE_BY_ID: updateByIdSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case RECLASSIFICATION_QUERY: updateQueryReclassificationSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case MASS_UPDATE: massUpdateSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; default: requestContext.abortWith( VitamCodeHelper.toVitamError(VitamCode.GLOBAL_INTERNAL_SERVER_ERROR, "Dsl schema is not valid.") .toResponse()); } requestContext.setEntityStream(new ByteArrayInputStream(bout.toByteArray())); } catch (ValidationException e) { LOGGER.warn(e); requestContext.abortWith( e.getVitamError().toResponse()); } catch (InvalidParseOperationException e) { LOGGER.warn(e); requestContext.abortWith( VitamCodeHelper.toVitamError(VitamCode.GLOBAL_INTERNAL_SERVER_ERROR, "Can not read Dsl query").toResponse()); } } DslScannerFilter(DslSchema dslSchema); @Override void filter(ContainerRequestContext requestContext); }
DslScannerFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws IOException { try { final InputStream bodyInputStream = requestContext.getEntityStream(); final ByteArrayOutputStream bout = new ByteArrayOutputStream(); StreamUtils.copy(bodyInputStream, bout); switch (this.dslSchema) { case SELECT_MULTIPLE: selectMultipleSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case SELECT_SINGLE: selectSingleSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case BATCH_PROCESSING: batchProcessingQuerySchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case GET_BY_ID: getByIdSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case UPDATE_BY_ID: updateByIdSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case RECLASSIFICATION_QUERY: updateQueryReclassificationSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; case MASS_UPDATE: massUpdateSchemaValidator.validate(JsonHandler.getFromBytes(bout.toByteArray())); break; default: requestContext.abortWith( VitamCodeHelper.toVitamError(VitamCode.GLOBAL_INTERNAL_SERVER_ERROR, "Dsl schema is not valid.") .toResponse()); } requestContext.setEntityStream(new ByteArrayInputStream(bout.toByteArray())); } catch (ValidationException e) { LOGGER.warn(e); requestContext.abortWith( e.getVitamError().toResponse()); } catch (InvalidParseOperationException e) { LOGGER.warn(e); requestContext.abortWith( VitamCodeHelper.toVitamError(VitamCode.GLOBAL_INTERNAL_SERVER_ERROR, "Can not read Dsl query").toResponse()); } } DslScannerFilter(DslSchema dslSchema); @Override void filter(ContainerRequestContext requestContext);  }