use of net.minidev.json.parser.ParseException in project Distributed-Noracle-Backend by Distributed-Noracle.
the class QuestionsResource method changeQuestionText.
@PUT
@Path("/{questionId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses({ @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "The updated question from the network", response = Question.class), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "No question id given", response = ExceptionEntity.class), @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = "Access Denied", response = ExceptionEntity.class), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Question Not Found", response = ExceptionEntity.class), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal Server Error", response = ExceptionEntity.class) })
public Question changeQuestionText(@PathParam("questionId") String questionId, ChangeQuestionPojo changeQuestionPojo) throws ServiceInvocationException {
Gson gson = new Gson();
String createRelationPojoJson = gson.toJson(changeQuestionPojo);
JSONParser p = new JSONParser(JSONParser.MODE_PERMISSIVE);
try {
JSONObject obj = (JSONObject) p.parse(createRelationPojoJson);
obj.put("qId", questionId);
obj.put("uid", Context.getCurrent().getMainAgent().getIdentifier());
Context.get().monitorEvent(MonitoringEvent.SERVICE_CUSTOM_MESSAGE_6, obj.toJSONString());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return changeQuestionText(questionId, changeQuestionPojo.getText());
}
use of net.minidev.json.parser.ParseException in project Distributed-Noracle-Backend by Distributed-Noracle.
the class QuestionsResource method createQuestion.
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_HTML)
@ApiResponses({ @ApiResponse(code = HttpURLConnection.HTTP_CREATED, message = "Question successfully created"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "No question text given", response = ExceptionEntity.class), @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "You have to be logged in to create a question", response = ExceptionEntity.class), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal Server Error", response = ExceptionEntity.class) })
public Response createQuestion(@PathParam("spaceId") String questionSpaceId, @ApiParam(required = true) CreateQuestionPojo createQuestionPojo) throws ServiceInvocationException {
Question question = createQuestion(questionSpaceId, createQuestionPojo.getText());
try {
Gson gson = new Gson();
String createRelationPojoJson = gson.toJson(createQuestionPojo);
JSONParser p = new JSONParser(JSONParser.MODE_PERMISSIVE);
JSONObject obj = new JSONObject();
JSONObject attributes = new JSONObject();
obj.put("functionName", "createQuestion");
obj.put("serviceAlias", "distributed-noracle");
obj.put("uid", Context.getCurrent().getMainAgent().getIdentifier());
obj.put("qid", question.getQuestionId());
attributes.put("spaceId", questionSpaceId);
attributes.put("userId", Context.getCurrent().getMainAgent().getIdentifier());
attributes.put("body", p.parse(createRelationPojoJson));
attributes.put("result", question.getQuestionId());
obj.put("attributes", attributes);
Context.get().monitorEvent(MonitoringEvent.SERVICE_CUSTOM_MESSAGE_5, obj.toJSONString());
return Response.created(new URI(null, null, SpacesResource.RESOURCE_NAME + "/" + questionSpaceId + "/" + RESOURCE_NAME + "/" + question.getQuestionId(), null)).build();
} catch (URISyntaxException | ParseException e) {
throw new InternalServerErrorException(e);
}
}
use of net.minidev.json.parser.ParseException in project scheduler by btrplace.
the class JSONObjectConverter method fromJSON.
/**
* Un-serialize an object from a stream.
* The stream must be close afterward
*
* @param r the stream to read
* @return the resulting object
* @throws JSONConverterException if the stream cannot be parsed
*/
default E fromJSON(Reader r) throws JSONConverterException {
try {
JSONParser p = new JSONParser(JSONParser.MODE_RFC4627);
Object o = p.parse(r);
if (!(o instanceof JSONObject)) {
throw new JSONConverterException("Unable to parse a JSON object");
}
return fromJSON((JSONObject) o);
} catch (ParseException ex) {
throw new JSONConverterException(ex);
}
}
use of net.minidev.json.parser.ParseException in project ddf by codice.
the class GeoNamesWebService method query.
private Object query(String urlStr) {
final String response;
try {
WebClient client = createWebClient(urlStr);
response = client.acceptEncoding(StandardCharsets.UTF_8.name()).accept("application/json").get(String.class);
} catch (WebApplicationException | ProcessingException e) {
LOGGER.debug("Error while making GeoNames request.", e);
return null;
}
try {
JSONParser parser = new JSONParser(JSONParser.MODE_JSON_SIMPLE);
return parser.parse(response);
} catch (ParseException e) {
LOGGER.debug("Error while parsing JSON message from GeoNames service.", e);
return null;
}
}
use of net.minidev.json.parser.ParseException in project ddf by codice.
the class GeoNamesWebService method webQuery.
private Object webQuery(String urlStr) {
final String response;
try {
WebClient client = createWebClient(urlStr);
response = client.acceptEncoding(StandardCharsets.UTF_8.name()).accept(MediaType.APPLICATION_JSON).get(String.class);
} catch (WebApplicationException | ProcessingException e) {
LOGGER.debug("Error while making GeoNames request: {}", urlStr, e);
return null;
}
try {
JSONParser parser = new JSONParser(JSONParser.MODE_JSON_SIMPLE);
return parser.parse(response);
} catch (ParseException e) {
LOGGER.debug("Error while parsing JSON message from GeoNames service.", e);
return null;
}
}
Aggregations