1 23 24 package org.infoglue.deliver.util.webservices; 25 26 import java.util.Collection ; 27 import java.util.HashMap ; 28 import java.util.Map ; 29 30 import javax.xml.namespace.QName ; 31 import javax.xml.rpc.ParameterMode ; 32 33 import org.apache.axis.client.Call; 34 import org.apache.axis.client.Service; 35 import org.apache.axis.encoding.XMLType; 36 import org.infoglue.cms.exception.SystemException; 37 38 42 43 public class WebServiceHelper 44 { 45 private String serviceUrl = ""; 46 47 private boolean isSuccessfull; 48 private String message; 49 50 53 54 public WebServiceHelper() 55 { 56 } 57 58 61 62 public String getServiceUrl() 63 { 64 return serviceUrl; 65 } 66 67 70 71 public void setServiceUrl(String serviceUrl) 72 { 73 this.serviceUrl = serviceUrl; 74 } 75 76 79 80 public String getString(String method) 81 { 82 String response = ""; 83 84 try 85 { 86 Service service = new Service(); 87 Call call = (Call)service.createCall(); 88 89 String endpoint = this.serviceUrl; 90 91 call.setTargetEndpointAddress(endpoint); call.setOperationName(new QName ("http://soapinterop.org/", method)); call.setEncodingStyle( "http://schemas.xmlsoap.org/soap/encoding/" ); 94 95 QName qnameAttachment = new QName ("urn:EchoAttachmentsService", "DataHandler"); 96 97 call.setReturnType(qnameAttachment); 98 99 response = (String )call.invoke(new Object [0]); } 101 catch (Exception e) 102 { 103 e.printStackTrace(); 104 } 105 return response; 106 } 107 108 111 112 public Collection getCollection(String method) 113 { 114 Collection response = null; 115 116 try 117 { 118 Service service = new Service(); 119 Call call = (Call)service.createCall(); 120 121 String endpoint = this.serviceUrl; 122 123 call.setTargetEndpointAddress(endpoint); call.setOperationName(new QName ("http://soapinterop.org/", method)); call.setEncodingStyle( "http://schemas.xmlsoap.org/soap/encoding/" ); 126 127 QName qnameAttachment = new QName ("urn:EchoAttachmentsService", "DataHandler"); 128 129 call.setReturnType(qnameAttachment); 130 131 response = (Collection )call.invoke(new Object [0]); } 133 catch (Exception e) 134 { 135 e.printStackTrace(); 136 } 137 return response; 138 } 139 140 143 144 public Map getMap(String method) 145 { 146 Map response = null; 147 148 try 149 { 150 Service service = new Service(); 151 Call call = (Call)service.createCall(); 152 153 String endpoint = this.serviceUrl; 154 155 call.setTargetEndpointAddress(endpoint); call.setOperationName(new QName ("http://soapinterop.org/", method)); call.setEncodingStyle( "http://schemas.xmlsoap.org/soap/encoding/" ); 158 159 QName qnameAttachment = new QName ("urn:EchoAttachmentsService", "DataHandler"); 160 161 call.setReturnType(qnameAttachment); 162 163 response = (Map )call.invoke(new Object [0]); } 165 catch (Exception e) 166 { 167 response.put("errorStatus", new Integer (1)); 168 response.put("errorMessage", e.getMessage()); 169 e.printStackTrace(); 170 } 171 return response; 172 } 173 174 175 178 179 public Map getMap(String method, Map argument) throws SystemException 180 { 181 Map response = new HashMap (); 182 183 try 184 { 185 Service service = new Service(); 186 Call call = (Call)service.createCall(); 187 188 String endpoint = this.serviceUrl; 189 190 call.setTargetEndpointAddress(endpoint); call.setOperationName(new QName ("http://soapinterop.org/", method)); call.setEncodingStyle( "http://schemas.xmlsoap.org/soap/encoding/" ); 193 194 QName qnameAttachment = new QName ("urn:EchoAttachmentsService", "DataHandler"); 195 196 call.addParameter("data", XMLType.XSD_STRING, ParameterMode.IN); 197 198 call.setReturnType(qnameAttachment); 199 Object [] args = {argument}; 200 response = (Map )call.invoke(args); } 202 catch (Exception e) 203 { 204 response.put("errorStatus", new Integer (1)); 205 response.put("errorMessage", e.getMessage()); 206 e.printStackTrace(); 207 } 208 209 return response; 210 } 211 212 213 216 217 public Map getMap() 218 { 219 return new HashMap (); 220 } 221 222 223 226 227 public boolean getIsSuccessfull() 228 { 229 return this.isSuccessfull; 230 } 231 232 235 236 public void setIsSuccessfull(boolean isSuccessfull) 237 { 238 this.isSuccessfull = isSuccessfull; 239 } 240 241 244 245 public String getMessage() 246 { 247 return this.message; 248 } 249 250 253 254 public void setMessage(String message) 255 { 256 this.message = message; 257 } 258 } | Popular Tags |