public void reportError( ValidationEvent ve ) throws SAXException { ValidationEventHandler handler; try { handler = marshaller.getEventHandler(); } catch( JAXBException e ) { throw new SAXException2(e); } if(!handler.handleEvent(ve)) { if(ve.getLinkedException() instanceof Exception) throw new SAXException2((Exception)ve.getLinkedException()); else throw new SAXException2(ve.getMessage()); } }
if (ve.getLinkedException()!=null && log.isDebugEnabled() ) { ve.getLinkedException().printStackTrace();
/** * Reports an error to the user, and asks if s/he wants * to recover. If the canRecover flag is false, regardless * of the client instruction, an exception will be thrown. * * Only if the flag is true and the user wants to recover from an error, * the method returns normally. * * The thrown exception will be catched by the unmarshaller. */ public void handleEvent(ValidationEvent event, boolean canRecover ) throws SAXException { ValidationEventHandler eventHandler = parent.getEventHandler(); boolean recover = eventHandler.handleEvent(event); // if the handler says "abort", we will not return the object // from the unmarshaller.getResult() if(!recover) aborted = true; if( !canRecover || !recover ) throw new SAXParseException2( event.getMessage(), locator, new UnmarshalException( event.getMessage(), event.getLinkedException() ) ); }
public void reportError( ValidationEvent ve ) throws SAXException { ValidationEventHandler handler; try { handler = marshaller.getEventHandler(); } catch( JAXBException e ) { throw new SAXException2(e); } if(!handler.handleEvent(ve)) { if(ve.getLinkedException() instanceof Exception) throw new SAXException2((Exception)ve.getLinkedException()); else throw new SAXException2(ve.getMessage()); } }
/** * Reports an error to the user, and asks if s/he wants * to recover. If the canRecover flag is false, regardless * of the client instruction, an exception will be thrown. * * Only if the flag is true and the user wants to recover from an error, * the method returns normally. * * The thrown exception will be catched by the unmarshaller. */ public void handleEvent(ValidationEvent event, boolean canRecover ) throws SAXException { ValidationEventHandler eventHandler = parent.getEventHandler(); boolean recover = eventHandler.handleEvent(event); // if the handler says "abort", we will not return the object // from the unmarshaller.getResult() if(!recover) aborted = true; if( !canRecover || !recover ) throw new SAXParseException2( event.getMessage(), locator, new UnmarshalException( event.getMessage(), event.getLinkedException() ) ); }
public class DeserializationEventHandler implements ValidationEventHandler { private static final Logger LOG = LoggerFactory.getLogger(DeserializationEventHandler.class); @Override public boolean handleEvent(ValidationEvent event) { LOG.warn("Error during XML conversion: {}", event); if (event.getLinkedException() instanceof NumberFormatException) return false; return true; }
@Override public boolean handleEvent(final ValidationEvent event) { LOG.warn("Received validation event: {}", event, event.getLinkedException()); return false; } });
@Override public boolean handleEvent(final ValidationEvent event) { LOG.trace("event = {}", event, event.getLinkedException()); return false; } }
setValidationEventHandler(new ValidationEventHandler() { @Override public boolean handleEvent(ValidationEvent event) { System.out.println(event.getLinkedException().getMessage()); return false; } });)
public boolean handleEvent(ValidationEvent event ) { throw new RuntimeException(event.getMessage(), event.getLinkedException()); } }
public boolean handleEvent(ValidationEvent event) { if (event.getSeverity() == ValidationEvent.WARNING) { LOG.warn("Ignored {}", event, event.getLinkedException()); return true; // handled - ignore as WARNING does not prevent unmarshalling } else { return false; // not handled - ERROR and FATAL_ERROR prevent successful unmarshalling } } };
@Override public boolean handleEvent(ValidationEvent event) { if(event.getLinkedException() != null && AccessorException.class.isAssignableFrom(event.getLinkedException().getClass()) && event.getLinkedException().getCause() != null && IllegalEnumValueException.class.isAssignableFrom(event.getLinkedException().getCause().getClass())) { throw (IllegalEnumValueException) event.getLinkedException().getCause(); } else if (event.getSeverity() == ValidationEvent.FATAL_ERROR || event.getSeverity() == ValidationEvent.ERROR) { logger.error(event.getMessage()); throw new OrcidBadRequestException(event.getMessage()); } else if (event.getSeverity() == ValidationEvent.WARNING) { logger.warn(event.getMessage()); } return true; } }
@Override public boolean handleEvent(final ValidationEvent event) { if (event.getSeverity() > 0) { final Throwable ex = event.getLinkedException(); if (ex == null) { throw new RuntimeException("Error unmarshalling the data: " + event.getMessage()); } throw new RuntimeException("Error unmarshalling the data", ex); } return true; } });
private String getLogEntry(ValidationEvent event) { StringBuilder sb = new StringBuilder(); sb.append(event.getMessage()); sb.append(event.getLinkedException()); Object failedObject = event.getLocator().getObject(); if(failedObject != null) { sb.append(failedObject.toString()); } return sb.toString(); } }
@Override public boolean handleEvent(ValidationEvent event) { LOG.warn("severity: " + event.getSeverity()); LOG.warn("message: " + event.getMessage()); LOG.warn("linked exception: " + event.getLinkedException()); ValidationEventLocator locator = event.getLocator(); LOG.warn("line number: " + locator.getLineNumber()); LOG.warn("column number: " + locator.getColumnNumber()); LOG.warn("offset: " + locator.getOffset()); LOG.warn("node: " + locator.getNode()); LOG.warn("url: " + locator.getURL()); return false; } }
public boolean equals(final Object obj) { boolean result = false; if (obj instanceof ValidationEvent) { final ValidationEvent event = (ValidationEvent) obj; result = (getSeverity() == event.getSeverity()) && (getLocator().equals(event.getLocator())) && (getLinkedException().equals(event.getLinkedException())); } return result; }
public class CustomEventHandler implements ValidationEventHandler{ @Override public boolean handleEvent(ValidationEvent event) { if (event.getSeverity() == event.ERROR || event.getSeverity() == event.FATAL_ERROR) { ValidationEventLocator locator = event.getLocator(); throw new RuntimeException(event.getMessage(), event.getLinkedException()); } return true; } }
public boolean handleEvent(ValidationEvent event) { LOGGER.info("\nEVENT"); LOGGER.info("SEVERITY: " + event.getSeverity()); LOGGER.info("MESSAGE: " + event.getMessage()); LOGGER.info("LINKED EXCEPTION: " + event.getLinkedException()); LOGGER.info("LOCATOR"); LOGGER.info(" LINE NUMBER: " + event.getLocator().getLineNumber()); LOGGER.info(" COLUMN NUMBER: " + event.getLocator().getColumnNumber()); LOGGER.info(" OFFSET: " + event.getLocator().getOffset()); LOGGER.info(" OBJECT: " + event.getLocator().getObject()); LOGGER.info(" NODE: " + event.getLocator().getNode()); LOGGER.info(" URL: " + event.getLocator().getURL()); return true; }
public void reportError( ValidationEvent ve ) throws SAXException { ValidationEventHandler handler; try { handler = marshaller.getEventHandler(); } catch( JAXBException e ) { throw new SAXException2(e); } if(!handler.handleEvent(ve)) { if(ve.getLinkedException() instanceof Exception) throw new SAXException2((Exception)ve.getLinkedException()); else throw new SAXException2(ve.getMessage()); } }
public boolean handleEvent(final ValidationEvent event) { logger.warning("JSL invalid per XSD, details: " + ("\nMESSAGE: " + event.getMessage()) + "\nSEVERITY: " + event.getSeverity() + "\nLINKED EXC: " + event.getLinkedException() + "\nLOCATOR INFO:\n------------" + "\n COLUMN NUMBER: " + event.getLocator().getColumnNumber() + "\n LINE NUMBER: " + event.getLocator().getLineNumber() + "\n OFFSET: " + event.getLocator().getOffset() + "\n CLASS: " + event.getLocator().getClass() + "\n NODE: " + event.getLocator().getNode() + "\n OBJECT: " + event.getLocator().getObject() + "\n URL: " + event.getLocator().getURL()); eventOccurred = true; // Allow more parsing feedback return true; }