Jagger
 All Classes Namespaces Files Functions Variables Groups Pages
String com.griddynamics.jagger.invoker.soap.SOAPInvoker.invoke ( SOAPQuery  query,
String  endpoint 
) throws InvocationException
46  {
47  try {
48  SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
49  SOAPConnection connection = soapConnectionFactory.createConnection();
50  SOAPFactory soapFactory = SOAPFactory.newInstance();
51 
52  MessageFactory factory = MessageFactory.newInstance();
53  SOAPMessage message = factory.createMessage();
54 
55  SOAPBody body = message.getSOAPBody();
56 
57  Name bodyName = soapFactory.createName(query.getMethod(), "", "urn:ActiveStations");
58  SOAPBodyElement soapBodyElement = body.addBodyElement(bodyName);
59  for (Map.Entry<String, Object> methodParam : query.getMethodParams().entrySet()) {
60  soapBodyElement.addChildElement(methodParam.getKey(), methodParam.getValue().toString());
61  }
62 //
63 // System.out.print("\nPrinting the message that is being sent: \n\n");
64 // message.writeTo(System.out);
65 // System.out.println("\n\n");
66 
67  URL url = new URL(endpoint);
68  SOAPMessage response = connection.call(message, url);
69  connection.close();
70 
71 // System.out.println("\nPrinting the respone that was recieved: \n\n");
72 // response.writeTo(System.out);
73 
74 // FileOutputStream fout = new FileOutputStream("SoapResponse.xml");
75 // response.writeTo(fout);
76 // fout.close();
77 
78  ByteArrayOutputStream out = new ByteArrayOutputStream();
79  response.writeTo(out);
80  return out.toString();
81 
82 // SOAPBody responseBody = response.getSOAPBody();
83  } catch (SOAPException e) {
84  throw new InvocationException("SOAPException: ", e);
85  } catch (IOException e) {
86  throw new InvocationException("IOException: ", e);
87  }
88  }