Guest User

Untitled

a guest
Nov 16th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.17 KB | None | 0 0
  1. import com.thoughtworks.xstream.XStream;
  2. import com.thoughtworks.xstream.io.xml.DomDriver;
  3. import java.rmi.RemoteException;
  4. import javax.swing.JOptionPane;
  5.  
  6. public class XmlConverter {
  7.  
  8. public static void main(String[] args) {
  9. JOptionPane.showMessageDialog(null, "O resultado é exibido no console.");
  10.  
  11. String xml = "<?xml version="1.0" encoding="UTF-8"?>n" +
  12. "<receiptList xmlns="dsReceipt.xsd">n" +
  13. " <receipt order_id="5">n" +
  14. " <receipt_shopper order_id="5" shopper_id="1" ship_to_name="João da Silva" ship_to_address1="Rua Alfredo Heisler" ship_to_address2="Curitiba" ship_to_address3="PR" ship_to_address4="82600470" ship_to_phone="3066-3055" ship_to_country="BRA" ship_to_ddd_phone="41" shopper_cpf="88427867301" ship_to_street_number="83" ship_to_street_compl="apto 102b" ship_to_district="Bacacheri" reference="perto do quartel" />n" +
  15. " <receipt_billing order_id="5" name="João da Silva" email="joao.silva@ciashop.com.br" customer_type="Person" document_type="Cpf" document_id="88427867301" regional_document_type="Rg" regional_document_id="57490000" regional_document_state="PR" street="Rua Alfredo Heisler" street_number="83" street_complement="apto 102b" district="Bacacheri" city="Curitiba" state="PR" country="BRA" zip_code="82600470" reference="perto ao quartel" phone_area_code="41" phone_number="3559-3055" phone_area_code_alternative="41" phone_number_alternative="9521-3425" gender="Male" birth_date="1976-09-21T00:00:00-03:00" />n" +
  16. " </receipt>n" +
  17. "</receiptList>";
  18.  
  19. try {
  20. XStream xstream = new XStream(new DomDriver());
  21.  
  22. xstream.alias("receipt_billing", ReceiptBilling.class);
  23. xstream.alias("receipt_shopper", ReceiptShopper.class);
  24. xstream.alias("receipt", Receipt.class);
  25. xstream.alias("receiptList", ReceiptList.class);
  26. ReceiptList receiptList = (ReceiptList) xstream.fromXML(xml);
  27.  
  28. System.out.println("Receipt - Order Id: " + receiptList.getReceipt().getOrder_id());
  29. System.out.println("Receipt - Receipt Shopper - Reference: " + receiptList.getReceipt().getReceipt_shopper().getReference());
  30.  
  31. } catch (NullPointerException e1) {
  32. e1.printStackTrace();
  33. }
  34.  
  35. }
  36.  
  37. }
  38.  
  39. public class Receipt {
  40. private ReceiptShopper receipt_shopper;
  41.  
  42. private String order_id;
  43.  
  44. private ReceiptBilling receipt_billing;
  45.  
  46. public ReceiptShopper getReceipt_shopper ()
  47. {
  48. return receipt_shopper;
  49. }
  50.  
  51. public void setReceipt_shopper (ReceiptShopper receipt_shopper)
  52. {
  53. this.receipt_shopper = receipt_shopper;
  54. }
  55.  
  56. public String getOrder_id ()
  57. {
  58. return order_id;
  59. }
  60.  
  61. public void setOrder_id (String order_id)
  62. {
  63. this.order_id = order_id;
  64. }
  65.  
  66. public ReceiptBilling getReceipt_billing ()
  67. {
  68. return receipt_billing;
  69. }
  70.  
  71. public void setReceipt_billing (ReceiptBilling receipt_billing)
  72. {
  73. this.receipt_billing = receipt_billing;
  74. }
  75. }
  76.  
  77. public class ReceiptBilling {
  78. private String phone_area_code;
  79.  
  80. private String phone_number;
  81.  
  82. private String regional_document_state;
  83.  
  84. private String birth_date;
  85.  
  86. private String zip_code;
  87.  
  88. private String document_id;
  89.  
  90. private String street;
  91.  
  92. private String state;
  93.  
  94. private String regional_document_type;
  95.  
  96. private String phone_area_code_alternative;
  97.  
  98. private String order_id;
  99.  
  100. private String phone_number_alternative;
  101.  
  102. private String document_type;
  103.  
  104. private String customer_type;
  105.  
  106. private String reference;
  107.  
  108. private String city;
  109.  
  110. private String country;
  111.  
  112. private String email;
  113.  
  114. private String name;
  115.  
  116. private String gender;
  117.  
  118. private String street_number;
  119.  
  120. private String district;
  121.  
  122. private String street_complement;
  123.  
  124. private String regional_document_id;
  125.  
  126. public String getPhone_area_code ()
  127. {
  128. return phone_area_code;
  129. }
  130.  
  131. public void setPhone_area_code (String phone_area_code)
  132. {
  133. this.phone_area_code = phone_area_code;
  134. }
  135.  
  136. public String getPhone_number ()
  137. {
  138. return phone_number;
  139. }
  140.  
  141. public void setPhone_number (String phone_number)
  142. {
  143. this.phone_number = phone_number;
  144. }
  145.  
  146. public String getRegional_document_state ()
  147. {
  148. return regional_document_state;
  149. }
  150.  
  151. public void setRegional_document_state (String regional_document_state)
  152. {
  153. this.regional_document_state = regional_document_state;
  154. }
  155.  
  156. public String getBirth_date ()
  157. {
  158. return birth_date;
  159. }
  160.  
  161. public void setBirth_date (String birth_date)
  162. {
  163. this.birth_date = birth_date;
  164. }
  165.  
  166. public String getZip_code ()
  167. {
  168. return zip_code;
  169. }
  170.  
  171. public void setZip_code (String zip_code)
  172. {
  173. this.zip_code = zip_code;
  174. }
  175.  
  176. public String getDocument_id ()
  177. {
  178. return document_id;
  179. }
  180.  
  181. public void setDocument_id (String document_id)
  182. {
  183. this.document_id = document_id;
  184. }
  185.  
  186. public String getStreet ()
  187. {
  188. return street;
  189. }
  190.  
  191. public void setStreet (String street)
  192. {
  193. this.street = street;
  194. }
  195.  
  196. public String getState ()
  197. {
  198. return state;
  199. }
  200.  
  201. public void setState (String state)
  202. {
  203. this.state = state;
  204. }
  205.  
  206. public String getRegional_document_type ()
  207. {
  208. return regional_document_type;
  209. }
  210.  
  211. public void setRegional_document_type (String regional_document_type)
  212. {
  213. this.regional_document_type = regional_document_type;
  214. }
  215.  
  216. public String getPhone_area_code_alternative ()
  217. {
  218. return phone_area_code_alternative;
  219. }
  220.  
  221. public void setPhone_area_code_alternative (String phone_area_code_alternative)
  222. {
  223. this.phone_area_code_alternative = phone_area_code_alternative;
  224. }
  225.  
  226. public String getOrder_id ()
  227. {
  228. return order_id;
  229. }
  230.  
  231. public void setOrder_id (String order_id)
  232. {
  233. this.order_id = order_id;
  234. }
  235.  
  236. public String getPhone_number_alternative ()
  237. {
  238. return phone_number_alternative;
  239. }
  240.  
  241. public void setPhone_number_alternative (String phone_number_alternative)
  242. {
  243. this.phone_number_alternative = phone_number_alternative;
  244. }
  245.  
  246. public String getDocument_type ()
  247. {
  248. return document_type;
  249. }
  250.  
  251. public void setDocument_type (String document_type)
  252. {
  253. this.document_type = document_type;
  254. }
  255.  
  256. public String getCustomer_type ()
  257. {
  258. return customer_type;
  259. }
  260.  
  261. public void setCustomer_type (String customer_type)
  262. {
  263. this.customer_type = customer_type;
  264. }
  265.  
  266. public String getReference ()
  267. {
  268. return reference;
  269. }
  270.  
  271. public void setReference (String reference)
  272. {
  273. this.reference = reference;
  274. }
  275.  
  276. public String getCity ()
  277. {
  278. return city;
  279. }
  280.  
  281. public void setCity (String city)
  282. {
  283. this.city = city;
  284. }
  285.  
  286. public String getCountry ()
  287. {
  288. return country;
  289. }
  290.  
  291. public void setCountry (String country)
  292. {
  293. this.country = country;
  294. }
  295.  
  296. public String getEmail ()
  297. {
  298. return email;
  299. }
  300.  
  301. public void setEmail (String email)
  302. {
  303. this.email = email;
  304. }
  305.  
  306. public String getName ()
  307. {
  308. return name;
  309. }
  310.  
  311. public void setName (String name)
  312. {
  313. this.name = name;
  314. }
  315.  
  316. public String getGender ()
  317. {
  318. return gender;
  319. }
  320.  
  321. public void setGender (String gender)
  322. {
  323. this.gender = gender;
  324. }
  325.  
  326. public String getStreet_number ()
  327. {
  328. return street_number;
  329. }
  330.  
  331. public void setStreet_number (String street_number)
  332. {
  333. this.street_number = street_number;
  334. }
  335.  
  336. public String getDistrict ()
  337. {
  338. return district;
  339. }
  340.  
  341. public void setDistrict (String district)
  342. {
  343. this.district = district;
  344. }
  345.  
  346. public String getStreet_complement ()
  347. {
  348. return street_complement;
  349. }
  350.  
  351. public void setStreet_complement (String street_complement)
  352. {
  353. this.street_complement = street_complement;
  354. }
  355.  
  356. public String getRegional_document_id ()
  357. {
  358. return regional_document_id;
  359. }
  360.  
  361. public void setRegional_document_id (String regional_document_id)
  362. {
  363. this.regional_document_id = regional_document_id;
  364. }
  365.  
  366. }
  367.  
  368. public class ReceiptList {
  369. private Receipt receipt;
  370.  
  371. private String xmlns;
  372.  
  373. public Receipt getReceipt ()
  374. {
  375. return receipt;
  376. }
  377.  
  378. public void setReceipt (Receipt receipt)
  379. {
  380. this.receipt = receipt;
  381. }
  382.  
  383. public String getXmlns ()
  384. {
  385. return xmlns;
  386. }
  387.  
  388. public void setXmlns (String xmlns)
  389. {
  390. this.xmlns = xmlns;
  391. }
  392.  
  393. }
  394.  
  395. public class ReceiptShopper {
  396. private String ship_to_address2;
  397.  
  398. private String ship_to_address1;
  399.  
  400. private String order_id;
  401.  
  402. private String shopper_cpf;
  403.  
  404. private String reference;
  405.  
  406. private String ship_to_name;
  407.  
  408. private String ship_to_address4;
  409.  
  410. private String ship_to_address3;
  411.  
  412. private String ship_to_street_number;
  413.  
  414. private String ship_to_street_compl;
  415.  
  416. private String ship_to_ddd_phone;
  417.  
  418. private String ship_to_district;
  419.  
  420. private String ship_to_phone;
  421.  
  422. private String shopper_id;
  423.  
  424. private String ship_to_country;
  425.  
  426. public String getShip_to_address2 ()
  427. {
  428. return ship_to_address2;
  429. }
  430.  
  431. public void setShip_to_address2 (String ship_to_address2)
  432. {
  433. this.ship_to_address2 = ship_to_address2;
  434. }
  435.  
  436. public String getShip_to_address1 ()
  437. {
  438. return ship_to_address1;
  439. }
  440.  
  441. public void setShip_to_address1 (String ship_to_address1)
  442. {
  443. this.ship_to_address1 = ship_to_address1;
  444. }
  445.  
  446. public String getOrder_id ()
  447. {
  448. return order_id;
  449. }
  450.  
  451. public void setOrder_id (String order_id)
  452. {
  453. this.order_id = order_id;
  454. }
  455.  
  456. public String getShopper_cpf ()
  457. {
  458. return shopper_cpf;
  459. }
  460.  
  461. public void setShopper_cpf (String shopper_cpf)
  462. {
  463. this.shopper_cpf = shopper_cpf;
  464. }
  465.  
  466. public String getReference ()
  467. {
  468. return reference;
  469. }
  470.  
  471. public void setReference (String reference)
  472. {
  473. this.reference = reference;
  474. }
  475.  
  476. public String getShip_to_name ()
  477. {
  478. return ship_to_name;
  479. }
  480.  
  481. public void setShip_to_name (String ship_to_name)
  482. {
  483. this.ship_to_name = ship_to_name;
  484. }
  485.  
  486. public String getShip_to_address4 ()
  487. {
  488. return ship_to_address4;
  489. }
  490.  
  491. public void setShip_to_address4 (String ship_to_address4)
  492. {
  493. this.ship_to_address4 = ship_to_address4;
  494. }
  495.  
  496. public String getShip_to_address3 ()
  497. {
  498. return ship_to_address3;
  499. }
  500.  
  501. public void setShip_to_address3 (String ship_to_address3)
  502. {
  503. this.ship_to_address3 = ship_to_address3;
  504. }
  505.  
  506. public String getShip_to_street_number ()
  507. {
  508. return ship_to_street_number;
  509. }
  510.  
  511. public void setShip_to_street_number (String ship_to_street_number)
  512. {
  513. this.ship_to_street_number = ship_to_street_number;
  514. }
  515.  
  516. public String getShip_to_street_compl ()
  517. {
  518. return ship_to_street_compl;
  519. }
  520.  
  521. public void setShip_to_street_compl (String ship_to_street_compl)
  522. {
  523. this.ship_to_street_compl = ship_to_street_compl;
  524. }
  525.  
  526. public String getShip_to_ddd_phone ()
  527. {
  528. return ship_to_ddd_phone;
  529. }
  530.  
  531. public void setShip_to_ddd_phone (String ship_to_ddd_phone)
  532. {
  533. this.ship_to_ddd_phone = ship_to_ddd_phone;
  534. }
  535.  
  536. public String getShip_to_district ()
  537. {
  538. return ship_to_district;
  539. }
  540.  
  541. public void setShip_to_district (String ship_to_district)
  542. {
  543. this.ship_to_district = ship_to_district;
  544. }
  545.  
  546. public String getShip_to_phone ()
  547. {
  548. return ship_to_phone;
  549. }
  550.  
  551. public void setShip_to_phone (String ship_to_phone)
  552. {
  553. this.ship_to_phone = ship_to_phone;
  554. }
  555.  
  556. public String getShopper_id ()
  557. {
  558. return shopper_id;
  559. }
  560.  
  561. public void setShopper_id (String shopper_id)
  562. {
  563. this.shopper_id = shopper_id;
  564. }
  565.  
  566. public String getShip_to_country ()
  567. {
  568. return ship_to_country;
  569. }
  570.  
  571. public void setShip_to_country (String ship_to_country)
  572. {
  573. this.ship_to_country = ship_to_country;
  574. }
  575.  
  576. }
  577.  
  578. Security framework of XStream not initialized, XStream is probably vulnerable.
  579. Exception in thread "main" com.thoughtworks.xstream.converters.ConversionException: Invalid reference
  580. ---- Debugging information ----
  581. message : Invalid reference
  582. reference : perto do quartel
  583. referenced-type : xmlconverter.ReceiptShopper
  584. referenceable : true
  585. class : xmlconverter.Receipt
  586. required-type : xmlconverter.Receipt
  587. converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
  588. path : /receiptList/receipt/receipt_shopper
  589. class[1] : xmlconverter.ReceiptList
  590. required-type[1] : xmlconverter.ReceiptList
  591. version : 1.4.11.1
  592. -------------------------------
  593. at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:58)
  594. at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
  595. at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:499)
  596. at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:425)
  597. at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:277)
  598. at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
  599. at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:72)
  600. at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
  601. at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:499)
  602. at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:425)
  603. at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:277)
  604. at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
  605. at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:72)
  606. at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
  607. at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
  608. at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134)
  609. at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
  610. at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1487)
  611. at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1467)
  612. at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1338)
  613. at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1329)
  614. at xmlconverter.XmlConverter.main(XmlConverter.java:33)
Add Comment
Please, Sign In to add comment