use of javax.ws.rs.core.StreamingOutput in project neo4j by neo4j.
the class TransactionalService method commitNewTransaction.
@POST
@Path("/commit")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Response commitNewTransaction(final InputStream input, @Context final UriInfo uriInfo, @Context final HttpServletRequest request) {
final TransactionHandle transactionHandle;
try {
SecurityContext securityContext = AuthorizedRequestWrapper.getSecurityContextFromHttpServletRequest(request);
long customTransactionTimeout = HttpHeaderUtils.getTransactionTimeout(request, log);
transactionHandle = facade.newTransactionHandle(uriScheme, true, securityContext, customTransactionTimeout);
} catch (TransactionLifecycleException e) {
return invalidTransaction(e, uriInfo.getBaseUri());
}
final StreamingOutput streamingResults = executeStatementsAndCommit(input, transactionHandle, uriInfo.getBaseUri(), request);
return okResponse(streamingResults);
}
use of javax.ws.rs.core.StreamingOutput in project neo4j by neo4j.
the class RepresentationFormatRepositoryTest method canProvideStreamingJsonOutputFormat.
@Test
public void canProvideStreamingJsonOutputFormat() throws Exception {
Response response = mock(Response.class);
final AtomicReference<StreamingOutput> ref = new AtomicReference<>();
final Response.ResponseBuilder responseBuilder = mockResponsBuilder(response, ref);
OutputFormat format = repository.outputFormat(asList(MediaType.APPLICATION_JSON_TYPE), null, streamingHeader());
assertNotNull(format);
Response returnedResponse = format.response(responseBuilder, new MapRepresentation(map("a", "test")));
assertSame(response, returnedResponse);
StreamingOutput streamingOutput = ref.get();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
streamingOutput.write(baos);
assertEquals("{\"a\":\"test\"}", baos.toString());
}
use of javax.ws.rs.core.StreamingOutput in project OpenClinica by OpenClinica.
the class OpenRosaServices method getMediaFile.
/**
* @api {get} /rest2/openrosa/:studyOID/downloadMedia Download media
* @apiName getMediaFile
* @apiPermission admin
* @apiVersion 3.8.0
* @apiParam {String} studyOID Study Oid.
* @apiGroup Form
* @apiDescription Downloads media associated with a form, including images and video.
*/
@GET
@Path("/{studyOID}/downloadMedia")
public Response getMediaFile(@Context HttpServletRequest request, @Context HttpServletResponse response, @PathParam("studyOID") String studyOID, @QueryParam("formLayoutMediaId") String formLayoutMediaId, @RequestHeader("Authorization") String authorization, @Context ServletContext context) throws Exception {
if (!mayProceedPreview(studyOID))
return null;
FormLayoutMedia media = formLayoutMediaDao.findById(Integer.valueOf(formLayoutMediaId));
File image = new File(Utils.getCrfMediaSysPath() + media.getPath() + media.getName());
FileInputStream fis = new FileInputStream(image);
StreamingOutput stream = new MediaStreamingOutput(fis);
ResponseBuilder builder = Response.ok(stream);
// Set content type, if known
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String type = fileNameMap.getContentTypeFor(media.getPath() + media.getName());
if (type != null && !type.isEmpty())
builder = builder.header("Content-Type", type);
return builder.build();
}
use of javax.ws.rs.core.StreamingOutput in project pulsar by yahoo.
the class AdminTest method brokerStats.
@Test
void brokerStats() throws Exception {
doReturn("client-id").when(brokerStats).clientAppId();
Collection<Metrics> metrics = brokerStats.getMetrics();
assertNotNull(metrics);
LoadReport loadReport = brokerStats.getLoadReport();
assertNotNull(loadReport);
assertEquals(loadReport.isOverLoaded(), false);
Collection<Metrics> mBeans = brokerStats.getMBeans();
assertTrue(!mBeans.isEmpty());
AllocatorStats allocatorStats = brokerStats.getAllocatorStats("default");
assertNotNull(allocatorStats);
Map<String, Map<String, PendingBookieOpsStats>> bookieOpsStats = brokerStats.getPendingBookieOpsStats();
assertTrue(bookieOpsStats.isEmpty());
StreamingOutput destination = brokerStats.getDestinations2();
assertNotNull(destination);
Map<Long, Collection<ResourceUnit>> resource = brokerStats.getBrokerResourceAvailability("prop", "use", "ns2");
// size should be 1 with default resourceUnit
assertTrue(resource.size() == 1);
}
use of javax.ws.rs.core.StreamingOutput in project ice by JBEI.
the class FileResource method getUploadCSV.
@GET
@Path("upload/{type}")
public Response getUploadCSV(@PathParam("type") final String type, @QueryParam("link") final String linkedType) {
EntryType entryAddType = EntryType.nameToType(type);
EntryType linked;
if (linkedType != null) {
linked = EntryType.nameToType(linkedType);
} else {
linked = null;
}
final StreamingOutput stream = output -> {
byte[] template = FileBulkUpload.getCSVTemplateBytes(entryAddType, linked, "existing".equalsIgnoreCase(linkedType));
ByteArrayInputStream input = new ByteArrayInputStream(template);
ByteStreams.copy(input, output);
};
String filename = type.toLowerCase();
if (linkedType != null) {
filename += ("_" + linkedType.toLowerCase());
}
return addHeaders(Response.ok(stream), filename + "_csv_upload.csv");
}
Aggregations