@Test public void toResponseメソッドが() { DcCoreExceptionMapper mapper = new DcCoreExceptionMapper(); DcCoreExceptionMapper.log = new TestLogger() { @Override public void error(String msg, Throwable t) { log.debug(msg); StackTraceElement[] ste = t.getStackTrace(); assertTrue(msg.indexOf(t.getMessage()) > 0); assertTrue(msg.indexOf(ste[0].getClassName()) > 0); assertTrue(msg.indexOf(ste[0].getMethodName()) > 0); log.debug(String.valueOf(ste[0].getLineNumber())); assertTrue(msg.indexOf(String.valueOf(ste[0].getLineNumber())) > 0); } }; try { Inner i = new Inner(); i.process(); } catch (Exception exception) { Response res = mapper.toResponse(exception); res.getStatus(); } }
@Override public Response toResponse(final Exception exception) { if (exception instanceof DcCoreException) { return this.handleDcCoreException((DcCoreException) exception); } if (exception instanceof WebApplicationException) { return this.handleWebApplicationException((WebApplicationException) exception); } String id = Math.abs(UUID.randomUUID().getMostSignificantBits() % ERROR_ID_ROOT) + ""; StackTraceElement[] ste = exception.getStackTrace(); StringBuilder sb = new StringBuilder("[PR500-SV-9999] - Unknown Exception [" + id + "] "); sb.append(exception.getMessage()); if (ste != null && ste.length > 0) { sb.append(" @ "); sb.append(ste[0].getClassName() + "#" + ste[0].getMethodName() + ": " + ste[0].getLineNumber()); } log.error(sb.toString(), exception); return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR) .entity(new ODataErrorMessage("PR500-SV-9999", "en_US", "Unknown Exception [" + id + "]")).build(); }
DcCoreExceptionMapper implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { if (exception instanceof DcCoreException) { return this.handleDcCoreException((DcCoreException) exception); } if (exception instanceof WebApplicationException) { return this.handleWebApplicationException((WebApplicationException) exception); } String id = Math.abs(UUID.randomUUID().getMostSignificantBits() % ERROR_ID_ROOT) + ""; StackTraceElement[] ste = exception.getStackTrace(); StringBuilder sb = new StringBuilder("[PR500-SV-9999] - Unknown Exception [" + id + "] "); sb.append(exception.getMessage()); if (ste != null && ste.length > 0) { sb.append(" @ "); sb.append(ste[0].getClassName() + "#" + ste[0].getMethodName() + ": " + ste[0].getLineNumber()); } log.error(sb.toString(), exception); return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR) .entity(new ODataErrorMessage("PR500-SV-9999", "en_US", "Unknown Exception [" + id + "]")).build(); } }
DcCoreExceptionMapper implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { if (exception instanceof DcCoreException) { return this.handleDcCoreException((DcCoreException) exception); } if (exception instanceof WebApplicationException) { return this.handleWebApplicationException((WebApplicationException) exception); } String id = Math.abs(UUID.randomUUID().getMostSignificantBits() % ERROR_ID_ROOT) + ""; StackTraceElement[] ste = exception.getStackTrace(); StringBuilder sb = new StringBuilder("[PR500-SV-9999] - Unknown Exception [" + id + "] "); sb.append(exception.getMessage()); if (ste != null && ste.length > 0) { sb.append(" @ "); sb.append(ste[0].getClassName() + "#" + ste[0].getMethodName() + ": " + ste[0].getLineNumber()); } log.error(sb.toString(), exception); return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR) .entity(new ODataErrorMessage("PR500-SV-9999", "en_US", "Unknown Exception [" + id + "]")).build(); }  }
DcCoreExceptionMapper implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { if (exception instanceof DcCoreException) { return this.handleDcCoreException((DcCoreException) exception); } if (exception instanceof WebApplicationException) { return this.handleWebApplicationException((WebApplicationException) exception); } String id = Math.abs(UUID.randomUUID().getMostSignificantBits() % ERROR_ID_ROOT) + ""; StackTraceElement[] ste = exception.getStackTrace(); StringBuilder sb = new StringBuilder("[PR500-SV-9999] - Unknown Exception [" + id + "] "); sb.append(exception.getMessage()); if (ste != null && ste.length > 0) { sb.append(" @ "); sb.append(ste[0].getClassName() + "#" + ste[0].getMethodName() + ": " + ste[0].getLineNumber()); } log.error(sb.toString(), exception); return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR) .entity(new ODataErrorMessage("PR500-SV-9999", "en_US", "Unknown Exception [" + id + "]")).build(); }  @Override Response toResponse(final Exception exception); }
DcCoreExceptionMapper implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { if (exception instanceof DcCoreException) { return this.handleDcCoreException((DcCoreException) exception); } if (exception instanceof WebApplicationException) { return this.handleWebApplicationException((WebApplicationException) exception); } String id = Math.abs(UUID.randomUUID().getMostSignificantBits() % ERROR_ID_ROOT) + ""; StackTraceElement[] ste = exception.getStackTrace(); StringBuilder sb = new StringBuilder("[PR500-SV-9999] - Unknown Exception [" + id + "] "); sb.append(exception.getMessage()); if (ste != null && ste.length > 0) { sb.append(" @ "); sb.append(ste[0].getClassName() + "#" + ste[0].getMethodName() + ": " + ste[0].getLineNumber()); } log.error(sb.toString(), exception); return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR) .entity(new ODataErrorMessage("PR500-SV-9999", "en_US", "Unknown Exception [" + id + "]")).build(); }  @Override Response toResponse(final Exception exception);  }