Search in sources :

Example 11 with JAXBException

use of javax.xml.bind.JAXBException in project hbase by apache.

the class RemoteAdmin method getClusterVersion.

/**
   * @return string representing the cluster's version
   * @throws IOException
   *           if the endpoint does not exist, there is a timeout, or some other
   *           general failure mode
   */
public StorageClusterVersionModel getClusterVersion() throws IOException {
    StringBuilder path = new StringBuilder();
    path.append('/');
    if (accessToken != null) {
        path.append(accessToken);
        path.append('/');
    }
    path.append("version/cluster");
    int code = 0;
    for (int i = 0; i < maxRetries; i++) {
        Response response = client.get(path.toString(), Constants.MIMETYPE_XML);
        code = response.getCode();
        switch(code) {
            case 200:
                try {
                    return (StorageClusterVersionModel) getUnmarsheller().unmarshal(getInputStream(response));
                } catch (JAXBException jaxbe) {
                    throw new IOException("Issue parsing StorageClusterVersionModel object in XML form: " + jaxbe.getLocalizedMessage(), jaxbe);
                }
            case 404:
                throw new IOException("Cluster version not found");
            case 509:
                try {
                    Thread.sleep(sleepTime);
                } catch (InterruptedException e) {
                    throw (InterruptedIOException) new InterruptedIOException().initCause(e);
                }
                break;
            default:
                throw new IOException(path.toString() + " request returned " + code);
        }
    }
    throw new IOException("get request to " + path.toString() + " request timed out");
}
Also used : InterruptedIOException(java.io.InterruptedIOException) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) StorageClusterVersionModel(org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel)

Example 12 with JAXBException

use of javax.xml.bind.JAXBException in project elastic-job by dangdangdotcom.

the class AbstractXmlRepositoryImpl method save.

@Override
public synchronized void save(final E entity) {
    try {
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(entity, file);
    } catch (final JAXBException ex) {
        throw new JobConsoleException(ex);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) JAXBException(javax.xml.bind.JAXBException) JobConsoleException(com.dangdang.ddframe.job.lite.console.exception.JobConsoleException)

Example 13 with JAXBException

use of javax.xml.bind.JAXBException in project Mycat-Server by MyCATApache.

the class XmlProcessBase method baseParseAndWriteToXml.

/**
     * 默认将bean序列化为xml对象信息并写入文件
    * 方法描述
    * @param user 用户对象
    * @param inputPath
    * @param name 当前的转换xml的dtd文件的信息
    * @创建日期 2016年9月15日
    */
public void baseParseAndWriteToXml(Object user, String inputPath, String name) throws IOException {
    try {
        Marshaller marshaller = this.jaxContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
        if (null != name) {
            marshaller.setProperty("com.sun.xml.internal.bind.xmlHeaders", String.format("<!DOCTYPE mycat:%1$s SYSTEM \"%1$s.dtd\">", name));
        }
        Path path = Paths.get(inputPath);
        OutputStream out = Files.newOutputStream(path, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);
        marshaller.marshal(user, out);
    } catch (JAXBException e) {
        lOG.error("ZookeeperProcessListen parseToXml  error:Exception info:", e);
    } catch (IOException e) {
        lOG.error("ZookeeperProcessListen parseToXml  error:Exception info:", e);
    }
}
Also used : Path(java.nio.file.Path) Marshaller(javax.xml.bind.Marshaller) OutputStream(java.io.OutputStream) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException)

Example 14 with JAXBException

use of javax.xml.bind.JAXBException in project Mycat-Server by MyCATApache.

the class XmltoZkMain method main.

public static void main(String[] args) throws JAXBException, InterruptedException {
    // 加载zk总服务
    ZookeeperProcessListen zkListen = new ZookeeperProcessListen();
    // 得到集群名称
    String custerName = ZkConfig.getInstance().getValue(ZkParamCfg.ZK_CFG_CLUSTERID);
    // 得到基本路径
    String basePath = ZookeeperPath.ZK_SEPARATOR.getKey() + ZookeeperPath.FLOW_ZK_PATH_BASE.getKey();
    basePath = basePath + ZookeeperPath.ZK_SEPARATOR.getKey() + custerName;
    zkListen.setBasePath(basePath);
    // 获得zk的连接信息
    CuratorFramework zkConn = buildConnection(ZkConfig.getInstance().getValue(ZkParamCfg.ZK_CFG_URL));
    // 获得公共的xml转换器对象
    XmlProcessBase xmlProcess = new XmlProcessBase();
    // 进行xmltozk的schema文件的操作
    new SchemasxmlTozkLoader(zkListen, zkConn, xmlProcess);
    // 进行xmltozk的server文件的操作
    new ServerxmlTozkLoader(zkListen, zkConn, xmlProcess);
    // 进行rule文件到zk的操作
    new RulesxmlTozkLoader(zkListen, zkConn, xmlProcess);
    // 进行序列信息入zk中
    new SequenceTozkLoader(zkListen, zkConn, xmlProcess);
    // 缓存配制信息
    new EcachesxmlTozkLoader(zkListen, zkConn, xmlProcess);
    // 将其他信息加载的zk中
    new OthermsgTozkLoader(zkListen, zkConn, xmlProcess);
    // 初始化xml转换操作
    xmlProcess.initJaxbClass();
    // 加载通知进程
    zkListen.notifly(ZkNofiflyCfg.ZK_NOTIFLY_LOAD_ALL.getKey());
    String clusterNodes = ZkConfig.getInstance().getValue(ZkParamCfg.ZK_CFG_CLUSTER_NODES);
    String clusterSize = ZkConfig.getInstance().getValue(ZkParamCfg.ZK_CFG_CLUSTER_SIZE);
    ClusterInfo info = new ClusterInfo();
    info.setClusterNodes(clusterNodes);
    info.setClusterSize(Integer.parseInt(clusterSize));
    try {
        zkConn.setData().forPath(basePath, JSON.toJSONBytes(info));
    } catch (Exception e) {
        LOGGER.error("error", e);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) EcachesxmlTozkLoader(io.mycat.config.loader.zkprocess.xmltozk.listen.EcachesxmlTozkLoader) ClusterInfo(io.mycat.config.loader.zkprocess.zookeeper.ClusterInfo) RulesxmlTozkLoader(io.mycat.config.loader.zkprocess.xmltozk.listen.RulesxmlTozkLoader) XmlProcessBase(io.mycat.config.loader.zkprocess.parse.XmlProcessBase) ServerxmlTozkLoader(io.mycat.config.loader.zkprocess.xmltozk.listen.ServerxmlTozkLoader) OthermsgTozkLoader(io.mycat.config.loader.zkprocess.xmltozk.listen.OthermsgTozkLoader) ZookeeperProcessListen(io.mycat.config.loader.zkprocess.comm.ZookeeperProcessListen) SchemasxmlTozkLoader(io.mycat.config.loader.zkprocess.xmltozk.listen.SchemasxmlTozkLoader) JAXBException(javax.xml.bind.JAXBException) SequenceTozkLoader(io.mycat.config.loader.zkprocess.xmltozk.listen.SequenceTozkLoader)

Example 15 with JAXBException

use of javax.xml.bind.JAXBException in project feign by OpenFeign.

the class JAXBDecoder method decode.

@Override
public Object decode(Response response, Type type) throws IOException {
    if (response.status() == 404)
        return Util.emptyValueOf(type);
    if (response.body() == null)
        return null;
    if (!(type instanceof Class)) {
        throw new UnsupportedOperationException("JAXB only supports decoding raw types. Found " + type);
    }
    try {
        SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
        /* Explicitly control sax configuration to prevent XXE attacks */
        saxParserFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
        saxParserFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
        saxParserFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false);
        saxParserFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        saxParserFactory.setNamespaceAware(namespaceAware);
        Source source = new SAXSource(saxParserFactory.newSAXParser().getXMLReader(), new InputSource(response.body().asInputStream()));
        Unmarshaller unmarshaller = jaxbContextFactory.createUnmarshaller((Class) type);
        return unmarshaller.unmarshal(source);
    } catch (JAXBException e) {
        throw new DecodeException(e.toString(), e);
    } catch (ParserConfigurationException e) {
        throw new DecodeException(e.toString(), e);
    } catch (SAXException e) {
        throw new DecodeException(e.toString(), e);
    } finally {
        if (response.body() != null) {
            response.body().close();
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) SAXSource(javax.xml.transform.sax.SAXSource) JAXBException(javax.xml.bind.JAXBException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Unmarshaller(javax.xml.bind.Unmarshaller) DecodeException(feign.codec.DecodeException) InputSource(org.xml.sax.InputSource) Source(javax.xml.transform.Source) SAXSource(javax.xml.transform.sax.SAXSource) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Aggregations

JAXBException (javax.xml.bind.JAXBException)402 JAXBContext (javax.xml.bind.JAXBContext)126 IOException (java.io.IOException)93 Unmarshaller (javax.xml.bind.Unmarshaller)91 Marshaller (javax.xml.bind.Marshaller)69 ArrayList (java.util.ArrayList)38 StringWriter (java.io.StringWriter)35 List (java.util.List)35 Map (java.util.Map)33 SAXException (org.xml.sax.SAXException)32 File (java.io.File)29 InputStream (java.io.InputStream)29 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)28 HashSet (java.util.HashSet)28 JAXBElement (javax.xml.bind.JAXBElement)24 XMLStreamException (javax.xml.stream.XMLStreamException)23 SAML2MetaException (com.sun.identity.saml2.meta.SAML2MetaException)22 StringReader (java.io.StringReader)21 HashMap (java.util.HashMap)21 SAML2MetaManager (com.sun.identity.saml2.meta.SAML2MetaManager)20