1 55 56 package org.jboss.axis.client; 57 58 import java.net.MalformedURLException ; 59 import java.net.URL ; 60 import java.rmi.RemoteException ; 61 import java.util.ArrayList ; 62 import java.util.HashMap ; 63 import java.util.Hashtable ; 64 import java.util.Iterator ; 65 import java.util.List ; 66 import java.util.Map ; 67 import java.util.StringTokenizer ; 68 import java.util.Vector ; 69 70 import javax.wsdl.Binding; 71 import javax.wsdl.BindingInput; 72 import javax.wsdl.BindingOperation; 73 import javax.wsdl.Operation; 74 import javax.wsdl.Part; 75 import javax.wsdl.Port; 76 import javax.wsdl.PortType; 77 import javax.wsdl.extensions.soap.SOAPAddress; 78 import javax.wsdl.extensions.soap.SOAPBody; 79 import javax.wsdl.extensions.soap.SOAPOperation; 80 import javax.xml.namespace.QName ; 81 import javax.xml.rpc.JAXRPCException ; 82 import javax.xml.rpc.ParameterMode ; 83 import javax.xml.rpc.holders.Holder ; 84 import javax.xml.soap.MimeHeaders ; 85 86 import org.jboss.axis.AxisEngine; 87 import org.jboss.axis.AxisFault; 88 import org.jboss.axis.AxisProperties; 89 import org.jboss.axis.Constants; 90 import org.jboss.axis.Handler; 91 import org.jboss.axis.InternalException; 92 import org.jboss.axis.Message; 93 import org.jboss.axis.MessageContext; 94 import org.jboss.axis.attachments.Attachments; 95 import org.jboss.axis.description.FaultDesc; 96 import org.jboss.axis.description.OperationDesc; 97 import org.jboss.axis.description.ParameterDesc; 98 import org.jboss.axis.encoding.DeserializerFactory; 99 import org.jboss.axis.encoding.SerializerFactory; 100 import org.jboss.axis.encoding.TypeMapping; 101 import org.jboss.axis.encoding.TypeMappingRegistry; 102 import org.jboss.axis.encoding.XMLType; 103 import org.jboss.axis.encoding.ser.BaseDeserializerFactory; 104 import org.jboss.axis.encoding.ser.BaseSerializerFactory; 105 import org.jboss.axis.enums.Style; 106 import org.jboss.axis.enums.Use; 107 import org.jboss.axis.handlers.soap.SOAPService; 108 import org.jboss.axis.message.RPCElement; 109 import org.jboss.axis.message.RPCHeaderParam; 110 import org.jboss.axis.message.RPCParam; 111 import org.jboss.axis.message.SOAPBodyElementAxisImpl; 112 import org.jboss.axis.message.SOAPEnvelopeAxisImpl; 113 import org.jboss.axis.message.SOAPFaultImpl; 114 import org.jboss.axis.message.SOAPHeaderElementAxisImpl; 115 import org.jboss.axis.soap.SOAPConstants; 116 import org.jboss.axis.transport.http.HTTPConstants; 117 import org.jboss.axis.transport.http.HTTPTransport; 118 import org.jboss.axis.transport.java.JavaTransport; 119 import org.jboss.axis.transport.local.LocalTransport; 120 import org.jboss.axis.utils.ClassUtils; 121 import org.jboss.axis.utils.JavaUtils; 122 import org.jboss.axis.utils.Messages; 123 import org.jboss.axis.wsdl.symbolTable.BindingEntry; 124 import org.jboss.axis.wsdl.symbolTable.FaultInfo; 125 import org.jboss.axis.wsdl.symbolTable.Parameter; 126 import org.jboss.axis.wsdl.symbolTable.Parameters; 127 import org.jboss.axis.wsdl.symbolTable.SymbolTable; 128 import org.jboss.axis.wsdl.toJava.Utils; 129 import org.jboss.logging.Logger; 130 131 155 156 public class Call implements javax.xml.rpc.Call 157 { 158 159 private static Logger log = Logger.getLogger(Call.class.getName()); 160 161 private static Logger tlog = Logger.getLogger(Constants.TIME_LOG_CATEGORY); 162 163 private boolean parmAndRetReq = true; 164 private Service service; 165 private QName portName; 166 private QName operationName; 167 168 protected MessageContext msgContext; 169 170 private Hashtable myProperties = new Hashtable (); 174 private String username; 175 private String password; 176 private boolean maintainSession; 177 private boolean useSOAPAction; 178 private String SOAPActionURI; 179 private Integer timeout; 180 181 184 private OperationDesc operation; 185 188 private boolean operationSetManually; 189 190 private boolean invokeOneWay; 192 private boolean isMsg; 193 194 private Transport transport; 196 private String transportName; 197 198 private HashMap outParams; 201 private ArrayList outParamsList; 203 204 private Vector headers; 206 207 protected Vector attachmentParts = new Vector (); 208 209 public static final String SEND_TYPE_ATTR = "send_type_attr"; 210 public static final String TRANSPORT_NAME = "transport_name"; 211 public static final String TRANSPORT_PROPERTY = "java.protocol.handler.pkgs"; 212 213 public static final String WSDL_SERVICE = "wsdl.service"; 214 215 public static final String WSDL_PORT_NAME = "wsdl.portName"; 216 217 public static final String JAXRPC_SERVICE = WSDL_SERVICE; 219 220 public static final String JAXRPC_PORTTYPE_NAME = WSDL_PORT_NAME; 222 223 public static final boolean FAULT_ON_NO_RESPONSE = false; 227 228 231 public static final String ATTACHMENT_ENCAPSULATION_FORMAT = 232 "attachment_encapsulation_format"; 233 236 public static final String ATTACHMENT_ENCAPSULATION_FORMAT_MIME = 237 "axis.attachment.style.mime"; 238 241 public static final String ATTACHMENT_ENCAPSULATION_FORMAT_DIME = 242 "axis.attachment.style.dime"; 243 244 247 private static Hashtable transports = new Hashtable (); 248 249 static ParameterMode [] modes = new ParameterMode []{null, 250 ParameterMode.IN, 251 ParameterMode.OUT, 252 ParameterMode.INOUT}; 253 254 257 private boolean encodingStyleExplicitlySet; 258 261 private boolean useExplicitlySet; 262 263 264 265 266 267 270 public Call(Service service) 271 { 272 this.service = service; 273 maintainSession = service.getMaintainSession(); 274 initialize(); 275 } 276 277 283 public Call(String url) throws MalformedURLException 284 { 285 this(new Service()); 286 setTargetEndpointAddress(new URL (url)); 287 } 288 289 294 public Call(URL url) 295 { 296 this(new Service()); 297 setTargetEndpointAddress(url); 298 } 299 300 305 318 public void setProperty(String name, Object value) 319 { 320 if (name == null || value == null) 321 { 322 throw new JAXRPCException (Messages.getMessage(name == null ? 323 "badProp03" : "badProp04")); 324 } 325 else if (name.equals(USERNAME_PROPERTY)) 326 { 327 if (!(value instanceof String )) 328 { 329 throw new JAXRPCException (Messages.getMessage("badProp00", new String []{ 330 name, "java.lang.String", value.getClass().getName()})); 331 } 332 setUsername((String )value); 333 } 334 else if (name.equals(PASSWORD_PROPERTY)) 335 { 336 if (!(value instanceof String )) 337 { 338 throw new JAXRPCException (Messages.getMessage("badProp00", new String []{ 339 name, "java.lang.String", value.getClass().getName()})); 340 } 341 setPassword((String )value); 342 } 343 else if (name.equals(SESSION_MAINTAIN_PROPERTY)) 344 { 345 if (!(value instanceof Boolean )) 346 { 347 throw new JAXRPCException (Messages.getMessage("badProp00", new String [] 348 {name, 349 "java.lang.Boolean", 350 value.getClass().getName()})); 351 } 352 setMaintainSession(((Boolean )value).booleanValue()); 353 } 354 else if (name.equals(OPERATION_STYLE_PROPERTY)) 355 { 356 if (!(value instanceof String )) 357 { 358 throw new JAXRPCException (Messages.getMessage("badProp00", new String []{ 359 name, "java.lang.String", value.getClass().getName()})); 360 } 361 setOperationStyle((String )value); 362 if (getOperationStyle() == Style.DOCUMENT || 363 getOperationStyle() == Style.WRAPPED) 364 { 365 setOperationUse(Use.LITERAL_STR); 366 } 367 else if (getOperationStyle() == Style.RPC) 368 { 369 setOperationUse(Use.ENCODED_STR); 370 } 371 } 372 else if (name.equals(SOAPACTION_USE_PROPERTY)) 373 { 374 if (!(value instanceof Boolean )) 375 { 376 throw new JAXRPCException (Messages.getMessage("badProp00", new String [] 377 {name, 378 "java.lang.Boolean", 379 value.getClass().getName()})); 380 } 381 setUseSOAPAction(((Boolean )value).booleanValue()); 382 } 383 else if (name.equals(SOAPACTION_URI_PROPERTY)) 384 { 385 if (!(value instanceof String )) 386 { 387 throw new JAXRPCException (Messages.getMessage("badProp00", new String [] 388 {name, 389 "java.lang.String", 390 value.getClass().getName()})); 391 } 392 setSOAPActionURI((String )value); 393 } 394 else if (name.equals(ENCODINGSTYLE_URI_PROPERTY)) 395 { 396 if (!(value instanceof String )) 397 { 398 throw new JAXRPCException (Messages.getMessage("badProp00", new String [] 399 {name, 400 "java.lang.String", 401 value.getClass().getName()})); 402 } 403 setEncodingStyle((String )value); 404 } 405 else if (name.equals(Stub.ENDPOINT_ADDRESS_PROPERTY)) 406 { 407 if (!(value instanceof String )) 408 { 409 throw new JAXRPCException (Messages.getMessage("badProp00", new String [] 410 {name, 411 "java.lang.String", 412 value.getClass().getName()})); 413 } 414 setTargetEndpointAddress((String )value); 415 } 416 else if (name.equals(TRANSPORT_NAME)) 417 { 418 if (!(value instanceof String )) 419 { 420 throw new JAXRPCException (Messages.getMessage("badProp00", new String []{ 421 name, "java.lang.String", value.getClass().getName()})); 422 } 423 transportName = (String )value; 424 if (transport != null) 425 transport.setTransportName((String )value); 426 } 427 else if (name.equals(ATTACHMENT_ENCAPSULATION_FORMAT)) 428 { 429 if (!(value instanceof String )) 430 { 431 throw new JAXRPCException (Messages.getMessage("badProp00", new String []{ 432 name, "java.lang.String", value.getClass().getName()})); 433 } 434 if (!value.equals(ATTACHMENT_ENCAPSULATION_FORMAT_MIME) && 435 !value.equals(ATTACHMENT_ENCAPSULATION_FORMAT_DIME)) 436 throw new JAXRPCException (Messages.getMessage("badattachmenttypeerr", new String []{ 437 (String )value, ATTACHMENT_ENCAPSULATION_FORMAT_MIME + " " 438 + ATTACHMENT_ENCAPSULATION_FORMAT_DIME})); 439 } 440 else if (name.startsWith("java.") || name.startsWith("javax.")) 441 { 442 throw new JAXRPCException (Messages.getMessage("badProp05", name)); 443 } 444 myProperties.put(name, value); 445 } 447 453 public Object getProperty(String name) 454 { 455 if (Stub.ENDPOINT_ADDRESS_PROPERTY.equals(name)) 456 { 457 return getTargetEndpointAddress(); 458 } 459 else if (!isPropertySupported(name)) 460 { 461 throw new JAXRPCException (name == null ? 462 Messages.getMessage("badProp03") : 463 Messages.getMessage("badProp05", name)); 464 } 465 return myProperties.get(name); 466 } 468 473 public void removeProperty(String name) 474 { 475 if (name == null || !isPropertySupported(name)) 476 { 477 throw new JAXRPCException (name == null ? 478 Messages.getMessage("badProp03") : 479 Messages.getMessage("badProp05", name)); 480 } 481 myProperties.remove(name); 482 } 484 495 public void setScopedProperty(String name, Object value) 496 { 497 if (name == null || value == null) 498 { 499 throw new JAXRPCException (Messages.getMessage(name == null ? 500 "badProp03" : "badProp04")); 501 } 502 myProperties.put(name, value); 503 } 505 515 public Object getScopedProperty(String name) 516 { 517 if (name != null) 518 { 519 return myProperties.get(name); 520 } 521 return null; 522 } 524 534 public void removeScopedProperty(String name) 535 { 536 if (name == null || myProperties == null) return; 537 myProperties.remove(name); 538 } 540 543 private static ArrayList propertyNames = new ArrayList (); 544 545 static 546 { 547 propertyNames.add(USERNAME_PROPERTY); 548 propertyNames.add(PASSWORD_PROPERTY); 549 propertyNames.add(SESSION_MAINTAIN_PROPERTY); 550 propertyNames.add(ATTACHMENT_ENCAPSULATION_FORMAT); 551 propertyNames.add(OPERATION_STYLE_PROPERTY); 552 propertyNames.add(SOAPACTION_USE_PROPERTY); 553 propertyNames.add(SOAPACTION_URI_PROPERTY); 554 propertyNames.add(ENCODINGSTYLE_URI_PROPERTY); 555 propertyNames.add(TRANSPORT_NAME); 556 propertyNames.add(ATTACHMENT_ENCAPSULATION_FORMAT); 557 } 558 559 public Iterator getPropertyNames() 560 { 561 return propertyNames.iterator(); 562 } 563 564 public boolean isPropertySupported(String name) 565 { 566 boolean isSupported = false; 567 if (name != null) 568 { 569 isSupported = propertyNames.contains(name) || (!name.startsWith("java.") && !name.startsWith("javax.")); 570 } 571 return isSupported; 572 } 573 574 577 public void setUsername(String username) 578 { 579 this.username = username; 580 } 582 585 public String getUsername() 586 { 587 return username; 588 } 590 593 public void setPassword(String password) 594 { 595 this.password = password; 596 } 598 601 public String getPassword() 602 { 603 return password; 604 } 606 614 public void setMaintainSession(boolean yesno) 615 { 616 maintainSession = yesno; 617 } 618 619 622 public boolean getMaintainSession() 623 { 624 return maintainSession; 625 } 626 627 632 public void setOperationStyle(String operationStyle) 633 { 634 Style style = Style.getStyle(operationStyle, Style.DEFAULT); 635 setOperationStyle(style); 636 } 638 643 public void setOperationStyle(Style operationStyle) 644 { 645 if (operation == null) 646 { 647 operation = new OperationDesc(); 648 } 649 650 operation.setStyle(operationStyle); 651 652 if (!useExplicitlySet) 655 { 656 if (operationStyle != Style.RPC) 657 { 658 operation.setUse(Use.LITERAL); 659 } 660 } 661 662 if (!encodingStyleExplicitlySet) 666 { 667 String encStyle = ""; 668 if (operationStyle == Style.RPC) 669 { 670 encStyle = getMessageContext().getSOAPConstants().getEncodingURI(); 672 } 673 getMessageContext().setEncodingStyle(encStyle); 674 } 675 } 676 677 680 public Style getOperationStyle() 681 { 682 if (operation != null) 683 { 684 return operation.getStyle(); 685 } 686 return Style.DEFAULT; 687 } 689 694 public void setOperationUse(String operationUse) 695 { 696 Use use = Use.getUse(operationUse, Use.DEFAULT); 697 setOperationUse(use); 698 } 700 705 public void setOperationUse(Use operationUse) 706 { 707 useExplicitlySet = true; 708 709 if (operation == null) 710 { 711 operation = new OperationDesc(); 712 } 713 714 operation.setUse(operationUse); 715 if (!encodingStyleExplicitlySet) 716 { 717 String encStyle = ""; 718 if (operationUse == Use.ENCODED) 719 { 720 encStyle = getMessageContext().getSOAPConstants().getEncodingURI(); 722 } 723 getMessageContext().setEncodingStyle(encStyle); 724 } 725 } 726 727 730 public Use getOperationUse() 731 { 732 if (operation != null) 733 { 734 return operation.getUse(); 735 } 736 return Use.DEFAULT; 737 } 739 742 public void setUseSOAPAction(boolean useSOAPAction) 743 { 744 this.useSOAPAction = useSOAPAction; 745 } 747 750 public boolean useSOAPAction() 751 { 752 return useSOAPAction; 753 } 755 758 public void setSOAPActionURI(String SOAPActionURI) 759 throws IllegalArgumentException 760 { 761 useSOAPAction = true; 762 this.SOAPActionURI = SOAPActionURI; 763 } 765 768 public String getSOAPActionURI() 769 { 770 return SOAPActionURI; 771 } 773 778 public void setEncodingStyle(String namespaceURI) 779 { 780 encodingStyleExplicitlySet = true; 781 getMessageContext().setEncodingStyle(namespaceURI); 782 } 783 784 790 public String getEncodingStyle() 791 { 792 return getMessageContext().getEncodingStyle(); 793 } 794 795 803 public void setTargetEndpointAddress(String address) 804 { 805 URL urlAddress; 806 try 807 { 808 urlAddress = new URL (address); 809 } 810 catch (MalformedURLException mue) 811 { 812 throw new JAXRPCException (mue); 813 } 814 setTargetEndpointAddress(urlAddress); 815 } 816 817 824 public void setTargetEndpointAddress(java.net.URL address) 825 { 826 try 827 { 828 if (address == null) 829 { 830 setTransport(null); 831 return; 832 } 833 834 String protocol = address.getProtocol(); 835 836 if (this.transport != null) 845 { 846 String oldAddr = this.transport.getUrl(); 847 if (oldAddr != null && !oldAddr.equals("")) 848 { 849 URL tmpURL = new URL (oldAddr); 850 String oldProto = tmpURL.getProtocol(); 851 if (protocol.equals(oldProto)) 852 { 853 this.transport.setUrl(address.toString()); 854 return; 855 } 856 } 857 } 858 859 Transport transport = service.getTransportForURL(address); 861 if (transport != null) 862 { 863 setTransport(transport); 864 } 865 else 866 { 867 transport = getTransportForProtocol(protocol); 869 if (transport == null) 870 throw new AxisFault("Call.setTargetEndpointAddress", 871 Messages.getMessage("noTransport01", 872 protocol), null, null); 873 transport.setUrl(address.toString()); 874 setTransport(transport); 875 service.registerTransportForURL(address, transport); 876 } 877 } 878 catch (Exception exp) 879 { 880 log.error(Messages.getMessage("exception00"), exp); 881 } 885 } 886 887 892 public String getTargetEndpointAddress() 893 { 894 try 895 { 896 if (transport == null) return (null); 897 return (transport.getUrl()); 898 } 899 catch (Exception exp) 900 { 901 return (null); 902 } 903 } 904 905 public Integer getTimeout() 906 { 907 return timeout; 908 } 909 910 public void setTimeout(Integer timeout) 911 { 912 this.timeout = timeout; 913 } 914 919 930 public boolean isParameterAndReturnSpecRequired(QName operationName) 931 { 932 return parmAndRetReq; 933 } 935 945 public void addParameter(QName paramName, QName xmlType, 946 ParameterMode parameterMode) 947 { 948 Class javaType = null; 949 TypeMapping tm = getTypeMapping(); 950 if (tm != null) 951 { 952 javaType = tm.getClassForQName(xmlType); 953 } 954 addParameter(paramName, xmlType, javaType, parameterMode); 955 } 956 957 969 public void addParameter(QName paramName, QName xmlType, 970 Class javaType, ParameterMode parameterMode, 971 boolean inHeader, boolean outHeader) 972 { 973 974 if (operationSetManually) 975 { 976 throw new RuntimeException (Messages.getMessage("operationAlreadySet")); 977 } 978 979 if (operation == null) 980 operation = new OperationDesc(); 981 982 987 ParameterDesc param = new ParameterDesc(); 989 param.setQName(paramName); 990 param.setTypeQName(xmlType); 991 992 byte mode = ParameterDesc.IN; 993 if (parameterMode == ParameterMode.INOUT) 994 { 995 mode = ParameterDesc.INOUT; 996 } 997 else if (parameterMode == ParameterMode.OUT) 998 { 999 mode = ParameterDesc.OUT; 1000 } 1001 param.setMode(mode); 1002 1003 param.setJavaType(javaType); 1004 1005 param.setInHeader(inHeader); 1006 param.setOutHeader(outHeader); 1007 1008 operation.addParameter(param); 1009 parmAndRetReq = true; 1010 } 1015 1016 1028 public void addParameter(QName paramName, QName xmlType, 1029 Class javaType, ParameterMode parameterMode) 1030 { 1031 1032 if (operationSetManually) 1033 { 1034 throw new RuntimeException (Messages.getMessage("operationAlreadySet")); 1035 } 1036 1037 if (operation == null) 1038 operation = new OperationDesc(); 1039 1040 1045 ParameterDesc param = new ParameterDesc(); 1047 param.setQName(paramName); 1048 param.setTypeQName(xmlType); 1049 param.setJavaType(javaType); 1050 byte mode = ParameterDesc.IN; 1051 if (parameterMode == ParameterMode.INOUT) 1052 { 1053 mode = ParameterDesc.INOUT; 1054 } 1055 else if (parameterMode == ParameterMode.OUT) 1056 { 1057 mode = ParameterDesc.OUT; 1058 } 1059 param.setMode(mode); 1060 1061 operation.addParameter(param); 1062 parmAndRetReq = true; 1063 } 1068 1069 1077 public void addParameter(String paramName, QName xmlType, 1078 ParameterMode parameterMode) 1079 { 1080 Class javaType = null; 1081 TypeMapping tm = getTypeMapping(); 1082 if (tm != null) 1083 { 1084 javaType = tm.getClassForQName(xmlType); 1085 } 1086 addParameter(new QName ("", paramName), xmlType, 1087 javaType, parameterMode); 1088 } 1089 1090 1106 public void addParameter(String paramName, QName xmlType, 1107 Class javaType, ParameterMode parameterMode) 1108 { 1109 addParameter(new QName ("", paramName), xmlType, 1110 javaType, parameterMode); 1111 } 1112 1113 1128 public void addParameterAsHeader(QName paramName, QName xmlType, 1129 Class javaType, ParameterMode parameterMode, 1130 ParameterMode headerMode) 1131 { 1132 if (operationSetManually) 1133 { 1134 throw new RuntimeException (Messages.getMessage("operationAlreadySet")); 1135 } 1136 1137 if (operation == null) 1138 operation = new OperationDesc(); 1139 1140 ParameterDesc param = new ParameterDesc(); 1141 param.setQName(paramName); 1142 param.setTypeQName(xmlType); 1143 param.setJavaType(javaType); 1144 if (parameterMode == ParameterMode.IN) 1145 { 1146 param.setMode(ParameterDesc.IN); 1147 } 1148 else if (parameterMode == ParameterMode.INOUT) 1149 { 1150 param.setMode(ParameterDesc.INOUT); 1151 } 1152 else if (parameterMode == ParameterMode.OUT) 1153 { 1154 param.setMode(ParameterDesc.OUT); 1155 } 1156 if (headerMode == ParameterMode.IN) 1157 { 1158 param.setInHeader(true); 1159 } 1160 else if (headerMode == ParameterMode.INOUT) 1161 { 1162 param.setInHeader(true); 1163 param.setOutHeader(true); 1164 } 1165 else if (headerMode == ParameterMode.OUT) 1166 { 1167 param.setOutHeader(true); 1168 } 1169 operation.addParameter(param); 1170 parmAndRetReq = true; 1171 } 1173 1179 public QName getParameterTypeByName(String paramName) 1180 { 1181 QName paramQName = new QName ("", paramName); 1182 1183 return getParameterTypeByQName(paramQName); 1184 } 1185 1186 1194 public QName getParameterTypeByQName(QName paramQName) 1195 { 1196 ParameterDesc param = operation.getParamByQName(paramQName); 1197 if (param != null) 1198 { 1199 return param.getTypeQName(); 1200 } 1201 return (null); 1202 } 1203 1204 1209 public void setReturnType(QName returnType) 1210 { 1211 if (operationSetManually) 1212 { 1213 throw new RuntimeException (Messages.getMessage("operationAlreadySet")); 1214 } 1215 1216 if (operation == null) 1217 operation = new OperationDesc(); 1218 1219 while (returnType != null && returnType.getLocalPart().startsWith(">")) 1221 { 1222 log.debug("Removing leading '>' from anonymous type" + returnType); 1223 returnType = new QName (returnType.getNamespaceURI(), returnType.getLocalPart().substring(1)); 1224 } 1225 1226 1231 operation.setReturnType(returnType); 1233 TypeMapping tm = getTypeMapping(); 1234 operation.setReturnClass(tm.getClassForQName(returnType)); 1235 parmAndRetReq = true; 1236 } 1241 1242 1251 public void setReturnType(QName xmlType, Class javaType) 1252 { 1253 setReturnType(xmlType); 1254 operation.setReturnClass(javaType); 1256 } 1257 1258 1261 public void setReturnTypeAsHeader(QName xmlType) 1262 { 1263 setReturnType(xmlType); 1264 operation.setReturnHeader(true); 1265 } 1267 1270 public void setReturnTypeAsHeader(QName xmlType, Class javaType) 1271 { 1272 setReturnType(xmlType, javaType); 1273 operation.setReturnHeader(true); 1274 } 1276 1284 public QName getReturnType() 1285 { 1286 if (operation != null) 1287 return operation.getReturnType(); 1288 1289 return null; 1290 } 1291 1292 1297 public void setReturnQName(QName qname) 1298 { 1299 if (operationSetManually) 1300 { 1301 throw new RuntimeException (Messages.getMessage("operationAlreadySet")); 1302 } 1303 1304 if (operation == null) 1305 operation = new OperationDesc(); 1306 1307 operation.setReturnQName(qname); 1308 } 1309 1310 1326 public void setReturnClass(Class cls) 1327 { 1328 if (operationSetManually) 1329 { 1330 throw new RuntimeException (Messages.getMessage("operationAlreadySet")); 1331 } 1332 1333 if (operation == null) 1334 operation = new OperationDesc(); 1335 1336 operation.setReturnClass(cls); 1337 TypeMapping tm = getTypeMapping(); 1338 operation.setReturnType(tm.getTypeQName(cls)); 1339 parmAndRetReq = true; 1340 } 1341 1342 1349 public void removeAllParameters() 1350 { 1351 operation = new OperationDesc(); 1353 operationSetManually = false; 1354 parmAndRetReq = true; 1355 } 1360 1361 1366 public QName getOperationName() 1367 { 1368 return (operationName); 1369 } 1370 1371 1378 public void setOperationName(QName opName) 1379 { 1380 operationName = opName; 1381 } 1382 1383 1388 public void setOperationName(String opName) 1389 { 1390 operationName = new QName (opName); 1391 } 1392 1393 1406 public void setOperation(String opName) 1407 { 1408 if (service == null) 1409 throw new JAXRPCException (Messages.getMessage("noService04")); 1410 1411 this.setOperationName(opName); 1414 this.setEncodingStyle(null); 1415 this.setReturnType(null); 1416 this.removeAllParameters(); 1417 1418 javax.wsdl.Service wsdlService = service.getWSDLService(); 1419 if (wsdlService == null) 1421 return; 1422 1423 Port port = wsdlService.getPort(portName.getLocalPart()); 1424 if (port == null) 1425 throw new JAXRPCException (Messages.getMessage("noPort00", "" + 1426 portName)); 1427 1428 Binding binding = port.getBinding(); 1429 PortType portType = binding.getPortType(); 1430 if (portType == null) 1431 throw new JAXRPCException (Messages.getMessage("noPortType00", "" + 1432 portName)); 1433 1434 List operations = portType.getOperations(); 1435 if (operations == null) 1436 throw new JAXRPCException (Messages.getMessage("noOperation01", 1437 opName)); 1438 1439 Operation wsdlOp = null; 1440 for (int i = 0; i < operations.size(); i++, wsdlOp = null) 1441 { 1442 wsdlOp = (Operation)operations.get(i); 1443 String wsdlOpName = getWsdlOpName(opName); 1444 if (wsdlOp.getName().equals(wsdlOpName)) break; 1445 } 1446 if (wsdlOp == null) 1447 throw new UnsupportedOperationException (Messages.getMessage("noOperation01", opName)); 1448 1449 opName = wsdlOp.getName(); 1451 1452 List list = port.getExtensibilityElements(); 1455 String opStyle = null; 1456 BindingOperation bop = binding.getBindingOperation(opName, 1457 null, null); 1458 if (bop == null) 1459 throw new JAXRPCException (Messages.getMessage("noOperation02", 1460 opName)); 1461 list = bop.getExtensibilityElements(); 1462 for (int i = 0; list != null && i < list.size(); i++) 1463 { 1464 Object obj = list.get(i); 1465 if (obj instanceof SOAPOperation) 1466 { 1467 SOAPOperation sop = (SOAPOperation)obj; 1468 opStyle = ((SOAPOperation)obj).getStyle(); 1469 String action = sop.getSoapActionURI(); 1470 if (action != null) 1471 { 1472 setUseSOAPAction(true); 1473 setSOAPActionURI(action); 1474 } 1475 else 1476 { 1477 setUseSOAPAction(false); 1478 setSOAPActionURI(null); 1479 } 1480 break; 1481 } 1482 } 1483 1484 BindingInput bIn = bop.getBindingInput(); 1487 if (bIn != null) 1488 { 1489 list = bIn.getExtensibilityElements(); 1490 for (int i = 0; list != null && i < list.size(); i++) 1491 { 1492 Object obj = list.get(i); 1493 if (obj instanceof 1494 javax.wsdl.extensions.mime.MIMEMultipartRelated) 1495 { 1496 javax.wsdl.extensions.mime.MIMEMultipartRelated mpr = 1497 (javax.wsdl.extensions.mime.MIMEMultipartRelated)obj; 1498 Object part = null; 1499 List l = mpr.getMIMEParts(); 1500 for (int j = 0; l != null && j < l.size() && part == null; j++) 1501 { 1502 javax.wsdl.extensions.mime.MIMEPart mp 1503 = (javax.wsdl.extensions.mime.MIMEPart)l.get(j); 1504 List ll = mp.getExtensibilityElements(); 1505 for (int k = 0; ll != null && k < ll.size() && part == null; 1506 k++) 1507 { 1508 part = ll.get(k); 1509 if (!(part instanceof SOAPBody)) part = null; 1510 } 1511 } 1512 if (null != part) obj = part; 1513 } 1514 1515 if (obj instanceof SOAPBody) 1516 { 1517 SOAPBody sBody = (SOAPBody)obj; 1518 list = sBody.getEncodingStyles(); 1519 if (list != null && list.size() > 0) 1520 this.setEncodingStyle((String )list.get(0)); 1521 String ns = sBody.getNamespaceURI(); 1522 if (ns != null && !ns.equals("")) 1523 setOperationName(new QName (ns, opName)); 1524 break; 1525 } 1526 } 1527 } 1528 1529 Service service = this.getService(); 1530 SymbolTable symbolTable = service.getWSDLParser().getSymbolTable(); 1531 BindingEntry bEntry = symbolTable.getBindingEntry(binding.getQName()); 1532 Parameters parameters = bEntry.getParameters(bop.getOperation()); 1533 1534 for (int j = 0; j < parameters.list.size(); ++j) 1536 { 1537 Parameter p = (Parameter)parameters.list.get(j); 1538 QName paramType = Utils.getXSIType(p); 1540 1541 boolean isInHeader = p.isInHeader(); 1542 boolean isOutHeader = p.isOutHeader(); 1543 this.addParameter(p.getQName(), paramType, modes[p.getMode()], isInHeader, isOutHeader); 1544 } 1545 1546 Map faultMap = bEntry.getFaults(); 1547 ArrayList faults = (ArrayList )faultMap.get(bop); 1549 1550 if (faults == null) 1552 { 1553 return; 1554 } 1555 for (Iterator faultIt = faults.iterator(); faultIt.hasNext();) 1557 { 1558 FaultInfo info = (FaultInfo)faultIt.next(); 1559 QName qname = info.getQName(); 1560 1561 if (qname == null) 1563 { 1564 continue; 1565 } 1566 try 1567 { 1568 Class clazz = getTypeMapping().getClassForQName(info.getXMLType()); 1569 addFault(qname, clazz, info.getXMLType(), true); 1570 } 1571 catch (Exception e) 1572 { 1573 } 1575 } 1576 1577 if (parameters.returnParam != null) 1579 { 1580 QName returnType = Utils.getXSIType(parameters.returnParam); 1582 QName returnQName = parameters.returnParam.getQName(); 1583 1584 String javaType = null; 1586 if (parameters.returnParam.getMIMEInfo() != null) 1587 { 1588 javaType = "javax.activation.DataHandler"; 1589 } 1590 else 1591 { 1592 javaType = parameters.returnParam.getType().getName(); 1593 } 1594 if (javaType == null) 1595 { 1596 javaType = ""; 1597 } 1598 else 1599 { 1600 javaType = javaType + ".class"; 1601 } 1602 this.setReturnType(returnType); 1603 try 1604 { 1605 this.setReturnClass(ClassUtils.forName(javaType)); 1606 } 1607 catch (Exception e) 1608 { 1609 } 1611 this.setReturnQName(returnQName); 1612 } 1613 else 1614 { 1615 this.setReturnType(XMLType.AXIS_VOID); 1616 } 1617 1618 boolean hasMIME = Utils.hasMIME(bEntry, bop); 1619 Use use = bEntry.getInputBodyType(bop.getOperation()); 1620 Style style = Style.getStyle(opStyle, bEntry.getBindingStyle()); 1621 if (use == Use.LITERAL) 1622 { 1623 setEncodingStyle(null); 1625 setProperty(Call.SEND_TYPE_ATTR, Boolean.FALSE); 1627 } 1628 if (hasMIME || use == Use.LITERAL) 1629 { 1630 setProperty(AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE); 1636 } 1637 1638 if (style == Style.DOCUMENT && symbolTable.isWrapped()) 1639 { 1640 style = Style.WRAPPED; 1641 } 1642 1643 if (style == Style.WRAPPED) 1645 { 1646 Map partsMap = bop.getOperation().getInput().getMessage().getParts(); 1650 Part p = (Part)partsMap.values().iterator().next(); 1651 QName q = p.getElementName(); 1652 setOperationName(q); 1653 } 1654 else 1655 { 1656 QName elementQName = 1657 Utils.getOperationQName(bop, bEntry, symbolTable); 1658 if (elementQName != null) 1659 { 1660 setOperationName(elementQName); 1661 } 1662 } 1663 1664 parmAndRetReq = false; 1667 return; 1668 1669 } 1670 1671 private void addParameter(QName paramName, QName xmlType, 1672 ParameterMode parameterMode, boolean inHeader, boolean outHeader) 1673 { 1674 Class javaType = null; 1675 TypeMapping tm = getTypeMapping(); 1676 if (tm != null) 1677 { 1678 javaType = tm.getClassForQName(xmlType); 1679 } 1680 1681 if (parameterMode != ParameterMode.IN && javaType != null && !Holder .class.isAssignableFrom(javaType)) 1682 javaType = JavaUtils.getHolderType(javaType); 1683 1684 addParameter(paramName, xmlType, javaType, parameterMode, inHeader, outHeader); 1685 } 1686 1687 1692 protected String getWsdlOpName(String javaOpName) 1693 { 1694 return javaOpName; 1695 } 1696 1697 1710 public void setOperation(QName portName, String opName) 1711 { 1712 if (service == null) 1713 throw new JAXRPCException (Messages.getMessage("noService04")); 1714 1715 this.setPortName(portName); 1717 this.setOperationName(opName); 1718 this.setEncodingStyle(null); 1719 this.setReturnType(null); 1720 this.removeAllParameters(); 1721 1722 javax.wsdl.Service wsdlService = service.getWSDLService(); 1723 if (wsdlService == null) 1725 return; 1726 1727 this.setTargetEndpointAddress((URL )null); 1729 1730 Port port = wsdlService.getPort(portName.getLocalPart()); 1731 if (port == null) 1732 throw new JAXRPCException (Messages.getMessage("noPort00", "" + 1733 portName)); 1734 1735 Binding binding = port.getBinding(); 1736 PortType portType = binding.getPortType(); 1737 if (portType == null) 1738 throw new JAXRPCException (Messages.getMessage("noPortType00", "" + 1739 portName)); 1740 1741 List list = port.getExtensibilityElements(); 1744 for (int i = 0; list != null && i < list.size(); i++) 1745 { 1746 Object obj = list.get(i); 1747 if (obj instanceof SOAPAddress) 1748 { 1749 try 1750 { 1751 SOAPAddress addr = (SOAPAddress)obj; 1752 URL url = new URL (addr.getLocationURI()); 1753 this.setTargetEndpointAddress(url); 1754 } 1755 catch (Exception exp) 1756 { 1757 throw new JAXRPCException (Messages.getMessage("cantSetURI00", "" + exp)); 1758 } 1759 } 1760 } 1761 1762 BindingOperation bop = binding.getBindingOperation(opName, 1765 null, null); 1766 if (bop == null) 1767 throw new JAXRPCException (Messages.getMessage("noOperation02", 1768 opName)); 1769 list = bop.getExtensibilityElements(); 1770 for (int i = 0; list != null && i < list.size(); i++) 1771 { 1772 Object obj = list.get(i); 1773 if (obj instanceof SOAPOperation) 1774 { 1775 SOAPOperation sop = (SOAPOperation)obj; 1776 String action = sop.getSoapActionURI(); 1777 if (action != null) 1778 { 1779 setUseSOAPAction(true); 1780 setSOAPActionURI(action); 1781 } 1782 else 1783 { 1784 setUseSOAPAction(false); 1785 setSOAPActionURI(null); 1786 } 1787 break; 1788 } 1789 } 1790 setOperation(opName); 1791 } 1792 1793 1799 public QName getPortName() 1800 { 1801 return (portName); 1802 } 1804 1811 public void setPortName(QName portName) 1812 { 1813 this.portName = portName; 1814 } 1816 1824 public QName getPortTypeName() 1825 { 1826 return portName == null ? new QName ("") : portName; 1827 } 1828 1829 1838 public void setPortTypeName(QName portType) 1839 { 1840 setPortName(portType); 1841 } 1842 1843 1850 public void setSOAPVersion(SOAPConstants soapConstants) 1851 { 1852 getMessageContext().setSOAPConstants(soapConstants); 1853 } 1854 1855 1867 public Object invoke(QName operationName, Object [] params) 1868 throws java.rmi.RemoteException 1869 { 1870 QName origOpName = this.operationName; 1871 this.operationName = operationName; 1872 try 1873 { 1874 return this.invoke(params); 1875 } 1876 catch (AxisFault af) 1877 { 1878 this.operationName = origOpName; 1879 if (af.detail != null && af.detail instanceof RemoteException ) 1880 { 1881 throw ((RemoteException )af.detail); 1882 } 1883 throw af; 1884 } 1885 catch (java.rmi.RemoteException re) 1886 { 1887 this.operationName = origOpName; 1888 throw re; 1889 } 1890 catch (RuntimeException re) 1891 { 1892 this.operationName = origOpName; 1893 throw re; 1894 } 1895 catch (Error e) 1896 { 1897 this.operationName = origOpName; 1898 throw e; 1899 } 1900 } 1902 1915 public Object invoke(Object [] params) throws java.rmi.RemoteException 1916 { 1917 return invokeInternal(params); 1918 } 1919 1920 private Object invokeInternal(Object [] params) throws java.rmi.RemoteException 1921 { 1922 long t0 = 0, t1 = 0; 1923 if (tlog.isDebugEnabled()) 1924 { 1925 t0 = System.currentTimeMillis(); 1926 } 1927 1928 1929 1930 1931 SOAPEnvelopeAxisImpl env = null; 1932 1933 boolean isSOAPBodyElement = (params != null && params.length == 1 && params[0] instanceof SOAPBodyElementAxisImpl); 1934 if (isSOAPBodyElement) 1935 { 1936 1937 1938 isMsg = true; 1939 1940 SOAPBodyElementAxisImpl sbElement = (SOAPBodyElementAxisImpl)params[0]; 1941 if (sbElement.getParentElement() != null && sbElement.getParentElement().getParentElement() != null) 1942 { 1943 env = (SOAPEnvelopeAxisImpl)sbElement.getParentElement().getParentElement(); 1944 } 1945 else 1946 { 1947 env = new SOAPEnvelopeAxisImpl(getMessageContext().getSOAPConstants(), getMessageContext().getSchemaVersion()); 1948 env.addBodyElement(sbElement); 1949 } 1950 1951 Message msg = new Message(env); 1952 setRequestMessage(msg); 1953 1954 invoke(); 1955 1956 msg = getMessageContext().getResponseMessage(); 1957 if (msg == null) 1958 { 1959 if (FAULT_ON_NO_RESPONSE) 1960 { 1961 throw new AxisFault(Messages.getMessage("nullResponse00")); 1962 } 1963 else 1964 { 1965 return null; 1966 } 1967 } 1968 1969 env = msg.getSOAPEnvelope(); 1970 Vector bodyElements = env.getBodyElements(); 1971 return (bodyElements.size() > 0 ? bodyElements.get(0) : null); 1972 } 1973 1974 1975 if (operationName == null) 1976 throw new AxisFault(Messages.getMessage("noOperation00")); 1977 try 1978 { 1979 Object res = this.invoke(operationName.getNamespaceURI(), 1980 operationName.getLocalPart(), params); 1981 if (tlog.isDebugEnabled()) 1982 { 1983 t1 = System.currentTimeMillis(); 1984 tlog.debug("axis.Call.invoke: " + (t1 - t0) + " " + operationName); 1985 } 1986 return res; 1987 } 1988 catch (AxisFault af) 1989 { 1990 if (af.detail != null && af.detail instanceof RemoteException ) 1991 { 1992 throw ((RemoteException )af.detail); 1993 } 1994 throw af; 1995 } 1996 catch (RuntimeException ex) 1997 { 1998 throw ex; 1999 } 2000 catch (Exception exp) 2001 { 2002 log.debug(Messages.getMessage("toAxisFault00"), exp); 2003 throw new AxisFault(Messages.getMessage("errorInvoking00", "\n" + exp)); 2004 } 2005 } 2006 2007 2018 public void invokeOneWay(Object [] params) 2019 { 2020 try 2021 { 2022 invokeOneWay = true; 2023 invokeInternal(params); 2024 } 2025 catch (Exception exp) 2026 { 2027 throw new JAXRPCException (exp.toString()); 2028 } 2029 finally 2030 { 2031 invokeOneWay = false; 2032 } 2033 } 2034 2035 2036 2037 2038 2039 2047 public SOAPEnvelopeAxisImpl invoke(SOAPEnvelopeAxisImpl env, MimeHeaders headers) 2048 throws java.rmi.RemoteException 2049 { 2050 try 2051 { 2052 Message msg = null; 2053 2054 msg = new Message(env, false, headers); 2055 setRequestMessage(msg); 2056 invoke(); 2057 msg = getMessageContext().getResponseMessage(); 2058 if (msg == null) 2059 { 2060 if (FAULT_ON_NO_RESPONSE) 2061 { 2062 throw new AxisFault(Messages.getMessage("nullResponse00")); 2063 } 2064 else 2065 { 2066 return null; 2067 } 2068 } 2069 return (msg.getSOAPEnvelope()); 2070 } 2071 catch (AxisFault fault) 2072 { 2073 throw (AxisFault)fault; 2074 } 2075 catch (Exception ex) 2076 { 2077 log.error(Messages.getMessage("toAxisFault00"), ex); 2078 throw AxisFault.makeFault(ex); 2079 } 2080 } 2081 2082 2083 2093 public static void setTransportForProtocol(String protocol, 2094 Class transportClass) 2095 { 2096 if (Transport.class.isAssignableFrom(transportClass)) 2097 transports.put(protocol, transportClass); 2098 else 2099 throw new InternalException(transportClass.toString()); 2100 } 2101 2102 2111 public static synchronized void initialize() 2112 { 2113 addTransportPackage("transport"); 2114 2115 setTransportForProtocol("java", JavaTransport.class); 2116 setTransportForProtocol("local", LocalTransport.class); 2117 setTransportForProtocol("http", HTTPTransport.class); 2118 setTransportForProtocol("https", HTTPTransport.class); 2119 } 2120 2121 2125 private static ArrayList transportPackages = null; 2126 2127 2141 public static synchronized void addTransportPackage(String packageName) 2142 { 2143 if (transportPackages == null) 2144 { 2145 transportPackages = new ArrayList (); 2146 String currentPackages = 2147 AxisProperties.getProperty(TRANSPORT_PROPERTY); 2148 if (currentPackages != null) 2149 { 2150 StringTokenizer tok = new StringTokenizer (currentPackages, 2151 "|"); 2152 while (tok.hasMoreTokens()) 2153 { 2154 transportPackages.add(tok.nextToken()); 2155 } 2156 } 2157 } 2158 2159 if (transportPackages.contains(packageName)) 2160 return; 2161 2162 transportPackages.add(packageName); 2163 2164 StringBuffer currentPackages = new StringBuffer (); 2165 for (Iterator i = transportPackages.iterator(); i.hasNext();) 2166 { 2167 String thisPackage = (String )i.next(); 2168 currentPackages.append(thisPackage); 2169 currentPackages.append('|'); 2170 } 2171 2172 System.setProperty(TRANSPORT_PROPERTY, currentPackages.toString()); 2173 } 2174 2175 2183 private Object [] getParamList(Object [] params) 2184 { 2185 int numParams = 0; 2186 2187 if (log.isDebugEnabled()) 2190 { 2191 log.debug("operation=" + operation); 2192 } 2193 if (operation == null || operation.getNumParams() == 0) 2194 return (params); 2195 2196 numParams = operation.getNumInParams(); 2200 2201 if (operation.getStyle() == Style.DOCUMENT && params == null && numParams == 1) 2204 { 2205 ParameterDesc param = operation.getParameter(0); 2206 Class javaType = param.getJavaType(); 2207 if (javaType != null) 2208 { 2209 try 2210 { 2211 Object obj = javaType.newInstance(); 2212 params = new Object []{obj}; 2213 } 2214 catch (Exception e) 2215 { 2216 log.warn("Cannot instanciate: " + javaType); 2217 } 2218 } 2219 } 2220 2221 if (params == null || numParams != params.length) 2222 throw new JAXRPCException ("Parameter count mismatch: " + numParams); 2223 2224 log.debug("getParamList number of params: " + params.length); 2225 2226 Vector result = new Vector (); 2229 int j = 0; 2230 ArrayList parameters = operation.getParameters(); 2231 2232 for (int i = 0; i < parameters.size(); i++) 2233 { 2234 ParameterDesc param = (ParameterDesc)parameters.get(i); 2235 if (param.getMode() != ParameterDesc.OUT) 2236 { 2237 QName paramQName = param.getQName(); 2238 2239 RPCParam rpcParam = null; 2241 Object p = params[j++]; 2242 if (p instanceof RPCParam) 2243 { 2244 rpcParam = (RPCParam)p; 2245 } 2246 else 2247 { 2248 rpcParam = new RPCParam(paramQName.getNamespaceURI(), 2249 paramQName.getLocalPart(), 2250 p); 2251 } 2252 rpcParam.setParamDesc(param); 2256 2257 if (param.isInHeader()) 2260 { 2261 addHeader(new RPCHeaderParam(rpcParam)); 2262 } 2263 else 2264 { 2265 result.add(rpcParam); 2266 } 2267 } 2268 } 2269 return (result.toArray()); 2270 } 2271 2272 2280 public void setTransport(Transport trans) 2281 { 2282 transport = trans; 2283 if (log.isDebugEnabled()) 2284 log.debug(Messages.getMessage("transport00", "" + transport)); 2285 } 2286 2287 public Object getTransportOption(String name) 2288 { 2289 return getMessageContext().getTransportOption(name); 2290 } 2291 2292 public void setTransportOption(String name, Object value) 2293 { 2294 getMessageContext().setTransportOption(name, value); 2295 } 2296 2297 2306 public Transport getTransportForProtocol(String protocol) 2307 { 2308 Class transportClass = (Class )transports.get(protocol); 2309 Transport ret = null; 2310 if (transportClass != null) 2311 { 2312 try 2313 { 2314 ret = (Transport)transportClass.newInstance(); 2315 } 2316 catch (InstantiationException e) 2317 { 2318 } 2319 catch (IllegalAccessException e) 2320 { 2321 } 2322 } 2323 return ret; 2324 } 2325 2326 2335 public void setRequestMessage(Message msg) 2336 { 2337 addAttachmentParts(msg); 2338 getMessageContext().setRequestMessage(msg); 2339 } 2340 2341 2343 protected void addAttachmentParts(Message msg) 2344 { 2345 String attachformat = (String )getProperty(ATTACHMENT_ENCAPSULATION_FORMAT); 2346 if (attachformat != null) 2347 { 2348 Attachments attachments = msg.getAttachmentsImpl(); 2349 if (attachments != null) 2350 { 2351 if (attachformat.equals(ATTACHMENT_ENCAPSULATION_FORMAT_MIME)) 2352 attachments.setSendType(Attachments.SEND_TYPE_MIME); 2353 else if (attachformat.equals(ATTACHMENT_ENCAPSULATION_FORMAT_DIME)) 2354 attachments.setSendType(Attachments.SEND_TYPE_DIME); 2355 } 2356 } 2357 2358 if (attachmentParts.isEmpty() == false) 2359 { 2360 try 2361 { 2362 Attachments attachments = msg.getAttachmentsImpl(); 2363 if (attachments != null) 2364 attachments.setAttachmentParts(attachmentParts); 2365 } 2366 catch (AxisFault ex) 2367 { 2368 log.info(Messages.getMessage("axisFault00"), ex); 2369 throw new RuntimeException (ex.getMessage()); 2370 } 2371 } 2372 attachmentParts.clear(); 2373 } 2374 2375 2384 public Message getResponseMessage() 2385 { 2386 return getMessageContext().getResponseMessage(); 2387 } 2388 2389 2396 public MessageContext getMessageContext() 2397 { 2398 if (msgContext == null) 2399 msgContext = new MessageContext(service.getEngine()); 2400 2401 return msgContext; 2402 } 2403 2404 2412 public void addHeader(SOAPHeaderElementAxisImpl header) 2413 { 2414 if (headers == null) 2415 { 2416 headers = new Vector (); 2417 } 2418 headers.add(header); 2419 } 2420 2421 2426 public void clearHeaders() 2427 { 2428 headers = null; 2429 } 2430 2431 public TypeMapping getTypeMapping() 2432 { 2433 TypeMappingRegistry tmr = getMessageContext().getTypeMappingRegistry(); 2435 2436 return tmr.getOrMakeTypeMapping(getEncodingStyle()); 2438 } 2439 2440 2449 public void registerTypeMapping(Class javaType, QName xmlType, 2450 SerializerFactory sf, 2451 DeserializerFactory df) 2452 { 2453 registerTypeMapping(javaType, xmlType, sf, df, true); 2454 } 2455 2456 2466 public void registerTypeMapping(Class javaType, QName xmlType, 2467 SerializerFactory sf, 2468 DeserializerFactory df, 2469 boolean force) 2470 { 2471 TypeMapping tm = getTypeMapping(); 2472 if (!force && tm.isRegistered(javaType, xmlType)) 2473 return; 2474 2475 tm.register(javaType, xmlType, sf, df); 2477 } 2478 2479 public void registerTypeMapping(Class javaType, QName xmlType, 2480 Class sfClass, Class dfClass) 2481 { 2482 registerTypeMapping(javaType, xmlType, sfClass, dfClass, true); 2483 } 2484 2485 public void registerTypeMapping(Class javaType, 2486 QName xmlType, 2487 Class sfClass, 2488 Class dfClass, 2489 boolean force) 2490 { 2491 SerializerFactory sf = 2493 BaseSerializerFactory.createFactory(sfClass, javaType, xmlType); 2494 DeserializerFactory df = 2495 BaseDeserializerFactory.createFactory(dfClass, 2496 javaType, 2497 xmlType); 2498 if (sf != null || df != null) 2499 { 2500 registerTypeMapping(javaType, xmlType, sf, df, force); 2501 } 2502 } 2503 2504 2507 2508 2526 public Object invoke(String namespace, String method, Object [] args) 2527 throws AxisFault 2528 { 2529 2530 if (log.isDebugEnabled()) 2531 { 2532 log.debug("Enter: Call::invoke(ns, meth, args)"); 2533 } 2534 2535 2540 if (getReturnType() != null && args != null && args.length != 0 2541 && operation.getNumParams() == 0) 2542 { 2543 throw new AxisFault(Messages.getMessage("mustSpecifyParms")); 2544 } 2545 2546 RPCElement body = new RPCElement(namespace, method, getParamList(args)); 2547 2548 Object ret = invoke(body); 2549 2550 if (log.isDebugEnabled()) 2551 { 2552 log.debug("Exit: Call::invoke(ns, meth, args)"); 2553 } 2554 2555 return ret; 2556 } 2557 2558 2573 public Object invoke(String method, Object [] args) throws AxisFault 2574 { 2575 return invoke("", method, args); 2576 } 2577 2578 2588 public Object invoke(RPCElement body) throws AxisFault 2589 { 2590 2591 if (log.isDebugEnabled()) 2592 { 2593 log.debug("Enter: Call::invoke(RPCElement)"); 2594 } 2595 2596 2601 if (!invokeOneWay && operation != null && 2602 operation.getNumParams() > 0 && getReturnType() == null) 2603 { 2604 log.error(Messages.getMessage("mustSpecifyReturnType")); 2608 } 2609 2610 SOAPEnvelopeAxisImpl reqEnv = 2611 new SOAPEnvelopeAxisImpl(getMessageContext().getSOAPConstants(), 2612 getMessageContext().getSchemaVersion()); 2613 SOAPEnvelopeAxisImpl resEnv = null; 2614 Message reqMsg = new Message(reqEnv); 2615 Message resMsg = null; 2616 Vector resArgs = null; 2617 Object result = null; 2618 2619 try 2620 { 2621 String encodingStyle = getEncodingStyle(); 2625 String bodyEncStyle = reqEnv.getBody().getEncodingStyle(); 2626 if (bodyEncStyle.equals(encodingStyle) == false) 2627 { 2628 if (bodyEncStyle.equals("")) 2629 reqEnv.getBody().setEncodingStyle(encodingStyle); 2630 else 2631 log.warn("Mixed encoding styles are not supported: " + bodyEncStyle + "!=" + encodingStyle); 2632 } 2633 2634 setRequestMessage(reqMsg); 2635 2636 reqEnv.addBodyElement(body); 2637 reqEnv.setMessageType(Message.REQUEST); 2638 2639 invoke(); 2640 } 2641 catch (Exception e) 2642 { 2643 log.debug(Messages.getMessage("toAxisFault00"), e); 2644 throw AxisFault.makeFault(e); 2645 } 2646 2647 resMsg = getMessageContext().getResponseMessage(); 2648 2649 if (resMsg == null) 2650 { 2651 if (FAULT_ON_NO_RESPONSE) 2652 { 2653 throw new AxisFault(Messages.getMessage("nullResponse00")); 2654 } 2655 else 2656 { 2657 return null; 2658 } 2659 } 2660 2661 resEnv = resMsg.getSOAPEnvelope(); 2662 SOAPBodyElementAxisImpl bodyEl = resEnv.getFirstBody(); 2663 if (bodyEl == null) 2664 { 2665 return null; 2666 } 2667 2668 if (bodyEl instanceof RPCElement) 2669 { 2670 try 2671 { 2672 resArgs = ((RPCElement)bodyEl).getParams(); 2673 } 2674 catch (Exception e) 2675 { 2676 log.error(Messages.getMessage("exception00"), e); 2677 throw AxisFault.makeFault(e); 2678 } 2679 2680 if (resArgs != null && resArgs.size() > 0) 2681 { 2682 2683 int outParamStart = 0; 2686 2687 2706 2710 boolean findReturnParam = false; 2711 QName returnParamQName = null; 2712 if (operation != null) 2713 returnParamQName = operation.getReturnQName(); 2714 2715 if (!XMLType.AXIS_VOID.equals(getReturnType())) 2716 { 2717 if (returnParamQName == null) 2718 { 2719 RPCParam param = (RPCParam)resArgs.get(0); 2721 result = param.getValue(); 2722 outParamStart = 1; 2723 } 2724 else 2725 { 2726 findReturnParam = true; 2729 } 2730 } 2731 2732 for (int i = outParamStart; i < resArgs.size(); i++) 2740 { 2741 RPCParam param = (RPCParam)resArgs.get(i); 2742 2743 Class javaType = getJavaTypeForQName(param.getQName()); 2744 Object value = param.getValue(); 2745 2746 if (javaType != null && value != null && 2748 !javaType.isAssignableFrom(value.getClass())) 2749 { 2750 value = JavaUtils.convert(value, javaType); 2751 } 2752 2753 if (javaType == null && value != null) 2755 { 2756 2757 if (value.getClass().isArray()) 2759 { 2760 if (!value.getClass().getComponentType().isPrimitive()) 2761 { 2762 int len = java.lang.reflect.Array.getLength(value); 2763 Class type = null; 2764 for (int x = 0; x < len; x++) 2765 { 2766 Object o = java.lang.reflect.Array.get(value, x); 2767 if (o != null) 2768 { 2769 if (type == null) 2770 { 2771 type = o.getClass(); 2773 } 2774 else 2775 { 2776 if (!type.getName().equals(o.getClass().getName())) 2777 { 2778 type = null; 2779 break; 2780 } 2781 } 2782 } 2783 } 2784 if (type != null) 2786 { 2787 Object convertedArray = java.lang.reflect.Array.newInstance(type, len); 2788 System.arraycopy(value, 0, convertedArray, 0, len); 2789 value = convertedArray; 2790 } 2791 } 2792 } 2793 } 2794 2795 if (findReturnParam && returnParamQName.equals(param.getQName())) 2798 { 2799 result = value; 2801 findReturnParam = false; 2802 } 2803 else 2804 { 2805 outParams.put(param.getQName(), value); 2806 outParamsList.add(value); 2807 } 2808 } 2809 2810 if (findReturnParam) 2818 { 2819 Iterator it = outParams.keySet().iterator(); 2820 while (it.hasNext() && findReturnParam) 2821 { 2822 QName qname = (QName )it.next(); 2823 ParameterDesc paramDesc = operation.getOutputParamByQName(qname); 2824 if (paramDesc == null) 2825 { 2826 findReturnParam = false; 2828 result = outParams.remove(qname); 2829 } 2830 } 2831 } 2832 2833 if (findReturnParam) 2836 { 2837 String returnParamName = returnParamQName.toString(); 2838 throw new AxisFault(Messages.getMessage("noReturnParam", 2839 returnParamName)); 2840 } 2841 } 2842 } 2843 else 2844 { 2845 try 2847 { 2848 result = bodyEl.getValueAsType(getReturnType()); 2849 } 2850 catch (Exception e) 2851 { 2852 result = bodyEl; 2854 } 2855 2856 } 2857 2858 if (log.isDebugEnabled()) 2859 { 2860 log.debug("Exit: Call::invoke(RPCElement)"); 2861 } 2862 2863 if (operation != null && operation.getReturnClass() != null) 2865 { 2866 result = JavaUtils.convert(result, operation.getReturnClass()); 2867 } 2868 2869 return (result); 2870 } 2871 2872 2875 private Class getJavaTypeForQName(QName name) 2876 { 2877 2878 if (operation == null) return null; 2879 2880 Class javaType = null; 2881 2882 ParameterDesc param = operation.getOutputParamByQName(name); 2883 if (param != null) 2884 { 2885 javaType = param.getJavaType(); 2886 log.debug("getJavaTypeForQName: " + name + " -> " + javaType); 2887 } 2888 else 2889 { 2890 log.debug("No output parameter for name: " + name); 2891 } 2892 2893 return javaType; 2894 } 2895 2896 2901 public void setOption(String name, Object value) 2902 { 2903 service.getEngine().setOption(name, value); 2904 } 2905 2906 2914 public void invoke() throws AxisFault 2915 { 2916 if (log.isDebugEnabled()) 2917 { 2918 log.debug("Enter: Call::invoke()"); 2919 } 2920 2921 outParams = new HashMap (); 2923 outParamsList = new ArrayList (); 2924 2925 Message reqMsg = null; 2926 SOAPEnvelopeAxisImpl reqEnv = null; 2927 2928 getMessageContext().reset(); 2929 getMessageContext().setResponseMessage(null); 2930 getMessageContext().setProperty(MessageContext.CALL, this); 2931 getMessageContext().setProperty(WSDL_SERVICE, service); 2932 getMessageContext().setProperty(WSDL_PORT_NAME, getPortName()); 2933 if (isMsg) 2934 getMessageContext().setProperty(MessageContext.IS_MSG, "true"); 2935 2936 if (username != null) 2937 { 2938 getMessageContext().setUsername(username); 2939 } 2940 if (password != null) 2941 { 2942 getMessageContext().setPassword(password); 2943 } 2944 getMessageContext().setMaintainSession(maintainSession); 2945 2946 if (operation != null) 2947 { 2948 getMessageContext().setOperation(operation); 2949 2950 operation.setStyle(getOperationStyle()); 2951 operation.setUse(getOperationUse()); 2952 } 2953 2954 if (useSOAPAction) 2955 { 2956 getMessageContext().setUseSOAPAction(true); 2957 } 2958 if (SOAPActionURI != null) 2959 { 2960 getMessageContext().setSOAPActionURI(SOAPActionURI); 2961 } 2962 if (timeout != null) 2963 { 2964 getMessageContext().setTimeout(timeout.intValue()); 2965 } 2966 2967 if (myService != null) 2969 { 2970 getMessageContext().setService(myService); 2972 } 2973 else 2974 { 2975 if (portName != null) 2976 { 2977 getMessageContext().setTargetService(portName.getLocalPart()); 2980 } 2981 else 2982 { 2983 reqMsg = getMessageContext().getRequestMessage(); 2985 2986 if (reqMsg != null) 2987 { 2988 reqEnv = reqMsg.getSOAPEnvelope(); 2989 2990 SOAPBodyElementAxisImpl body = reqEnv.getFirstBody(); 2991 2992 if (body != null) 2993 { 2994 if (body.getNamespaceURI() == null) 2995 { 2996 throw new AxisFault("Call.invoke", 2997 Messages.getMessage("cantInvoke00", body.getName()), 2998 null, null); 2999 } 3000 else 3001 { 3002 getMessageContext().setTargetService(body.getNamespaceURI()); 3003 } 3004 } 3005 } 3006 } 3007 3008 SOAPService svc = getMessageContext().getService(); 3009 if (svc != null) 3010 { 3011 svc.setPropertyParent(myProperties); 3012 } 3013 else 3014 { 3015 getMessageContext().setPropertyParent(myProperties); 3016 } 3017 } 3018 if (log.isDebugEnabled()) 3019 { 3020 log.debug(Messages.getMessage("targetService", 3021 getMessageContext().getTargetService())); 3022 } 3023 3024 Message requestMessage = getMessageContext().getRequestMessage(); 3025 if (requestMessage != null) 3026 { 3027 reqEnv = requestMessage.getSOAPEnvelope(); 3028 3029 for (int i = 0; headers != null && i < headers.size(); i++) 3031 { 3032 SOAPHeaderElementAxisImpl header = (SOAPHeaderElementAxisImpl)headers.get(i); 3033 reqEnv.addHeader(header); 3034 } 3035 } 3036 3037 if (transport != null) 3039 { 3040 transport.setupMessageContext(msgContext, this, service.getEngine()); 3041 } 3042 else 3043 { 3044 getMessageContext().setTransportName(transportName); 3045 } 3046 3047 if (!invokeOneWay) 3048 { 3049 invokeEngine(msgContext); 3050 } 3051 else 3052 { 3053 invokeEngineOneWay(msgContext); 3054 } 3055 3056 if (log.isDebugEnabled()) 3057 { 3058 log.debug("Exit: Call::invoke()"); 3059 } 3060 } 3061 3062 private void invokeEngine(MessageContext msgContext) throws AxisFault 3063 { 3064 service.getEngine().invoke(msgContext); 3065 3066 if (transport != null) 3067 transport.processReturnedMessageContext(msgContext); 3068 3069 Message resMsg = getMessageContext().getResponseMessage(); 3070 3071 if (resMsg == null) 3072 { 3073 if (FAULT_ON_NO_RESPONSE) 3074 { 3075 throw new AxisFault(Messages.getMessage("nullResponse00")); 3076 } 3077 else 3078 { 3079 return; 3080 } 3081 } 3082 3083 3085 resMsg.setMessageType(Message.RESPONSE); 3086 3087 SOAPEnvelopeAxisImpl resEnv = resMsg.getSOAPEnvelope(); 3088 3089 SOAPBodyElementAxisImpl respBody = resEnv.getFirstBody(); 3090 if (respBody instanceof SOAPFaultImpl) 3091 { 3092 if (operation == null || 3093 operation.getReturnClass() == null || 3094 operation.getReturnClass() != 3095 javax.xml.soap.SOAPMessage .class) 3096 throw ((SOAPFaultImpl)respBody).getFault(); 3097 } 3098 } 3099 3100 private void invokeEngineOneWay(final MessageContext msgContext) 3101 { 3102 Runnable runnable = new Runnable () 3103 { 3104 public void run() 3105 { 3106 try 3107 { 3108 service.getEngine().invoke(msgContext); 3109 } 3110 catch (AxisFault af) 3111 { 3112 log.debug(Messages.getMessage("exceptionPrinting"), af); 3113 } 3114 } 3115 }; 3116 Thread thread = new Thread (runnable); 3117 thread.start(); 3118 } 3119 3120 3129 public Map getOutputParams() 3130 { 3131 if (outParams != null) 3132 { 3133 return outParams; 3134 } 3135 else 3136 { 3137 throw new JAXRPCException ("Cannot get output parameters before invoke is called."); 3139 } 3140 } 3141 3142 3152 public List getOutputValues() 3153 { 3154 return outParamsList; 3155 } 3156 3157 3164 public Service getService() 3165 { 3166 return this.service; 3167 } 3168 3169 private SOAPService myService = null; 3170 3171 3174 public void setSOAPService(SOAPService service) 3175 { 3176 myService = service; 3177 if (service != null) 3178 { 3179 service.setPropertyParent(myProperties); 3183 service.setEngine(this.service.getAxisClient()); 3184 } 3185 } 3186 3187 3192 public void setClientHandlers(Handler reqHandler, Handler respHandler) 3193 { 3194 setSOAPService(new SOAPService(reqHandler, null, respHandler)); 3197 } 3198 3199 3206 public void addAttachmentPart(Object attachment) 3207 { 3208 attachmentParts.add(attachment); 3209 } 3210 3211 3216 public void addFault(QName qname, Class cls, 3217 QName xmlType, boolean isComplex) 3218 { 3219 if (operationSetManually) 3220 { 3221 throw new RuntimeException (Messages.getMessage("operationAlreadySet")); 3222 } 3223 3224 if (operation == null) 3225 operation = new OperationDesc(); 3226 3227 FaultDesc fault = new FaultDesc(); 3228 fault.setQName(qname); 3229 fault.setClassName(cls.getName()); 3230 fault.setXmlType(xmlType); 3231 fault.setComplex(isComplex); 3232 operation.addFault(fault); 3233 } 3234 3235 3242 public void setOperation(OperationDesc operation) 3243 { 3244 this.operation = operation; 3245 operationSetManually = true; 3246 } 3247 3248 public OperationDesc getOperation() 3249 { 3250 return operation; 3251 } 3252 3253 public void clearOperation() 3254 { 3255 operation = null; 3256 operationSetManually = false; 3257 } 3258} 3259 | Popular Tags |