Search in sources :

Example 1 with JSONPObject

use of com.fasterxml.jackson.databind.util.JSONPObject in project metrics by dropwizard.

the class MetricsServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType(CONTENT_TYPE);
    if (allowedOrigin != null) {
        resp.setHeader("Access-Control-Allow-Origin", allowedOrigin);
    }
    resp.setHeader("Cache-Control", "must-revalidate,no-cache,no-store");
    resp.setStatus(HttpServletResponse.SC_OK);
    final OutputStream output = resp.getOutputStream();
    try {
        if (jsonpParamName != null && req.getParameter(jsonpParamName) != null) {
            getWriter(req).writeValue(output, new JSONPObject(req.getParameter(jsonpParamName), registry));
        } else {
            getWriter(req).writeValue(output, registry);
        }
    } finally {
        output.close();
    }
}
Also used : OutputStream(java.io.OutputStream) JSONPObject(com.fasterxml.jackson.databind.util.JSONPObject)

Example 2 with JSONPObject

use of com.fasterxml.jackson.databind.util.JSONPObject in project ninja by ninjaframework.

the class TemplateEngineJsonP method invoke.

@Override
public void invoke(Context context, Result result) {
    ResponseStreams responseStreams = context.finalizeHeaders(result);
    String callback = getCallbackName(context);
    try (OutputStream outputStream = responseStreams.getOutputStream()) {
        objectMapper.writeValue(outputStream, new JSONPObject(callback, result.getRenderable()));
    } catch (IOException e) {
        logger.error("Error while rendering jsonp.", e);
    }
}
Also used : ResponseStreams(ninja.utils.ResponseStreams) OutputStream(java.io.OutputStream) JSONPObject(com.fasterxml.jackson.databind.util.JSONPObject) IOException(java.io.IOException)

Example 3 with JSONPObject

use of com.fasterxml.jackson.databind.util.JSONPObject in project jackson-databind by FasterXML.

the class TestJSONP method testWithType.

/**
     * Test to ensure that it is possible to force a static type for wrapped
     * value.
     */
public void testWithType() throws Exception {
    Object ob = new Impl("abc", "def");
    JavaType type = MAPPER.constructType(Base.class);
    assertEquals("do({\"a\":\"abc\"})", MAPPER.writeValueAsString(new JSONPObject("do", ob, type)));
}
Also used : JSONPObject(com.fasterxml.jackson.databind.util.JSONPObject) JSONWrappedObject(com.fasterxml.jackson.databind.util.JSONWrappedObject) JSONPObject(com.fasterxml.jackson.databind.util.JSONPObject)

Aggregations

JSONPObject (com.fasterxml.jackson.databind.util.JSONPObject)3 OutputStream (java.io.OutputStream)2 JSONWrappedObject (com.fasterxml.jackson.databind.util.JSONWrappedObject)1 IOException (java.io.IOException)1 ResponseStreams (ninja.utils.ResponseStreams)1