本文整理汇总了Java中com.thoughtworks.xstream.XStream.toXML方法的典型用法代码示例。如果您正苦于以下问题:Java XStream.toXML方法的具体用法?Java XStream.toXML怎么用?Java XStream.toXML使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.thoughtworks.xstream.XStream
的用法示例。
在下文中一共展示了XStream.toXML方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unifiedorder
import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
/**
* 微信统一下单,同时支援扫码支付统一下单 和 微信公众号统一下单 <br>
* @see <a href="https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_1">https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_1</a>
* @see <a href="https://pay.weixin.qq.com/wiki/doc/api/native_sl.php?chapter=9_1">https://pay.weixin.qq.com/wiki/doc/api/native_sl.php?chapter=9_1</a>
* @param data 统一下单参数对象 {@link UnifiedOrderInput}
* @param apiKey 微信API秘钥
* @return 统一下单结果对象 {@link UnifiedOrderOutput}
*/
public static UnifiedOrderOutput unifiedorder(UnifiedOrderInput data, String apiKey){
UnifiedOrderOutput output = null;
try {
Object input = WechatUtil.buildRequest(data,UnifiedOrderInput.class,apiKey);
XStream xStream = XStreamCreator.create(UnifiedOrderInput.class);
String xml = xStream.toXML(input);
log.info("微信统一下单请求数据[unifiedorder]->xmlRequest:\n {}",xml);
String xmlResponse = ConnUtil.connRemoteWithXml(xml,pay_unifiedorder);
log.info("微信统一下单返回数据[unifiedorder]->xmlResponse:\n {}",ThlwsBeanUtil.formatXml(xmlResponse));
XStream xStreamOut = XStreamCreator.create(UnifiedOrderOutput.class);
output = (UnifiedOrderOutput) xStreamOut.fromXML(xmlResponse);
} catch (Exception e) {
log.info("微信统一下单[unifiedorder]失败:{}",e.getMessage());
}
return output;
}
示例2: orderQuery
import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
/**
* 微信订单查询,除核心参数外(appid,mch_id等为核心参数)业务参数 transaction_id ,out_trade_no 二选一即可<br>
*
* 需要调用查询接口的情况<br>
*
* <ol>
* <li>当商户后台、网络、服务器等出现异常,商户系统最终未接收到支付通知;</li>
* <li>调用支付接口后,返回系统错误或未知交易状态情况;</li>
* <li>调用刷卡支付API,返回USERPAYING的状态;</li>
* <li>调用关单或撤销接口API之前,需确认支付状态;</li>
* </ol>
*
* @see <a href="https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_2">https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_2</a>
* @see <a href="https://pay.weixin.qq.com/wiki/doc/api/native_sl.php?chapter=9_2">https://pay.weixin.qq.com/wiki/doc/api/native_sl.php?chapter=9_2</a>
* @param data 查询参数对象 {@link OrderQueryInput}
* @param apiKey API秘钥
* @return 订单查询结果对象 {@link OrderQueryOutput}
*/
public static OrderQueryOutput orderQuery(OrderQueryInput data, String apiKey){
OrderQueryOutput output = null;
try {
Object input = WechatUtil.buildRequest(data,OrderQueryInput.class,apiKey);
XStream xStream = XStreamCreator.create(OrderQueryInput.class);
String xml = xStream.toXML(input);
log.info("微信订单查询请求数据[orderQuery]->xmlRequest:\n {}",xml);
String xmlResponse = ConnUtil.connRemoteWithXml(xml,pay_orderquery);
log.info("微信订单查询响应数据[orderQuery]->response xmlResponse:\n {}",ThlwsBeanUtil.formatXml(xmlResponse));
XStream xStreamOut = XStreamCreator.create(OrderQueryOutput.class);
output = (OrderQueryOutput) xStreamOut.fromXML(xmlResponse);
} catch (Exception e) {
log.error("微信订单查询失败:{}",e.getMessage());
}
return output;
}
示例3: closeOrder
import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
/**
* 微信订单关闭,商户订单支付失败需要生成新单号重新发起支付,要对原订单号调用关单,避免重复支付;系统下单后,用户支付超时,系统退出不再受理,避免用户继续,请调用关单接口.<br>
* <span style="color:red;">订单生成后不能马上调用关单接口,最短调用时间间隔为5分钟。</span>
* @see <a href="https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_3">普通商户关闭订单接口</a> <br>
* @see <a href="https://pay.weixin.qq.com/wiki/doc/api/native_sl.php?chapter=9_3">服务商关闭订单接口</a>
* @param data 参数对象 {@link CloseOrderInput}
* @param apiKey 微信API秘钥
* @return 订单关闭结果对象 {@link CloseOrderOutput}
*/
public static CloseOrderOutput closeOrder(CloseOrderInput data, String apiKey){
CloseOrderOutput output = null;
try {
Object input = WechatUtil.buildRequest(data,CloseOrderInput.class,apiKey);
XStream xStream = XStreamCreator.create(CloseOrderInput.class);
String xml = xStream.toXML(input);
log.info("微信关闭订单请求数据[closeOrder]->xmlRequest:\n {}",xml);
String xmlResponse = ConnUtil.connRemoteWithXml(xml,close_order);
log.info("微信关闭订单响应数据[closeOrder]->xmlResponse:\n {}",ThlwsBeanUtil.formatXml(xmlResponse));
XStream xStreamOut = XStreamCreator.create(CloseOrderOutput.class);
output = (CloseOrderOutput) xStreamOut.fromXML(xmlResponse);
} catch (Exception e) {
log.error("微信关闭订单[closeOrder]失败:{}",e.getMessage());
}
return output;
}
示例4: save
import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
@Override
public void save(SummarySectionsConfig element)
{
HashMap<String, String> settings = new HashMap<String, String>();
settings.put(SHOW_OWNER_KEY, "true"); //$NON-NLS-1$
if( limitDesc.isSelected() )
{
settings.put(DESCRIPTION_LENGTH_KEY, maxLengthDesc.getCurrentValue());
}
if( limitTitle.isSelected() )
{
settings.put(TITLE_LENGTH_KEY, maxLengthTitle.getCurrentValue());
}
XStream xstream = new XStream();
String toXML = xstream.toXML(settings);
element.setConfiguration(toXML);
super.save(element);
}
示例5: converterParaXml
import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
public String converterParaXml() {
String XML_HEADER = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
XStream xstream = new XStream();
xstream.setMode(XStream.NO_REFERENCES);
xstream.autodetectAnnotations(true);
return XML_HEADER + xstream.toXML(this);
}
示例6: toXml
import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
public static String toXml(DnaTable object){
XStream xStream = new XStream();
xStream.autodetectAnnotations(true);
xStream.processAnnotations(DnaTable.class);
String top = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n";
return top + xStream.toXML(object);
}
示例7: writeXML
import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
private static void writeXML(String filename, List<FeatureExtractor1<Token>> featureExtractors) throws FileNotFoundException {
XStream xstream = XStreamFactory.createXStream();
String xml = xstream.toXML(featureExtractors);
xml = removeLogger(xml);
PrintStream ps = new PrintStream(filename);
ps.println(xml);
ps.close();
}
示例8: saveToFile
import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
public void saveToFile(Object data, File location){
XStream xstream = new XStream(new DomDriver());
String content = xstream.toXML(data);
try {
FileWriter fileWriter = new FileWriter(location);
fileWriter.write(content);
fileWriter.close();
} catch (Exception e) {
// user clicked cancel. No need to exclaim anything went wrong
}
}
示例9: toString
import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
/**
* Produces an XML serialisation of this {@link ObjectWrapper} instance, that
* can be deserialised by using the {@link #ObjectWrapper(String)} constructor.
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
// Use XML 1.1 in case the XML representation includes characters
// that 1.0 forbids (typically control characters).
XStream xstream = new XStream(new XML11StaxDriver());
StringWriter out = new StringWriter();
xstream.toXML(this, out);
return out.toString();
}
示例10: postMicroMch
import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
/**
* 申请小微收款识别码
*
* @param o the o
* @param apiKey the api key
* @param p12FilePath the p 12 file path
* @return the micro mch output
*/
public static MicroMchOutput postMicroMch(MicroMchInput o, String apiKey, String p12FilePath){
MicroMchOutput resp = null;
try {
Map<String, Object> mapData = ThlwsBeanUtil.ObjectToMap(o);
mapData = ThlwsBeanUtil.dataFilter(mapData);
String sign = WechatUtil.sign(mapData,apiKey);
mapData.put("sign", sign);
MicroMchInput xwr = (MicroMchInput) ThlwsBeanUtil.mapToObject(mapData,MicroMchInput.class);
String nonceStr = ThlwsBeanUtil.getRandomString(32);//随机生成32为的字符串
xwr.setNonce_str(nonceStr);
XStream xStream = XStreamCreator.create(MicroMchInput.class);
String xml = xStream.toXML(xwr);
log.info("申请小微收款识别码 [submchmanage] xml request:\n {}",xml);
//p12FilePath = "/zone/1.p12";
String xmlResp = ConnUtil.encryptPost(xml, micro_mch_add, o.getMch_id(), p12FilePath);
log.info("申请小微收款识别码 [submchmanage] xml response:\n {}", ThlwsBeanUtil.formatXml(xmlResp));
XStream xStreamOut = XStreamCreator.create( MicroMchOutput.class);
resp = (MicroMchOutput) xStreamOut.fromXML(xmlResp);
} catch (Exception e) {
log.error("申请小微收款识别码失败:{}",e.getMessage());
}
return resp;
}
示例11: toXML
import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
/**
* 将对象转化为xml
*
* @param obj
* @return
*/
@SuppressWarnings("unused")
private String toXML(Object obj) {
XStream xstream = new XStream();
xstream.alias("response", ResponseEntity.class);
String xml = xstream.toXML(obj);
return xml;
}
示例12: request
import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
/**
* 请求统计上报API
* @param reportReqData 这个数据对象里面包含了API要求提交的各种数据字段
* @return API返回的数据
* @throws Exception
*/
public static String request(ReportReqData reportReqData) throws Exception {
//--------------------------------------------------------------------
//发送HTTPS的Post请求到API地址
//--------------------------------------------------------------------
//解决XStream对出现双下划线的bug, 将要提交给API的数据对象转换成XML格式数据Post给API
XStream xStreamForRequestPostData = new XStream(new DomDriver("UTF-8", new XmlFriendlyNameCoder("-_", "_")));
String postDataXML = xStreamForRequestPostData.toXML(reportReqData);
String responseString = new HttpsRequest().sendPost(Configure.REPORT_API, postDataXML);
Util.log("report返回的数据:" + responseString);
return responseString;
}
示例13: saveAsXml
import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
private void saveAsXml(List<ContactData> contacts, File file) throws IOException {
XStream xstream = new XStream();
xstream.processAnnotations(ContactData.class);
String xml = xstream.toXML(contacts);
try (Writer writer = new FileWriter(file)) {
writer.write(xml);
}
}
示例14: writeXmlFile
import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
public void writeXmlFile(TemporaryFileHandle file, String path, Object obj, XStream xstream)
{
try( OutputStream outStream = fileSystemService.getOutputStream(file, path, false) )
{
xstream.toXML(obj, new OutputStreamWriter(outStream, Constants.UTF8));
}
catch( IOException ioe )
{
throw new RuntimeException("Error writing file " + file.getAbsolutePath(), ioe);
}
}
示例15: recieveNotify
import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
@RequestMapping(value = "/h5web/wxpay.action", method = RequestMethod.POST)
public String recieveNotify(HttpServletRequest request) {
WxPaiedNotifyResponse wxPaiedNotifyResponse = new WxPaiedNotifyResponse();
String wxPaiedNotifyRequestStr = "";
try {
wxPaiedNotifyRequestStr = charReader(request);
logger.info("receive wx request[{}]", wxPaiedNotifyRequestStr);
} catch (IOException e) {
logger.error(e);
}
if (StringUtil.isNullOrEmpty(wxPaiedNotifyRequestStr)) {
logger.error("wx requst empty");
wxPaiedNotifyResponse.setReturn_code("FAIL");
wxPaiedNotifyResponse.setReturn_msg("ERROR");
} else {
WxPaiedNotifyRequest wxPaiedNotifyRequest = (WxPaiedNotifyRequest) Util.getObjectFromXML(wxPaiedNotifyRequestStr,
WxPaiedNotifyRequest.class);
if (!wxPaiedNotifyRequest.getResult_code().equals("SUCCESS")) {
wxPaiedNotifyResponse.setReturn_code("FAIL");
wxPaiedNotifyResponse.setReturn_msg("ERROR");
} else {
// 更新订单结果
// GuestOrder guestOrder = new GuestOrder();
// guestOrder.setOrderId(wxPaiedNotifyRequest.getOut_trade_no());
// guestOrder.setOrderPayStatus(OrderPayStatusInterfaces.ORDER_PAY_STATUS_PAID);
// guestOrder.setOrderStatus(OrderStatusInterfaces.ORDER_STATUS_PAIDINCOMMON);
// int affected = (int)
// guestOrderStatusServiceImpl.updateGuestOrder(guestOrder);
int affected = 1;
if (affected <= 0) {
wxPaiedNotifyResponse.setReturn_code("FAIL");
wxPaiedNotifyResponse.setReturn_msg("ERROR");
} else {
wxPaiedNotifyResponse.setReturn_code("SUCCESS");
wxPaiedNotifyResponse.setReturn_msg("OK");
}
}
}
// 解决XStream对出现双下划线的bug
XStream xStreamForRequestPostData = new XStream(new DomDriver("UTF-8", new XmlFriendlyNameCoder("-_", "_")));
xStreamForRequestPostData.alias("xml", WxPaiedNotifyResponse.class);
String xmlobject = xStreamForRequestPostData.toXML(wxPaiedNotifyResponse);
return xmlobject;
}