本文整理匯總了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;
}