Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package example;
- import javax.jws.WebMethod;
- import javax.jws.WebService;
- import javax.xml.soap.*;
- import java.io.UnsupportedEncodingException;
- import java.lang.reflect.Field;
- import java.nio.charset.Charset;
- import java.nio.charset.StandardCharsets;
- import java.util.ArrayList;
- import java.util.List;
- import ru.gismeteo.ws.registration.*;
- import ru.gismeteo.ws.locations.*;
- /**
- * Created by 4<8=8AB@0B>@ on 04.11.2015.
- */
- @WebService()
- public class HelloWorld {
- @WebMethod
- public static String sayHelloWorldFrom(String from) {
- String result = "Hello, world, from " + from;
- System.out.println(result);
- return result;
- }
- public static void main(String[] argv) throws Exception {
- createSOAPMsg();
- }
- public static ArrayList<String> createSOAPMsg() throws Exception {
- System.setProperty("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", "true");
- System.setProperty("com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump", "true");
- System.setProperty("com.sun.xml.ws.transport.http.HttpAdapter.dump", "true");
- System.setProperty("com.sun.xml.internal.ws.transport.http.HttpAdapter.dump", "true");
- //System.setProperty( "jaxb.encoding", "UTF-8" );
- Register register = new Register();
- RegisterSoap registerSoap = register.getRegisterSoap();
- RegisterResult registerResult = registerSoap.registerHHUser("Arcfag", "nomad9000@mail.ru", "123");
- Locations locations = new Locations();
- LocationsSoap locationsSoap = locations.getLocationsSoap();
- String city = "Москва";
- byte[] pt;
- try {
- pt = city.getBytes();
- city = new String(pt, "CP1251");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- LocationInfoFullResult locationInfoFullResult = locationsSoap.findByNameFull(registerResult.getKey(), city, 10, "RU");
- ArrayOfLocationInfoFull arrayOfLocationInfoFull = locationInfoFullResult.getData();
- List<LocationInfoFull> locationInfoFulls = arrayOfLocationInfoFull.getLocationInfoFull();
- ArrayList<String> result = new ArrayList<>();
- for (LocationInfoFull lif : locationInfoFulls) {
- result.add(lif.getCountry());
- System.out.println(lif.getCountry()+": "+lif.getTown());
- }
- return result;
- /* String test = "";
- try {
- MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
- SOAPConnectionFactory conFactory = SOAPConnectionFactory.newInstance();
- SOAPMessage msg = msgFactory.createMessage();
- MimeHeaders headers = msg.getMimeHeaders();
- headers.addHeader("Host", "ws.gismeteo.ru");
- headers.addHeader("Content-Type", "application/soap+xml; charset=utf-8");
- headers.addHeader("Content-Length", "300");
- msg.getSOAPHeader().setPrefix("soap12");
- msg.setProperty(msg.WRITE_XML_DECLARATION, "true");
- msg.setProperty(msg.CHARACTER_SET_ENCODING, "utf-8");
- SOAPPart part = msg.getSOAPPart();
- part.setXmlVersion("1.0");
- SOAPEnvelope envelope = part.getEnvelope();
- envelope.setPrefix("soap12");
- envelope.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
- envelope.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema");
- envelope.addNamespaceDeclaration("soap12", "http://www.w3.org/2003/05/soap-envelope");
- envelope.removeNamespaceDeclaration("SOAP-ENV");
- SOAPBody body = envelope.getBody();
- body.setPrefix("soap12");
- SOAPBodyElement element = body.addBodyElement(envelope.createName("RegisterHHUser", "", "http://ws.gismeteo.ru/"));
- element.addChildElement("name").addTextNode("Arcfag");
- element.addChildElement("email").addTextNode("anonov@mail.ru");
- element.addChildElement("deviceid").addTextNode("1231231442");
- envelope.getHeader().detachNode();
- msg.writeTo(System.out);
- FileOutputStream fOut = new FileOutputStream("C:\\SoapMessage.xml");
- msg.writeTo(fOut);
- SOAPConnection con = conFactory.createConnection();
- test += "Connestion set up; ";
- SOAPMessage responseMsg = con.call(msg, "http://ws.gismeteo.ru/");
- test += "connestion called; ";
- FileOutputStream resOut = new FileOutputStream("C:\\SoapResponse.xml");
- test += "output file created; ";
- responseMsg.writeTo(resOut);
- test += "response written; ";
- con.close();
- test += "connection close, everything done.";
- return "Done!";
- } catch (SOAPException e) {
- e.printStackTrace();
- return test + e.toString();
- } catch (IOException e) {
- e.printStackTrace();
- return test + e.toString();
- }
- //return null;*/
- }
- public HelloWorld() {
- }
- public static int sum(int a, int b) {
- return a + b;
- }
- public static int sub(int a, int b) {
- return a - b;
- }
- public static int mult(int a, int b) {
- return a * b;
- }
- public static double div(int a, int b) {
- return a / b;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement