use of org.codehaus.jackson.JsonProcessingException in project OpenAttestation by OpenAttestation.
the class AbstractSimpleResource method deleteOne.
// /**
// * Add an item to the collection. Input Content-Type is any of
// * application/json, application/xml, application/yaml, or text/yaml Output
// * Content-Type is any of application/json, application/xml,
// * application/yaml, or text/yaml
// *
// * The input must represent a single item NOT wrapped in a collection.
// *
// * @param item
// * @return
// */
// @POST
// public T createOne(@BeanParam L locator, T item, @Context HttpServletRequest httpServletRequest, @Context HttpServletResponse httpServletResponse){
// //try { log.debug("createOne: {}", mapper.writeValueAsString(locator)); } catch(JsonProcessingException e) { log.debug("createOne: cannot serialize locator: {}", e.getMessage()); }
// try { log.debug("createOne: {}", mapper.writeValueAsString(locator)); } catch(Exception e) { log.debug("createOne: cannot serialize locator: {}", e.getMessage()); }
// locator.copyTo(item);
// ValidationUtil.validate(item); // throw new MWException(e, ErrorCode.AS_INPUT_VALIDATION_ERROR, input, method.getName());
// if (item.getId() == null) {
// item.setId(new UUID());
// }
// getRepository().create(item);
// httpServletResponse.setStatus(Status.CREATED.getStatusCode());
// return item;
// }
// the delete method is on a specific resource id and because we don't return any content it's the same whether its simple object or json api
// jersey automatically returns status code 204 No Content (successful) to the client because
// we have a void return type
@Path("/{id}")
@DELETE
public void deleteOne(@BeanParam L locator, @Context HttpServletRequest httpServletRequest, @Context HttpServletResponse httpServletResponse) throws IOException {
try {
log.debug("deleteOne: {}", mapper.writeValueAsString(locator));
} catch (JsonProcessingException e) {
log.debug("deleteOne: cannot serialize locator: {}", e.getMessage());
}
// subclass is responsible for validating the id in whatever manner it needs to; most will return null if !UUID.isValid(id) but we don't do it here because a resource might want to allow using something other than uuid as the url key, for example uuid OR hostname for hosts
T item = getRepository().retrieve(locator);
if (item == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
getRepository().delete(locator);
httpServletResponse.setStatus(Status.NO_CONTENT.getStatusCode());
/*
T item = getRepository().retrieve(id); // subclass is responsible for validating the id in whatever manner it needs to; most will return null if !UUID.isValid(id) but we don't do it here because a resource might want to allow using something other than uuid as the url key, for example uuid OR hostname for hosts
if (item == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
getRepository().delete(id);*/
/*
// C collection = getRepository().search(selector);
// if( collection.getDocuments().isEmpty() ) {
// throw new WebApplicationException(Response.Status.NOT_FOUND);
// }
// T item = collection.getDocuments().get(0);
// getRepository().delete(item.getId().toString());
* */
}
use of org.codehaus.jackson.JsonProcessingException in project openhab1-addons by openhab.
the class MyqData method request.
/**
* Make a request to the server, optionally retry the call if there is a
* login issue. Will throw a InvalidLoginExcpetion if the account is
* invalid, locked or soon to be locked.
*
* @param method
* The Http Method Type (GET,PUT)
* @param url
* The request URL
* @param payload
* Payload string for put operations
* @param payloadType
* Payload content type for put operations
* @param retry
* Retry the attempt if our session key is not valid
* @return The JsonNode representing the response data
* @throws IOException
* @throws InvalidLoginException
*/
private synchronized JsonNode request(String method, String url, String payload, String payloadType, boolean retry) throws IOException, InvalidLoginException {
logger.trace("Requesting URL {}", url);
String dataString = executeUrl(method, url, header, payload == null ? null : IOUtils.toInputStream(payload), payloadType, timeout);
logger.trace("Received MyQ JSON: {}", dataString);
if (dataString == null) {
throw new IOException("Null response from MyQ server");
}
try {
ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode = mapper.readTree(dataString);
int returnCode = rootNode.get("ReturnCode").asInt();
logger.trace("myq ReturnCode: {}", returnCode);
MyQResponseCode rc = MyQResponseCode.fromCode(returnCode);
switch(rc) {
case OK:
{
return rootNode;
}
case ACCOUNT_INVALID:
case ACCOUNT_NOT_FOUND:
case ACCOUNT_LOCKED:
case ACCOUNT_LOCKED_PENDING:
// lock an account
throw new InvalidLoginException(rc.getDesc());
case LOGIN_ERROR:
// Our session key has expired, request a new one
if (retry) {
login();
return request(method, url, payload, payloadType, false);
}
// fall through to default
default:
throw new IOException("Request Failed: " + rc.getDesc());
}
} catch (JsonProcessingException e) {
throw new IOException("Could not parse response", e);
}
}
use of org.codehaus.jackson.JsonProcessingException in project perun by CESNET.
the class JsonSerializer method write.
@Override
public void write(Object object) throws RpcException, IOException {
JsonGenerator gen = jsonFactory.createJsonGenerator(out, JsonEncoding.UTF8);
try {
gen.writeObject(object);
gen.flush();
gen.close();
} catch (JsonProcessingException ex) {
throw new RpcException(RpcException.Type.CANNOT_SERIALIZE_VALUE, ex);
}
}
use of org.codehaus.jackson.JsonProcessingException in project perun by CESNET.
the class JsonSerializer method write.
@Override
public void write(Object object) throws RpcException, IOException {
JsonGenerator gen = jsonFactory.createJsonGenerator(out, JsonEncoding.UTF8);
if (object instanceof Throwable) {
throw new IllegalArgumentException("Tried to serialize a throwable object using write()", (Throwable) object);
}
try {
gen.writeObject(object);
gen.close();
} catch (JsonProcessingException ex) {
throw new RpcException(RpcException.Type.CANNOT_SERIALIZE_VALUE, ex);
}
}
use of org.codehaus.jackson.JsonProcessingException in project perun by CESNET.
the class JsonSerializerJSONP method write.
@Override
public void write(Object object) throws RpcException, IOException {
JsonGenerator gen = jsonFactory.createJsonGenerator(out, JsonEncoding.UTF8);
if (object instanceof Throwable) {
throw new IllegalArgumentException("Tried to serialize a throwable object using write()", (Throwable) object);
}
try {
gen.writeRaw(callback + "(");
gen.writeObject(object);
gen.writeRaw(");");
gen.flush();
gen.close();
} catch (JsonProcessingException ex) {
throw new RpcException(RpcException.Type.CANNOT_SERIALIZE_VALUE, ex);
}
}
Aggregations