private static String getMessage(final JAXBException ex) { String ret = ex.getMessage(); if (ret == null && ex.getLinkedException() != null) { ret = ex.getLinkedException().getMessage(); } return ret; }
private static String getMessage(JAXBException ex) { String ret = ex.getMessage(); if (ret == null && ex.getLinkedException() != null) { ret = ex.getLinkedException().getMessage(); } return ret; }
public static String toXml(Organization organization) { try { Marshaller marshaller = jaxbContext.createMarshaller(); Writer writer = new StringWriter(); marshaller.marshal(organization, writer); return writer.toString(); } catch (JAXBException e) { throw new IllegalStateException(e.getLinkedException() != null ? e.getLinkedException() : e); } }
public void printStackTrace(PrintWriter pWriter) { super.printStackTrace(pWriter); Throwable t = getLinkedException(); if (t != null) { pWriter.println("Caused by:"); t.printStackTrace(pWriter); } } }
public static String toXml(User user) { try { Marshaller marshaller = jaxbContext.createMarshaller(); Writer writer = new StringWriter(); marshaller.marshal(user, writer); return writer.toString(); } catch (JAXBException e) { throw new IllegalStateException(e.getLinkedException() != null ? e.getLinkedException() : e); } }
public void printStackTrace(PrintStream pStream) { super.printStackTrace(pStream); Throwable t = getLinkedException(); if (t != null) { pStream.println("Caused by:"); t.printStackTrace(pStream); } }
public void printStackTrace(PrintWriter pWriter) { super.printStackTrace(pWriter); Throwable t = getLinkedException(); if (t != null) { pWriter.println("Caused by:"); t.printStackTrace(pWriter); } } }
public void printStackTrace(PrintStream pStream) { super.printStackTrace(pStream); Throwable t = getLinkedException(); if (t != null) { pStream.println("Caused by:"); t.printStackTrace(pStream); } }
public static User fromXml(String xml) { InputStream in = null; try { in = IOUtils.toInputStream(xml); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); return unmarshaller.unmarshal(new StreamSource(in), JaxbUser.class).getValue(); } catch (JAXBException e) { throw new IllegalStateException(e.getLinkedException() != null ? e.getLinkedException() : e); } finally { IOUtils.closeQuietly(in); } }
public static Organization fromXml(String xml) { InputStream in = null; try { in = IOUtils.toInputStream(xml); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); return unmarshaller.unmarshal(new StreamSource(in), JaxbOrganization.class).getValue(); } catch (JAXBException e) { throw new IllegalStateException(e.getLinkedException() != null ? e.getLinkedException() : e); } finally { IOUtils.closeQuietly(in); } }
/** * Parses the serialized media package element and returns its object representation. * * @param xml * the serialized element * @return the media package element instance * @throws MediaPackageException * if de-serializing the element fails */ public static MediaPackageElement getFromXml(String xml) throws MediaPackageException { Unmarshaller m = null; try { m = MediaPackageImpl.context.createUnmarshaller(); return (MediaPackageElement) m.unmarshal(new InputSource(toInputStream(xml))); } catch (JAXBException e) { throw new MediaPackageException(e.getLinkedException() != null ? e.getLinkedException() : e); } }
/** * Writes an xml representation of this MediaPackage to a stream. * * @param mediaPackage * the mediaPackage * @param out * The output stream * @param format * Whether to format the output for readability, or not (false gives better performance) * @throws MediaPackageException * if serializing or reading from a serialized media package fails */ public static void getAsXml(MediaPackage mediaPackage, OutputStream out, boolean format) throws MediaPackageException { try { Marshaller marshaller = MediaPackageImpl.context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, format); marshaller.marshal(mediaPackage, out); } catch (JAXBException e) { throw new MediaPackageException(e.getLinkedException() != null ? e.getLinkedException() : e); } }
/** * Reads the media package from the input stream. * * @param xml * the input stream * @return the deserialized media package */ public static MediaPackageImpl valueOf(InputStream xml) throws MediaPackageException { try { Unmarshaller unmarshaller = context.createUnmarshaller(); return unmarshaller.unmarshal(new StreamSource(xml), MediaPackageImpl.class).getValue(); } catch (JAXBException e) { throw new MediaPackageException(e.getLinkedException() != null ? e.getLinkedException() : e); } finally { IoSupport.closeQuietly(xml); } }
public static void toXML(AuditMessage message, OutputStream os, boolean format, String encoding, String schemaURI) throws IOException { try { Marshaller m = jc().createMarshaller(); if (format) m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); if (schemaURI != null) m.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, schemaURI); if (encoding != null) m.setProperty(Marshaller.JAXB_ENCODING, encoding); m.marshal(of.createAuditMessage(message), os ); } catch( JAXBException jbe ){ if (jbe.getLinkedException() instanceof IOException) throw (IOException) jbe.getLinkedException(); throw new IllegalStateException(jbe); } }
public static void toXML(AuditMessage message, OutputStream os, boolean format, String encoding, String schemaURI) throws IOException { try { Marshaller m = jc().createMarshaller(); if (format) m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); if (schemaURI != null) m.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, schemaURI); if (encoding != null) m.setProperty(Marshaller.JAXB_ENCODING, encoding); m.marshal(of.createAuditMessage(message), os ); } catch( JAXBException jbe ){ if (jbe.getLinkedException() instanceof IOException) throw (IOException) jbe.getLinkedException(); throw new IllegalStateException(jbe); } }
protected void handleJAXBException(JAXBException e, boolean read) { StringBuilder sb = handleExceptionStart(e); Throwable linked = e.getLinkedException(); if (linked != null && linked.getMessage() != null) { if (read && linked instanceof XMLStreamException && linked.getMessage().startsWith("Maximum Number")) { throw ExceptionUtils.toWebApplicationException(null, JAXRSUtils.toResponse(413)); } sb.append(linked.getMessage()).append(". "); } Throwable t = linked != null ? linked : e.getCause() != null ? e.getCause() : e; String message = new org.apache.cxf.common.i18n.Message("JAXB_EXCEPTION", BUNDLE, sb.toString()).toString(); handleExceptionEnd(t, message, read); }
public String run() throws JAXBException { try { config = configInterface.getConfig(); if (config == null) { throw new SensorException("Please setup configInterface"); } if ((sensorName == null) || (sensorName.isEmpty())) { throw new SensorException("No parameter: name"); } LOG.info(String.format("run(): %s", sensorName)); process(); } catch (Throwable ex) { final Throwable _ex = (ex instanceof javax.xml.bind.JAXBException) ? ((javax.xml.bind.JAXBException) ex).getLinkedException() : ex; prtg.setError(BooleanType.TRUE); prtg.setErrorText(String.format("%s: %s", ex.getClass().getName(), _ex)); LOG.log(Level.SEVERE, ex.getMessage(), ex); } return getManager().toXML(prtg); }
/** * Adds a single field to a Solr document * * @param in Solr document * @param out Solr document with added field */ @Override public void run(Reader in, Writer out) throws RuleException { //log("Adding field [" + field + "]"); try { AddDoc addDoc = AddDoc.read(in); addDoc.getFields().add(field); addDoc.write(out); } catch (JAXBException jaxbe) { throw new RuleException(jaxbe.getLinkedException()); } } }
@Override public void run(Reader in, Writer out) throws RuleException { log("Changing '" + fieldName + "' value to lower case"); try { AddDoc addDoc = AddDoc.read(in); List<Field> fields = addDoc.getFields(fieldName); for (Field field : fields) { field.setValue(field.getValue().toLowerCase()); } addDoc.write(out); } catch (JAXBException jaxbe) { throw new RuleException(jaxbe.getLinkedException()); } } }
@Override public void run(Reader in, Writer out) throws RuleException { log("Copying field " + sourceFieldName + " as " + newFieldName); try { AddDoc addDoc = AddDoc.read(in); List<Field> sourceFields = addDoc.getFields(sourceFieldName); for (Field sourceField : sourceFields) { Field newField = new Field(newFieldName, sourceField.getValue()); addDoc.getFields().add(newField); } addDoc.write(out); } catch (JAXBException jaxbe) { throw new RuleException(jaxbe.getLinkedException()); } } }