Search in sources :

Example 16 with StreamingOutput

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);
}
Also used : TransactionHandle(org.neo4j.server.rest.transactional.TransactionHandle) SecurityContext(org.neo4j.kernel.api.security.SecurityContext) StreamingOutput(javax.ws.rs.core.StreamingOutput) TransactionLifecycleException(org.neo4j.server.rest.transactional.error.TransactionLifecycleException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 17 with StreamingOutput

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());
}
Also used : Response(javax.ws.rs.core.Response) AtomicReference(java.util.concurrent.atomic.AtomicReference) StreamingOutput(javax.ws.rs.core.StreamingOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 18 with StreamingOutput

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();
}
Also used : FormLayoutMedia(org.akaza.openclinica.domain.datamap.FormLayoutMedia) StreamingOutput(javax.ws.rs.core.StreamingOutput) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) FileNameMap(java.net.FileNameMap) MediaFile(org.akaza.openclinica.web.pform.manifest.MediaFile) File(java.io.File) FileInputStream(java.io.FileInputStream) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 19 with StreamingOutput

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);
}
Also used : Metrics(com.yahoo.pulsar.broker.stats.Metrics) LoadReport(com.yahoo.pulsar.common.policies.data.loadbalancer.LoadReport) AllocatorStats(com.yahoo.pulsar.common.stats.AllocatorStats) Collection(java.util.Collection) StreamingOutput(javax.ws.rs.core.StreamingOutput) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 20 with StreamingOutput

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");
}
Also used : RemoteSequence(org.jbei.ice.lib.net.RemoteSequence) AttachmentInfo(org.jbei.ice.lib.dto.entry.AttachmentInfo) FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence) Setting(org.jbei.ice.lib.dto.Setting) SequenceAnalysisController(org.jbei.ice.lib.entry.sequence.SequenceAnalysisController) ConfigurationKey(org.jbei.ice.lib.dto.ConfigurationKey) EntryField(org.jbei.ice.lib.dto.entry.EntryField) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Entries(org.jbei.ice.lib.entry.Entries) Sequence(org.jbei.ice.storage.model.Sequence) MediaType(javax.ws.rs.core.MediaType) ConfigurationController(org.jbei.ice.lib.config.ConfigurationController) DAOFactory(org.jbei.ice.storage.DAOFactory) Logger(org.jbei.ice.lib.common.logging.Logger) FileBulkUpload(org.jbei.ice.lib.bulkupload.FileBulkUpload) SequenceInfo(org.jbei.ice.lib.dto.entry.SequenceInfo) PigeonSBOLv(org.jbei.ice.lib.entry.sequence.composers.pigeon.PigeonSBOLv) Entry(org.jbei.ice.storage.model.Entry) EntryType(org.jbei.ice.lib.dto.entry.EntryType) URI(java.net.URI) Utils(org.jbei.ice.lib.utils.Utils) AttachmentController(org.jbei.ice.lib.entry.attachment.AttachmentController) EntrySelection(org.jbei.ice.lib.entry.EntrySelection) FileUtils(org.apache.commons.io.FileUtils) StreamingOutput(javax.ws.rs.core.StreamingOutput) SequenceController(org.jbei.ice.lib.entry.sequence.SequenceController) Collectors(java.util.stream.Collectors) RemoteEntries(org.jbei.ice.lib.net.RemoteEntries) FormDataParam(org.glassfish.jersey.media.multipart.FormDataParam) List(java.util.List) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) java.io(java.io) Paths(java.nio.file.Paths) ByteStreams(com.google.common.io.ByteStreams) ByteArrayWrapper(org.jbei.ice.lib.entry.sequence.ByteArrayWrapper) ShotgunSequenceDAO(org.jbei.ice.storage.hibernate.dao.ShotgunSequenceDAO) TraceSequence(org.jbei.ice.storage.model.TraceSequence) EntriesAsCSV(org.jbei.ice.lib.entry.EntriesAsCSV) ShotgunSequence(org.jbei.ice.storage.model.ShotgunSequence) EntryType(org.jbei.ice.lib.dto.entry.EntryType) StreamingOutput(javax.ws.rs.core.StreamingOutput)

Aggregations

StreamingOutput (javax.ws.rs.core.StreamingOutput)23 OutputStream (java.io.OutputStream)13 IOException (java.io.IOException)8 Path (javax.ws.rs.Path)7 Produces (javax.ws.rs.Produces)7 WebApplicationException (javax.ws.rs.WebApplicationException)7 Response (javax.ws.rs.core.Response)6 GET (javax.ws.rs.GET)5 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)4 Consumes (javax.ws.rs.Consumes)4 POST (javax.ws.rs.POST)4 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)4 QueryInterruptedException (io.druid.query.QueryInterruptedException)3 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 ByteStreams (com.google.common.io.ByteStreams)2 ISE (io.druid.java.util.common.ISE)2 Writer (java.io.Writer)2