Advertisement
Guest User

Untitled

a guest
Jul 16th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.41 KB | None | 0 0
  1. public class MegentoCategory {
  2.  
  3. String user = "xxx";
  4. String pass = "xxx";
  5. String host = "http://www.xxx.co.xx/index.php/api/soap/?wsdl";
  6.  
  7.  
  8. public MegentoCategory() throws MalformedURLException
  9. {
  10.  
  11. try{
  12. // Create SOAP Connection
  13. SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
  14. SOAPConnection soapConnection = soapConnectionFactory.createConnection();
  15.  
  16. // Send SOAP Message to SOAP Server
  17. SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), host);
  18.  
  19. // print SOAP Response
  20. System.out.print("Response SOAP Message:");
  21. soapResponse.writeTo(System.out);
  22. soapConnection.close();
  23. }
  24. catch(Exception e)
  25. {
  26. e.getMessage();
  27. }
  28. }
  29.  
  30. private static SOAPMessage createSOAPRequest() throws Exception {
  31. MessageFactory messageFactory = MessageFactory.newInstance();
  32. SOAPMessage soapMessage = messageFactory.createMessage();
  33. SOAPPart soapPart = soapMessage.getSOAPPart();
  34.  
  35. String serverURI = "<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelopexmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'><soapenv:Body><mag:loginxmlns:mag='urn:Magento'<mag:username>xxx</mag:username<mag:apiKey>xxx</mag:apiKey></mag:login></soapenv:Body></soapenv:Envelope>";
  36.  
  37. MimeHeaders headers = soapMessage.getMimeHeaders();
  38. headers.addHeader("SOAPAction", serverURI + "login");
  39.  
  40. soapMessage.saveChanges();
  41.  
  42.  
  43. /* Print the request message */
  44. System.out.print("Request SOAP Message:");
  45. soapMessage.writeTo(System.out);
  46. System.out.println();
  47.  
  48. return soapMessage;
  49. }
  50. }
  51.  
  52. <?xml version="1.0" encoding="UTF-8"?>
  53. <definitions xmlns:typens="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  54. xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"
  55. name="Magento" targetNamespace="urn:Magento">
  56. <types>
  57. <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
  58. <!-- <import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />-->
  59. <complexType name="FixedArray">
  60. <complexContent>
  61. <restriction base="soapenc:Array">
  62. <attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:anyType[]" />
  63. </restriction>
  64. </complexContent>
  65. </complexType>
  66. </schema>
  67. </types>
  68. <message name="call">
  69. <part name="sessionId" type="xsd:string" />
  70. <part name="resourcePath" type="xsd:string" />
  71. <part name="args" type="xsd:anyType" />
  72. </message>
  73. <message name="callResponse">
  74. <part name="callReturn" type="xsd:anyType" />
  75. </message>
  76. <message name="multiCall">
  77. <part name="sessionId" type="xsd:string" />
  78. <part name="calls" type="typens:FixedArray" />
  79. <part name="options" type="xsd:anyType" />
  80. </message>
  81. <message name="multiCallResponse">
  82. <part name="multiCallReturn" type="typens:FixedArray" />
  83. </message>
  84. <message name="endSession">
  85. <part name="sessionId" type="xsd:string" />
  86. </message>
  87. <message name="endSessionResponse">
  88. <part name="endSessionReturn" type="xsd:boolean" />
  89. </message>
  90. <message name="login">
  91. <part name="username" type="xsd:string" />
  92. <part name="apiKey" type="xsd:string" />
  93. </message>
  94. <message name="loginResponse">
  95. <part name="loginReturn" type="xsd:string" />
  96. </message>
  97. <message name="resources">
  98. <part name="sessionId" type="xsd:string" />
  99. </message>
  100. <message name="resourcesResponse">
  101. <part name="resourcesReturn" type="typens:FixedArray" />
  102. </message>
  103. <message name="globalFaults">
  104. <part name="sessionId" type="xsd:string" />
  105. </message>
  106. <message name="globalFaultsResponse">
  107. <part name="globalFaultsReturn" type="typens:FixedArray" />
  108. </message>
  109. <message name="resourceFaults">
  110. <part name="resourceName" type="xsd:string" />
  111. <part name="sessionId" type="xsd:string" />
  112. </message>
  113. <message name="resourceFaultsResponse">
  114. <part name="resourceFaultsReturn" type="typens:FixedArray" />
  115. </message>
  116. <message name="startSession" />
  117. <message name="startSessionResponse">
  118. <part name="startSessionReturn" type="xsd:string" />
  119. </message>
  120. <portType name="PortType">
  121. <operation name="call">
  122. <documentation>Call api functionality</documentation>
  123. <input message="typens:call" />
  124. <output message="typens:callResponse" />
  125. </operation>
  126. <operation name="multiCall">
  127. <documentation>Multiple calls of resource functionality</documentation>
  128. <input message="typens:multiCall" />
  129. <output message="typens:multiCallResponse" />
  130. </operation>
  131. <operation name="endSession">
  132. <documentation>End web service session</documentation>
  133. <input message="typens:endSession" />
  134. <output message="typens:endSessionResponse" />
  135. </operation>
  136. <operation name="login">
  137. <documentation>Login user and retrive session id</documentation>
  138. <input message="typens:login" />
  139. <output message="typens:loginResponse" />
  140. </operation>
  141. <operation name="startSession">
  142. <documentation>Start web service session</documentation>
  143. <input message="typens:startSession" />
  144. <output message="typens:startSessionResponse" />
  145. </operation>
  146. <operation name="resources">
  147. <documentation>List of available resources</documentation>
  148. <input message="typens:resources" />
  149. <output message="typens:resourcesResponse" />
  150. </operation>
  151. <operation name="globalFaults">
  152. <documentation>List of resource faults</documentation>
  153. <input message="typens:globalFaults" />
  154. <output message="typens:globalFaultsResponse" />
  155. </operation>
  156. <operation name="resourceFaults">
  157. <documentation>List of global faults</documentation>
  158. <input message="typens:resourceFaults" />
  159. <output message="typens:resourceFaultsResponse" />
  160. </operation>
  161. </portType>
  162. <binding name="Binding" type="typens:PortType">
  163. <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
  164. <operation name="call">
  165. <soap:operation soapAction="urn:Action" />
  166. <input>
  167. <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  168. </input>
  169. <output>
  170. <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  171. </output>
  172. </operation>
  173. <operation name="multiCall">
  174. <soap:operation soapAction="urn:Action" />
  175. <input>
  176. <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  177. </input>
  178. <output>
  179. <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  180. </output>
  181. </operation>
  182. <operation name="endSession">
  183. <soap:operation soapAction="urn:Action" />
  184. <input>
  185. <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  186. </input>
  187. <output>
  188. <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  189. </output>
  190. </operation>
  191. <operation name="login">
  192. <soap:operation soapAction="urn:Action" />
  193. <input>
  194. <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  195. </input>
  196. <output>
  197. <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  198. </output>
  199. </operation>
  200. <operation name="startSession">
  201. <soap:operation soapAction="urn:Action" />
  202. <input>
  203. <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  204. </input>
  205. <output>
  206. <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  207. </output>
  208. </operation>
  209. <operation name="resources">
  210. <soap:operation soapAction="urn:Action" />
  211. <input>
  212. <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  213. </input>
  214. <output>
  215. <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  216. </output>
  217. </operation>
  218. <operation name="globalFaults">
  219. <soap:operation soapAction="urn:Action" />
  220. <input>
  221. <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  222. </input>
  223. <output>
  224. <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  225. </output>
  226. </operation>
  227. <operation name="resourceFaults">
  228. <soap:operation soapAction="urn:Action" />
  229. <input>
  230. <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  231. </input>
  232. <output>
  233. <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  234. </output>
  235. </operation>
  236. </binding>
  237. <service name="MagentoService">
  238. <port name="Port" binding="typens:Binding">
  239. <soap:address location="http://www.gsequestrian.co.uk/index.php/api/soap/index/" />
  240. </port>
  241. </service>
  242. </definitions>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement