Search in sources :

Example 11 with MappingJsonFactory

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

the class LocalBundleDeployerServiceImpl method jsonSerializer.

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 12 with MappingJsonFactory

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

the class ValidateRemoteResource method validate.

@Path("/{bundleDirectory}/{bundleName}/{id}/create")
@GET
@Produces("application/json")
public Response validate(@PathParam("bundleDirectory") String bundleDirectory, @PathParam("bundleName") String bundleName, @PathParam("id") String id) {
    Response response = null;
    if (!isAuthorized()) {
        return Response.noContent().build();
    }
    BundleRequest bundleRequest = new BundleRequest();
    _log.debug("bundleName=" + bundleName + ", bundleDirectory=" + bundleDirectory);
    bundleRequest.setBundleBuildName(bundleName);
    bundleRequest.setBundleDirectory(bundleDirectory);
    bundleRequest.setId(id);
    BundleResponse bundleResponse = new BundleResponse(id);
    try {
        bundleResponse.addStatusMessage("server started");
        bundleResponse.addStatusMessage("queueing");
        // place execution in its own thread
        _executorService.execute(new ValidateThread(bundleRequest, bundleResponse));
        // place handle to response in map
        _validationMap.put(id, bundleResponse);
        final StringWriter sw = new StringWriter();
        final MappingJsonFactory jsonFactory = new MappingJsonFactory();
        final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(sw);
        // write back response
        _log.debug("returning id=" + bundleResponse.getId() + " for bundleResponse=" + bundleResponse);
        _mapper.writeValue(jsonGenerator, bundleResponse);
        response = Response.ok(sw.toString()).build();
    } catch (Exception any) {
        _log.error("validate resource caught 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) BundleResponse(org.onebusaway.admin.model.BundleResponse) StringWriter(java.io.StringWriter) BundleRequest(org.onebusaway.admin.model.BundleRequest) JsonGenerator(org.codehaus.jackson.JsonGenerator) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 13 with MappingJsonFactory

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

the class ValidateResource 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();
    }
    BundleResponse bundleResponse = null;
    try {
        bundleResponse = _bundleService.lookupValidationRequest(id);
        bundleResponse.setBuildName(bundleName);
        bundleResponse.setDirectoryName(directoryName);
        final StringWriter sw = new StringWriter();
        final MappingJsonFactory jsonFactory = new MappingJsonFactory();
        final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(sw);
        _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) BundleResponse(org.onebusaway.admin.model.BundleResponse) StringWriter(java.io.StringWriter) JsonGenerator(org.codehaus.jackson.JsonGenerator) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 14 with MappingJsonFactory

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

the class BuildRemoteResource 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);
        BundleBuildResponse bbr = _buildMap.get(id);
        if (bbr == null) {
            bbr = _bundleService.getBundleBuildResponseForId(id);
        }
        if (bbr != null && bbr.getException() != null) {
            _log.error("id=" + id + " has exception=" + bbr.getException());
        }
        _mapper.writeValue(jsonGenerator, bbr);
        response = Response.ok(sw.toString()).build();
    } catch (Exception 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) 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