Search in sources :

Example 31 with JsonGenerationException

use of org.codehaus.jackson.JsonGenerationException in project onebusaway-application-modules by camsys.

the class KeysResource method deleteKey.

@Path("/delete/{keyValue}")
@GET
@Produces("application/json")
public Response deleteKey(@PathParam("keyValue") String keyValue) throws JsonGenerationException, JsonMappingException, IOException {
    log.info("Starting deleteKey with parameter " + keyValue);
    String message = "API Key deleted: " + keyValue;
    try {
        validateSecurity();
        delete(keyValue);
    } catch (Exception e) {
        log.error(e.getMessage());
        message = "Failed to delete key: " + e.getMessage();
    }
    Response response = constructResponse(message);
    log.info("Returning deleteKey result.");
    return response;
}
Also used : Response(javax.ws.rs.core.Response) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 32 with JsonGenerationException

use of org.codehaus.jackson.JsonGenerationException in project onebusaway-application-modules by camsys.

the class KeysResource method listKeys.

@Path("/list")
@GET
@Produces("application/json")
public Response listKeys() throws JsonGenerationException, JsonMappingException, IOException {
    log.info("Starting listKeys");
    try {
        validateSecurity();
        List<String> apiKeys = _userService.getUserIndexKeyValuesForKeyType(UserIndexTypes.API_KEY);
        Response response = constructResponse(apiKeys);
        log.info("Returning response from listKeys");
        return response;
    } catch (Exception e) {
        log.error(e.getMessage());
        throw new WebApplicationException(e, Response.serverError().build());
    }
}
Also used : Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 33 with JsonGenerationException

use of org.codehaus.jackson.JsonGenerationException in project databus by linkedin.

the class DbusEventAvroDecoder method dumpEventValueInJSON.

public void dumpEventValueInJSON(DbusEvent e, OutputStream out) {
    byte[] md5 = new byte[16];
    e.schemaId(md5);
    SchemaId schemaId = new SchemaId(md5);
    VersionedSchema sourceSchema = _schemaSet.getById(schemaId);
    ByteBuffer valueBuffer = e.value();
    byte[] valueBytes = new byte[valueBuffer.remaining()];
    valueBuffer.get(valueBytes);
    try {
        Schema schema = sourceSchema.getSchema();
        DatumReader<Object> reader = new GenericDatumReader<Object>(schema);
        binDecoder.set(DecoderFactory.defaultFactory().createBinaryDecoder(valueBytes, binDecoder.get()));
        Object datum = reader.read(null, binDecoder.get());
        DatumWriter<Object> writer = new GenericDatumWriter<Object>(schema);
        JsonGenerator g = new JsonFactory().createJsonGenerator(out, JsonEncoding.UTF8);
        // write the src ID
        g.writeStartObject();
        g.writeFieldName(SRC_ID_FIELD_NAME);
        g.writeNumber(e.getSourceId());
        g.writeFieldName(OPCODE_FIELD_NAME);
        g.writeString(e.getOpcode().toString());
        g.writeFieldName("partId");
        g.writeNumber(Integer.valueOf(e.getPartitionId()));
        g.writeFieldName(VALUE_FIELD_NAME);
        writer.write(datum, new JsonEncoder(schema, g));
        g.writeEndObject();
        g.writeEndObject();
        try {
            g.writeEndObject();
        } catch (JsonGenerationException e_json) {
        // ignore the error as some how avro JsonEncoder may some times missing two }
        }
        g.flush();
    } catch (IOException e1) {
        LOG.error("event value serialization error; event = " + e, e1);
    }
}
Also used : JsonEncoder(org.apache.avro.io.JsonEncoder) GenericDatumReader(org.apache.avro.generic.GenericDatumReader) Schema(org.apache.avro.Schema) VersionedSchema(com.linkedin.databus2.schemas.VersionedSchema) JsonFactory(org.codehaus.jackson.JsonFactory) GenericDatumWriter(org.apache.avro.generic.GenericDatumWriter) IOException(java.io.IOException) VersionedSchema(com.linkedin.databus2.schemas.VersionedSchema) ByteBuffer(java.nio.ByteBuffer) SchemaId(com.linkedin.databus2.schemas.SchemaId) JsonGenerator(org.codehaus.jackson.JsonGenerator) JsonGenerationException(org.codehaus.jackson.JsonGenerationException)

Example 34 with JsonGenerationException

use of org.codehaus.jackson.JsonGenerationException in project BetterBatteryStats by asksven.

the class ReferenceDto method toJson.

/**
 * Serialize to JSON
 * @return
 */
private byte[] toJson() {
    byte[] ret = null;
    StringWriter buffer = new StringWriter();
    ObjectMapper mapper = new ObjectMapper();
    // mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
    try {
        ret = mapper.writeValueAsBytes(this);
    // mapper.writeValue(buffer, this);
    // ret = buffer.toString();
    } catch (JsonGenerationException e) {
        e.printStackTrace();
    } catch (JsonMappingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return ret;
}
Also used : StringWriter(java.io.StringWriter) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

JsonGenerationException (org.codehaus.jackson.JsonGenerationException)34 IOException (java.io.IOException)30 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)27 Response (javax.ws.rs.core.Response)13 GET (javax.ws.rs.GET)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 ArrayList (java.util.ArrayList)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 JsonGenerator (org.codehaus.jackson.JsonGenerator)7 StringWriter (java.io.StringWriter)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Enterprise (com.itrus.portal.db.Enterprise)4 UserCert (com.itrus.portal.db.UserCert)4 UserInfo (com.itrus.portal.db.UserInfo)4 HttpSession (javax.servlet.http.HttpSession)4 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)4 Bill (com.itrus.portal.db.Bill)3