Advertisement
Guest User

Untitled

a guest
Nov 10th, 2015
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. package example;
  2. import javax.jws.WebMethod;
  3. import javax.jws.WebService;
  4. import javax.xml.soap.*;
  5. import java.io.UnsupportedEncodingException;
  6.  
  7. import java.lang.reflect.Field;
  8.  
  9. import java.nio.charset.Charset;
  10. import java.nio.charset.StandardCharsets;
  11. import java.util.ArrayList;
  12. import java.util.List;
  13.  
  14. import ru.gismeteo.ws.registration.*;
  15. import ru.gismeteo.ws.locations.*;
  16.  
  17.  
  18. /**
  19. * Created by 4<8=8AB@0B>@ on 04.11.2015.
  20. */
  21. @WebService()
  22. public class HelloWorld {
  23. @WebMethod
  24. public static String sayHelloWorldFrom(String from) {
  25. String result = "Hello, world, from " + from;
  26. System.out.println(result);
  27. return result;
  28. }
  29. public static void main(String[] argv) throws Exception {
  30. createSOAPMsg();
  31. }
  32. public static ArrayList<String> createSOAPMsg() throws Exception {
  33.  
  34. System.setProperty("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", "true");
  35. System.setProperty("com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump", "true");
  36. System.setProperty("com.sun.xml.ws.transport.http.HttpAdapter.dump", "true");
  37. System.setProperty("com.sun.xml.internal.ws.transport.http.HttpAdapter.dump", "true");
  38. //System.setProperty( "jaxb.encoding", "UTF-8" );
  39.  
  40. Register register = new Register();
  41. RegisterSoap registerSoap = register.getRegisterSoap();
  42. RegisterResult registerResult = registerSoap.registerHHUser("Arcfag", "nomad9000@mail.ru", "123");
  43.  
  44. Locations locations = new Locations();
  45. LocationsSoap locationsSoap = locations.getLocationsSoap();
  46. String city = "Москва";
  47.  
  48.  
  49. byte[] pt;
  50. try {
  51. pt = city.getBytes();
  52. city = new String(pt, "CP1251");
  53. } catch (UnsupportedEncodingException e) {
  54. e.printStackTrace();
  55. }
  56.  
  57. LocationInfoFullResult locationInfoFullResult = locationsSoap.findByNameFull(registerResult.getKey(), city, 10, "RU");
  58. ArrayOfLocationInfoFull arrayOfLocationInfoFull = locationInfoFullResult.getData();
  59. List<LocationInfoFull> locationInfoFulls = arrayOfLocationInfoFull.getLocationInfoFull();
  60. ArrayList<String> result = new ArrayList<>();
  61. for (LocationInfoFull lif : locationInfoFulls) {
  62. result.add(lif.getCountry());
  63. System.out.println(lif.getCountry()+": "+lif.getTown());
  64. }
  65.  
  66.  
  67.  
  68. return result;
  69.  
  70.  
  71.  
  72. /* String test = "";
  73. try {
  74.  
  75. MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
  76. SOAPConnectionFactory conFactory = SOAPConnectionFactory.newInstance();
  77. SOAPMessage msg = msgFactory.createMessage();
  78. MimeHeaders headers = msg.getMimeHeaders();
  79. headers.addHeader("Host", "ws.gismeteo.ru");
  80. headers.addHeader("Content-Type", "application/soap+xml; charset=utf-8");
  81. headers.addHeader("Content-Length", "300");
  82. msg.getSOAPHeader().setPrefix("soap12");
  83. msg.setProperty(msg.WRITE_XML_DECLARATION, "true");
  84. msg.setProperty(msg.CHARACTER_SET_ENCODING, "utf-8");
  85.  
  86. SOAPPart part = msg.getSOAPPart();
  87. part.setXmlVersion("1.0");
  88. SOAPEnvelope envelope = part.getEnvelope();
  89. envelope.setPrefix("soap12");
  90. envelope.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
  91. envelope.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema");
  92. envelope.addNamespaceDeclaration("soap12", "http://www.w3.org/2003/05/soap-envelope");
  93. envelope.removeNamespaceDeclaration("SOAP-ENV");
  94. SOAPBody body = envelope.getBody();
  95. body.setPrefix("soap12");
  96. SOAPBodyElement element = body.addBodyElement(envelope.createName("RegisterHHUser", "", "http://ws.gismeteo.ru/"));
  97. element.addChildElement("name").addTextNode("Arcfag");
  98. element.addChildElement("email").addTextNode("anonov@mail.ru");
  99. element.addChildElement("deviceid").addTextNode("1231231442");
  100. envelope.getHeader().detachNode();
  101. msg.writeTo(System.out);
  102. FileOutputStream fOut = new FileOutputStream("C:\\SoapMessage.xml");
  103. msg.writeTo(fOut);
  104. SOAPConnection con = conFactory.createConnection();
  105. test += "Connestion set up; ";
  106. SOAPMessage responseMsg = con.call(msg, "http://ws.gismeteo.ru/");
  107. test += "connestion called; ";
  108. FileOutputStream resOut = new FileOutputStream("C:\\SoapResponse.xml");
  109. test += "output file created; ";
  110. responseMsg.writeTo(resOut);
  111. test += "response written; ";
  112. con.close();
  113. test += "connection close, everything done.";
  114. return "Done!";
  115. } catch (SOAPException e) {
  116. e.printStackTrace();
  117. return test + e.toString();
  118. } catch (IOException e) {
  119. e.printStackTrace();
  120. return test + e.toString();
  121. }
  122. //return null;*/
  123. }
  124. public HelloWorld() {
  125.  
  126. }
  127. public static int sum(int a, int b) {
  128. return a + b;
  129. }
  130. public static int sub(int a, int b) {
  131. return a - b;
  132. }
  133. public static int mult(int a, int b) {
  134. return a * b;
  135. }
  136. public static double div(int a, int b) {
  137. return a / b;
  138. }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement