/** * manifest.jsonのバリデート. * @param jp Jsonパーサー * @param mapper ObjectMapper * @return JSONManifestオブジェクト * @throws IOException データの読み込みに失敗した場合 */ protected JSONManifest manifestJsonValidate(JsonParser jp, ObjectMapper mapper) throws IOException { // TODO BARファイルのバージョンチェック JSONManifest manifest = null; try { manifest = mapper.readValue(jp, JSONManifest.class); } catch (UnrecognizedPropertyException ex) { throw PersoniumCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.params( "manifest.json unrecognized property"); } if (manifest.getBarVersion() == null) { throw PersoniumCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.params("manifest.json#barVersion"); } if (manifest.getBoxVersion() == null) { throw PersoniumCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.params("manifest.json#boxVersion"); } if (manifest.getDefaultPath() == null) { throw PersoniumCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.params("manifest.json#DefaultPath"); } return manifest; }
/** * barファイルエントリからJSONファイルを読み込む. * @param <T> JSONMappedObject * @param inStream barファイルエントリのInputStream * @param entryName entryName * @param clazz clazz * @return JSONファイルから読み込んだオブジェクト * @throws IOException JSONファイル読み込みエラー */ public static <T> T readJsonEntry( InputStream inStream, String entryName, Class<T> clazz) throws IOException { JsonParser jp = null; ObjectMapper mapper = new ObjectMapper(); JsonFactory f = new JsonFactory(); jp = f.createJsonParser(inStream); JsonToken token = jp.nextToken(); // JSONルート要素("{") Pattern formatPattern = Pattern.compile(".*/+(.*)"); Matcher formatMatcher = formatPattern.matcher(entryName); String jsonName = formatMatcher.replaceAll("$1"); T json = null; if (token == JsonToken.START_OBJECT) { try { json = mapper.readValue(jp, clazz); } catch (UnrecognizedPropertyException ex) { throw PersoniumCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.params(jsonName); } } else { throw PersoniumCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.params(jsonName); } return json; }
public void signIn(String username, String password) throws Exception { Entity payload = Entity.json("{ \"ClientType\": 6, \"Password\": \"" + password + "\", \"UserName\": \"" + username + "\"}"); Response response = client.target(endpoint.toString()).request(MediaType.APPLICATION_JSON_TYPE).post(payload); String res = response.readEntity(String.class); try { JSONAuthSession jsonSession = new ObjectMapper().readValue(res, JSONAuthSession.class); this.session = jsonSession.getSession(); ((Stub) this.downloadService).clearHeaders(); ((Stub) this.downloadService).setHeader(this.getSoapSessionHeader()); } catch (UnrecognizedPropertyException e) { JSONAuthFault fault = new ObjectMapper().readValue(res, JSONAuthFault.class); logger.error("Could not sign in user `" + username + "`, reason:"); logger.error(fault.getMessage()); throw new Exception("Unable to sign in"); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { if (e.getCause() instanceof IllegalStateException) { // hiding exception logging - expected because of the way we do // JSON message decoding // logger.debug("Illegal State exception ", // e.getCause().toString()); } else if (e.getCause() instanceof UnrecognizedPropertyException) { logger.error("Jackson unrecognized property error {}", e.getCause()); } else if (e.getCause() instanceof JsonMappingException) { logger.error("Jackson mapping error {}", e.getCause()); } else if (e.getCause() instanceof JsonParseException) { logger.error("Jackson parsing error {}", e.getCause()); } else if (e.getCause() instanceof ClosedChannelException) { logger.error("Netty closed channel error", e.getCause()); } else if (e.getCause() instanceof ConnectException) { logger.error("Connection refused", e.getCause()); } else if (e.getCause() instanceof IOException) { logger.error("IO problem", e.getCause()); } else { super.exceptionCaught(ctx, e); } }
@Override protected ApiErrorResponse toApiErrorResponse(UnrecognizedPropertyException upe) { return new ApiErrorResponse( buildMessage(upe), getCode(), getLocationType(), upe.getUnrecognizedPropertyName() ); }
public Response toResponse(Exception exception) { String msg = "General Exception at CXF layer:" +exception.toString(); log.debug(msg,exception); if(exception instanceof NullPointerException){ return new NullPointerExceptionMapper().toResponse((NullPointerException)exception); } else if(exception instanceof HomePiAppException){ return new HomePiAppExceptionMapper().toResponse((HomePiAppException)exception); } else if(exception instanceof JsonProcessingException){ return new JsonProcessingExceptionMapper().toResponse((JsonProcessingException)exception); } else if(exception instanceof UnrecognizedPropertyException){ return new UnrecognizedPropertyExceptionMapper().toResponse((UnrecognizedPropertyException)exception); } else if(exception instanceof WebApplicationException){ WebApplicationException wae = (WebApplicationException)exception; Status status = Status.fromStatusCode(wae.getResponse().getStatus()); String cause = (wae.getCause()!= null)?wae.getCause().toString():""; if(status == null && wae.getResponse().getStatus() == 405){ msg += (" [Unmapped Status:" + wae.getResponse().getStatus()+"] " + wae.getResponse().getMetadata()); if(cause == null) cause = "Method Not Allowed"; } return Response .status(status) .entity(new HomePiAppException(status, msg, cause,0).toResponse()) .type(MediaType.APPLICATION_JSON) .build(); } return Response .status(Status.BAD_REQUEST) .entity(new HomePiAppException(Status.BAD_REQUEST, msg, "",0).toResponse()) .type(MediaType.APPLICATION_JSON) .build(); }
public Response toResponse(UnrecognizedPropertyException exception) { String message = "Invalid JSON field: '"+exception.getUnrecognizedPropertyName()+"'"; return Response .status(Status.BAD_REQUEST) .entity(new HomePiAppException(Status.BAD_REQUEST, message, "Invalid JSON, Unrecognized Property.",0).toResponse()) .type( MediaType.APPLICATION_JSON) .build(); }
public JsonMappingException unknownFieldException(Object paramObject, String paramString) { return UnrecognizedPropertyException.from(this._parser, paramObject, paramString); }
/** * Builds an error message indicating which property is unknown. * * @param upe the cause * @return a message indicating the position (line and column) of the unknown property in the * JSON document */ private String buildMessage(UnrecognizedPropertyException upe) { return "JSON parsing error due to unknown JSON object property " + upe.getUnrecognizedPropertyName() + getLocationDetails(upe) + "."; }