1 16 17 package sample.amazon.search; 18 19 import org.apache.axis2.context.ConfigurationContext; 20 import org.apache.axis2.context.ConfigurationContextFactory; 21 import org.apache.axis2.context.MessageContext; 22 import org.apache.axis2.deployment.DeploymentException; 23 import org.apache.axis2.engine.AxisFault; 24 import org.apache.axis2.om.OMAbstractFactory; 25 import org.apache.axis2.om.OMElement; 26 import org.apache.axis2.om.OMNamespace; 27 import org.apache.axis2.soap.SOAPEnvelope; 28 import org.apache.axis2.soap.SOAPFactory; 29 30 37 public class ClientUtil { 38 39 42 private static MessageContext msgContext; 43 44 49 public static MessageContext getMessageContext() { 50 OMNamespace namespace,nulNS; 51 OMElement operation,value1,value2; 52 OMElement subValue1,subValue2,subValue3,subValue4,subValue5; 53 54 SOAPFactory omFactory = OMAbstractFactory.getSOAP11Factory(); 55 SOAPEnvelope reqEnv = omFactory.getDefaultEnvelope(); 56 namespace = reqEnv.declareNamespace("http://schemas.xmlsoap.org/soap/envelope/", 57 "SOAP-ENV"); 58 namespace = reqEnv.declareNamespace("http://schemas.xmlsoap.org/soap/encoding/", 59 "SOAP-ENC"); 60 namespace = reqEnv.declareNamespace("http://www.w3.org/1999/XMLSchema-instance/", "xsi"); 61 namespace = reqEnv.declareNamespace("http://www.w3.org/2001/XMLSchema", "xsd"); 62 namespace = reqEnv.declareNamespace("http://schemas.xmlsoap.org/wsdl/soap/", 63 "soap"); 64 namespace = reqEnv.declareNamespace("http://schemas.xmlsoap.org/wsdl/", 65 "wsdl"); 66 namespace = reqEnv.declareNamespace("http://webservices.amazon.com/AWSAlexa/2005-02-01", 67 "tns"); 68 69 nulNS = omFactory.createOMNamespace("", ""); 70 71 operation = omFactory.createOMElement("Search", 72 "http://webservices.amazon.com/AWSAlexa/2005-02-01", "ns1"); 73 reqEnv.getBody().addChild(operation); 74 operation.addAttribute("encordingStyle", "http://schemas.xmlsoap.org/soap/encoding/", null); 75 76 77 value1 = omFactory.createOMElement("SubscriptionId", nulNS); 78 value1.addChild(omFactory.createText(AsynchronousClient.amazonkey)); 79 81 value2 = omFactory.createOMElement("Request", nulNS); 82 83 subValue1= omFactory.createOMElement("ResponseGroup", nulNS); 84 subValue1.addChild(omFactory.createText("Web")); 85 86 subValue2 = omFactory.createOMElement("Query", nulNS); 87 subValue2.addChild(omFactory.createText(AsynchronousClient.search)); 88 89 subValue3 = omFactory.createOMElement("Count", nulNS); 90 subValue3.addChild(omFactory.createText(AsynchronousClient.maxResults)); 91 92 subValue4 = omFactory.createOMElement("IgnoreWords", nulNS); 93 subValue4.addChild(omFactory.createText("90")); 94 95 subValue5 = omFactory.createOMElement("AdultFilter", nulNS); 96 subValue5.addChild(omFactory.createText("yes")); 97 98 value2.addChild(subValue5); 99 value2.addChild(subValue4); 100 value2.addChild(subValue3); 101 value2.addChild(subValue2); 102 value2.addChild(subValue1); 103 operation.addChild(value2); 104 operation.addChild(value1); 105 106 ConfigurationContextFactory fac = new ConfigurationContextFactory(); 107 ConfigurationContext configContext = null; 108 try { 109 configContext = fac.buildClientConfigurationContext("Search"); 110 } catch (DeploymentException e) { 111 e.printStackTrace(); 112 } 113 try { 114 msgContext = new MessageContext(configContext); 115 } catch (AxisFault axisFault) { 116 axisFault.printStackTrace(); 117 } 118 msgContext.setEnvelope(reqEnv); 119 return msgContext; 120 } 121 122 123 } 124 125 126 127 | Popular Tags |