Example usage for javax.xml.datatype DatatypeConfigurationException getMessage

List of usage examples for javax.xml.datatype DatatypeConfigurationException getMessage

Introduction

In this page you can find the example usage for javax.xml.datatype DatatypeConfigurationException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:be.fedict.eid.tsl.TrustServiceList.java

protected TrustServiceList() {
    super();//from w  ww  .  j a  v a  2  s. com
    this.changed = true;
    this.changeListeners = new LinkedList<ChangeListener>();
    this.objectFactory = new ObjectFactory();
    this.xadesObjectFactory = new be.fedict.eid.tsl.jaxb.xades.ObjectFactory();
    this.xmldsigObjectFactory = new be.fedict.eid.tsl.jaxb.xmldsig.ObjectFactory();
    this.tslxObjectFactory = new be.fedict.eid.tsl.jaxb.tslx.ObjectFactory();
    try {
        this.datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException("datatype config error: " + e.getMessage(), e);
    }
}

From source file:be.fedict.eid.tsl.TrustServiceList.java

protected TrustServiceList(TrustStatusListType trustStatusList, Document tslDocument, File tslFile) {
    this.trustStatusList = trustStatusList;
    this.tslDocument = tslDocument;
    this.tslFile = tslFile;
    this.changeListeners = new LinkedList<ChangeListener>();
    this.objectFactory = new ObjectFactory();
    this.xadesObjectFactory = new be.fedict.eid.tsl.jaxb.xades.ObjectFactory();
    this.xmldsigObjectFactory = new be.fedict.eid.tsl.jaxb.xmldsig.ObjectFactory();
    this.tslxObjectFactory = new be.fedict.eid.tsl.jaxb.tslx.ObjectFactory();
    try {/*from www .jav  a  2 s. c om*/
        this.datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException("datatype config error: " + e.getMessage(), e);
    }
}

From source file:org.apache.metron.dataloads.taxii.TaxiiHandler.java

/**
 * The action to be performed by this timer task.
 *///from w ww.  j  a  v a  2  s  .c o  m
@Override
public void run() {
    if (inProgress) {
        return;
    }
    Date ts = new Date();
    LOG.info("Polling..." + new SimpleDateFormat().format(ts));
    try {
        inProgress = true;
        // Prepare the message to send.
        String sessionID = MessageHelper.generateMessageId();
        PollRequest request = messageFactory.get().createPollRequest().withMessageId(sessionID)
                .withCollectionName(collection);
        if (subscriptionId != null) {
            request = request.withSubscriptionID(subscriptionId);
        } else {
            request = request.withPollParameters(messageFactory.get().createPollParametersType());
        }
        if (beginTime != null) {
            Calendar gc = GregorianCalendar.getInstance();
            gc.setTime(beginTime);
            XMLGregorianCalendar gTime = null;
            try {
                gTime = DatatypeFactory.newInstance().newXMLGregorianCalendar((GregorianCalendar) gc)
                        .normalize();
            } catch (DatatypeConfigurationException e) {
                LOG.error("Unable to set the begin time", e);
            }
            gTime.setFractionalSecond(null);
            LOG.info("Begin Time: " + gTime);
            request.setExclusiveBeginTimestamp(gTime);
        }

        try {
            PollResponse response = call(request, PollResponse.class);
            LOG.info("Got Poll Response with " + response.getContentBlocks().size() + " blocks");
            int numProcessed = 0;
            long avgTimeMS = 0;
            long timeStartedBlock = System.currentTimeMillis();
            for (ContentBlock block : response.getContentBlocks()) {
                AnyMixedContentType content = block.getContent();
                for (Object o : content.getContent()) {
                    numProcessed++;
                    long timeS = System.currentTimeMillis();
                    String xml = null;
                    if (o instanceof Element) {
                        Element element = (Element) o;
                        xml = getStringFromDocument(element.getOwnerDocument());
                        if (LOG.isDebugEnabled() && Math.random() < 0.01) {
                            LOG.debug("Random Stix doc: " + xml);
                        }
                        for (LookupKV<ThreatIntelKey, ThreatIntelValue> kv : extractor.extract(xml)) {
                            String indicatorType = kv.getValue().getMetadata().get("indicator-type");
                            TableInfo tableInfo = tableMap.get(indicatorType);
                            boolean persisted = false;
                            if (tableInfo != null) {
                                kv.getValue().getMetadata().put("source_type", "taxii");
                                kv.getValue().getMetadata().put("taxii_url", endpoint.toString());
                                kv.getValue().getMetadata().put("taxii_collection", collection);
                                Put p = converter.toPut(tableInfo.getColumnFamily(), kv.getKey(),
                                        kv.getValue());
                                HTableInterface table = getTable(tableInfo);
                                table.put(p);
                                persisted = true;
                            }
                            LOG.info("Found Threat Intel: " + persisted + ", " + kv.getKey() + " => "
                                    + kv.getValue());
                        }
                    }
                    avgTimeMS += System.currentTimeMillis() - timeS;
                }
                if ((numProcessed + 1) % 100 == 0) {
                    LOG.info("Processed " + numProcessed + " in "
                            + (System.currentTimeMillis() - timeStartedBlock) + " ms, avg time: "
                            + avgTimeMS / content.getContent().size());
                    timeStartedBlock = System.currentTimeMillis();
                    avgTimeMS = 0;
                    numProcessed = 0;
                }
            }
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
            throw new RuntimeException("Unable to make request", e);
        }
    } finally {
        inProgress = false;
        beginTime = ts;
    }
}

From source file:org.accada.epcis.repository.query.QuerySubscription.java

/**
 * Serializes and sends the given object back to the client. The Object must
 * be an instance of QueryResults, QueryTooLargeException, or
 * ImplementationException.//from   ww  w.  j a  v  a 2s.  c o m
 * 
 * @param o
 *            The object to be sent back to the client. An instance of
 *            QueryResults, QueryTooLargeException, or
 *            ImplementationException.
 */
private void callbackObject(final Object o) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Callback " + o + " at " + new Date());
    }
    // create the EPCIS document
    EPCISQueryDocumentType epcisDoc = new EPCISQueryDocumentType();
    epcisDoc.setSchemaVersion(BigDecimal.valueOf(1.0));
    try {
        DatatypeFactory dataFactory = DatatypeFactory.newInstance();
        XMLGregorianCalendar now = dataFactory.newXMLGregorianCalendar(new GregorianCalendar());
        epcisDoc.setCreationDate(now);
    } catch (DatatypeConfigurationException e) {
        // oh well - don't care about setting the creation date
    }
    EPCISQueryBodyType epcisBody = new EPCISQueryBodyType();
    if (o instanceof QueryResults) {
        epcisBody.setQueryResults((QueryResults) o);
    } else if (o instanceof QueryTooLargeException) {
        epcisBody.setQueryTooLargeException((QueryTooLargeException) o);
    } else if (o instanceof ImplementationException) {
        epcisBody.setImplementationException((ImplementationException) o);
    } else {
        epcisBody = null;
    }
    epcisDoc.setEPCISBody(epcisBody);

    // serialize the response
    String data;
    try {
        data = marshalQueryDoc(epcisDoc);
    } catch (JAXBException e) {
        String msg = "An error serializing contents occurred: " + e.getMessage();
        LOG.error(msg, e);
        return;
    }

    // set up connection and send data to given destination
    try {
        URL serviceUrl = new URL(dest.toString());
        if (LOG.isDebugEnabled()) {
            LOG.debug("Sending results of subscribed query '" + subscriptionID + "' to '" + serviceUrl + "'");
            if (data.length() < 10 * 1024) {
                LOG.debug("Sending data:\n" + data);
            } else {
                LOG.debug("Sending data: [" + data.length() + " bytes]");
            }
        }
        int responseCode;
        try {
            responseCode = sendData(serviceUrl, data);
        } catch (Exception e) {
            LOG.warn("Unable to send results of subscribed query '" + subscriptionID + "' to '" + serviceUrl
                    + "', retrying in 3 sec ...");
            // wait 3 seconds and try again
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e1) {
                // never mind
            }
            try {
                responseCode = sendData(serviceUrl, data);
            } catch (Exception e2) {
                LOG.warn("Unable to send results of subscribed query '" + subscriptionID + "' to '" + serviceUrl
                        + "', retrying in 3 sec ...");
                // wait 3 seconds and try again
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e1) {
                    // never mind
                }
                responseCode = sendData(serviceUrl, data);
            }
        }
        LOG.debug("Response " + responseCode);
    } catch (IOException e) {
        String msg = "Unable to send results of subscribed query '" + subscriptionID + "' to '" + dest + "': "
                + e.getMessage();
        LOG.error(msg, e);
        return;
    }
}

From source file:org.alfresco.opencmis.CMISConnector.java

private String convertAspectPropertyValue(Object value) {
    if (value instanceof Date) {
        GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        cal.setTime((Date) value);
        value = cal;//  ww w.  j a  va  2s  . c  o m
    }

    if (value instanceof GregorianCalendar) {
        DatatypeFactory df;
        try {
            df = DatatypeFactory.newInstance();
        } catch (DatatypeConfigurationException e) {
            throw new IllegalArgumentException("Aspect conversation exception: " + e.getMessage(), e);
        }
        return df.newXMLGregorianCalendar((GregorianCalendar) value).toXMLFormat();
    }

    // MNT-12496 MNT-15044
    // Filter for AtomPub and Web services bindings only. Browser/json binding already encodes.
    if (AlfrescoCmisServiceCall.get() != null
            && (CallContext.BINDING_ATOMPUB.equals(AlfrescoCmisServiceCall.get().getBinding())
                    || CallContext.BINDING_WEBSERVICES.equals(AlfrescoCmisServiceCall.get().getBinding()))) {
        return filterXmlRestrictedCharacters(value.toString());
    } else {
        return value.toString();
    }
}

From source file:org.alfresco.opencmis.CMISConnector.java

private void setAspectProperties(NodeRef nodeRef, boolean isNameChanging,
        CmisExtensionElement aspectExtension) {
    if (aspectExtension.getChildren() == null) {
        return;/*from  w  w  w .j  a v  a  2  s.c om*/
    }

    List<String> aspectsToAdd = new ArrayList<String>();
    List<String> aspectsToRemove = new ArrayList<String>();
    Map<QName, List<Serializable>> aspectProperties = new HashMap<QName, List<Serializable>>();

    for (CmisExtensionElement extension : aspectExtension.getChildren()) {
        if (!ALFRESCO_EXTENSION_NAMESPACE.equals(extension.getNamespace())) {
            continue;
        }

        if (ASPECTS_TO_ADD.equals(extension.getName()) && (extension.getValue() != null)) {
            aspectsToAdd.add(extension.getValue());
        } else if (ASPECTS_TO_REMOVE.equals(extension.getName()) && (extension.getValue() != null)) {
            aspectsToRemove.add(extension.getValue());
        } else if (PROPERTIES.equals(extension.getName()) && (extension.getChildren() != null)) {
            for (CmisExtensionElement property : extension.getChildren()) {
                if (!property.getName().startsWith("property")) {
                    continue;
                }

                String propertyId = (property.getAttributes() == null ? null
                        : property.getAttributes().get("propertyDefinitionId"));
                if ((propertyId == null) || (property.getChildren() == null)) {
                    continue;
                }

                PropertyType propertyType = PropertyType.STRING;
                DatatypeFactory df = null;
                if (property.getName().equals("propertyBoolean")) {
                    propertyType = PropertyType.BOOLEAN;
                } else if (property.getName().equals("propertyInteger")) {
                    propertyType = PropertyType.INTEGER;
                } else if (property.getName().equals("propertyDateTime")) {
                    propertyType = PropertyType.DATETIME;
                    try {
                        df = DatatypeFactory.newInstance();
                    } catch (DatatypeConfigurationException e) {
                        throw new CmisRuntimeException("Aspect conversation exception: " + e.getMessage(), e);
                    }
                } else if (property.getName().equals("propertyDecimal")) {
                    propertyType = PropertyType.DECIMAL;
                }

                ArrayList<Serializable> values = new ArrayList<Serializable>();
                if (property.getChildren() != null) {
                    //                        try
                    //                        {
                    for (CmisExtensionElement valueElement : property.getChildren()) {
                        if ("value".equals(valueElement.getName())) {
                            switch (propertyType) {
                            case BOOLEAN:
                                try {
                                    values.add(Boolean.parseBoolean(valueElement.getValue()));
                                } catch (Exception e) {
                                    throw new CmisInvalidArgumentException(
                                            "Invalid property aspect value: " + propertyId, e);
                                }
                                break;
                            case DATETIME:
                                try {
                                    values.add(df.newXMLGregorianCalendar(valueElement.getValue())
                                            .toGregorianCalendar());
                                } catch (Exception e) {
                                    throw new CmisInvalidArgumentException(
                                            "Invalid property aspect value: " + propertyId, e);
                                }
                                break;
                            case INTEGER:
                                BigInteger value = null;
                                try {
                                    value = new BigInteger(valueElement.getValue());
                                } catch (Exception e) {
                                    throw new CmisInvalidArgumentException(
                                            "Invalid property aspect value: " + propertyId, e);
                                }

                                // overflow check
                                PropertyDefinitionWrapper propDef = getOpenCMISDictionaryService()
                                        .findProperty(propertyId);
                                if (propDef == null) {
                                    throw new CmisInvalidArgumentException(
                                            "Property " + propertyId + " is unknown!");
                                }

                                QName propertyQName = propDef.getPropertyAccessor().getMappedProperty();
                                if (propertyQName == null) {
                                    throw new CmisConstraintException(
                                            "Unable to set property " + propertyId + "!");
                                }

                                org.alfresco.service.cmr.dictionary.PropertyDefinition def = dictionaryService
                                        .getProperty(propertyQName);
                                QName dataDef = def.getDataType().getName();

                                if (dataDef.equals(DataTypeDefinition.INT)
                                        && (value.compareTo(maxInt) > 0 || value.compareTo(minInt) < 0)) {
                                    throw new CmisConstraintException(
                                            "Value is out of range for property " + propertyId);
                                }

                                if (dataDef.equals(DataTypeDefinition.LONG)
                                        && (value.compareTo(maxLong) > 0 || value.compareTo(minLong) < 0)) {
                                    throw new CmisConstraintException(
                                            "Value is out of range for property " + propertyId);
                                }

                                values.add(value);
                                break;
                            case DECIMAL:
                                try {
                                    values.add(new BigDecimal(valueElement.getValue()));
                                } catch (Exception e) {
                                    throw new CmisInvalidArgumentException(
                                            "Invalid property aspect value: " + propertyId, e);
                                }
                                break;
                            default:
                                values.add(valueElement.getValue());
                            }
                        }
                    }
                }

                aspectProperties.put(QName.createQName(propertyId, namespaceService), values);
            }
        }
    }

    // remove and add aspects
    String aspectType = null;
    try {
        for (String aspect : aspectsToRemove) {
            aspectType = aspect;

            TypeDefinitionWrapper type = getType(aspect);
            if (type == null) {
                throw new CmisInvalidArgumentException("Invalid aspect: " + aspectType);
            }

            QName typeName = type.getAlfrescoName();
            // if aspect is hidden aspect, remove only if hidden node is not client controlled
            if (typeName.equals(ContentModel.ASPECT_HIDDEN)) {
                if (hiddenAspect.isClientControlled(nodeRef)
                        || aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED)) {
                    // manipulate hidden aspect only if client controlled
                    nodeService.removeAspect(nodeRef, typeName);
                }

                //                   if(!isNameChanging && !hiddenAspect.isClientControlled(nodeRef) && !aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED))
                //                   {
                //                       nodeService.removeAspect(nodeRef, typeName);   
                //                   }
            } else {
                nodeService.removeAspect(nodeRef, typeName);
            }
        }

        for (String aspect : aspectsToAdd) {
            aspectType = aspect;

            TypeDefinitionWrapper type = getType(aspect);
            if (type == null) {
                throw new CmisInvalidArgumentException("Invalid aspect: " + aspectType);
            }

            QName typeName = type.getAlfrescoName();
            // if aspect is hidden aspect, remove only if hidden node is not client controlled
            if (typeName.equals(ContentModel.ASPECT_HIDDEN)) {
                if (hiddenAspect.isClientControlled(nodeRef)
                        || aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED)) {
                    // manipulate hidden aspect only if client controlled
                    nodeService.addAspect(nodeRef, type.getAlfrescoName(),
                            Collections.<QName, Serializable>emptyMap());
                }

                //                   if(!isNameChanging && !hiddenAspect.isClientControlled(nodeRef) && !aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED))
                //                   {
                //                      nodeService.addAspect(nodeRef, type.getAlfrescoName(),
                //                               Collections.<QName, Serializable> emptyMap());   
                //                   }
            } else {
                nodeService.addAspect(nodeRef, type.getAlfrescoName(),
                        Collections.<QName, Serializable>emptyMap());
            }
        }
    } catch (InvalidAspectException e) {
        throw new CmisInvalidArgumentException("Invalid aspect: " + aspectType);
    } catch (InvalidNodeRefException e) {
        throw new CmisInvalidArgumentException("Invalid node: " + nodeRef);
    }

    // set property
    for (Map.Entry<QName, List<Serializable>> property : aspectProperties.entrySet()) {
        QName propertyQName = property.getKey();

        if (property.getValue().isEmpty()) {
            if (HiddenAspect.HIDDEN_PROPERTIES.contains(property.getKey())) {
                if (hiddenAspect.isClientControlled(nodeRef)
                        || aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED)) {
                    // manipulate hidden aspect property only if client controlled
                    nodeService.removeProperty(nodeRef, propertyQName);
                }
            } else {
                nodeService.removeProperty(nodeRef, property.getKey());
            }
        } else {
            if (HiddenAspect.HIDDEN_PROPERTIES.contains(property.getKey())) {
                if (hiddenAspect.isClientControlled(nodeRef)
                        || aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED)) {
                    // manipulate hidden aspect property only if client controlled
                    nodeService.setProperty(nodeRef, property.getKey(),
                            property.getValue().size() == 1 ? property.getValue().get(0)
                                    : (Serializable) property.getValue());
                }
            } else {
                Serializable value = (Serializable) property.getValue();
                nodeService.setProperty(nodeRef, property.getKey(),
                        property.getValue().size() == 1 ? property.getValue().get(0) : value);
            }
        }
    }
}

From source file:org.entrystore.repository.impl.EntryImpl.java

protected void registerEntryModified(RepositoryConnection rc, ValueFactory vf) throws RepositoryException {
    try {//from   w w  w  . j  a  v  a 2  s. c o  m
        modified = DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar());
    } catch (DatatypeConfigurationException e) {
        log.error(e.getMessage());
        throw new RepositoryException(e.getMessage(), e);
    }
    rc.remove(rc.getStatements(entryURI, RepositoryProperties.Modified, null, false, entryURI), entryURI);
    rc.add(entryURI, RepositoryProperties.Modified, vf.createLiteral(modified), entryURI);

    //Also adding the one who update using dcterms:contributor
    if (this.repositoryManager != null && this.repositoryManager.getPrincipalManager() != null
            && this.repositoryManager.getPrincipalManager().getAuthenticatedUserURI() != null) {
        java.net.URI contrib = this.repositoryManager.getPrincipalManager().getAuthenticatedUserURI();
        String contributor = contrib.toString();
        URI contributorURI = vf.createURI(contributor);

        //Do not add if the contributor is the same as the creator
        if (contrib != null && !contrib.equals(this.getCreator()) && contributors != null
                && !contributors.contains(contributorURI)) {
            rc.add(this.entryURI, RepositoryProperties.Contributor, contributorURI, this.entryURI);
            contributors.add(contributorURI);
        }
    }
}

From source file:org.jrecruiter.common.CalendarUtils.java

/**
 * Get a XML-date representation (ISO 8601) of the provided calendar object.
 *
 * For more details @see http://www.w3.org/TR/xmlschema-2/#dateTime
 *
 * @return XML-date as String/*  ww  w. j  a v  a  2  s.c o  m*/
 */
public static String getXmlFormatedDate(final Calendar calendar) {

    if (calendar == null) {
        throw new IllegalArgumentException("Calendar is a required parameter");
    }

    final GregorianCalendar gregorianCalendar = new GregorianCalendar(calendar.getTimeZone());
    gregorianCalendar.setTime(calendar.getTime());

    final DatatypeFactory dataTypeFactory;

    try {
        dataTypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }

    final XMLGregorianCalendar xmlCalendar = dataTypeFactory.newXMLGregorianCalendar(gregorianCalendar);

    return xmlCalendar.toXMLFormat();
}

From source file:org.kitodo.dataformat.access.MetsXmlElementAccess.java

/**
 * Creates an object of class XMLGregorianCalendar. Creating this
 * JAXB-specific class is quite complicated and has therefore been
 * outsourced to a separate method./*from  w ww  .  j  a  v a  2  s.  c o m*/
 * 
 * @param gregorianCalendar
 *            value of the calendar
 * @return an object of class XMLGregorianCalendar
 */
private static XMLGregorianCalendar convertDate(GregorianCalendar gregorianCalendar) {
    DatatypeFactory datatypeFactory;
    try {
        datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
        String message = e.getMessage();
        throw new NoClassDefFoundError(message != null ? message
                : "Implementation of DatatypeFactory not available or cannot be instantiated.");
    }
    return datatypeFactory.newXMLGregorianCalendar(gregorianCalendar);
}

From source file:test.unit.be.e_contract.dssp.client.DigitalSignatureServiceTestPort.java

public DigitalSignatureServiceTestPort() {
    this.objectFactory = new ObjectFactory();
    this.asyncObjectFactory = new be.e_contract.dssp.ws.jaxb.dss.async.ObjectFactory();
    this.wstObjectFactory = new be.e_contract.dssp.ws.jaxb.wst.ObjectFactory();
    this.wsscObjectFactory = new be.e_contract.dssp.ws.jaxb.wssc.ObjectFactory();
    this.vrObjectFactory = new be.e_contract.dssp.ws.jaxb.dss.vr.ObjectFactory();
    this.xmldsigObjectFactory = new be.e_contract.dssp.ws.jaxb.xmldsig.ObjectFactory();
    this.dsspObjectFactory = new be.e_contract.dssp.ws.jaxb.dssp.ObjectFactory();
    try {/* ww  w.  ja va 2  s  . co  m*/
        this.datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException("datatype factory error: " + e.getMessage(), e);
    }
}