1 16 17 package org.apache.axis.client ; 18 19 import org.apache.axis.AxisFault; 20 import org.apache.axis.AxisProperties; 21 import org.apache.axis.Constants; 22 import org.apache.axis.Handler; 23 import org.apache.axis.InternalException; 24 import org.apache.axis.Message; 25 import org.apache.axis.MessageContext; 26 import org.apache.axis.AxisEngine; 27 import org.apache.axis.SOAPPart; 28 import org.apache.axis.attachments.Attachments; 29 import org.apache.axis.components.logger.LogFactory; 30 import org.apache.axis.description.FaultDesc; 31 import org.apache.axis.description.OperationDesc; 32 import org.apache.axis.description.ParameterDesc; 33 import org.apache.axis.encoding.DeserializerFactory; 34 import org.apache.axis.encoding.SerializationContext; 35 import org.apache.axis.encoding.SerializerFactory; 36 import org.apache.axis.encoding.TypeMapping; 37 import org.apache.axis.encoding.TypeMappingRegistry; 38 import org.apache.axis.encoding.XMLType; 39 import org.apache.axis.encoding.ser.BaseDeserializerFactory; 40 import org.apache.axis.encoding.ser.BaseSerializerFactory; 41 import org.apache.axis.constants.Style; 42 import org.apache.axis.constants.Use; 43 import org.apache.axis.handlers.soap.SOAPService; 44 import org.apache.axis.message.RPCElement; 45 import org.apache.axis.message.RPCHeaderParam; 46 import org.apache.axis.message.RPCParam; 47 import org.apache.axis.message.SOAPBodyElement; 48 import org.apache.axis.message.SOAPEnvelope; 49 import org.apache.axis.message.SOAPFault; 50 import org.apache.axis.message.SOAPHeaderElement; 51 import org.apache.axis.soap.SOAPConstants; 52 import org.apache.axis.transport.http.HTTPTransport; 53 import org.apache.axis.utils.ClassUtils; 54 import org.apache.axis.utils.JavaUtils; 55 import org.apache.axis.utils.Messages; 56 import org.apache.axis.utils.LockableHashtable; 57 import org.apache.axis.wsdl.symbolTable.BindingEntry; 58 import org.apache.axis.wsdl.symbolTable.Parameter; 59 import org.apache.axis.wsdl.symbolTable.Parameters; 60 import org.apache.axis.wsdl.symbolTable.SymbolTable; 61 import org.apache.axis.wsdl.symbolTable.FaultInfo; 62 import org.apache.axis.wsdl.toJava.Utils; 63 import org.apache.commons.logging.Log; 64 65 import javax.wsdl.Binding; 66 import javax.wsdl.BindingInput; 67 import javax.wsdl.BindingOperation; 68 import javax.wsdl.Operation; 69 import javax.wsdl.extensions.mime.MIMEPart; 70 import javax.wsdl.extensions.mime.MIMEMultipartRelated; 71 import javax.wsdl.Part; 72 import javax.wsdl.Port; 73 import javax.wsdl.PortType; 74 import javax.wsdl.extensions.soap.SOAPAddress; 75 import javax.wsdl.extensions.soap.SOAPBody; 76 import javax.wsdl.extensions.soap.SOAPOperation; 77 import javax.xml.namespace.QName ; 78 import javax.xml.rpc.JAXRPCException ; 79 import javax.xml.rpc.ParameterMode ; 80 import javax.xml.soap.SOAPException ; 81 import javax.xml.soap.SOAPMessage ; 82 83 import java.io.StringWriter ; 84 import java.net.MalformedURLException ; 85 import java.net.URL ; 86 import java.util.ArrayList ; 87 import java.util.HashMap ; 88 import java.util.Hashtable ; 89 import java.util.Iterator ; 90 import java.util.List ; 91 import java.util.Map ; 92 import java.util.StringTokenizer ; 93 import java.util.Vector ; 94 import java.rmi.RemoteException ; 95 96 122 123 public class Call implements javax.xml.rpc.Call { 124 protected static Log log = 125 LogFactory.getLog(Call.class.getName()); 126 private static Log tlog = 127 LogFactory.getLog(Constants.TIME_LOG_CATEGORY); 128 129 protected static Log entLog = 133 LogFactory.getLog(Constants.ENTERPRISE_LOG_CATEGORY); 134 135 private boolean parmAndRetReq = true ; 136 private Service service = null ; 137 private QName portName = null; 138 private QName portTypeName = null; 139 private QName operationName = null ; 140 141 private MessageContext msgContext = null ; 142 143 private LockableHashtable myProperties = new LockableHashtable(); 147 private String username = null; 148 private String password = null; 149 private boolean maintainSession = false; 150 private boolean useSOAPAction = false; 151 private String SOAPActionURI = null; 152 private Integer timeout = null; 153 private boolean useStreaming = false; 154 155 156 private OperationDesc operation = null; 157 158 private boolean operationSetManually = false; 159 160 private boolean invokeOneWay = false; 162 private boolean isMsg = false; 163 164 private Transport transport = null ; 166 private String transportName = null ; 167 168 private HashMap outParams = null; 171 private ArrayList outParamsList = null; 173 174 private Vector myHeaders = null; 176 177 public static final String SEND_TYPE_ATTR = AxisEngine.PROP_SEND_XSI; 178 179 184 public static final String TRANSPORT_NAME = "transport_name" ; 185 186 191 public static final String CHARACTER_SET_ENCODING = SOAPMessage.CHARACTER_SET_ENCODING; 192 193 197 public static final String TRANSPORT_PROPERTY= "java.protocol.handler.pkgs"; 198 199 203 public static final String WSDL_SERVICE = "wsdl.service"; 204 205 209 public static final String WSDL_PORT_NAME = "wsdl.portName"; 210 211 214 public static final String JAXRPC_SERVICE = WSDL_SERVICE; 215 216 219 public static final String JAXRPC_PORTTYPE_NAME = WSDL_PORT_NAME; 220 221 226 public static final String FAULT_ON_NO_RESPONSE = "call.FaultOnNoResponse"; 227 228 232 public static final String CHECK_MUST_UNDERSTAND = "call.CheckMustUnderstand"; 233 234 241 public static final String ATTACHMENT_ENCAPSULATION_FORMAT= 242 "attachment_encapsulation_format"; 243 246 public static final String ATTACHMENT_ENCAPSULATION_FORMAT_MIME= 247 "axis.attachment.style.mime"; 248 251 public static final String ATTACHMENT_ENCAPSULATION_FORMAT_DIME= 252 "axis.attachment.style.dime"; 253 254 258 public static final String CONNECTION_TIMEOUT_PROPERTY = 259 "axis.connection.timeout"; 260 261 266 public static final String STREAMING_PROPERTY = 267 "axis.streaming"; 268 269 273 protected static final String ONE_WAY = 274 "axis.one.way"; 275 276 279 private static Hashtable transports = new Hashtable(); 280 281 static ParameterMode [] modes = new ParameterMode [] { null, 282 ParameterMode.IN, 283 ParameterMode.OUT, 284 ParameterMode.INOUT }; 285 286 287 private boolean encodingStyleExplicitlySet = false; 288 289 private boolean useExplicitlySet = false; 290 291 294 private SOAPService myService = null; 295 296 299 protected java.util.Vector attachmentParts = new java.util.Vector (); 300 301 302 private boolean isNeverInvoked = true; 303 304 static { 305 initialize(); 306 } 307 308 309 310 311 312 318 public Call(Service service) { 319 this.service = service ; 320 AxisEngine engine = service.getEngine(); 321 msgContext = new MessageContext( engine ); 322 myProperties.setParent(engine.getOptions()); 323 maintainSession = service.getMaintainSession(); 324 } 325 326 337 public Call(String url) throws MalformedURLException { 338 this(new Service()); 339 setTargetEndpointAddress(new URL (url)); 340 } 341 342 347 public Call(URL url) { 348 this(new Service()); 349 setTargetEndpointAddress(url); 350 } 351 352 357 390 public void setProperty(String name, Object value) { 391 if (name == null || value == null) { 392 throw new JAXRPCException ( 393 Messages.getMessage(name == null ? 394 "badProp03" : "badProp04")); 395 } 396 else if (name.equals(USERNAME_PROPERTY)) { 397 verifyStringProperty(name, value); 398 setUsername((String ) value); 399 } 400 else if (name.equals(PASSWORD_PROPERTY)) { 401 verifyStringProperty(name, value); 402 setPassword((String ) value); 403 } 404 else if (name.equals(SESSION_MAINTAIN_PROPERTY)) { 405 verifyBooleanProperty(name, value); 406 setMaintainSession(((Boolean ) value).booleanValue()); 407 } 408 else if (name.equals(OPERATION_STYLE_PROPERTY)) { 409 verifyStringProperty(name, value); 410 setOperationStyle((String ) value); 411 if (getOperationStyle() == Style.DOCUMENT || 412 getOperationStyle() == Style.WRAPPED) { 413 setOperationUse(Use.LITERAL_STR); 414 } else if (getOperationStyle() == Style.RPC) { 415 setOperationUse(Use.ENCODED_STR); 416 } 417 } 418 else if (name.equals(SOAPACTION_USE_PROPERTY)) { 419 verifyBooleanProperty(name, value); 420 setUseSOAPAction(((Boolean ) value).booleanValue()); 421 } 422 else if (name.equals(SOAPACTION_URI_PROPERTY)) { 423 verifyStringProperty(name, value); 424 setSOAPActionURI((String ) value); 425 } 426 else if (name.equals(ENCODINGSTYLE_URI_PROPERTY)) { 427 verifyStringProperty(name, value); 428 setEncodingStyle((String ) value); 429 } 430 else if (name.equals(Stub.ENDPOINT_ADDRESS_PROPERTY)) { 431 verifyStringProperty(name, value); 432 setTargetEndpointAddress((String ) value); 433 } 434 else if ( name.equals(TRANSPORT_NAME) ) { 435 verifyStringProperty(name, value); 436 transportName = (String ) value ; 437 if (transport != null) { 438 transport.setTransportName((String ) value); 439 } 440 } 441 else if ( name.equals(ATTACHMENT_ENCAPSULATION_FORMAT) ) { 442 verifyStringProperty(name, value); 443 if(!value.equals(ATTACHMENT_ENCAPSULATION_FORMAT_MIME ) && 444 !value.equals(ATTACHMENT_ENCAPSULATION_FORMAT_DIME )) 445 throw new JAXRPCException ( 446 Messages.getMessage("badattachmenttypeerr", new String [] { 447 (String ) value, ATTACHMENT_ENCAPSULATION_FORMAT_MIME + " " 448 +ATTACHMENT_ENCAPSULATION_FORMAT_DIME })); 449 } 450 else if (name.equals(CONNECTION_TIMEOUT_PROPERTY)) { 451 verifyIntegerProperty(name,value); 452 setTimeout((Integer )value); 453 } 454 else if (name.equals(STREAMING_PROPERTY)) { 455 verifyBooleanProperty(name, value); 456 setStreaming(((Boolean ) value).booleanValue()); 457 } 458 else if (name.equals(CHARACTER_SET_ENCODING)) { 459 verifyStringProperty(name, value); 460 } 461 else if (name.startsWith("java.") || name.startsWith("javax.")) { 462 throw new JAXRPCException ( 463 Messages.getMessage("badProp05", name)); 464 } 465 myProperties.put(name, value); 466 } 468 475 private void verifyStringProperty(String name, Object value) { 476 if (!(value instanceof String )) { 477 throw new JAXRPCException ( 478 Messages.getMessage("badProp00", new String [] 479 {name, 480 "java.lang.String", 481 value.getClass().getName()})); 482 } 483 } 484 485 492 private void verifyBooleanProperty(String name, Object value) { 493 if (!(value instanceof Boolean )) { 494 throw new JAXRPCException ( 495 Messages.getMessage("badProp00", new String [] 496 {name, 497 "java.lang.Boolean", 498 value.getClass().getName()})); 499 } 500 } 501 502 509 private void verifyIntegerProperty(String name, Object value) { 510 if (!(value instanceof Integer )) { 511 throw new JAXRPCException ( 512 Messages.getMessage("badProp00", new String [] 513 {name, 514 "java.lang.Integer", 515 value.getClass().getName()})); 516 } 517 } 518 519 526 public Object getProperty(String name) { 527 if (name == null || !isPropertySupported(name)) { 528 throw new JAXRPCException (name == null ? 529 Messages.getMessage("badProp03") : 530 Messages.getMessage("badProp05", name)); 531 } 532 return myProperties.get(name); 533 } 535 540 public void removeProperty(String name) { 541 if (name == null || !isPropertySupported(name)) { 542 throw new JAXRPCException (name == null ? 543 Messages.getMessage("badProp03") : 544 Messages.getMessage("badProp05", name)); 545 } 546 myProperties.remove(name); 547 } 549 552 private static ArrayList propertyNames = new ArrayList (); 553 static { 554 propertyNames.add(USERNAME_PROPERTY); 555 propertyNames.add(PASSWORD_PROPERTY); 556 propertyNames.add(SESSION_MAINTAIN_PROPERTY); 557 propertyNames.add(OPERATION_STYLE_PROPERTY); 558 propertyNames.add(SOAPACTION_USE_PROPERTY); 559 propertyNames.add(SOAPACTION_URI_PROPERTY); 560 propertyNames.add(ENCODINGSTYLE_URI_PROPERTY); 561 propertyNames.add(Stub.ENDPOINT_ADDRESS_PROPERTY); 562 propertyNames.add(TRANSPORT_NAME); 563 propertyNames.add(ATTACHMENT_ENCAPSULATION_FORMAT); 564 propertyNames.add(CONNECTION_TIMEOUT_PROPERTY); 565 propertyNames.add(CHARACTER_SET_ENCODING); 566 } 567 568 public Iterator getPropertyNames() { 569 return propertyNames.iterator(); 570 } 571 572 public boolean isPropertySupported(String name) { 573 return propertyNames.contains(name) || (!name.startsWith("java.") 574 && !name.startsWith("javax.")); 575 } 576 577 582 public void setUsername(String username) { 583 this.username = username; 584 } 586 591 public String getUsername() { 592 return username; 593 } 595 600 public void setPassword(String password) { 601 this.password = password; 602 } 604 609 public String getPassword() { 610 return password; 611 } 613 621 public void setMaintainSession(boolean yesno) { 622 maintainSession = yesno; 623 } 624 625 630 public boolean getMaintainSession() { 631 return maintainSession; 632 } 633 634 638 public void setOperationStyle(String operationStyle) { 639 Style style = Style.getStyle(operationStyle, Style.DEFAULT); 640 setOperationStyle(style); 641 } 643 648 public void setOperationStyle(Style operationStyle) { 649 if (operation == null) { 650 operation = new OperationDesc(); 651 } 652 653 operation.setStyle(operationStyle); 654 655 if (!useExplicitlySet) { 658 if (operationStyle != Style.RPC) { 659 operation.setUse(Use.LITERAL); 660 } 661 } 662 663 if (!encodingStyleExplicitlySet) { 667 String encStyle = ""; 668 if (operationStyle == Style.RPC) { 669 encStyle = msgContext.getSOAPConstants().getEncodingURI(); 671 } 672 msgContext.setEncodingStyle(encStyle); 673 } 674 } 675 676 681 public Style getOperationStyle() { 682 if (operation != null) { 683 return operation.getStyle(); 684 } 685 return Style.DEFAULT; 686 } 688 692 public void setOperationUse(String operationUse) { 693 Use use = Use.getUse(operationUse, Use.DEFAULT); 694 setOperationUse(use); 695 } 697 701 public void setOperationUse(Use operationUse) { 702 useExplicitlySet = true; 703 704 if (operation == null) { 705 operation = new OperationDesc(); 706 } 707 708 operation.setUse(operationUse); 709 if (!encodingStyleExplicitlySet) { 710 String encStyle = ""; 711 if (operationUse == Use.ENCODED) { 712 encStyle = msgContext.getSOAPConstants().getEncodingURI(); 714 } 715 msgContext.setEncodingStyle(encStyle); 716 } 717 } 718 719 724 public Use getOperationUse() { 725 if (operation != null) { 726 return operation.getUse(); 727 } 728 return Use.DEFAULT; 729 } 731 737 public void setUseSOAPAction(boolean useSOAPAction) { 738 this.useSOAPAction = useSOAPAction; 739 } 741 746 public boolean useSOAPAction() { 747 return useSOAPAction; 748 } 750 755 public void setSOAPActionURI(String SOAPActionURI) { 756 useSOAPAction = true; 757 this.SOAPActionURI = SOAPActionURI; 758 } 760 765 public String getSOAPActionURI() { 766 return SOAPActionURI; 767 } 769 774 public void setEncodingStyle(String namespaceURI) { 775 encodingStyleExplicitlySet = true; 776 msgContext.setEncodingStyle(namespaceURI); 777 } 778 779 785 public String getEncodingStyle() { 786 return msgContext.getEncodingStyle(); 787 } 788 789 797 public void setTargetEndpointAddress(String address) { 798 URL urlAddress; 799 try { 800 urlAddress = new URL (address); 801 } 802 catch (MalformedURLException mue) { 803 throw new JAXRPCException (mue); 804 } 805 setTargetEndpointAddress(urlAddress); 806 } 807 808 815 public void setTargetEndpointAddress(java.net.URL address) { 816 try { 817 if ( address == null ) { 818 setTransport(null); 819 return ; 820 } 821 822 String protocol = address.getProtocol(); 823 824 if ( this.transport != null ) { 833 String oldAddr = this.transport.getUrl(); 834 if ( oldAddr != null && !oldAddr.equals("") ) { 835 URL tmpURL = new URL ( oldAddr ); 836 String oldProto = tmpURL.getProtocol(); 837 if ( protocol.equals(oldProto) ) { 838 this.transport.setUrl( address.toString() ); 839 return ; 840 } 841 } 842 } 843 844 Transport transport = service.getTransportForURL(address); 846 if (transport != null) { 847 setTransport(transport); 848 } 849 else { 850 transport = getTransportForProtocol(protocol); 852 if (transport == null) 853 throw new AxisFault("Call.setTargetEndpointAddress", 854 Messages.getMessage("noTransport01", 855 protocol), null, null); 856 transport.setUrl(address.toString()); 857 setTransport(transport); 858 service.registerTransportForURL(address, transport); 859 } 860 } 861 catch( Exception exp ) { 862 log.error(Messages.getMessage("exception00"), exp); 863 } 867 } 868 869 874 public String getTargetEndpointAddress() { 875 try { 876 if ( transport == null ) return( null ); 877 return( transport.getUrl() ); 878 } 879 catch( Exception exp ) { 880 return( null ); 881 } 882 } 883 884 public Integer getTimeout() { 885 return timeout; 886 } 887 888 public void setTimeout(Integer timeout) { 889 this.timeout = timeout; 890 } 891 892 public boolean getStreaming() { 893 return useStreaming; 894 } 895 896 public void setStreaming(boolean useStreaming) { 897 this.useStreaming = useStreaming; 898 } 899 904 915 public boolean isParameterAndReturnSpecRequired(QName operationName) { 916 return parmAndRetReq; 917 } 919 929 public void addParameter(QName paramName, QName xmlType, 930 ParameterMode parameterMode) { 931 Class javaType = null; 932 TypeMapping tm = getTypeMapping(); 933 if (tm != null) { 934 javaType = tm.getClassForQName(xmlType); 935 } 936 addParameter(paramName, xmlType, javaType, parameterMode); 937 } 938 939 951 public void addParameter(QName paramName, QName xmlType, 952 Class javaType, ParameterMode parameterMode) { 953 954 if (operationSetManually) { 955 throw new RuntimeException ( 956 Messages.getMessage("operationAlreadySet")); 957 } 958 959 if (operation == null) 960 operation = new OperationDesc(); 961 962 ParameterDesc param = new ParameterDesc(); 963 byte mode = ParameterDesc.IN; 964 if (parameterMode == ParameterMode.INOUT) { 965 mode = ParameterDesc.INOUT; 966 param.setIsReturn(true); 967 } else if (parameterMode == ParameterMode.OUT) { 968 mode = ParameterDesc.OUT; 969 param.setIsReturn(true); 970 } 971 param.setMode(mode); 972 param.setQName(new QName (paramName.getNamespaceURI(),Utils.getLastLocalPart(paramName.getLocalPart()))); 973 param.setTypeQName( xmlType ); 974 param.setJavaType( javaType ); 975 976 operation.addParameter(param); 977 parmAndRetReq = true; 978 } 979 980 988 public void addParameter(String paramName, QName xmlType, 989 ParameterMode parameterMode) { 990 Class javaType = null; 991 TypeMapping tm = getTypeMapping(); 992 if (tm != null) { 993 javaType = tm.getClassForQName(xmlType); 994 } 995 addParameter(new QName ("", paramName), xmlType, 996 javaType, parameterMode); 997 } 998 999 1015 public void addParameter(String paramName, QName xmlType, 1016 Class javaType, ParameterMode parameterMode) { 1017 addParameter(new QName ("", paramName), xmlType, 1018 javaType, parameterMode); 1019 } 1020 1021 1035 public void addParameterAsHeader(QName paramName, QName xmlType, 1036 ParameterMode parameterMode, 1037 ParameterMode headerMode) { 1038 Class javaType = null; 1039 TypeMapping tm = getTypeMapping(); 1040 if (tm != null) { 1041 javaType = tm.getClassForQName(xmlType); 1042 } 1043 addParameterAsHeader(paramName, xmlType, javaType, 1044 parameterMode, headerMode); 1045 } 1046 1047 1062 public void addParameterAsHeader(QName paramName, QName xmlType, 1063 Class javaType, ParameterMode parameterMode, 1064 ParameterMode headerMode) { 1065 if (operationSetManually) { 1066 throw new RuntimeException ( 1067 Messages.getMessage("operationAlreadySet")); 1068 } 1069 1070 if (operation == null) 1071 operation = new OperationDesc(); 1072 1073 ParameterDesc param = new ParameterDesc(); 1074 param.setQName(new QName (paramName.getNamespaceURI(),Utils.getLastLocalPart(paramName.getLocalPart()))); 1075 param.setTypeQName(xmlType); 1076 param.setJavaType(javaType); 1077 if (parameterMode == ParameterMode.IN) { 1078 param.setMode(ParameterDesc.IN); 1079 } 1080 else if (parameterMode == ParameterMode.INOUT) { 1081 param.setMode(ParameterDesc.INOUT); 1082 } 1083 else if (parameterMode == ParameterMode.OUT) { 1084 param.setMode(ParameterDesc.OUT); 1085 } 1086 if (headerMode == ParameterMode.IN) { 1087 param.setInHeader(true); 1088 } 1089 else if (headerMode == ParameterMode.INOUT) { 1090 param.setInHeader(true); 1091 param.setOutHeader(true); 1092 } 1093 else if (headerMode == ParameterMode.OUT) { 1094 param.setOutHeader(true); 1095 } 1096 operation.addParameter(param); 1097 parmAndRetReq = true; 1098 } 1100 1106 public QName getParameterTypeByName(String paramName) { 1107 QName paramQName = new QName ("", paramName); 1108 1109 return getParameterTypeByQName(paramQName); 1110 } 1111 1112 1120 public QName getParameterTypeByQName(QName paramQName) { 1121 ParameterDesc param = operation.getParamByQName(paramQName); 1122 if (param != null) { 1123 return param.getTypeQName(); 1124 } 1125 return( null ); 1126 } 1127 1128 1133 public void setReturnType(QName type) { 1134 if (operationSetManually) { 1135 throw new RuntimeException ( 1136 Messages.getMessage("operationAlreadySet")); 1137 } 1138 1139 if (operation == null) 1140 operation = new OperationDesc(); 1141 1142 1147 operation.setReturnType(type); 1149 TypeMapping tm = getTypeMapping(); 1150 operation.setReturnClass(tm.getClassForQName(type)); 1151 parmAndRetReq = true; 1152 } 1157 1158 1167 public void setReturnType(QName xmlType, Class javaType) { 1168 setReturnType(xmlType); 1169 operation.setReturnClass(javaType); 1171 } 1172 1173 1176 public void setReturnTypeAsHeader(QName xmlType) { 1177 setReturnType(xmlType); 1178 operation.setReturnHeader(true); 1179 } 1181 1184 public void setReturnTypeAsHeader(QName xmlType, Class javaType) { 1185 setReturnType(xmlType, javaType); 1186 operation.setReturnHeader(true); 1187 } 1189 1197 public QName getReturnType() { 1198 if (operation != null) 1199 return operation.getReturnType(); 1200 1201 return null; 1202 } 1203 1204 1209 public void setReturnQName(QName qname) { 1210 if (operationSetManually) { 1211 throw new RuntimeException ( 1212 Messages.getMessage("operationAlreadySet")); 1213 } 1214 1215 if (operation == null) 1216 operation = new OperationDesc(); 1217 1218 operation.setReturnQName(qname); 1219 } 1220 1236 public void setReturnClass(Class cls) { 1237 if (operationSetManually) { 1238 throw new RuntimeException ( 1239 Messages.getMessage("operationAlreadySet")); 1240 } 1241 1242 if (operation == null) 1243 operation = new OperationDesc(); 1244 1245 operation.setReturnClass(cls); 1246 TypeMapping tm = getTypeMapping(); 1247 operation.setReturnType(tm.getTypeQName(cls)); 1248 parmAndRetReq = true; 1249 } 1250 1251 1257 public void removeAllParameters() { 1258 operation = new OperationDesc(); 1260 operationSetManually = false; 1261 parmAndRetReq = true; 1262 } 1267 1268 1273 public QName getOperationName() { 1274 return( operationName ); 1275 } 1276 1277 1284 public void setOperationName(QName opName) { 1285 operationName = opName ; 1286 } 1287 1288 1293 public void setOperationName(String opName) { 1294 operationName = new QName (opName); 1295 } 1296 1297 1311 public void setOperation(String opName) { 1312 if ( service == null ) { 1313 throw new JAXRPCException ( Messages.getMessage("noService04") ); 1314 } 1315 1316 this.setOperationName( opName ); 1319 this.setEncodingStyle( null ); 1320 this.setReturnType( null ); 1321 this.removeAllParameters(); 1322 1323 javax.wsdl.Service wsdlService = service.getWSDLService(); 1324 if(wsdlService == null) { 1326 return; 1327 } 1328 1329 Port port = wsdlService.getPort( portName.getLocalPart() ); 1330 if ( port == null ) { 1331 throw new JAXRPCException ( Messages.getMessage("noPort00", "" + 1332 portName) ); 1333 } 1334 1335 Binding binding = port.getBinding(); 1336 PortType portType = binding.getPortType(); 1337 if ( portType == null ) { 1338 throw new JAXRPCException ( Messages.getMessage("noPortType00", "" + 1339 portName) ); 1340 } 1341 this.setPortTypeName(portType.getQName()); 1342 1343 List operations = portType.getOperations(); 1344 if ( operations == null ) { 1345 throw new JAXRPCException ( Messages.getMessage("noOperation01", 1346 opName) ); 1347 } 1348 1349 Operation op = null ; 1350 for ( int i = 0 ; i < operations.size() ; i++, op=null ) { 1351 op = (Operation) operations.get( i ); 1352 if ( opName.equals( op.getName() ) ) { 1353 break ; 1354 } 1355 } 1356 if ( op == null ) { 1357 throw new JAXRPCException ( Messages.getMessage("noOperation01", 1358 opName) ); 1359 } 1360 1361 List list = port.getExtensibilityElements(); 1364 String opStyle = null; 1365 BindingOperation bop = binding.getBindingOperation(opName, 1366 null, null); 1367 if ( bop == null ) { 1368 throw new JAXRPCException ( Messages.getMessage("noOperation02", 1369 opName )); 1370 } 1371 list = bop.getExtensibilityElements(); 1372 for ( int i = 0 ; list != null && i < list.size() ; i++ ) { 1373 Object obj = list.get(i); 1374 if ( obj instanceof SOAPOperation ) { 1375 SOAPOperation sop = (SOAPOperation) obj ; 1376 opStyle = ((SOAPOperation) obj).getStyle(); 1377 String action = sop.getSoapActionURI(); 1378 if ( action != null ) { 1379 setUseSOAPAction(true); 1380 setSOAPActionURI(action); 1381 } 1382 else { 1383 setUseSOAPAction(false); 1384 setSOAPActionURI(null); 1385 } 1386 break ; 1387 } 1388 } 1389 1390 BindingInput bIn = bop.getBindingInput(); 1393 if ( bIn != null ) { 1394 list = bIn.getExtensibilityElements(); 1395 for ( int i = 0 ; list != null && i < list.size() ; i++ ) { 1396 Object obj = list.get(i); 1397 if( obj instanceof MIMEMultipartRelated){ 1398 MIMEMultipartRelated mpr=(MIMEMultipartRelated) obj; 1399 Object part= null; 1400 List l= mpr.getMIMEParts(); 1401 for(int j=0; l!= null && j< l.size() && part== null; j++){ 1402 MIMEPart mp = (MIMEPart)l.get(j); 1403 List ll= mp.getExtensibilityElements(); 1404 for(int k=0; ll != null && k < ll.size() && part == null; 1405 k++){ 1406 part= ll.get(k); 1407 if ( !(part instanceof SOAPBody)) { 1408 part = null; 1409 } 1410 } 1411 } 1412 if(null != part) { 1413 obj= part; 1414 } 1415 } 1416 1417 if ( obj instanceof SOAPBody ) { 1418 SOAPBody sBody = (SOAPBody) obj ; 1419 list = sBody.getEncodingStyles(); 1420 if ( list != null && list.size() > 0 ) { 1421 this.setEncodingStyle( (String ) list.get(0) ); 1422 } 1423 String ns = sBody.getNamespaceURI(); 1424 if (ns != null && !ns.equals("")) { 1425 setOperationName( new QName ( ns, opName ) ); 1426 } 1427 break ; 1428 } 1429 } 1430 } 1431 1432 Service service = this.getService(); 1433 SymbolTable symbolTable = service.getWSDLParser().getSymbolTable(); 1434 BindingEntry bEntry = symbolTable.getBindingEntry(binding.getQName()); 1435 Parameters parameters = bEntry.getParameters(bop.getOperation()); 1436 1437 for (int j = 0; j < parameters.list.size(); ++j) { 1439 Parameter p = (Parameter) parameters.list.get(j); 1440 QName paramType = Utils.getXSIType(p); 1442 1443 ParameterMode mode = modes[p.getMode()]; 1447 if (p.isInHeader() || p.isOutHeader()) { 1448 this.addParameterAsHeader(p.getQName(), paramType, 1449 mode, mode); 1450 } else { 1451 this.addParameter(p.getQName(), paramType, mode); 1452 } 1453 } 1454 1455 Map faultMap = bEntry.getFaults(); 1456 ArrayList faults = (ArrayList ) faultMap.get(bop); 1458 1459 if (faults == null) { 1461 return; 1462 } 1463 for (Iterator faultIt = faults.iterator(); faultIt.hasNext();) { 1465 FaultInfo info = (FaultInfo) faultIt.next(); 1466 QName qname = info.getQName(); 1467 info.getMessage(); 1468 1469 if (qname == null) { 1471 continue; 1472 } 1473 1474 QName xmlType = info.getXMLType(); 1475 Class clazz = getTypeMapping().getClassForQName(xmlType); 1476 if (clazz != null) { 1477 addFault(qname, clazz, xmlType, true); 1478 } else { 1479 1482 log.debug(Messages.getMessage("clientNoTypemapping", xmlType.toString())); 1483 } 1484 } 1485 1486 if (parameters.returnParam != null) { 1488 QName returnType = Utils.getXSIType(parameters.returnParam); 1490 QName returnQName = parameters.returnParam.getQName(); 1491 1492 String javaType = null; 1494 if (parameters.returnParam.getMIMEInfo() != null) { 1495 javaType = "javax.activation.DataHandler"; 1496 } 1497 else { 1498 javaType = parameters.returnParam.getType().getName(); 1499 } 1500 if (javaType == null) { 1501 javaType = ""; 1502 } 1503 else { 1504 javaType = javaType + ".class"; 1505 } 1506 this.setReturnType(returnType); 1507 try { 1508 Class clazz = ClassUtils.forName(javaType); 1509 this.setReturnClass(clazz); 1510 } catch (ClassNotFoundException swallowedException) { 1511 log.debug(Messages.getMessage("clientNoReturnClass", 1513 javaType)); 1514 } 1515 this.setReturnQName(returnQName); 1516 } 1517 else { 1518 this.setReturnType(org.apache.axis.encoding.XMLType.AXIS_VOID); 1519 } 1520 1521 boolean hasMIME = Utils.hasMIME(bEntry, bop); 1522 Use use = bEntry.getInputBodyType(bop.getOperation()); 1523 setOperationUse(use); 1524 if (use == Use.LITERAL) { 1525 setEncodingStyle(null); 1527 setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE); 1529 } 1530 if (hasMIME || use == Use.LITERAL) { 1531 setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE); 1537 } 1538 1539 Style style = Style.getStyle(opStyle, bEntry.getBindingStyle()); 1540 if (style == Style.DOCUMENT && symbolTable.isWrapped()) { 1541 style = Style.WRAPPED; 1542 } 1543 setOperationStyle(style); 1544 1545 if (style == Style.WRAPPED) { 1547 Map partsMap = bop.getOperation().getInput().getMessage().getParts(); 1551 Part p = (Part)partsMap.values().iterator().next(); 1552 QName q = p.getElementName(); 1553 setOperationName(q); 1554 } else { 1555 QName elementQName = 1556 Utils.getOperationQName(bop, bEntry, symbolTable); 1557 if (elementQName != null) { 1558 setOperationName(elementQName); 1559 } 1560 } 1561 1562 parmAndRetReq = false; 1565 return; 1566 1567 } 1568 1569 1570 1583 public void setOperation(QName portName, String opName) { 1584 setOperation(portName, new QName (opName)); 1585 } 1586 1587 1588 1601 public void setOperation(QName portName, QName opName) { 1602 if ( service == null ) 1603 throw new JAXRPCException ( Messages.getMessage("noService04") ); 1604 1605 this.setPortName( portName ); 1607 this.setOperationName( opName ); 1608 this.setReturnType( null ); 1609 this.removeAllParameters(); 1610 1611 javax.wsdl.Service wsdlService = service.getWSDLService(); 1612 if(wsdlService == null) { 1614 return; 1615 } 1616 1617 this.setTargetEndpointAddress( (URL ) null ); 1619 1620 Port port = wsdlService.getPort( portName.getLocalPart() ); 1621 if ( port == null ) { 1622 throw new JAXRPCException ( Messages.getMessage("noPort00", "" + 1623 portName) ); 1624 } 1625 1626 List list = port.getExtensibilityElements(); 1629 for ( int i = 0 ; list != null && i < list.size() ; i++ ) { 1630 Object obj = list.get(i); 1631 if ( obj instanceof SOAPAddress ) { 1632 try { 1633 SOAPAddress addr = (SOAPAddress) obj ; 1634 URL url = new URL (addr.getLocationURI()); 1635 this.setTargetEndpointAddress(url); 1636 } 1637 catch(Exception exp) { 1638 throw new JAXRPCException ( 1639 Messages.getMessage("cantSetURI00", "" + exp) ); 1640 } 1641 } 1642 } 1643 1644 setOperation(opName.getLocalPart()); 1645 } 1646 1647 1653 public QName getPortName() { 1654 return( portName ); 1655 } 1657 1664 public void setPortName(QName portName) { 1665 this.portName = portName; 1666 } 1668 1674 public QName getPortTypeName() { 1675 return portTypeName == null ? new QName ("") : portTypeName; 1676 } 1677 1678 1685 public void setPortTypeName(QName portType) { 1686 this.portTypeName = portType; 1687 } 1688 1689 1696 public void setSOAPVersion(SOAPConstants soapConstants) { 1697 msgContext.setSOAPConstants(soapConstants); 1698 } 1699 1700 1714 public Object invoke(QName operationName, Object [] params) 1715 throws java.rmi.RemoteException { 1716 QName origOpName = this.operationName; 1717 this.operationName = operationName; 1718 try { 1719 return this.invoke(params); 1720 } 1721 catch (AxisFault af) { 1722 this.operationName = origOpName; 1723 if(af.detail != null && af.detail instanceof RemoteException ) { 1724 throw ((RemoteException )af.detail); 1725 } 1726 throw af; 1727 } 1728 catch (java.rmi.RemoteException re) { 1729 this.operationName = origOpName; 1730 throw re; 1731 } 1732 catch (RuntimeException re) { 1733 this.operationName = origOpName; 1734 throw re; 1735 } 1736 catch (Error e) { 1737 this.operationName = origOpName; 1738 throw e; 1739 } 1740 } 1742 1755 public Object invoke(Object [] params) throws java.rmi.RemoteException { 1756 long t0=0, t1=0; 1757 if( tlog.isDebugEnabled() ) { 1758 t0=System.currentTimeMillis(); 1759 } 1760 1761 1762 1763 1764 SOAPEnvelope env = null ; 1765 int i ; 1766 1767 for ( i = 0 ; params != null && i < params.length ; i++ ) 1768 if ( !(params[i] instanceof SOAPBodyElement) ) break ; 1769 1770 if ( params != null && params.length > 0 && i == params.length ) { 1771 1772 1773 isMsg = true ; 1774 env = new SOAPEnvelope(msgContext.getSOAPConstants(), 1775 msgContext.getSchemaVersion()); 1776 1777 for (i = 0; i < params.length; i++) { 1778 env.addBodyElement((SOAPBodyElement) params[i]); 1779 } 1780 1781 Message msg = new Message( env ); 1782 setRequestMessage(msg); 1783 1784 invoke(); 1785 1786 msg = msgContext.getResponseMessage(); 1787 if (msg == null) { 1788 if (msgContext.isPropertyTrue(FAULT_ON_NO_RESPONSE, false)) { 1789 throw new AxisFault(Messages.getMessage("nullResponse00")); 1790 } else { 1791 return null; 1792 } 1793 } 1794 1795 env = msg.getSOAPEnvelope(); 1796 return( env.getBodyElements() ); 1797 } 1798 1799 1800 if ( operationName == null ) { 1801 throw new AxisFault( Messages.getMessage("noOperation00") ); 1802 } 1803 try { 1804 Object res=this.invoke(operationName.getNamespaceURI(), 1805 operationName.getLocalPart(), params); 1806 if( tlog.isDebugEnabled() ) { 1807 t1=System.currentTimeMillis(); 1808 tlog.debug("axis.Call.invoke: " + (t1-t0) + " " + operationName); 1809 } 1810 return res; 1811 } 1812 catch( AxisFault af) { 1813 if(af.detail != null && af.detail instanceof RemoteException ) { 1814 throw ((RemoteException )af.detail); 1815 } 1816 throw af; 1817 } 1818 catch( Exception exp ) { 1819 entLog.debug(Messages.getMessage("toAxisFault00"), exp); 1820 throw AxisFault.makeFault(exp); 1821 } 1822 } 1823 1824 1835 public void invokeOneWay(Object [] params) { 1836 try { 1837 invokeOneWay = true; 1838 invoke( params ); 1839 } catch( Exception exp ) { 1840 throw new JAXRPCException ( exp.toString() ); 1841 } finally { 1842 invokeOneWay = false; 1843 } 1844 } 1845 1846 1847 1848 1849 1850 1859 public SOAPEnvelope invoke(Message msg) throws AxisFault { 1860 try { 1861 setRequestMessage( msg ); 1862 invoke(); 1863 msg = msgContext.getResponseMessage(); 1864 if (msg == null) { 1865 if (msgContext.isPropertyTrue(FAULT_ON_NO_RESPONSE, false)) { 1866 throw new AxisFault(Messages.getMessage("nullResponse00")); 1867 } else { 1868 return null; 1869 } 1870 } 1871 SOAPEnvelope res = null; 1872 res = msg.getSOAPEnvelope(); 1873 return res; 1874 } 1875 catch (Exception exp) { 1876 if (exp instanceof AxisFault) { 1877 throw (AxisFault) exp ; 1878 } 1879 entLog.debug(Messages.getMessage("toAxisFault00"), exp); 1880 throw new AxisFault( 1881 Messages.getMessage("errorInvoking00", "\n" + exp)); 1882 } 1883 } 1884 1885 1893 public SOAPEnvelope invoke(SOAPEnvelope env) throws AxisFault { 1894 try { 1895 Message msg = new Message( env ); 1896 if (getProperty(CHARACTER_SET_ENCODING) != null) { 1897 msg.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, getProperty(CHARACTER_SET_ENCODING)); 1898 } else if (msgContext.getProperty(CHARACTER_SET_ENCODING) != null) { 1899 msg.setProperty(CHARACTER_SET_ENCODING, msgContext.getProperty(CHARACTER_SET_ENCODING)); 1900 } 1901 setRequestMessage( msg ); 1902 invoke(); 1903 msg = msgContext.getResponseMessage(); 1904 if (msg == null) { 1905 if (msgContext.isPropertyTrue(FAULT_ON_NO_RESPONSE, false)) { 1906 throw new AxisFault(Messages.getMessage("nullResponse00")); 1907 } else { 1908 return null; 1909 } 1910 } 1911 return( msg.getSOAPEnvelope() ); 1912 } 1913 catch( Exception exp ) { 1914 if ( exp instanceof AxisFault ) { 1915 throw (AxisFault) exp ; 1916 } 1917 1918 entLog.debug(Messages.getMessage("toAxisFault00"), exp); 1919 throw AxisFault.makeFault(exp); 1920 } 1921 } 1922 1923 1924 1933 public static void setTransportForProtocol(String protocol, 1934 Class transportClass) { 1935 if (Transport.class.isAssignableFrom(transportClass)) { 1936 transports.put(protocol, transportClass); 1937 } 1938 else { 1939 throw new InternalException(transportClass.toString()); 1940 } 1941 } 1942 1943 1952 public static synchronized void initialize() { 1953 addTransportPackage("org.apache.axis.transport"); 1954 1955 setTransportForProtocol("java", 1956 org.apache.axis.transport.java.JavaTransport.class); 1957 setTransportForProtocol("local", 1958 org.apache.axis.transport.local.LocalTransport.class); 1959 setTransportForProtocol("http", HTTPTransport.class); 1960 setTransportForProtocol("https", HTTPTransport.class); 1961 } 1962 1963 1967 private static ArrayList transportPackages = null; 1968 1969 1982 public static synchronized void addTransportPackage(String packageName) { 1983 if (transportPackages == null) { 1984 transportPackages = new ArrayList (); 1985 String currentPackages = 1986 AxisProperties.getProperty(TRANSPORT_PROPERTY); 1987 if (currentPackages != null) { 1988 StringTokenizer tok = new StringTokenizer (currentPackages, 1989 "|"); 1990 while (tok.hasMoreTokens()) { 1991 transportPackages.add(tok.nextToken()); 1992 } 1993 } 1994 } 1995 1996 if (transportPackages.contains(packageName)) { 1997 return; 1998 } 1999 2000 transportPackages.add(packageName); 2001 2002 StringBuffer currentPackages = new StringBuffer (); 2003 for (Iterator i = transportPackages.iterator(); i.hasNext();) { 2004 String thisPackage = (String ) i.next(); 2005 currentPackages.append(thisPackage); 2006 currentPackages.append('|'); 2007 } 2008 2009 System.setProperty(TRANSPORT_PROPERTY, currentPackages.toString()); 2010 } 2011 2012 2020 private Object [] getParamList(Object [] params) { 2021 int numParams = 0 ; 2022 2023 if (log.isDebugEnabled()) { 2026 log.debug( "operation=" + operation); 2027 if (operation != null) { 2028 log.debug("operation.getNumParams()=" + 2029 operation.getNumParams()); 2030 } 2031 } 2032 if ( operation == null || operation.getNumParams() == 0 ) { 2033 return( params ); 2034 } 2035 2036 numParams = operation.getNumInParams(); 2040 2041 if ( params == null || numParams != params.length ) { 2042 throw new JAXRPCException ( 2043 Messages.getMessage( 2044 "parmMismatch00", 2045 (params == null) ? "no params" : "" + params.length, 2046 "" + numParams 2047 ) 2048 ); 2049 } 2050 2051 log.debug( "getParamList number of params: " + params.length); 2052 2053 Vector result = new Vector (); 2056 int j = 0 ; 2057 ArrayList parameters = operation.getParameters(); 2058 2059 for (int i = 0; i < parameters.size(); i++) { 2060 ParameterDesc param = (ParameterDesc)parameters.get(i); 2061 if (param.getMode() != ParameterDesc.OUT) { 2062 QName paramQName = param.getQName(); 2063 2064 RPCParam rpcParam = null; 2066 Object p = params[j++]; 2067 if(p instanceof RPCParam) { 2068 rpcParam = (RPCParam)p; 2069 } else { 2070 rpcParam = new RPCParam(paramQName.getNamespaceURI(), 2071 paramQName.getLocalPart(), 2072 p); 2073 } 2074 rpcParam.setParamDesc(param); 2078 2079 if (param.isInHeader()) { 2082 addHeader(new RPCHeaderParam(rpcParam)); 2083 } else { 2084 result.add(rpcParam); 2085 } 2086 } 2087 } 2088 return( result.toArray() ); 2089 } 2090 2091 2099 public void setTransport(Transport trans) { 2100 transport = trans; 2101 if (log.isDebugEnabled()) 2102 log.debug(Messages.getMessage("transport00", "" + transport)); 2103 } 2104 2105 2113 public Transport getTransportForProtocol(String protocol) 2114 { 2115 Class transportClass = (Class )transports.get(protocol); 2116 Transport ret = null; 2117 if (transportClass != null) { 2118 try { 2119 ret = (Transport)transportClass.newInstance(); 2120 } catch (InstantiationException e) { 2121 } catch (IllegalAccessException e) { 2122 } 2123 } 2124 return ret; 2125 } 2126 2127 2138 public void setRequestMessage(Message msg) { 2139 String attachformat= (String )getProperty( 2140 ATTACHMENT_ENCAPSULATION_FORMAT); 2141 2142 if(null != attachformat) { 2143 Attachments attachments=msg.getAttachmentsImpl(); 2144 if(null != attachments) { 2145 if( ATTACHMENT_ENCAPSULATION_FORMAT_MIME.equals(attachformat)) { 2146 attachments.setSendType(Attachments.SEND_TYPE_MIME); 2147 } else if ( ATTACHMENT_ENCAPSULATION_FORMAT_DIME.equals(attachformat)) { 2148 attachments.setSendType(Attachments.SEND_TYPE_DIME); 2149 } 2150 } 2151 } 2152 2153 if(null != attachmentParts && !attachmentParts.isEmpty()){ 2154 try{ 2155 Attachments attachments= msg.getAttachmentsImpl(); 2156 if(null == attachments) { 2157 throw new RuntimeException ( 2158 Messages.getMessage("noAttachments")); 2159 } 2160 2161 attachments.setAttachmentParts(attachmentParts); 2162 }catch(AxisFault ex){ 2163 log.info(Messages.getMessage("axisFault00"), ex); 2164 throw new RuntimeException (ex.getMessage()); 2165 } 2166 } 2167 2168 msgContext.setRequestMessage(msg); 2169 attachmentParts.clear(); 2170 } 2171 2172 2181 public Message getResponseMessage() { 2182 return msgContext.getResponseMessage(); 2183 } 2184 2185 2192 public MessageContext getMessageContext () { 2193 return msgContext; 2194 } 2195 2196 2204 public void addHeader(SOAPHeaderElement header) 2205 { 2206 if (myHeaders == null) { 2207 myHeaders = new Vector (); 2208 } 2209 myHeaders.add(header); 2210 } 2211 2212 2217 public void clearHeaders() 2218 { 2219 myHeaders = null; 2220 } 2221 2222 public TypeMapping getTypeMapping() 2223 { 2224 TypeMappingRegistry tmr = msgContext.getTypeMappingRegistry(); 2226 2227 return tmr.getOrMakeTypeMapping(getEncodingStyle()); 2229 } 2230 2231 2240 public void registerTypeMapping(Class javaType, QName xmlType, 2241 SerializerFactory sf, 2242 DeserializerFactory df) { 2243 registerTypeMapping(javaType, xmlType, sf, df, true); 2244 } 2245 2246 2256 public void registerTypeMapping(Class javaType, QName xmlType, 2257 SerializerFactory sf, 2258 DeserializerFactory df, 2259 boolean force) { 2260 TypeMapping tm = getTypeMapping(); 2261 if (!force && tm.isRegistered(javaType, xmlType)) { 2262 return; 2263 } 2264 2265 tm.register(javaType, xmlType, sf, df); 2267 } 2268 2269 2276 public void registerTypeMapping(Class javaType, QName xmlType, 2277 Class sfClass, Class dfClass) { 2278 registerTypeMapping(javaType, xmlType, sfClass, dfClass, true); 2279 } 2280 2281 2290 public void registerTypeMapping(Class javaType, 2291 QName xmlType, 2292 Class sfClass, 2293 Class dfClass, 2294 boolean force) { 2295 SerializerFactory sf = 2297 BaseSerializerFactory.createFactory(sfClass, javaType, xmlType); 2298 DeserializerFactory df = 2299 BaseDeserializerFactory.createFactory(dfClass, 2300 javaType, 2301 xmlType); 2302 if (sf != null || df != null) { 2303 registerTypeMapping(javaType, xmlType, sf, df, force); 2304 } 2305 } 2306 2307 2310 2311 2328 public Object invoke(String namespace, String method, Object [] args) 2329 throws AxisFault { 2330 2331 if (log.isDebugEnabled()) { 2332 log.debug("Enter: Call::invoke(ns, meth, args)"); 2333 } 2334 2335 2340 if (getReturnType() != null && args != null && args.length != 0 2341 && operation.getNumParams() == 0) { 2342 throw new AxisFault(Messages.getMessage("mustSpecifyParms")); 2343 } 2344 2345 RPCElement body = new RPCElement(namespace, method, getParamList(args)); 2346 2347 Object ret = invoke( body ); 2348 2349 if (log.isDebugEnabled()) { 2350 log.debug("Exit: Call::invoke(ns, meth, args)"); 2351 } 2352 2353 return ret; 2354 } 2355 2356 2370 public Object invoke( String method, Object [] args ) throws AxisFault 2371 { 2372 return invoke("", method, args); 2373 } 2374 2375 2384 public Object invoke( RPCElement body ) throws AxisFault { 2385 if (log.isDebugEnabled()) { 2386 log.debug("Enter: Call::invoke(RPCElement)"); 2387 } 2388 2389 2394 if (!invokeOneWay && operation != null && 2395 operation.getNumParams() > 0 && getReturnType() == null) { 2396 log.error(Messages.getMessage("mustSpecifyReturnType")); 2400 } 2401 2402 SOAPEnvelope reqEnv = 2403 new SOAPEnvelope(msgContext.getSOAPConstants(), 2404 msgContext.getSchemaVersion()); 2405 SOAPEnvelope resEnv = null ; 2406 Message reqMsg = new Message( reqEnv ); 2407 Message resMsg = null ; 2408 Vector resArgs = null ; 2409 Object result = null ; 2410 2411 outParams = new HashMap (); 2413 outParamsList = new ArrayList (); 2414 2415 try { 2417 body.setEncodingStyle(getEncodingStyle()); 2418 2419 setRequestMessage(reqMsg); 2420 2421 reqEnv.addBodyElement(body); 2422 reqEnv.setMessageType(Message.REQUEST); 2423 2424 invoke(); 2425 } catch (Exception e) { 2426 entLog.debug(Messages.getMessage("toAxisFault00"), e); 2427 throw AxisFault.makeFault(e); 2428 } 2429 2430 resMsg = msgContext.getResponseMessage(); 2431 2432 if (resMsg == null) { 2433 if (msgContext.isPropertyTrue(FAULT_ON_NO_RESPONSE, false)) { 2434 throw new AxisFault(Messages.getMessage("nullResponse00")); 2435 } else { 2436 return null; 2437 } 2438 } 2439 2440 resEnv = resMsg.getSOAPEnvelope(); 2441 SOAPBodyElement bodyEl = resEnv.getFirstBody(); 2442 if (bodyEl == null) { 2443 return null; 2444 } 2445 2446 if (bodyEl instanceof RPCElement) { 2447 try { 2448 resArgs = ((RPCElement) bodyEl).getParams(); 2449 } catch (Exception e) { 2450 log.error(Messages.getMessage("exception00"), e); 2451 throw AxisFault.makeFault(e); 2452 } 2453 2454 if (resArgs != null && resArgs.size() > 0) { 2455 2456 int outParamStart = 0; 2459 2460 2479 2483 boolean findReturnParam = false; 2484 QName returnParamQName = null; 2485 if (operation != null) { 2486 returnParamQName = operation.getReturnQName(); 2487 } 2488 2489 if (!XMLType.AXIS_VOID.equals(getReturnType())) { 2490 if (returnParamQName == null) { 2491 RPCParam param = (RPCParam)resArgs.get(0); 2493 result = param.getObjectValue(); 2494 outParamStart = 1; 2495 } else { 2496 findReturnParam = true; 2499 } 2500 } 2501 2502 for (int i = outParamStart; i < resArgs.size(); i++) { 2510 RPCParam param = (RPCParam) resArgs.get(i); 2511 2512 Class javaType = getJavaTypeForQName(param.getQName()); 2513 Object value = param.getObjectValue(); 2514 2515 if (javaType != null && value != null && 2517 !javaType.isAssignableFrom(value.getClass())) { 2518 value = JavaUtils.convert(value, javaType); 2519 } 2520 2521 if (findReturnParam && 2524 returnParamQName.equals(param.getQName())) { 2525 result = value; 2527 findReturnParam = false; 2528 } else { 2529 outParams.put(param.getQName(), value); 2530 outParamsList.add(value); 2531 } 2532 } 2533 2534 if (findReturnParam) { 2542 Iterator it = outParams.keySet().iterator(); 2543 while (it.hasNext() && findReturnParam) { 2544 QName qname = (QName ) it.next(); 2545 ParameterDesc paramDesc = 2546 operation.getOutputParamByQName(qname); 2547 if (paramDesc == null) { 2548 findReturnParam = false; 2550 result = outParams.remove(qname); 2551 } 2552 } 2553 } 2554 2555 if (findReturnParam) { 2558 String returnParamName = returnParamQName.toString(); 2559 throw new AxisFault(Messages.getMessage("noReturnParam", 2560 returnParamName)); 2561 } 2562 } 2563 } else { 2564 try { 2566 result = bodyEl.getValueAsType(getReturnType()); 2567 } catch (Exception e) { 2568 result = bodyEl; 2570 } 2571 2572 } 2573 2574 if (log.isDebugEnabled()) { 2575 log.debug("Exit: Call::invoke(RPCElement)"); 2576 } 2577 2578 if (operation != null && operation.getReturnClass() != null) { 2580 result = JavaUtils.convert(result, operation.getReturnClass()); 2581 } 2582 2583 return( result ); 2584 } 2585 2586 2592 private Class getJavaTypeForQName(QName name) { 2593 if (operation == null) { 2594 return null; 2595 } 2596 ParameterDesc param = operation.getOutputParamByQName(name); 2597 return param == null ? null : param.getJavaType(); 2598 } 2599 2600 2605 public void setOption(String name, Object value) { 2606 service.getEngine().setOption(name, value); 2607 } 2608 2609 2617 public void invoke() throws AxisFault { 2618 if (log.isDebugEnabled()) { 2619 log.debug("Enter: Call::invoke()"); 2620 } 2621 2622 isNeverInvoked = false; 2623 2624 Message reqMsg = null ; 2625 SOAPEnvelope reqEnv = null ; 2626 2627 msgContext.reset(); 2628 msgContext.setResponseMessage(null); 2629 msgContext.setProperty( MessageContext.CALL, this ); 2630 msgContext.setProperty( WSDL_SERVICE, service ); 2631 msgContext.setProperty( WSDL_PORT_NAME, getPortName() ); 2632 if ( isMsg ) { 2633 msgContext.setProperty( MessageContext.IS_MSG, "true" ); 2634 } 2635 2636 if (username != null) { 2637 msgContext.setUsername(username); 2638 } 2639 if (password != null) { 2640 msgContext.setPassword(password); 2641 } 2642 msgContext.setMaintainSession(maintainSession); 2643 2644 if (operation != null) { 2645 msgContext.setOperation(operation); 2646 operation.setStyle(getOperationStyle()); 2647 operation.setUse(getOperationUse()); 2648 } 2649 2650 if (useSOAPAction) { 2651 msgContext.setUseSOAPAction(true); 2652 } 2653 if (SOAPActionURI != null) { 2654 msgContext.setSOAPActionURI(SOAPActionURI); 2655 } else { 2656 msgContext.setSOAPActionURI(null); 2657 } 2658 if (timeout != null) { 2659 msgContext.setTimeout(timeout.intValue()); 2660 } 2661 msgContext.setHighFidelity(!useStreaming); 2662 2663 if (myService != null) { 2665 msgContext.setService(myService); 2667 } else { 2668 if (portName != null) { 2669 msgContext.setTargetService(portName.getLocalPart()); 2672 } else { 2673 reqMsg = msgContext.getRequestMessage(); 2675 2676 boolean isStream = ((SOAPPart)reqMsg.getSOAPPart()).isBodyStream(); 2677 2678 if (reqMsg != null && !isStream) { 2679 reqEnv = reqMsg.getSOAPEnvelope(); 2680 2681 SOAPBodyElement body = reqEnv.getFirstBody(); 2682 2683 if (body != null) { 2684 if ( body.getNamespaceURI() == null ) { 2685 throw new AxisFault("Call.invoke", 2686 Messages.getMessage("cantInvoke00", body.getName()), 2687 null, null); 2688 } else { 2689 msgContext.setTargetService(body.getNamespaceURI()); 2690 } 2691 } 2692 } 2693 } 2694 } 2695 if (log.isDebugEnabled()) { 2696 log.debug(Messages.getMessage("targetService", 2697 msgContext.getTargetService())); 2698 } 2699 2700 Message requestMessage = msgContext.getRequestMessage(); 2701 if (requestMessage != null) { 2702 try { 2703 msgContext.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, requestMessage.getProperty(SOAPMessage.CHARACTER_SET_ENCODING)); 2704 } catch (SOAPException e) { 2705 } 2706 2707 if(myHeaders != null) { 2708 reqEnv = requestMessage.getSOAPEnvelope(); 2709 2710 for (int i = 0 ; myHeaders != null && i < myHeaders.size() ; i++ ) { 2712 reqEnv.addHeader((SOAPHeaderElement)myHeaders.get(i)); 2713 } 2714 } 2715 } 2716 2717 if (transport != null) { 2719 transport.setupMessageContext(msgContext, this, service.getEngine()); 2720 } 2721 else { 2722 msgContext.setTransportName( transportName ); 2723 } 2724 2725 SOAPService svc = msgContext.getService(); 2726 if (svc != null) { 2727 svc.setPropertyParent(myProperties); 2728 } else { 2729 msgContext.setPropertyParent(myProperties); 2730 } 2731 2732 if (log.isDebugEnabled()) { 2734 StringWriter writer = new StringWriter (); 2735 try { 2736 SerializationContext ctx = new SerializationContext(writer, 2737 msgContext); 2738 requestMessage.getSOAPEnvelope().output(ctx); 2739 writer.close(); 2740 } catch (Exception e) { 2741 throw AxisFault.makeFault(e); 2742 } finally { 2743 log.debug(writer.getBuffer().toString()); 2744 } 2745 } 2746 2747 if(!invokeOneWay) { 2748 invokeEngine(msgContext); 2749 } else { 2750 invokeEngineOneWay(msgContext); 2751 } 2752 2753 if (log.isDebugEnabled()) { 2754 log.debug("Exit: Call::invoke()"); 2755 } 2756 } 2757 2758 2764 private void invokeEngine(MessageContext msgContext) throws AxisFault { 2765 service.getEngine().invoke( msgContext ); 2766 2767 if (transport != null) { 2768 transport.processReturnedMessageContext(msgContext); 2769 } 2770 2771 Message resMsg = msgContext.getResponseMessage(); 2772 2773 if (resMsg == null) { 2774 if (msgContext.isPropertyTrue(FAULT_ON_NO_RESPONSE, false)) { 2775 throw new AxisFault(Messages.getMessage("nullResponse00")); 2776 } else { 2777 return; 2778 } 2779 } 2780 2781 2783 resMsg.setMessageType(Message.RESPONSE); 2784 2785 SOAPEnvelope resEnv = resMsg.getSOAPEnvelope(); 2786 2787 SOAPBodyElement respBody = resEnv.getFirstBody(); 2788 if (respBody instanceof SOAPFault) { 2789 if(operation == null || 2791 operation.getReturnClass() == null || 2792 operation.getReturnClass() != 2793 javax.xml.soap.SOAPMessage .class) { 2794 throw ((SOAPFault)respBody).getFault(); 2798 } 2799 } 2800 } 2801 2802 2806 private void invokeEngineOneWay(final MessageContext msgContext) { 2807 Runnable runnable = new Runnable (){ 2810 public void run() { 2811 msgContext.setProperty(Call.ONE_WAY, Boolean.TRUE); 2812 try { 2813 service.getEngine().invoke( msgContext ); 2814 } catch (AxisFault af){ 2815 log.debug(Messages.getMessage("exceptionPrinting"), af); 2817 } 2818 msgContext.removeProperty(Call.ONE_WAY); 2819 } 2820 }; 2821 Thread thread = new Thread (runnable); 2823 thread.start(); 2825 } 2826 2827 2835 public Map getOutputParams() 2836 { 2837 if (isNeverInvoked) { 2838 throw new JAXRPCException ( 2839 Messages.getMessage("outputParamsUnavailable")); 2840 } 2841 return this.outParams; 2842 } 2843 2844 2855 public List getOutputValues() { 2856 if (isNeverInvoked) { 2857 throw new JAXRPCException ( 2858 Messages.getMessage("outputParamsUnavailable")); 2859 } 2860 return outParamsList; 2861 } 2862 2863 2870 public Service getService() 2871 { 2872 return this.service; 2873 } 2874 2875 2881 public void setSOAPService(SOAPService service) 2882 { 2883 myService = service; 2884 if (service != null) { 2885 2889 service.setEngine(this.service.getAxisClient()); 2892 service.setPropertyParent(myProperties); 2893 } 2894 } 2895 2896 2901 public void setClientHandlers(Handler reqHandler, Handler respHandler) 2902 { 2903 setSOAPService(new SOAPService(reqHandler, null, respHandler)); 2906 } 2907 2908 2909 2918 public void addAttachmentPart( Object attachment){ 2919 attachmentParts.add(attachment); 2920 } 2921 2922 2932 public void addFault(QName qname, Class cls, 2933 QName xmlType, boolean isComplex) { 2934 if (operationSetManually) { 2935 throw new RuntimeException ( 2936 Messages.getMessage("operationAlreadySet")); 2937 } 2938 2939 if (operation == null) { 2940 operation = new OperationDesc(); 2941 } 2942 2943 FaultDesc fault = new FaultDesc(); 2944 fault.setQName(qname); 2945 fault.setClassName(cls.getName()); 2946 fault.setXmlType(xmlType); 2947 fault.setComplex(isComplex); 2948 operation.addFault(fault); 2949 } 2950 2951 2958 public void setOperation(OperationDesc operation) { 2959 this.operation = operation; 2960 operationSetManually = true; 2961 } 2962 2963 public OperationDesc getOperation() 2964 { 2965 return operation; 2966 } 2967 2968 public void clearOperation() { 2969 operation = null; 2970 operationSetManually = false; 2971 } 2972} | Popular Tags |