use of javax.ws.rs.ext.Providers in project jersey by jersey.
the class JaxrsProvidersTest method testProviders.
@Test
public void testProviders() throws Exception {
final InjectionManager injectionManager = Injections.createInjectionManager(new MessagingBinders.MessageBodyProviders(null, RuntimeType.SERVER), new Binder());
injectionManager.register(new TestBinder(injectionManager));
TestBinder.initProviders(injectionManager);
RequestScope scope = injectionManager.getInstance(RequestScope.class);
scope.runInScope(new Callable<Object>() {
@Override
public Object call() throws Exception {
Providers instance = injectionManager.getInstance(Providers.class);
assertNotNull(instance);
assertSame(JaxrsProviders.class, instance.getClass());
assertNotNull(instance.getExceptionMapper(Throwable.class));
assertNotNull(instance.getMessageBodyReader(String.class, String.class, new Annotation[0], MediaType.TEXT_PLAIN_TYPE));
assertNotNull(instance.getMessageBodyWriter(String.class, String.class, new Annotation[0], MediaType.TEXT_PLAIN_TYPE));
assertNotNull(instance.getContextResolver(String.class, MediaType.TEXT_PLAIN_TYPE));
return null;
}
});
}
use of javax.ws.rs.ext.Providers in project component-runtime by Talend.
the class ExecutionResource method read.
/**
* Read inputs from an instance of mapper. The number of returned records if enforced to be limited to 1000.
* The format is a JSON based format where each like is a json record.
*
* @param family the component family.
* @param component the component name.
* @param size the maximum number of records to read.
* @param configuration the component configuration as key/values.
*/
@POST
@Deprecated
@Produces("talend/stream")
@Path("read/{family}/{component}")
public void read(@Suspended final AsyncResponse response, @Context final Providers providers, @PathParam("family") final String family, @PathParam("component") final String component, @QueryParam("size") @DefaultValue("50") final long size, final Map<String, String> configuration) {
final long maxSize = Math.min(size, MAX_RECORDS);
response.setTimeoutHandler(asyncResponse -> log.warn("Timeout on dataset retrieval"));
response.setTimeout(appConfiguration.datasetRetrieverTimeout(), SECONDS);
executorService.submit(() -> {
final Optional<Mapper> mapperOptional = manager.findMapper(family, component, getConfigComponentVersion(configuration), configuration);
if (!mapperOptional.isPresent()) {
response.resume(new WebApplicationException(Response.status(BAD_REQUEST).entity(new ErrorPayload(COMPONENT_MISSING, "Didn't find the input component")).build()));
return;
}
final Mapper mapper = mapperOptional.get();
mapper.start();
try {
final Input input = mapper.create();
try {
input.start();
response.resume((StreamingOutput) output -> {
Object data;
int current = 0;
while (current++ < maxSize && (data = input.next()) != null) {
if (CharSequence.class.isInstance(data) || Number.class.isInstance(data) || Boolean.class.isInstance(data)) {
final PrimitiveWrapper wrapper = new PrimitiveWrapper();
wrapper.setValue(data);
data = wrapper;
}
inlineStreamingMapper.toJson(data, output);
output.write(EOL);
}
});
} finally {
input.stop();
}
} finally {
mapper.stop();
}
});
}
use of javax.ws.rs.ext.Providers in project activemq-artemis by apache.
the class ActiveMQ method getEntity.
public static <T> T getEntity(ClientMessage msg, Class<T> type, Type genericType, ResteasyProviderFactory factory) {
int size = msg.getBodySize();
if (size <= 0)
return null;
byte[] body = new byte[size];
msg.getBodyBuffer().readBytes(body);
String contentType = msg.getStringProperty(HttpHeaderProperty.CONTENT_TYPE);
if (contentType == null) {
throw new UnknownMediaType("Message did not have a Content-Type header cannot extract entity");
}
MediaType ct = MediaType.valueOf(contentType);
MessageBodyReader<T> reader = factory.getMessageBodyReader(type, genericType, null, ct);
if (reader == null) {
throw new UnmarshalException("Unable to find a JAX-RS reader for type " + type.getName() + " and media type " + contentType);
}
Providers current = ResteasyProviderFactory.getContextData(Providers.class);
ResteasyProviderFactory.pushContext(Providers.class, factory);
try {
return reader.readFrom(type, genericType, null, ct, new Headers<String>(), new ByteArrayInputStream(body));
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
ResteasyProviderFactory.popContextData(Providers.class);
if (current != null)
ResteasyProviderFactory.pushContext(Providers.class, current);
}
}
use of javax.ws.rs.ext.Providers in project cloudbreak by hortonworks.
the class SearchCauseExceptionMapperTest method setup.
@BeforeEach
public void setup() {
List<ServiceHolder<ExceptionMapper>> ret = exceptionMappers.stream().map(em -> new ServiceHolderImpl<>(em, emptySet())).collect(toList());
Mockito.when(injectionManager.getAllServiceHolders(ExceptionMapper.class)).thenReturn(ret);
Provider<ExceptionMappers> mappers = () -> new ExceptionMapperFactory(injectionManager);
Providers providers = new JaxrsProviders();
ReflectionTestUtils.setField(providers, "mappers", mappers);
ReflectionTestUtils.setField(underTest, "providers", providers);
}
use of javax.ws.rs.ext.Providers in project component-runtime by Talend.
the class ProjectResource method createOpenAPIZip.
@POST
@Path("openapi/zip/form")
@Produces("application/zip")
public Response createOpenAPIZip(@FormParam("project") final String compressedModel, @Context final Providers providers) {
final ProjectModel model = readProjectModel(compressedModel, providers);
final String filename = ofNullable(model.getArtifact()).orElse("zip") + ".zip";
return Response.ok().entity((StreamingOutput) out -> {
generator.generateFromOpenAPI(toRequest(model), out);
out.flush();
}).header("Content-Disposition", "inline; filename=" + filename).build();
}
Aggregations