net.sf.json.xml.XMLSerializer Java Examples

The following examples show how to use net.sf.json.xml.XMLSerializer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Dispatcher.java    From jeewx with Apache License 2.0 5 votes vote down vote up
/**
 * 根据业务参数获取业务执行器
 * 
 * @param params
 * @return
 * @throws MyException
 */
public static ActionExecutor getExecutor(Map<String, String> params) throws MyException {
    //获取服务信息
    String service = params.get("service");
    if (StringUtils.isEmpty(service)) {
        throw new MyException("无法取得服务名");
    }
    //获取内容信息
    String bizContent = params.get("biz_content");
    if (StringUtils.isEmpty(bizContent)) {
        throw new MyException("无法取得业务内容信息");
    }

    //将XML转化成json对象
    JSONObject bizContentJson = (JSONObject) new XMLSerializer().read(bizContent);

    // 1.获取消息类型信息 
    String msgType = bizContentJson.getString("MsgType");
    if (StringUtils.isEmpty(msgType)) {
        throw new MyException("无法取得消息类型");
    }

    // 2.根据消息类型(msgType)进行执行器的分类转发
    //  2.1 纯文本聊天类型
    if ("text".equals(msgType)) {

        return ApplicationContextUtil.getContext().getBean(InAlipayChatTextExecutor.class);

        // 2.2 事件类型
    } else if ("event".equals(msgType)) {

        return getEventExecutor(service, bizContentJson);

    } else {

        // 2.3 后续支付宝还会新增其他类型,因此默认返回ack应答
        return new InAlipayDefaultExecutor(bizContentJson);
    }

}
 
Example #2
Source File: AlipayCoreService.java    From jeewx with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param params
 * @return 返回加密验证串
 * @throws MyException
 */
public String excute(Map<String, String> params) throws MyException {
	// 获取服务信息
	String service = params.get("service");
	if (StringUtils.isEmpty(service)) {
		throw new MyException("无法取得服务名");
	}
	// 获取内容信息
	String bizContent = params.get("biz_content");
	if (StringUtils.isEmpty(bizContent)) {
		throw new MyException("无法取得业务内容信息");
	}

	// 将XML转化成json对象
	JSONObject bizContentJson = (JSONObject) new XMLSerializer().read(bizContent);

	// 1.获取消息类型信息
	String msgType = bizContentJson.getString("MsgType");
	if (StringUtils.isEmpty(msgType)) {
		throw new MyException("无法取得消息类型");
	}

	// 2.根据消息类型(msgType)进行执行器的分类转发
	// 2.1 纯文本聊天类型
	if ("text".equals(msgType)) {
		//文本,按关键字消息进行回复	
		return doSendKeyMessage(bizContentJson);

		// 2.2 事件类型
	} else if ("event".equals(msgType)) {

		return doEventExcute(service, bizContentJson);
	} else {

		// 2.3 后续支付宝还会新增其他类型,因此默认返回ack应答
		return doSendDefaultMessage(bizContentJson);
	}

}
 
Example #3
Source File: Feature.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public static String ConvertXMLtoJSON(String xml)  {  
	XMLSerializer xmlSerializer = new XMLSerializer();  
	JSON json =null;
	  
       json = xmlSerializer.read(xml);  
	return json.toString(1);  
}
 
Example #4
Source File: Graph.java    From ankush with GNU Lesser General Public License v3.0 5 votes vote down vote up
private JSON exeExportCommand(String command) throws Exception {
	try {
		// puting json in result.
		return new XMLSerializer().read(exeCommand(command).replaceAll(
				"NaN", "0"));
	} catch (Exception e) {
		logger.error("Could not run export command." + e.getMessage());
		throw new AnkushException("Coud not run export command.");
	}
}
 
Example #5
Source File: JSONToXMLConverter.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Deprecated
private String ConvertToXML(String jsonData) {
    XMLSerializer serializer = new XMLSerializer();
    JSON json = JSONSerializer.toJSON(jsonData);
    serializer.setRootName("xmlOutput");
    serializer.setTypeHintsEnabled(false);
    return serializer.write(json);
}
 
Example #6
Source File: JSONToXMLConverter.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
private void convertToXML() {
    XMLSerializer serializer = new XMLSerializer();
    JSON json = JSONSerializer.toJSON(this.getJsonInput());
    serializer.setRootName("xmlOutput");
    serializer.setTypeHintsEnabled(false);
    setXmlOutput(serializer.write(json));
}
 
Example #7
Source File: Formatter.java    From DevToolBox with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static String xml2json(String xmlString) {
    XMLSerializer xmlSerializer = new XMLSerializer();
    JSON json = xmlSerializer.read(xmlString);
    return json.toString(1);
}
 
Example #8
Source File: Formatter.java    From DevToolBox with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static String json2xml(String jsonString) throws Exception {
    XMLSerializer xmlSerializer = new XMLSerializer();
    return formatXML(xmlSerializer.write(JSONSerializer.toJSON(jsonString)));
}
 
Example #9
Source File: NodeGraph.java    From ankush with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
	 * Method to extract json from the rrd file.
	 * hostNames = GangliaUtils.getGangliaHostNames(hostname, username,
//				password, privateKey);
	 * @param startTime
	 *            the start time
	 * @param hostName
	 *            the hostName
	 * @return the map
	 * @throws Exception
	 *             the exception
	 */
	public Map extractRRD(StartTime startTime, String hostName) throws Exception {

		Map result = new HashMap();
		// rrd director for the given ip address.
		String rrdDir = rrdsDirectory + clusterName + "/" + hostName + "/";

		// making connection.
		SSHConnection connection = new SSHConnection(this.hostname,
				this.username, this.authInfo, this.authUsingPassword);

		if (connection.isConnected()) {

			// json creation command using the rrdtool.
			StringBuilder command = new StringBuilder();
			command.append("cd " + rrdDir).append(";rrdtool xport ")
					.append(timeMap.get(startTime.ordinal()))
					.append("DEF:cn=cpu_num.rrd:sum:AVERAGE ")
					.append("DEF:ci=cpu_idle.rrd:sum:AVERAGE ")
					.append("DEF:mt=mem_total.rrd:sum:AVERAGE ")
					.append("DEF:mf=mem_free.rrd:sum:AVERAGE ")
					.append("DEF:mb=mem_buffers.rrd:sum:AVERAGE ")
					.append("DEF:mc=mem_cached.rrd:sum:AVERAGE ")
					.append("DEF:ms=mem_shared.rrd:sum:AVERAGE ")
					.append("CDEF:mu=mt,ms,-,mf,-,mc,-,mb,- ")
					.append("CDEF:mem=100,mu,*,mt,/ ")
					.append("CDEF:cpu=100,ci,- ")
					.append("XPORT:cpu:\"CPU %\" ")
					.append("XPORT:mem:\"Memory %\" ");

			/* Executing the command. */
			if (connection.exec(command.toString())) {
				String output = connection.getOutput();
				if (output == null) {
					throw new Exception(COULD_NOT_FETCH_DATA_MSG);
				}

				// puting json in result.
				result.put("json",
						new XMLSerializer().read(output.replaceAll("NaN", "0")));
			} else {
				throw new Exception(
						COULD_NOT_EXECUTE_COMMAND_MSG);
			}
		}
		return result;
	}
 
Example #10
Source File: LiveGraph.java    From ankush with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Method to provide Data from cluster memory, cpu, load and network data
 * for given time period.
 * 
 * @param startTime
 * @param pattern
 * @return
 * @throws Exception
 */
public Map fetchGraphJson(StartTime startTime, String type)
		throws Exception {
	// output.
	Map result = new HashMap();
	// rrd cluster directory.
	String clusterRrdDir = FileNameUtils.convertToValidPath(rrdsDirectory
			+ clusterName + "/__SummaryInfo__");
	// making connection.
	SSHConnection connection = new SSHConnection(this.hostname,
			this.username, this.authInfo, this.authUsingPassword);

	if (connection.isConnected()) {

		// json creation command using the rrdtool.
		StringBuilder command = new StringBuilder();
		command.append("cd " + clusterRrdDir).append(";rrdtool xport ")
				.append(timeMap.get(startTime.ordinal()));

		String unit = "%";
		// cpu graphs
		if (type.equalsIgnoreCase(Constant.Graph.Type.cpu.toString())) {
			command.append(getClusterCpu(false));
			// memory graphs
		} else if (type.equalsIgnoreCase(Constant.Graph.Type.memory
				.toString())) {
			command.append(getClusterMemory(false));
			// network graphs.
		} else if (type.equalsIgnoreCase(Constant.Graph.Type.network
				.toString())) {
			unit = "MB/s";
			command.append(getClusterNetwork(false));
			// load graphs.
		} else if (type.equalsIgnoreCase(Constant.Graph.Type.load
				.toString())) {
			command.append(getClusterLoad(false));
		} else {
			return result;
		}

		logger.debug(command.toString());

		/* Executing the command. */
		if (connection.exec(command.toString())) {
			String output = connection.getOutput();
			if (output == null) {
				throw new Exception(COULD_NOT_FETCH_DATA_MSG);
			} else {
				// puting json in result.
				Map map = (Map) new XMLSerializer().read(output.replaceAll(
						"NaN", "0"));
				map.put("unit", unit);
				result.put("json", map);
			}
		} else {
			throw new Exception(COULD_NOT_EXECUTE_COMMAND_MSG);
		}
	}
	return result;
}