use of org.springframework.http.ResponseEntity in project nikita-noark5-core by HiOA-ABI.
the class DocumentObjectHateoasController method handleFileUpload.
// API - All POST Requests (CRUD - CREATE)
// upload a file and associate it with a documentObject
// POST [contextPath][api]/arkivstruktur/dokumentobjekt/{systemID}/referanseFil
@ApiOperation(value = "Uploads a file and associates it with the documentObject identified by a systemId", response = DocumentObjectHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "File uploaded successfully", response = DocumentObjectHateoas.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + REFERENCE_FILE, method = RequestMethod.POST, headers = "Accept=*/*", produces = { NOARK5_V4_CONTENT_TYPE_JSON, NOARK5_V4_CONTENT_TYPE_JSON_XML })
public ResponseEntity<DocumentObjectHateoas> handleFileUpload(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the documentObject you wish to associate a file with", required = true) @PathVariable("systemID") final String documentObjectSystemId) {
try {
DocumentObject documentObject = documentObjectService.findBySystemIdOrderBySystemId(documentObjectSystemId);
if (documentObject == null) {
throw new NoarkEntityNotFoundException(documentObjectSystemId);
}
InputStream inputStream;
// Following will be needed for uploading file in chunks
//String headerContentRange = request.getHeader("content-range");//Content-Range:bytes 737280-819199/845769
// Check that content-length is set, > 0 and in agreement with the value set in documentObject
Long contentLength = 0L;
if (request.getHeader("content-length") == null) {
throw new StorageException("Attempt to upload a document without content-length set. The document " + "was attempted to be associated with " + documentObject);
}
contentLength = (long) request.getIntHeader("content-length");
if (contentLength < 1) {
throw new StorageException("Attempt to upload a document with 0 or negative content-length set. " + "Actual value was (" + contentLength + "). The document was attempted to be associated with " + documentObject);
}
if (null == documentObject.getFileSize()) {
throw new StorageException("Attempt to upload a document with a content-length set in the header (" + contentLength + "), but the value in documentObject has not been set (== null). The " + "document was attempted to be associated with " + documentObject);
}
if (!contentLength.equals(documentObject.getFileSize())) {
throw new StorageException("Attempt to upload a document with a content-length set in the header (" + contentLength + ") that is not the same as the value in documentObject (" + documentObject.getFileSize() + "). The document was attempted to be associated with " + documentObject);
}
// Check that the content-type is set and in agreement with mimeType value in documentObject
String headerContentType = request.getHeader("content-type");
if (headerContentType == null) {
throw new StorageException("Attempt to upload a document without content-type set. The document " + "was attempted to be associated with " + documentObject);
}
if (!headerContentType.equals(documentObject.getMimeType())) {
throw new StorageException("Attempt to upload a document with a content-type set in the header (" + contentLength + ") that is not the same as the mimeType in documentObject (" + documentObject.getMimeType() + "). The document was attempted to be associated with " + documentObject);
}
documentObjectService.storeAndCalculateChecksum(request.getInputStream(), documentObject);
// We need to update the documentObject in the database as checksum and checksum algorithm are set after
// the document has been uploaded
documentObjectService.update(documentObject);
DocumentObjectHateoas documentObjectHateoas = new DocumentObjectHateoas(documentObject);
documentObjectHateoasHandler.addLinks(documentObjectHateoas, request, new Authorisation());
return new ResponseEntity<>(documentObjectHateoas, HttpStatus.OK);
} catch (IOException e) {
throw new StorageException(e.toString());
}
}
use of org.springframework.http.ResponseEntity in project sic by belluccifranco.
the class PedidoController method getReportePedido.
@GetMapping("/pedidos/{idPedido}/reporte")
public ResponseEntity<byte[]> getReportePedido(@PathVariable long idPedido) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_PDF);
headers.add("content-disposition", "inline; filename=Pedido.pdf");
headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
byte[] reportePDF = pedidoService.getReportePedido(pedidoService.getPedidoPorId(idPedido));
return new ResponseEntity<>(reportePDF, headers, HttpStatus.OK);
}
use of org.springframework.http.ResponseEntity in project vulnmanager by xebia-research.
the class NMapController method getNMapReport.
@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseBody
ResponseEntity<?> getNMapReport(@ModelAttribute("isAuthenticated") boolean isAuthenticated) {
if (!isAuthenticated) {
return new ResponseEntity(new ErrorMsg("Auth not correct!"), HttpStatus.BAD_REQUEST);
}
Object parsedDocument = ReportUtil.parseDocument(ReportUtil.getDocumentFromFile(new File("example_logs/nmap.xml")));
NMapReport report = getNMapReportFromObject(parsedDocument);
if (report == null) {
return new ResponseEntity<>(new ErrorMsg("The file requested is not of the right type"), HttpStatus.BAD_REQUEST);
}
return new ResponseEntity<>(report, HttpStatus.OK);
}
use of org.springframework.http.ResponseEntity in project nikita-noark5-core by HiOA-ABI.
the class DocumentObjectHateoasController method handleFileUpload.
// API - All POST Requests (CRUD - CREATE)
// upload a file and associate it with a documentObject
// POST [contextPath][api]/arkivstruktur/dokumentobjekt/{systemID}/referanseFil
@ApiOperation(value = "Uploads a file and associates it with the documentObject identified by a systemId", response = DocumentObjectHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "File uploaded successfully", response = DocumentObjectHateoas.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + REFERENCE_FILE, method = RequestMethod.POST, headers = "Accept=*/*", produces = { NOARK5_V4_CONTENT_TYPE_JSON, NOARK5_V4_CONTENT_TYPE_JSON_XML })
public ResponseEntity<DocumentObjectHateoas> handleFileUpload(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the documentObject you wish to associate a file with", required = true) @PathVariable("systemID") final String documentObjectSystemId) {
try {
DocumentObject documentObject = documentObjectService.findBySystemId(documentObjectSystemId);
if (documentObject == null) {
throw new NoarkEntityNotFoundException(documentObjectSystemId);
}
InputStream inputStream;
// Following will be needed for uploading file in chunks
// String headerContentRange = request.getHeader("content-range");//Content-Range:bytes 737280-819199/845769
// Check that content-length is set, > 0 and in agreement with the value set in documentObject
Long contentLength = 0L;
if (request.getHeader("content-length") == null) {
throw new StorageException("Attempt to upload a document without content-length set. The document " + "was attempted to be associated with " + documentObject);
}
contentLength = (long) request.getIntHeader("content-length");
if (contentLength < 1) {
throw new StorageException("Attempt to upload a document with 0 or negative content-length set. " + "Actual value was (" + contentLength + "). The document was attempted to be associated with " + documentObject);
}
if (null == documentObject.getFileSize()) {
throw new StorageException("Attempt to upload a document with a content-length set in the header (" + contentLength + "), but the value in documentObject has not been set (== null). The " + "document was attempted to be associated with " + documentObject);
}
if (!contentLength.equals(documentObject.getFileSize())) {
throw new StorageException("Attempt to upload a document with a content-length set in the header (" + contentLength + ") that is not the same as the value in documentObject (" + documentObject.getFileSize() + "). The document was attempted to be associated with " + documentObject);
}
// Check that the content-type is set and in agreement with mimeType value in documentObject
String headerContentType = request.getHeader("content-type");
if (headerContentType == null) {
throw new StorageException("Attempt to upload a document without content-type set. The document " + "was attempted to be associated with " + documentObject);
}
if (!headerContentType.equals(documentObject.getMimeType())) {
throw new StorageException("Attempt to upload a document with a content-type set in the header (" + contentLength + ") that is not the same as the mimeType in documentObject (" + documentObject.getMimeType() + "). The document was attempted to be associated with " + documentObject);
}
documentObjectService.storeAndCalculateChecksum(request.getInputStream(), documentObject);
// We need to update the documentObject in the database as checksum and checksum algorithm are set after
// the document has been uploaded
documentObjectService.update(documentObject);
DocumentObjectHateoas documentObjectHateoas = new DocumentObjectHateoas(documentObject);
documentObjectHateoasHandler.addLinks(documentObjectHateoas, new Authorisation());
return new ResponseEntity<>(documentObjectHateoas, HttpStatus.OK);
} catch (IOException e) {
throw new StorageException(e.toString());
}
}
use of org.springframework.http.ResponseEntity in project cas by apereo.
the class Saml2ClientMetadataController method getSaml2ClientServiceProviderMetadataResponseEntity.
private ResponseEntity<String> getSaml2ClientServiceProviderMetadataResponseEntity(final SAML2Client saml2Client) {
final HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_XML);
return new ResponseEntity<>(saml2Client.getServiceProviderMetadataResolver().getMetadata(), headers, HttpStatus.OK);
}
Aggregations