use of org.codehaus.jackson.map.MappingJsonFactory in project onebusaway-application-modules by camsys.
the class ValidateResource method validate.
@Path("/{bundleDirectory}/{bundleName}/create")
@GET
@Produces("application/json")
public Response validate(@PathParam("bundleDirectory") String bundleDirectory, @PathParam("bundleName") String bundleName) {
Response response = null;
if (!isAuthorized()) {
return Response.noContent().build();
}
BundleRequest bundleRequest = new BundleRequest();
directoryName = bundleDirectory;
this.bundleName = bundleName;
bundleRequest.setBundleBuildName(bundleName);
bundleRequest.setBundleDirectory(bundleDirectory);
String session = RequestContextHolder.currentRequestAttributes().getSessionId();
bundleRequest.setSessionId(session);
BundleResponse bundleResponse = null;
try {
bundleResponse = _bundleService.validate(bundleRequest);
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) {
_log.error("validate resource caught exception:" + any);
response = Response.serverError().build();
}
return response;
}
use of org.codehaus.jackson.map.MappingJsonFactory in project onebusaway-application-modules by camsys.
the class BuildRemoteResource method build.
@Path("/create")
@POST
@Produces("application/json")
public Response build(@FormParam("bundleDirectory") String bundleDirectory, @FormParam("bundleBuildName") String bundleName, @FormParam("email") String email, @FormParam("id") String id, @FormParam("bundleStartDate") String bundleStartDate, @FormParam("bundleEndDate") String bundleEndDate, @FormParam("bundleComment") String bundleComment, @FormParam("archive") boolean archive, @FormParam("consolidate") boolean consolidate, @FormParam("predate") boolean predate) {
Response response = null;
if (!isAuthorized()) {
return Response.noContent().build();
}
_log.info("in build(local) with archive=" + archive + ", and consolidate=" + consolidate);
BundleBuildRequest bundleRequest = new BundleBuildRequest();
bundleRequest.setBundleDirectory(bundleDirectory);
bundleRequest.setBundleName(bundleName);
bundleRequest.setEmailAddress(email);
bundleRequest.setId(id);
bundleRequest.setBundleStartDate(bundleStartDate);
bundleRequest.setBundleEndDate(bundleEndDate);
bundleRequest.setBundleComment(bundleComment);
bundleRequest.setArchiveFlag(archive);
bundleRequest.setConsolidateFlag(consolidate);
bundleRequest.setPredate(predate);
BundleBuildResponse bundleResponse = new BundleBuildResponse(id);
try {
bundleResponse.addStatusMessage("server started");
bundleResponse.addStatusMessage("queueing");
// place execution in its own thread
_executorService.execute(new BuildThread(bundleRequest, bundleResponse));
// place handle to response in map
_buildMap.put(id, bundleResponse);
final StringWriter sw = new StringWriter();
final MappingJsonFactory jsonFactory = new MappingJsonFactory();
final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(sw);
// write back response
_mapper.writeValue(jsonGenerator, bundleResponse);
response = Response.ok(sw.toString()).build();
} catch (Exception any) {
_log.error("execption in build:", any);
response = Response.serverError().build();
}
return response;
}
use of org.codehaus.jackson.map.MappingJsonFactory in project onebusaway-application-modules by camsys.
the class AgencyMetadataResource method constructResponse.
// Private methods
private Response constructResponse(Object result) {
final StringWriter sw = new StringWriter();
final MappingJsonFactory jsonFactory = new MappingJsonFactory();
Response response = null;
try {
final org.codehaus.jackson.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;
}
use of org.codehaus.jackson.map.MappingJsonFactory in project onebusaway-application-modules by camsys.
the class KeysResource 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;
}
use of org.codehaus.jackson.map.MappingJsonFactory in project onebusaway-application-modules by camsys.
the class BundleServerServiceImpl method toJson.
private String toJson(Object payload) {
String jsonPayload = null;
if (payload != null) {
StringWriter sw = new StringWriter();
try {
final MappingJsonFactory jsonFactory = new MappingJsonFactory();
final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(sw);
_mapper.writeValue(jsonGenerator, payload);
} catch (Exception any) {
_log.error("json execption=", any);
}
jsonPayload = sw.toString();
}
return jsonPayload;
}
Aggregations