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 tika by apache.
the class TikaResource method produceText.
public StreamingOutput produceText(final InputStream is, MultivaluedMap<String, String> httpHeaders, final UriInfo info) {
final Parser parser = createParser();
final Metadata metadata = new Metadata();
final ParseContext context = new ParseContext();
fillMetadata(parser, metadata, context, httpHeaders);
fillParseContext(context, httpHeaders, parser);
logRequest(LOG, info, metadata);
return new StreamingOutput() {
public void write(OutputStream outputStream) throws IOException, WebApplicationException {
Writer writer = new OutputStreamWriter(outputStream, UTF_8);
BodyContentHandler body = new BodyContentHandler(new RichTextContentHandler(writer));
parse(parser, LOG, info.getPath(), is, body, metadata, context);
}
};
}
use of javax.ws.rs.core.StreamingOutput in project tika by apache.
the class TikaResource method produceTextMain.
public StreamingOutput produceTextMain(final InputStream is, @Context MultivaluedMap<String, String> httpHeaders, @Context final UriInfo info) {
final Parser parser = createParser();
final Metadata metadata = new Metadata();
final ParseContext context = new ParseContext();
fillMetadata(parser, metadata, context, httpHeaders);
fillParseContext(context, httpHeaders, parser);
logRequest(LOG, info, metadata);
return new StreamingOutput() {
public void write(OutputStream outputStream) throws IOException, WebApplicationException {
Writer writer = new OutputStreamWriter(outputStream, UTF_8);
ContentHandler handler = new BoilerpipeContentHandler(writer);
parse(parser, LOG, info.getPath(), is, handler, metadata, context);
}
};
}
use of javax.ws.rs.core.StreamingOutput in project nifi by apache.
the class ProvenanceEventResource method getInputContent.
/**
* Gets the content for the input of the specified event.
*
* @param clusterNodeId The id of the node within the cluster this content is on. Required if clustered.
* @param id The id of the provenance event associated with this content.
* @return The content stream
*/
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.WILDCARD)
@Path("{id}/content/input")
@ApiOperation(value = "Gets the input content for a provenance event", response = StreamingOutput.class, authorizations = { @Authorization(value = "Read Component Data - /data/{component-type}/{uuid}") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 404, message = "The specified resource could not be found."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response getInputContent(@ApiParam(value = "The id of the node where the content exists if clustered.", required = false) @QueryParam("clusterNodeId") final String clusterNodeId, @ApiParam(value = "The provenance event id.", required = true) @PathParam("id") final LongParameter id) {
// ensure proper input
if (id == null) {
throw new IllegalArgumentException("The event id must be specified.");
}
// replicate if cluster manager
if (isReplicateRequest()) {
// determine where this request should be sent
if (clusterNodeId == null) {
throw new IllegalArgumentException("The id of the node in the cluster is required.");
} else {
return replicate(HttpMethod.GET, clusterNodeId);
}
}
// get the uri of the request
final String uri = generateResourceUri("provenance", "events", String.valueOf(id.getLong()), "content", "input");
// get an input stream to the content
final DownloadableContent content = serviceFacade.getContent(id.getLong(), uri, ContentDirection.INPUT);
// generate a streaming response
final StreamingOutput response = new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
try (InputStream is = content.getContent()) {
// stream the content to the response
StreamUtils.copy(is, output);
// flush the response
output.flush();
}
}
};
// use the appropriate content type
String contentType = content.getType();
if (contentType == null) {
contentType = MediaType.APPLICATION_OCTET_STREAM;
}
return generateOkResponse(response).type(contentType).header("Content-Disposition", String.format("attachment; filename=\"%s\"", content.getFilename())).build();
}
use of javax.ws.rs.core.StreamingOutput in project pentaho-platform by pentaho.
the class FileServiceTest method testDoGetFileAsInline.
@Test
public void testDoGetFileAsInline() throws FileNotFoundException {
/*
* TEST 1
*/
doReturn(true).when(fileService).isPath(anyString());
doReturn(true).when(fileService).isPathValid(anyString());
RepositoryDownloadWhitelist mockWhiteList = mock(RepositoryDownloadWhitelist.class);
doReturn(mockWhiteList).when(fileService).getWhitelist();
doReturn(true).when(mockWhiteList).accept(anyString());
RepositoryFile mockRepoFile = mock(RepositoryFile.class);
doReturn(mockRepoFile).when(fileService.repository).getFile(anyString());
SimpleRepositoryFileData mockData = mock(SimpleRepositoryFileData.class);
doReturn(mockData).when(fileService.repository).getDataForRead(any(Serializable.class), any(Class.class));
InputStream mockInputStream = mock(InputStream.class);
doReturn(mockInputStream).when(mockData).getInputStream();
StreamingOutput mockStreamingOutput = mock(StreamingOutput.class);
doReturn(mockStreamingOutput).when(fileService).getStreamingOutput(mockInputStream);
FileService.RepositoryFileToStreamWrapper wrapper = fileService.doGetFileAsInline("test");
verify(fileService.repository, times(1)).getFile(anyString());
verify(mockWhiteList, times(1)).accept(anyString());
verify(fileService, times(2)).getRepository();
verify(fileService.repository, times(1)).getDataForRead(any(Serializable.class), any(Class.class));
verify(mockData, times(1)).getInputStream();
assertEquals(mockRepoFile, wrapper.getRepositoryFile());
assertEquals(mockStreamingOutput, wrapper.getOutputStream());
/*
* TEST 2
*/
doReturn(false).when(fileService).isPath(anyString());
doReturn(mockRepoFile).when(fileService.repository).getFileById(anyString());
wrapper = fileService.doGetFileAsInline("test");
verify(fileService.repository, times(1)).getFileById(anyString());
verify(fileService, times(4)).getRepository();
assertEquals(mockRepoFile, wrapper.getRepositoryFile());
assertEquals(mockStreamingOutput, wrapper.getOutputStream());
}
Aggregations