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");
}
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);
}
}
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);
}
}
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);
}
}
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();
}
}
}
Aggregations