use of io.javalin.plugin.json.JavalinJackson in project cwms-radar-api by USACE.
the class CatalogControllerTest method catalog_returns_only_original_ids_by_default.
@Test
public void catalog_returns_only_original_ids_by_default() throws Exception {
CatalogController controller = new CatalogController(new MetricRegistry());
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = new TestHttpServletResponse();
HashMap<String, Object> attributes = new HashMap<>();
attributes.put(ContextUtil.maxRequestSizeKey, Integer.MAX_VALUE);
attributes.put(JsonMapperKt.JSON_MAPPER_KEY, new JavalinJackson());
attributes.put("PolicyFactory", this.sanitizer);
when(request.getInputStream()).thenReturn(new TestServletInputStream(""));
when(request.getAttribute("database")).thenReturn(this.conn);
when(request.getRequestURI()).thenReturn("/catalog/TIMESERIES");
when(request.getHeader(Header.ACCEPT)).thenReturn("application/json;version=2");
Context context = ContextUtil.init(request, response, "*", new HashMap<String, String>(), HandlerType.GET, attributes);
context.attribute("database", this.conn);
controller.getOne(context, CatalogableEndpoint.TIMESERIES.getValue());
assertEquals(HttpCode.OK.getStatus(), response.getStatus(), "200 OK was not returned");
assertNotNull(response.getOutputStream(), "Output stream wasn't created");
}
use of io.javalin.plugin.json.JavalinJackson in project javalin by tipsy.
the class ExampleController method main.
public static void main(String[] args) {
ObjectMapper objectMapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
OpenApiOptions openApiOptions = new OpenApiOptions(new Info().version("1.0").description("My Application")).activateAnnotationScanningFor("io.javalin.examples").path("/swagger-docs").swagger(new SwaggerOptions("/swagger").title("My Swagger Documentation")).reDoc(new ReDocOptions("/redoc", new RedocOptionsObject.Builder().setHideDownloadButton(true).setTheme(new RedocOptionsTheme.Builder().setSpacingUnit(10).setTypographyOptimizeSpeed(true).build()).build()).title("My ReDoc Documentation"));
Javalin app = Javalin.create(config -> {
config.registerPlugin(new OpenApiPlugin(openApiOptions));
config.jsonMapper(new JavalinJackson(objectMapper));
}).start(7070);
app.post("/users", ExampleController::create);
}
use of io.javalin.plugin.json.JavalinJackson in project javalin by tipsy.
the class JavalinConfig method applyUserConfig.
public static void applyUserConfig(Javalin app, JavalinConfig config, Consumer<JavalinConfig> userConfig) {
// apply user config to the default config
userConfig.accept(config);
AtomicBoolean anyHandlerAdded = new AtomicBoolean(false);
app.events(listener -> {
listener.handlerAdded(x -> anyHandlerAdded.set(true));
listener.wsHandlerAdded(x -> anyHandlerAdded.set(true));
});
config.getPluginsExtending(PluginLifecycleInit.class).forEach(plugin -> {
plugin.init(app);
if (anyHandlerAdded.get()) {
// check if any "init" added a handler
throw new PluginInitLifecycleViolationException(((Plugin) plugin).getClass());
}
});
config.inner.plugins.values().forEach(plugin -> plugin.apply(app));
if (config.enforceSsl) {
app.before(SecurityUtil::sslRedirect);
}
config.inner.appAttributes.putIfAbsent(JSON_MAPPER_KEY, new JavalinJackson());
app.attribute(maxRequestSizeKey, config.maxRequestSize);
config.inner.appAttributes.putIfAbsent(CONTEXT_RESOLVER_KEY, new ContextResolver());
}
use of io.javalin.plugin.json.JavalinJackson in project emfcloud-modelserver by eclipse-emfcloud.
the class ProviderDefaults method provideJavalin.
public static Javalin provideJavalin() {
return Javalin.create(config -> {
config.enableCorsForAllOrigins();
config.requestLogger((ctx, ms) -> {
String requestPath = ctx.path() + (ctx.queryString() == null ? "" : "?" + ctx.queryString());
LOG.info(ctx.method() + " " + requestPath + " -> Status: " + ctx.status() + " (took " + ms + " ms)");
});
config.asyncRequestTimeout = 5000L;
config.jsonMapper(new JavalinJackson(ProviderDefaults.provideObjectMapper()));
config.wsLogger(ws -> {
ws.onConnect(ctx -> LOG.info("WS Connected: " + ctx.getSessionId()));
ws.onMessage(ctx -> LOG.info("WS Received: " + ctx.message() + " by " + ctx.getSessionId()));
ws.onClose(ctx -> LOG.info("WS Closed: " + ctx.getSessionId()));
ws.onError(ctx -> LOG.info("WS Errored: " + ctx.getSessionId()));
});
if (ProviderDefaults.isDevLoggingEnabled) {
config.enableDevLogging();
}
});
}
use of io.javalin.plugin.json.JavalinJackson in project okaeri-platform by OkaeriPoland.
the class JavalinSetupTask method execute.
@Override
public void execute(OkaeriWebApplication platform) {
// basic setup
JavalinConfig.applyUserConfig(platform.getJavalin(), platform.getJavalin()._conf, config -> {
// simple properties
config.showJavalinBanner = false;
// json mapper
JsonMapper jsonMapper = new JsonMapper();
jsonMapper.addMixIn(Document.class, DocumentMixIn.class);
jsonMapper.addMixIn(OkaeriConfig.class, OkaeriConfigMixIn.class);
config.jsonMapper(new JavalinJackson(jsonMapper));
// access manager
config.accessManager(platform.getInjector().getExact("accessManager", AccessManager.class).orElse(new FallbackAccessManager()));
});
// custom setup routine
platform.getInjector().getExact("javalinConfigurer", Consumer.class).ifPresent(configurer -> {
@SuppressWarnings("unchecked") Consumer<JavalinConfig> javalinConfigurer = (Consumer<JavalinConfig>) configurer;
JavalinConfig.applyUserConfig(platform.getJavalin(), platform.getJavalin()._conf, javalinConfigurer);
});
}
Aggregations