Search in sources :

Example 1 with MappingJsonFactory

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

the class ValidateRemoteResource method list.

@Path("/{id}/list")
@GET
@Produces("application/json")
public Response list(@PathParam("id") String id) {
    Response response = null;
    if (!isAuthorized()) {
        return Response.noContent().build();
    }
    try {
        final StringWriter sw = new StringWriter();
        final MappingJsonFactory jsonFactory = new MappingJsonFactory();
        final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(sw);
        BundleResponse bundleResponse = _validationMap.get(id);
        _log.debug("found bundleResponse=" + bundleResponse + " for id=" + id);
        _mapper.writeValue(jsonGenerator, bundleResponse);
        response = Response.ok(sw.toString()).build();
    } catch (Exception any) {
        response = Response.serverError().build();
    }
    return response;
}
Also used : BundleResponse(org.onebusaway.admin.model.BundleResponse) Response(javax.ws.rs.core.Response) MappingJsonFactory(org.codehaus.jackson.map.MappingJsonFactory) StringWriter(java.io.StringWriter) BundleResponse(org.onebusaway.admin.model.BundleResponse) JsonGenerator(org.codehaus.jackson.JsonGenerator) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with MappingJsonFactory

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

the class LocalBundleStagerServiceImpl method jsonSerializer.

/*private String getBundleDirectory() {
      return bundleStager.getStagedBundleDirectory();
    }*/
private String jsonSerializer(Object object) throws IOException {
    // serialize the status object and send to client -- it contains an id for querying
    final StringWriter sw = new StringWriter();
    final MappingJsonFactory jsonFactory = new MappingJsonFactory();
    final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(sw);
    ObjectMapper mapper = new ObjectMapper();
    mapper.writeValue(jsonGenerator, object);
    return sw.toString();
}
Also used : MappingJsonFactory(org.codehaus.jackson.map.MappingJsonFactory) StringWriter(java.io.StringWriter) JsonGenerator(org.codehaus.jackson.JsonGenerator) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 3 with MappingJsonFactory

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

the class UserResource method constructResponse.

private Response constructResponse(Object result) {
    final StringWriter sw = new StringWriter();
    final MappingJsonFactory jsonFactory = new MappingJsonFactory();
    Response response = null;
    try {
        final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(sw);
        mapper.writeValue(jsonGenerator, result);
        response = Response.ok(sw.toString()).build();
    } catch (JsonGenerationException e) {
        log.error("Error generating response JSON");
        response = Response.serverError().build();
        e.printStackTrace();
    } catch (JsonMappingException e) {
        log.error("Error mapping response to JSON");
        response = Response.serverError().build();
        e.printStackTrace();
    } catch (IOException e) {
        log.error("I/O error while creating response JSON");
        response = Response.serverError().build();
        e.printStackTrace();
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) MappingJsonFactory(org.codehaus.jackson.map.MappingJsonFactory) StringWriter(java.io.StringWriter) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) JsonGenerator(org.codehaus.jackson.JsonGenerator) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException)

Example 4 with MappingJsonFactory

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

the class BuildResource method constructResponse.

private Response constructResponse(BundleBuildResponse buildResponse) throws IOException, JsonGenerationException, JsonMappingException {
    final StringWriter sw = new StringWriter();
    final MappingJsonFactory jsonFactory = new MappingJsonFactory();
    final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(sw);
    _mapper.writeValue(jsonGenerator, buildResponse);
    return Response.ok(sw.toString()).build();
}
Also used : MappingJsonFactory(org.codehaus.jackson.map.MappingJsonFactory) StringWriter(java.io.StringWriter) JsonGenerator(org.codehaus.jackson.JsonGenerator)

Example 5 with MappingJsonFactory

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

the class BuildResource method list.

@Path("/{id}/list")
@GET
@Produces("application/json")
public Response list(@PathParam("id") String id) {
    Response response = null;
    if (!isAuthorized()) {
        return Response.noContent().build();
    }
    BundleBuildResponse buildResponse = _bundleService.lookupBuildRequest(id);
    String dirName = buildResponse.getBundleDirectoryName();
    if (dirName == null || dirName.isEmpty()) {
        buildResponse.setBundleBuildName(bundleName);
        buildResponse.setBundleDirectoryName(directoryName);
        buildResponse.setBundleEmailTo(emailTo);
        buildResponse.setBundleStartDate(startDate);
        buildResponse.setBundleEndDate(endDate);
        buildResponse.setBundleComment(comment);
    }
    try {
        final StringWriter sw = new StringWriter();
        final MappingJsonFactory jsonFactory = new MappingJsonFactory();
        final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(sw);
        _mapper.writeValue(jsonGenerator, buildResponse);
        response = Response.ok(sw.toString()).build();
    } catch (Exception any) {
        _log.error("exception looking up build:", any);
        response = Response.serverError().build();
    }
    return response;
}
Also used : BundleBuildResponse(org.onebusaway.admin.model.BundleBuildResponse) Response(javax.ws.rs.core.Response) MappingJsonFactory(org.codehaus.jackson.map.MappingJsonFactory) StringWriter(java.io.StringWriter) JsonGenerator(org.codehaus.jackson.JsonGenerator) BundleBuildResponse(org.onebusaway.admin.model.BundleBuildResponse) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) DateValidationException(org.onebusaway.admin.service.exceptions.DateValidationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

StringWriter (java.io.StringWriter)14 MappingJsonFactory (org.codehaus.jackson.map.MappingJsonFactory)14 JsonGenerator (org.codehaus.jackson.JsonGenerator)13 Response (javax.ws.rs.core.Response)10 Path (javax.ws.rs.Path)7 Produces (javax.ws.rs.Produces)7 GET (javax.ws.rs.GET)6 IOException (java.io.IOException)5 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)5 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)4 BundleResponse (org.onebusaway.admin.model.BundleResponse)4 BundleBuildResponse (org.onebusaway.admin.model.BundleBuildResponse)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 BundleRequest (org.onebusaway.admin.model.BundleRequest)2 POST (javax.ws.rs.POST)1 JsonParseException (org.codehaus.jackson.JsonParseException)1 BundleBuildRequest (org.onebusaway.admin.model.BundleBuildRequest)1 DateValidationException (org.onebusaway.admin.service.exceptions.DateValidationException)1