Example usage for javax.xml.bind JAXBException getMessage

List of usage examples for javax.xml.bind JAXBException getMessage

Introduction

In this page you can find the example usage for javax.xml.bind JAXBException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.mondora.chargify.controller.ChargifyAdapter.java

protected String toXml(Object o) {
    try {//www. ja  v  a 2s.c  om
        StringWriter sw = new StringWriter();
        JAXBContext context = JAXBContext.newInstance(o.getClass());
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.setProperty(Marshaller.JAXB_ENCODING, charset);
        marshaller.setSchema(null);
        marshaller.marshal(o, sw);
        return sw.toString();
    } catch (JAXBException e) {
        if (logger.isTraceEnabled())
            logger.trace(e.getMessage(), e);
        if (logger.isInfoEnabled())
            logger.info(e.getMessage());
    }
    return null;
}

From source file:eu.trentorise.smartcampus.permissionprovider.manager.ResourceAdapter.java

/**
 * Read the resources from the XML descriptor
 * @return//w  ww . ja v  a2s  . c o  m
 */
private List<Service> loadResourceTemplates() {
    try {
        JAXBContext jaxb = JAXBContext.newInstance(Service.class, Services.class, ResourceMapping.class,
                ResourceDeclaration.class);
        Unmarshaller unm = jaxb.createUnmarshaller();
        JAXBElement<Services> element = (JAXBElement<Services>) unm.unmarshal(
                new StreamSource(getClass().getResourceAsStream("resourceTemplates.xml")), Services.class);
        return element.getValue().getService();
    } catch (JAXBException e) {
        logger.error("Failed to load resource templates: " + e.getMessage(), e);
        return Collections.emptyList();
    }
}

From source file:net.itransformers.idiscover.v2.core.listeners.Neo4JGraphmlLoggerLogDiscoveryListener.java

@Override
public void nodeDiscovered(NodeDiscoveryResult discoveryResult) {
    File baseDir = new File(projectPath, labelDirName);
    File xsltFile = new File(xsltFileName);
    File graphmlDir = new File(baseDir, graphmDirName);

    GraphDatabaseService graphdb = new org.neo4j.rest.graphdb.RestGraphDatabase(graphDbUrl);

    if (!graphmlDir.exists())
        graphmlDir.mkdir();//from   w  ww .j  av a  2s  . c o m

    String deviceName = discoveryResult.getNodeId();
    DiscoveredDeviceData discoveredDeviceData = (DiscoveredDeviceData) discoveryResult
            .getDiscoveredData(dataType);
    ByteArrayOutputStream graphMLOutputStream = new ByteArrayOutputStream();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        JaxbMarshalar.marshal(discoveredDeviceData, out, "DiscoveredDevice");
    } catch (JAXBException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }

    XsltTransformer transformer = new XsltTransformer();
    try {
        transformer.transformXML(new ByteArrayInputStream(out.toByteArray()), xsltFile, graphMLOutputStream,
                null, null);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }

    final String fileName = "node-" + deviceName + ".graphml";
    final File nodeFile = new File(graphmlDir, fileName);
    String unformatedGraphml = new String(graphMLOutputStream.toByteArray());

    try {
        String graphml = new XmlFormatter().format(unformatedGraphml);

        FileUtils.writeStringToFile(nodeFile, graphml);
        FileWriter writer = new FileWriter(new File(labelDirName, "undirected" + ".graphmls"), true);
        writer.append(String.valueOf(fileName)).append("\n");
        writer.close();
    } catch (IOException e) {
        logger.debug("Unformated xml is not in correct format: \n" + unformatedGraphml);
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    }

    Neo4jGraphmlMerger neo4jMerger = new Neo4jGraphmlMerger(graphdb, "v1");
    Transaction tx = graphdb.beginTx();

    try {
        tx = graphdb.beginTx();
        neo4jMerger.merge(nodeFile);
        tx.success();
    } catch (Exception e) {
        if (tx != null)
            tx.failure();
    } finally {
        if (tx != null)
            tx.finish();
    }

}

From source file:ca.phon.session.io.xml.v12.XMLSessionWriter_v12.java

@Override
public void writeSession(Session session, OutputStream out) throws IOException {
    final JAXBElement<SessionType> ele = toSessionType(session);

    try {//from  w w w  .  j  av  a  2 s . com
        final JAXBContext context = JAXBContext.newInstance(ObjectFactory.class);
        final Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

        marshaller.marshal(ele, out);
    } catch (JAXBException e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    }
}

From source file:com.cloud.network.brocade.BrocadeVcsApi.java

protected <T> String convertToString(T object) throws BrocadeVcsApiException {

    final StringWriter stringWriter = new StringWriter();

    try {/*  w  w w  .j  a v  a 2 s  .c om*/
        final JAXBContext context = JAXBContext.newInstance(object.getClass());
        final Marshaller marshaller = context.createMarshaller();

        marshaller.marshal(object, stringWriter);

    } catch (JAXBException e) {
        s_logger.error("Failed to convert object to string : " + e.getMessage());
        throw new BrocadeVcsApiException("Failed to convert object to string : " + e.getMessage());
    }

    String str = stringWriter.toString();
    s_logger.info(str);

    return str;

}

From source file:com.cloud.network.brocade.BrocadeVcsApi.java

protected Output convertToXML(String object) throws BrocadeVcsApiException {

    Output output = null;//  w  w  w  .  ja va 2  s . co m
    try {
        JAXBContext context = JAXBContext.newInstance(Output.class);

        StringReader reader = new StringReader(object);

        final Unmarshaller unmarshaller = context.createUnmarshaller();
        Object result = unmarshaller.unmarshal(reader);

        if (result instanceof Output) {
            output = (Output) result;
            s_logger.info(output);
        }

    } catch (JAXBException e) {
        s_logger.error("Failed to convert string to object : " + e.getMessage());
        throw new BrocadeVcsApiException("Failed to convert string to object : " + e.getMessage());
    }

    return output;

}

From source file:org.tellervo.desktop.wsi.WebJaxbAccessor.java

private INTYPE doRequest() throws IOException {
    HttpClient client = new ContentEncodingHttpClient();
    HttpUriRequest req;/*from  www  .  ja  va 2  s .  c  om*/
    JAXBContext context;
    Document outDocument = null;

    try {
        context = getJAXBContext();
    } catch (JAXBException jaxb) {
        throw new IOException("Unable to acquire JAXB context: " + jaxb.getMessage());
    }

    try {
        if (requestMethod == RequestMethod.POST) {
            if (this.sendingObject == null)
                throw new NullPointerException("requestDocument is null yet required for this type of query");

            // Create a new POST request
            HttpPost post = new HttpPost(url);
            // Make it a multipart post
            MultipartEntity postEntity = new MultipartEntity();
            req = post;

            // create an XML document from the given objects
            outDocument = marshallToDocument(context, sendingObject, getNamespacePrefixMapper());

            // add it to the http post request
            XMLBody xmlb = new XMLBody(outDocument, "application/tellervo+xml", null);
            postEntity.addPart("xmlrequest", xmlb);
            postEntity.addPart("traceback", new StringBody(getStackTrace()));
            post.setEntity(postEntity);
        } else {
            // well, that's nice and easy
            req = new HttpGet(url);
        }

        // debug this transaction...
        TransactionDebug.sent(outDocument, noun);

        // load cookies
        ((AbstractHttpClient) client).setCookieStore(WSCookieStoreHandler.getCookieStore().toCookieStore());

        req.setHeader("User-Agent", "Tellervo WSI " + Build.getUTF8Version() + " (" + clientModuleVersion
                + "; ts " + Build.getCompleteVersionNumber() + ")");

        if (App.prefs.getBooleanPref(PrefKey.WEBSERVICE_USE_STRICT_SECURITY, false)) {
            // Using strict security so don't allow self signed certificates for SSL
        } else {
            // Not using strict security so allow self signed certificates for SSL
            if (url.getScheme().equals("https"))
                WebJaxbAccessor.setSelfSignableHTTPSScheme(client);
        }

        // create a responsehandler
        JaxbResponseHandler<INTYPE> responseHandler = new JaxbResponseHandler<INTYPE>(context,
                receivingObjectClass);

        // set the schema we validate against
        responseHandler.setValidateSchema(getValidationSchema());

        // execute the actual http query
        INTYPE inObject = null;
        try {
            inObject = client.execute(req, responseHandler);
        } catch (EOFException e4) {
            log.debug("Caught EOFException");
        }

        TransactionDebug.received(inObject, noun, context);

        // save our cookies?
        WSCookieStoreHandler.getCookieStore().fromCookieStore(((AbstractHttpClient) client).getCookieStore());

        // ok, now inspect the document we got back
        //TellervoDocumentInspector inspector = new TellervoDocumentInspector(inDocument);

        // Verify our document based on schema validity
        //inspector.validate();

        // Verify our document structure, throw any exceptions!
        //inspector.verifyDocument();

        return inObject;
    } catch (UnknownHostException e) {
        throw new IOException("The URL of the server you have specified is unknown");
    }

    catch (HttpResponseException hre) {

        if (hre.getStatusCode() == 404) {
            throw new IOException("The URL of the server you have specified is unknown");
        }

        BugReport bugs = new BugReport(hre);

        bugs.addDocument("sent.xml", outDocument);

        new BugDialog(bugs);

        throw new IOException("The server returned a protocol error " + hre.getStatusCode() + ": "
                + hre.getLocalizedMessage());
    } catch (IllegalStateException ex) {
        throw new IOException("Webservice URL must be a full URL qualified with a communications protocol.\n"
                + "Tellervo currently supports http:// and https://.");
    }

    catch (ResponseProcessingException rspe) {
        Throwable cause = rspe.getCause();
        BugReport bugs = new BugReport(cause);
        Document invalidDoc = rspe.getNonvalidatingDocument();
        File invalidFile = rspe.getInvalidFile();

        if (outDocument != null)
            bugs.addDocument("sent.xml", outDocument);
        if (invalidDoc != null)
            bugs.addDocument("recv-nonvalid.xml", invalidDoc);
        if (invalidFile != null)
            bugs.addDocument("recv-malformed.xml", invalidFile);

        new BugDialog(bugs);

        XMLDebugView.addDocument(BugReport.getStackTrace(cause), "Parsing Exception", true);

        // it's probably an ioexception...
        if (cause instanceof IOException)
            throw (IOException) cause;

        throw rspe;
    } catch (XMLParsingException xmlpe) {
        Throwable cause = xmlpe.getCause();
        BugReport bugs = new BugReport(cause);
        Document invalidDoc = xmlpe.getNonvalidatingDocument();
        File invalidFile = xmlpe.getInvalidFile();

        bugs.addDocument("sent.xml", outDocument);
        if (invalidDoc != null)
            bugs.addDocument("recv-nonvalid.xml", invalidDoc);
        if (invalidFile != null)
            bugs.addDocument("recv-malformed.xml", invalidFile);

        new BugDialog(bugs);

        XMLDebugView.addDocument(BugReport.getStackTrace(cause), "Parsing Exception", true);

        // it's probably an ioexception...
        if (cause instanceof IOException)
            throw (IOException) cause;

        throw xmlpe;
    } catch (IOException ioe) {
        throw ioe;

    } catch (Exception uhe) {
        BugReport bugs = new BugReport(uhe);

        bugs.addDocument("sent.xml", outDocument);

        /*
        // MalformedDocs are handled automatically by BugReport class
        if(!(uhe instanceof MalformedDocumentException) && inDocument != null)
           bugs.addDocument("received.xml", inDocument);
        */

        new BugDialog(bugs);

        throw new IOException("Exception " + uhe.getClass().getName() + ": " + uhe.getLocalizedMessage());
    } finally {
        //?
    }
}

From source file:be.fedict.eid.applet.service.signer.facets.XAdESXLSignatureFacet.java

/**
 * Main constructor.//from   w  w w.j a va 2 s.c o  m
 * 
 * @param timeStampService
 *            the time-stamp service used for XAdES-T and XAdES-X.
 * @param revocationDataService
 *            the optional revocation data service used for XAdES-C and
 *            XAdES-X-L. When <code>null</code> the signature will be
 *            limited to XAdES-T only.
 * @param digestAlgorithm
 *            the digest algorithm to be used for construction of the
 *            XAdES-X-L elements.
 */
public XAdESXLSignatureFacet(TimeStampService timeStampService, RevocationDataService revocationDataService,
        DigestAlgo digestAlgorithm) {
    this.objectFactory = new ObjectFactory();
    this.c14nAlgoId = CanonicalizationMethod.EXCLUSIVE;
    this.digestAlgorithm = digestAlgorithm;
    this.timeStampService = timeStampService;
    this.revocationDataService = revocationDataService;
    this.xmldsigObjectFactory = new be.fedict.eid.applet.service.signer.jaxb.xmldsig.ObjectFactory();
    this.xades141ObjectFactory = new be.fedict.eid.applet.service.signer.jaxb.xades141.ObjectFactory();

    try {
        JAXBContext context = JAXBContext
                .newInstance(be.fedict.eid.applet.service.signer.jaxb.xades141.ObjectFactory.class);
        this.marshaller = context.createMarshaller();
        this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        this.marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new XAdESNamespacePrefixMapper());
    } catch (JAXBException e) {
        throw new RuntimeException("JAXB error: " + e.getMessage(), e);
    }

    try {
        this.certificateFactory = CertificateFactory.getInstance("X.509");
    } catch (CertificateException e) {
        throw new RuntimeException("X509 JCA error: " + e.getMessage(), e);
    }

    try {
        this.datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException("datatype config error: " + e.getMessage(), e);
    }
}

From source file:eu.europa.ec.markt.dss.report.Tsl2PdfExporter.java

private void printExtension(ExtensionType extension, Document document) throws DocumentException {
    addTitle("Extension (critical: " + extension.isCritical() + ")", title3Font, Paragraph.ALIGN_LEFT, 0, 0,
            document);//  w w  w .  j  a v a2 s .c o m
    List<Object> contentList = extension.getContent();
    for (Object content : contentList) {
        LOG.debug("extension content: " + content.getClass().getName());
        if (content instanceof JAXBElement<?>) {
            JAXBElement<?> element = (JAXBElement<?>) content;
            LOG.debug("QName: " + element.getName());
            if (false == ADDITIONAL_SERVICE_INFORMATION_QNAME.equals(element.getName())) {
                continue;
            }
            addTitle("Additional service information", title4Font, Paragraph.ALIGN_LEFT, 0, 0, document);
            AdditionalServiceInformationType additionalServiceInformation = (AdditionalServiceInformationType) element
                    .getValue();
            LOG.debug("information value: " + additionalServiceInformation.getInformationValue());
            NonEmptyMultiLangURIType multiLangUri = additionalServiceInformation.getURI();
            LOG.debug("URI : " + multiLangUri.getValue() + " (language: " + multiLangUri.getLang() + ")");
            document.add(new Paragraph(
                    multiLangUri.getValue()
                            .substring(multiLangUri.getValue().indexOf("SvcInfoExt/") + "SvcInfoExt/".length()),
                    this.valueFont));
        } else if (content instanceof Element) {
            addTitle("Qualifications", title4Font, Paragraph.ALIGN_LEFT, 0, 0, document);
            Element element = (Element) content;
            LOG.debug("element namespace: " + element.getNamespaceURI());
            LOG.debug("element name: " + element.getLocalName());
            if ("http://uri.etsi.org/TrstSvc/SvcInfoExt/eSigDir-1999-93-EC-TrustedList/#"
                    .equals(element.getNamespaceURI()) && "Qualifications".equals(element.getLocalName())) {
                try {
                    QualificationsType qualifications = unmarshallQualifications(element);
                    List<QualificationElementType> qualificationElements = qualifications
                            .getQualificationElement();
                    for (QualificationElementType qualificationElement : qualificationElements) {
                        QualifiersType qualifiers = qualificationElement.getQualifiers();
                        List<QualifierType> qualifierList = qualifiers.getQualifier();
                        for (QualifierType qualifier : qualifierList) {
                            document.add(new Paragraph(
                                    "Qualifier: " + qualifier.getUri().substring(
                                            qualifier.getUri().indexOf("SvcInfoExt/") + "SvcInfoExt/".length()),
                                    this.valueFont));
                        }

                        CriteriaListType criteriaList = qualificationElement.getCriteriaList();
                        String description = criteriaList.getDescription();
                        if (null != description) {
                            document.add(new Paragraph("Criterial List Description", this.labelFont));
                            document.add(new Paragraph(description, this.valueFont));
                        }
                        document.add(new Paragraph("Assert: " + criteriaList.getAssert(), this.valueFont));
                        List<PoliciesListType> policySet = criteriaList.getPolicySet();
                        for (PoliciesListType policiesList : policySet) {
                            List<ObjectIdentifierType> oids = policiesList.getPolicyIdentifier();
                            for (ObjectIdentifierType oid : oids) {
                                document.add(new Paragraph("Policy OID: " + oid.getIdentifier().getValue(),
                                        this.valueFont));
                            }
                        }
                    }
                } catch (JAXBException e) {
                    LOG.error("JAXB error: " + e.getMessage(), e);
                }
            }
        }
    }
}

From source file:hydrograph.ui.propertywindow.widgets.customwidgets.schema.GridRowLoader.java

/**
 * The method exports schema rows from schema grid into schema file.
 * /*ww  w  . ja  va 2s .  c o m*/
 */
public void exportXMLfromGridRowsWithoutMessage(List<GridRow> schemaGridRowList) {
    Schema schema = new Schema();
    fields = new Fields();

    try {
        if (StringUtils.isNotBlank(schemaFile.getPath())) {
            exportFile(schemaGridRowList, schema);
        } else {
            logger.error(Messages.EXPORT_XML_EMPTY_FILENAME);
            throw new Exception(Messages.EXPORT_XML_EMPTY_FILENAME);
        }
    } catch (JAXBException e) {
        showMessageBox(
                Messages.EXPORT_XML_ERROR + " -\n"
                        + ((e.getCause() != null) ? e.getLinkedException().getMessage() : e.getMessage()),
                "Error", SWT.ERROR);
        logger.error(Messages.EXPORT_XML_ERROR);
    } catch (Exception e) {
        showMessageBox(Messages.EXPORT_XML_ERROR + " -\n" + e.getMessage(), "Error", SWT.ERROR);
        logger.error(Messages.EXPORT_XML_ERROR);
    }

}