1 7 8 package org.jboss.webservice.client; 10 11 13 import org.jboss.axis.Message; 14 import org.jboss.logging.Logger; 15 import org.jboss.webservice.deployment.OperationDescription; 16 import org.jboss.webservice.deployment.ServiceDescription; 17 18 import javax.activation.DataHandler ; 19 import javax.activation.DataSource ; 20 import javax.activation.URLDataSource ; 21 import javax.mail.internet.MimeMultipart ; 22 import javax.xml.soap.AttachmentPart ; 23 import javax.xml.transform.Source ; 24 import java.net.MalformedURLException ; 25 import java.net.URL ; 26 import java.rmi.RemoteException ; 27 import java.util.Collections ; 28 import java.util.HashMap ; 29 import java.util.Iterator ; 30 import java.util.Map ; 31 import java.util.Properties ; 32 33 41 public class CallImpl extends org.jboss.axis.client.Call 42 { 43 private static final Logger log = Logger.getLogger(CallImpl.class); 45 46 private ServiceImpl jaxrpcService; 47 private OperationDescription opDescription; 48 49 private Map attachments = new HashMap (); 51 52 55 public CallImpl(ServiceImpl service) 56 { 57 super(service); 58 this.jaxrpcService = service; 59 } 60 61 67 public CallImpl(Object url) throws MalformedURLException 68 { 69 this(new ServiceImpl()); 70 setTargetEndpointAddress(new URL (url.toString())); 71 } 72 73 79 public void setOperation(String javaOpName) 80 { 81 super.setOperation(javaOpName); 82 83 org.jboss.axis.description.OperationDesc axisOp = getOperation(); 84 String wsdlOpName = getOperationName().getLocalPart(); 85 86 String portName = (getPortName() != null ? getPortName().getLocalPart() : null); 88 ServiceDescription serviceDesc = jaxrpcService.getServiceDescription(portName); 89 Properties callProperties = serviceDesc.getCallProperties(); 90 if (callProperties != null) 91 { 92 Iterator keys = callProperties.keySet().iterator(); 94 while (keys.hasNext()) 95 { 96 String key = (String )keys.next(); 97 String value = callProperties.getProperty(key); 98 this.setProperty(key, value); 99 } 100 } 101 102 this.opDescription = null; 104 105 Iterator itOp = serviceDesc.getOperations(); 106 while (opDescription == null && itOp.hasNext()) 107 { 108 OperationDescription operation = (OperationDescription)itOp.next(); 109 if (operation.getWsdlName().equals(wsdlOpName)) 110 opDescription = operation; 111 } 112 113 if (opDescription != null) 114 { 115 if (serviceDesc.getStyle().equals(axisOp.getStyle()) == false) 116 { 117 log.debug("Fixing style: [was=" + axisOp.getStyle() + ",is=" + serviceDesc.getStyle() + "]"); 118 axisOp.setStyle(serviceDesc.getStyle()); 119 } 120 121 if (serviceDesc.getUse().equals(axisOp.getUse()) == false) 122 { 123 log.debug("Fixing use: [was=" + axisOp.getUse() + ",is=" + serviceDesc.getUse() + "]"); 124 axisOp.setUse(serviceDesc.getUse()); 125 } 126 } 127 else 128 { 129 log.warn("Cannot find operation description for: " + wsdlOpName); 130 } 131 } 132 133 138 protected String getWsdlOpName(String javaOpName) 139 { 140 String wsdlOpName = javaOpName; 141 142 ServiceDescription serviceDesc = getServiceDescription(); 143 if (serviceDesc != null) 144 { 145 Iterator it = serviceDesc.getOperations(); 146 while (it.hasNext()) 147 { 148 OperationDescription operation = (OperationDescription)it.next(); 149 if (javaOpName.equals(operation.getJavaName())) 150 { 151 if (wsdlOpName.equals(operation.getWsdlName()) == false) 152 { 153 wsdlOpName = operation.getWsdlName(); 154 log.debug("Replacing operation name '" + javaOpName + "' with '" + wsdlOpName + "'"); 155 } 156 } 157 } 158 } 159 160 return wsdlOpName; 161 } 162 163 164 private ServiceDescription getServiceDescription() 165 { 166 ServiceDescription serviceDesc = null; 167 if (jaxrpcService != null) 168 { 169 String portName = (getPortName() != null ? getPortName().getLocalPart() : null); 170 serviceDesc = jaxrpcService.getServiceDescription(portName); 171 } 172 return serviceDesc; 173 } 174 175 182 public void addAttachment(String contentID, Object mimepart) 183 { 184 attachments.put(contentID, mimepart); 185 } 186 187 188 public Iterator getAttachmentIdentifiers() 189 { 190 return Collections.unmodifiableSet(attachments.keySet()).iterator(); 191 } 192 193 194 public Object getAttachment(String contentID) 195 { 196 return attachments.get(contentID); 197 } 198 199 200 public void removeAttachment(String contentID) 201 { 202 attachments.remove(contentID); 203 } 204 205 207 protected void addAttachmentParts(Message msg) 208 { 209 Iterator it = getAttachmentIdentifiers(); 210 while (it.hasNext()) 211 { 212 String contentID = (String )it.next(); 213 Object part = getAttachment(contentID); 214 215 AttachmentPart ap = null; 216 if (part instanceof String ) 217 { 218 ap = msg.createAttachmentPart(part, "text/plain"); 219 } 220 else if (part instanceof Source ) 221 { 222 ap = msg.createAttachmentPart(part, "application/xml"); 223 } 224 else if (part instanceof URL ) 225 { 226 DataSource ds = new URLDataSource ((URL )part); 227 ap = msg.createAttachmentPart(new DataHandler (ds)); 228 } 229 else if (part instanceof DataHandler ) 230 { 231 ap = msg.createAttachmentPart((DataHandler )part); 232 } 233 else if (part instanceof MimeMultipart ) 234 { 235 ap = msg.createAttachmentPart((MimeMultipart )part, "multipart/mixed"); 236 } 237 238 if (ap == null) 239 throw new IllegalArgumentException ("Unsupported attachment part: " + part); 240 241 ap.setContentId(contentID); 242 243 attachmentParts.add(ap); 245 } 246 247 super.addAttachmentParts(msg); 248 attachments.clear(); 249 } 250 251 253 public Object invoke(Object [] params) throws RemoteException 254 { 255 try 256 { 257 if (opDescription != null && opDescription.isOneWay()) 258 { 259 log.debug("Using one-way call semantics for: " + getOperationName()); 260 super.invokeOneWay(params); 261 return null; 262 } 263 else 264 { 265 return super.invoke(params); 266 } 267 } 268 finally 269 { 270 msgContext = null; 273 274 clearHeaders(); 276 } 277 } 278 } 279 | Popular Tags |