use of javax.json.spi.JsonProvider in project javaee7-firstcup by ecabrerar.
the class DeviceSessionHandler method removeDevice.
public void removeDevice(int id) {
Device device = getDeviceById(id);
if (device != null) {
devices.remove(device);
JsonProvider provider = JsonProvider.provider();
JsonObject removeMessage = provider.createObjectBuilder().add("action", "remove").add("id", id).build();
sendToAllConnectedSessions(removeMessage);
}
}
use of javax.json.spi.JsonProvider in project javaee7-firstcup by ecabrerar.
the class DeviceSessionHandler method createAddMessage.
private JsonObject createAddMessage(Device device) {
JsonProvider provider = JsonProvider.provider();
JsonObject addMessage = provider.createObjectBuilder().add("action", "add").add("id", device.getId()).add("name", device.getName()).add("type", device.getType()).add("status", device.getStatus()).add("description", device.getDescription()).build();
return addMessage;
}
use of javax.json.spi.JsonProvider in project meecrowave by apache.
the class ConfigurableBus method initProviders.
public void initProviders(final Configuration builder, final ClassLoader loader) {
final List<Object> providers = ofNullable(builder.getJaxrsDefaultProviders()).map(s -> Stream.of(s.split(" *, *")).map(String::trim).filter(p -> !p.isEmpty()).map(name -> {
try {
return Thread.currentThread().getContextClassLoader().loadClass(name).newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new IllegalArgumentException(name + " can't be created");
}
}).collect(Collectors.<Object>toList())).orElseGet(() -> {
// ensure both providers share the same memory reuse logic
final JsonProvider provider = JsonProvider.provider();
final JsonReaderFactory readerFactory = provider.createReaderFactory(new HashMap<String, Object>() {
{
put(JsonParserFactoryImpl.SUPPORTS_COMMENTS, builder.isJsonpSupportsComment());
Optional.of(builder.getJsonpMaxStringLen()).filter(v -> v > 0).ifPresent(s -> put(JsonParserFactoryImpl.MAX_STRING_LENGTH, s));
Optional.of(builder.getJsonpMaxReadBufferLen()).filter(v -> v > 0).ifPresent(s -> put(JsonParserFactoryImpl.BUFFER_LENGTH, s));
ofNullable(builder.getJsonpBufferStrategy()).ifPresent(s -> put(AbstractJsonFactory.BUFFER_STRATEGY, s));
}
});
final JsonWriterFactory writerFactory = provider.createWriterFactory(new HashMap<String, Object>() {
{
put(JsonGenerator.PRETTY_PRINTING, builder.isJsonpPrettify());
Optional.of(builder.getJsonpMaxWriteBufferLen()).filter(v -> v > 0).ifPresent(v -> put(JsonGeneratorFactoryImpl.GENERATOR_BUFFER_LENGTH, v));
ofNullable(builder.getJsonpBufferStrategy()).ifPresent(s -> put(AbstractJsonFactory.BUFFER_STRATEGY, s));
}
});
return Stream.<Object>of(new ConfiguredJsonbJaxrsProvider(builder.getJsonbEncoding(), builder.isJsonbNulls(), builder.isJsonbIJson(), builder.isJsonbPrettify(), builder.getJsonbBinaryStrategy(), builder.getJsonbNamingStrategy(), builder.getJsonbOrderStrategy(), new DelegateJsonProvider(provider, readerFactory, writerFactory))).collect(toList());
});
if (builder.isJaxrsAutoActivateBeanValidation()) {
try {
// we don't need the jaxrsbeanvalidationfeature since bean validation cdi extension handles it normally
loader.loadClass("javax.validation.Validation");
final Object instance = loader.loadClass("org.apache.cxf.jaxrs.validation.ValidationExceptionMapper").getConstructor().newInstance();
// validate bval can be used, check NoClassDefFoundError javax.validation.ValidationException
instance.getClass().getGenericInterfaces();
providers.add(instance);
} catch (final Exception | NoClassDefFoundError e) {
// no-op
}
}
// client
if (getProperty("org.apache.cxf.jaxrs.bus.providers") == null) {
setProperty("skip.default.json.provider.registration", "true");
setProperty("org.apache.cxf.jaxrs.bus.providers", providers);
}
}
use of javax.json.spi.JsonProvider in project meecrowave by apache.
the class ConfigurableBus method initProviders.
public void initProviders(final Meecrowave.Builder builder, final ClassLoader loader) {
final List<Object> providers = ofNullable(builder.getJaxrsDefaultProviders()).map(s -> Stream.of(s.split(" *, *")).map(String::trim).filter(p -> !p.isEmpty()).map(name -> {
try {
return Thread.currentThread().getContextClassLoader().loadClass(name).newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new IllegalArgumentException(name + " can't be created");
}
}).collect(Collectors.<Object>toList())).orElseGet(() -> {
// ensure both providers share the same memory reuse logic
final JsonProvider provider = JsonProvider.provider();
final JsonReaderFactory readerFactory = provider.createReaderFactory(new HashMap<String, Object>() {
{
put(JsonParserFactoryImpl.SUPPORTS_COMMENTS, builder.isJsonpSupportsComment());
of(builder.getJsonpMaxStringLen()).filter(v -> v > 0).ifPresent(s -> put(JsonParserFactoryImpl.MAX_STRING_LENGTH, s));
of(builder.getJsonpMaxReadBufferLen()).filter(v -> v > 0).ifPresent(s -> put(JsonParserFactoryImpl.BUFFER_LENGTH, s));
ofNullable(builder.getJsonpBufferStrategy()).ifPresent(s -> put(AbstractJsonFactory.BUFFER_STRATEGY, s));
}
});
final JsonWriterFactory writerFactory = provider.createWriterFactory(new HashMap<String, Object>() {
{
put(JsonGenerator.PRETTY_PRINTING, builder.isJsonpPrettify());
of(builder.getJsonpMaxWriteBufferLen()).filter(v -> v > 0).ifPresent(v -> put(JsonGeneratorFactoryImpl.GENERATOR_BUFFER_LENGTH, v));
ofNullable(builder.getJsonpBufferStrategy()).ifPresent(s -> put(AbstractJsonFactory.BUFFER_STRATEGY, s));
}
});
return Stream.<Object>of(new ConfiguredJsonbJaxrsProvider(builder.getJsonbEncoding(), builder.isJsonbNulls(), builder.isJsonbIJson(), builder.isJsonbPrettify(), builder.getJsonbBinaryStrategy(), builder.getJsonbNamingStrategy(), builder.getJsonbOrderStrategy(), new DelegateJsonProvider(provider, readerFactory, writerFactory)), new ConfiguredJsrProvider(readerFactory, writerFactory)).collect(toList());
});
if (builder.isJaxrsAutoActivateBeanValidation()) {
try {
// we don't need the jaxrsbeanvalidationfeature since bean validation cdi extension handles it normally
loader.loadClass("javax.validation.Validation");
final Object instance = loader.loadClass("org.apache.cxf.jaxrs.validation.ValidationExceptionMapper").getConstructor().newInstance();
// validate bval can be used, check NoClassDefFoundError javax.validation.ValidationException
instance.getClass().getGenericInterfaces();
providers.add(instance);
} catch (final Exception | NoClassDefFoundError e) {
// no-op
}
}
// client
if (getProperty("org.apache.cxf.jaxrs.bus.providers") == null) {
setProperty("skip.default.json.provider.registration", "true");
setProperty("org.apache.cxf.jaxrs.bus.providers", providers);
}
}
use of javax.json.spi.JsonProvider in project jaqy by Teradata.
the class JsonExporter method export.
@Override
public long export(JaqyResultSet rs, JaqyInterpreter interpreter) throws Exception {
JsonProvider provider = new CookJsonProvider();
CookJsonGenerator g = null;
HashMap<String, Object> config = new HashMap<String, Object>();
switch(m_format) {
case Text:
{
config.put(CookJsonProvider.FORMAT, CookJsonProvider.FORMAT_JSON);
if (m_pretty)
config.put(JsonGenerator.PRETTY_PRINTING, Boolean.TRUE);
switch(m_binaryFormat) {
case Base64:
config.put(CookJsonProvider.BINARY_FORMAT, CookJsonProvider.BINARY_FORMAT_BASE64);
break;
case Hex:
config.put(CookJsonProvider.BINARY_FORMAT, CookJsonProvider.BINARY_FORMAT_HEX);
break;
}
g = (CookJsonGenerator) provider.createGeneratorFactory(config).createGenerator(m_out);
break;
}
case Bson:
config.put(CookJsonProvider.FORMAT, CookJsonProvider.FORMAT_BSON);
g = (CookJsonGenerator) provider.createGeneratorFactory(config).createGenerator(m_os);
break;
}
long count = JsonUtils.print(interpreter.getGlobals(), g, rs, 0);
g.close();
return count;
}
Aggregations