1 55 56 package org.jboss.axis; 57 58 import java.io.File ; 59 import java.util.ArrayList ; 60 import java.util.HashMap ; 61 import java.util.Hashtable ; 62 63 import javax.xml.namespace.QName ; 64 import javax.xml.rpc.Call ; 65 import javax.xml.rpc.handler.soap.SOAPMessageContext ; 66 67 import org.jboss.axis.attachments.Attachments; 68 import org.jboss.axis.client.AxisClient; 69 import org.jboss.axis.description.OperationDesc; 70 import org.jboss.axis.description.ServiceDesc; 71 import org.jboss.axis.encoding.TypeMapping; 72 import org.jboss.axis.encoding.TypeMappingRegistry; 73 import org.jboss.axis.enums.Style; 74 import org.jboss.axis.enums.Use; 75 import org.jboss.axis.handlers.soap.SOAPService; 76 import org.jboss.axis.schema.SchemaVersion; 77 import org.jboss.axis.session.Session; 78 import org.jboss.axis.soap.SOAPConstants; 79 import org.jboss.axis.utils.JavaUtils; 80 import org.jboss.axis.utils.LockableHashtable; 81 import org.jboss.axis.utils.Messages; 82 import org.jboss.logging.Logger; 83 84 108 public class MessageContext implements SOAPMessageContext 109 { 110 private static Logger log = Logger.getLogger(MessageContext.class.getName()); 111 112 117 private Message requestMessage; 118 119 124 private Message responseMessage; 125 126 130 private String targetService; 131 132 136 private String transportName; 137 138 141 private ClassLoader classLoader; 142 143 146 private AxisEngine axisEngine; 147 148 151 private Session session; 152 153 159 private boolean maintainSession = false; 160 161 164 private boolean havePassedPivot = false; 165 166 169 private int timeout = 60 * 1000; 171 176 private boolean highFidelity = true; 177 178 182 private LockableHashtable bag = new LockableHashtable(); 183 184 188 private String username = null; 189 private String password = null; 190 private String encodingStyle = Use.ENCODED.getEncoding(); 191 private boolean useSOAPAction = false; 192 private String SOAPActionURI = null; 193 194 197 private SOAPConstants soapConstants = Constants.DEFAULT_SOAP_VERSION; 198 199 202 private SchemaVersion schemaVersion = SchemaVersion.SCHEMA_2001; 203 204 207 private OperationDesc currentOperation = null; 208 209 212 private HashMap transportOptions = new HashMap (); 213 214 219 public OperationDesc getOperation() 220 { 221 return currentOperation; 222 } 223 224 229 public void setOperation(OperationDesc operation) 230 { 231 currentOperation = operation; 232 } 233 234 245 public OperationDesc[] getPossibleOperationsByQName(QName qname) throws AxisFault 246 { 247 if (currentOperation != null) 248 { 249 return new OperationDesc[]{currentOperation}; 250 } 251 252 OperationDesc[] possibleOperations = null; 253 254 if (serviceHandler == null) 255 { 256 try 257 { 258 if (log.isDebugEnabled()) 259 { 260 log.debug(Messages.getMessage("dispatching00", 261 qname.getNamespaceURI())); 262 } 263 264 setService(axisEngine.getConfig(). 266 getServiceByNamespaceURI(qname.getNamespaceURI())); 267 } 268 catch (ConfigurationException e) 269 { 270 } 272 273 } 274 275 if (serviceHandler != null) 276 { 277 ServiceDesc desc = serviceHandler.getInitializedServiceDesc(this); 278 279 if (desc != null) 280 { 281 if (desc.getStyle() != Style.DOCUMENT) 282 { 283 possibleOperations = desc.getOperationsByQName(qname); 284 } 285 else 286 { 287 ArrayList allOperations = desc.getOperations(); 291 ArrayList foundOperations = new ArrayList (); 292 for (int i = 0; i < allOperations.size(); i++) 293 { 294 OperationDesc tryOp = (OperationDesc)allOperations.get(i); 295 if (tryOp.getParamByQName(qname) != null) 296 { 297 foundOperations.add(tryOp); 298 } 299 else if (tryOp.getParamByQName(new QName (null, qname.getLocalPart())) != null) 301 { 302 foundOperations.add(tryOp); 303 } 304 } 305 306 if (foundOperations.size() == 0) 307 log.debug("Cannot find any doc style operations with param: " + qname); 308 309 if (foundOperations.size() > 0) 311 { 312 possibleOperations = (OperationDesc[])JavaUtils.convert(foundOperations, OperationDesc[].class); 313 } 314 } 315 } 316 } 317 318 if (possibleOperations == null) 319 log.debug("Cannot find any operations for: " + qname); 320 321 return possibleOperations; 322 } 323 324 334 public OperationDesc getOperationByQName(QName qname) throws AxisFault 335 { 336 if (currentOperation == null) 337 { 338 OperationDesc[] possibleOperations = getPossibleOperationsByQName(qname); 339 if (possibleOperations != null && possibleOperations.length > 0) 340 { 341 currentOperation = possibleOperations[0]; 342 } 343 } 344 345 return currentOperation; 346 } 347 348 353 public static MessageContext getCurrentContext() 354 { 355 return AxisEngine.getCurrentMessageContext(); 356 } 357 358 361 protected static String systemTempDir = null; 362 367 static 368 { 369 try 370 { 371 systemTempDir = AxisProperties.getProperty(AxisEngine.ENV_ATTACHMENT_DIR); 373 } 374 catch (Throwable t) 375 { 376 systemTempDir = null; 377 } 378 379 if (systemTempDir == null) 380 { 381 try 382 { 383 File tf = File.createTempFile("Axis", "Axis"); 386 File dir = tf.getParentFile(); 387 if (tf.exists()) 388 { 389 tf.delete(); 390 } 391 if (dir != null) 392 { 393 systemTempDir = dir.getCanonicalPath(); 394 } 395 } 396 catch (Throwable t) 397 { 398 log.debug("Unable to find a temp dir with write access"); 399 systemTempDir = null; 400 } 401 } 402 } 403 404 411 public MessageContext(AxisEngine engine) 412 { 413 this.axisEngine = engine; 414 415 if (null != engine) 416 { 417 java.util.Hashtable opts = engine.getOptions(); 418 String attachmentsdir = null; 419 if (null != opts) 420 { 421 attachmentsdir = (String )opts.get(AxisEngine.PROP_ATTACHMENT_DIR); 422 } 423 if (null == attachmentsdir) 424 { 425 attachmentsdir = systemTempDir; 426 } 427 if (attachmentsdir != null) 428 { 429 setProperty(ATTACHMENTS_DIR, attachmentsdir); 430 } 431 432 String defaultSOAPVersion = (String )engine.getOption(AxisEngine.PROP_SOAP_VERSION); 435 if (defaultSOAPVersion != null && "1.2".equals(defaultSOAPVersion)) 436 { 437 setSOAPConstants(SOAPConstants.SOAP12_CONSTANTS); 438 } 439 440 String singleSOAPVersion = (String )engine.getOption(AxisEngine.PROP_SOAP_ALLOWED_VERSION); 441 if (singleSOAPVersion != null) 442 { 443 if ("1.2".equals(singleSOAPVersion)) 444 { 445 setProperty(Constants.MC_SINGLE_SOAP_VERSION, 446 SOAPConstants.SOAP12_CONSTANTS); 447 } 448 else if ("1.1".equals(singleSOAPVersion)) 449 { 450 setProperty(Constants.MC_SINGLE_SOAP_VERSION, 451 SOAPConstants.SOAP11_CONSTANTS); 452 } 453 } 454 } 455 } 456 457 461 private TypeMappingRegistry mappingRegistry = null; 462 463 468 public void setTypeMappingRegistry(TypeMappingRegistry reg) 469 { 470 mappingRegistry = reg; 471 } 472 473 482 public TypeMappingRegistry getTypeMappingRegistry() 483 { 484 if (mappingRegistry == null) 485 { 486 return axisEngine.getTypeMappingRegistry(); 487 } 488 489 return mappingRegistry; 490 } 491 492 495 public TypeMapping getTypeMapping() 496 { 497 return (TypeMapping)getTypeMappingRegistry(). 498 getTypeMapping(encodingStyle); 499 } 500 501 504 public String getTransportName() 505 { 506 return transportName; 507 } 508 509 public void setTransportName(String transportName) 510 { 511 this.transportName = transportName; 512 } 513 514 517 public SOAPConstants getSOAPConstants() 518 { 519 return soapConstants; 520 } 521 522 public void setSOAPConstants(SOAPConstants soapConstants) 523 { 524 if (this.soapConstants.getEncodingURI().equals(encodingStyle)) 527 { 528 encodingStyle = soapConstants.getEncodingURI(); 529 } 530 531 this.soapConstants = soapConstants; 532 } 533 534 537 538 public SchemaVersion getSchemaVersion() 539 { 540 return schemaVersion; 541 } 542 543 public void setSchemaVersion(SchemaVersion schemaVersion) 544 { 545 this.schemaVersion = schemaVersion; 546 } 547 548 551 public Session getSession() 552 { 553 return session; 554 } 555 556 public void setSession(Session session) 557 { 558 this.session = session; 559 } 560 561 564 public boolean isEncoded() 565 { 566 return (getOperationUse() == Use.ENCODED); 567 } 569 570 575 public void setMaintainSession(boolean yesno) 576 { 577 maintainSession = yesno; 578 } 579 580 583 public boolean getMaintainSession() 584 { 585 return maintainSession; 586 } 587 588 593 public Message getRequestMessage() 594 { 595 return requestMessage; 596 }; 597 598 604 public void setRequestMessage(Message reqMsg) 605 { 606 requestMessage = reqMsg; 607 if (requestMessage != null) 608 { 609 requestMessage.setMessageContext(this); 610 } 611 }; 612 613 618 public Message getResponseMessage() 619 { 620 return responseMessage; 621 } 622 623 629 public void setResponseMessage(Message respMsg) 630 { 631 responseMessage = respMsg; 632 if (responseMessage != null) 633 { 634 responseMessage.setMessageContext(this); 635 636 Message reqMsg = getRequestMessage(); 639 if (null != reqMsg) 640 { 641 Attachments reqAttch = reqMsg.getAttachmentsImpl(); 642 Attachments respAttch = respMsg.getAttachmentsImpl(); 643 if (null != reqAttch && null != respAttch) 644 { 645 if (respAttch.getSendType() == Attachments.SEND_TYPE_NOTSET) 646 respAttch.setSendType(reqAttch.getSendType()); 648 } 649 } 650 } 651 } 652 653 657 public Message getCurrentMessage() 658 { 659 return (havePassedPivot ? responseMessage : requestMessage); 660 } 661 662 668 public javax.xml.soap.SOAPMessage getMessage() 669 { 670 return getCurrentMessage(); 671 } 672 673 677 public void setCurrentMessage(Message curMsg) 678 { 679 curMsg.setMessageContext(this); 680 681 if (havePassedPivot) 682 { 683 responseMessage = curMsg; 684 } 685 else 686 { 687 requestMessage = curMsg; 688 } 689 } 690 691 699 public void setMessage(javax.xml.soap.SOAPMessage message) 700 { 701 setCurrentMessage((Message)message); 702 } 703 704 707 public boolean getPastPivot() 708 { 709 return havePassedPivot; 710 } 711 712 715 public void setPastPivot(boolean pastPivot) 716 { 717 havePassedPivot = pastPivot; 718 } 719 720 725 public void setTimeout(int value) 726 { 727 timeout = value; 728 } 729 730 735 public int getTimeout() 736 { 737 return timeout; 738 } 739 740 public Object getTransportOption(String name) 741 { 742 Object transOpt = transportOptions.get(name); 743 return transOpt; 744 } 745 746 public void setTransportOption(String name, Object value) 747 { 748 transportOptions.put(name, value); 749 } 750 751 public HashMap getTransportOptions() 752 { 753 return transportOptions; 754 } 755 756 762 public ClassLoader getClassLoader() 763 { 764 if (classLoader == null) 765 { 766 classLoader = Thread.currentThread().getContextClassLoader(); 767 } 768 return (classLoader); 769 } 770 771 776 public void setClassLoader(ClassLoader cl) 777 { 778 classLoader = cl; 779 } 780 781 public String getTargetService() 782 { 783 return (targetService); 784 } 785 786 792 public AxisEngine getAxisEngine() 793 { 794 return axisEngine; 795 } 796 797 806 public void setTargetService(String tServ) throws AxisFault 807 { 808 log.debug("MessageContext: setTargetService(" + tServ + ")"); 809 810 if (tServ == null) 811 { 812 setService(null); 813 } 814 else 815 { 816 try 817 { 818 SOAPService service = getAxisEngine().getService(tServ); 819 setService(service); 820 } 821 catch (AxisFault fault) 822 { 823 if (!isClient()) 825 { 826 throw fault; 827 } 828 } 829 } 830 targetService = tServ; 831 } 832 833 838 private SOAPService serviceHandler; 839 840 public SOAPService getService() 841 { 842 return (serviceHandler); 843 } 844 845 public void setService(SOAPService sh) throws AxisFault 846 { 847 log.debug("MessageContext: setServiceHandler(" + sh + ")"); 848 serviceHandler = sh; 849 if (sh != null) 850 { 851 targetService = sh.getName(); 852 SOAPService service = sh; 853 TypeMappingRegistry tmr = service.getTypeMappingRegistry(); 854 setTypeMappingRegistry(tmr); 855 856 setEncodingStyle(service.getUse().getEncoding()); 858 859 bag.setParent(sh.getOptions()); 862 863 highFidelity = service.needsHighFidelityRecording(); 867 868 service.getInitializedServiceDesc(this); 869 } 870 } 871 872 875 public boolean isClient() 876 { 877 return (axisEngine instanceof AxisClient); 878 } 879 880 887 public final static String ENGINE_HANDLER = "engine.handler"; 888 889 892 public final static String TRANS_URL = "transport.url"; 893 894 897 public final static String QUIT_REQUESTED = "quit.requested"; 898 899 902 public final static String AUTHUSER = "authenticatedUser"; 903 904 907 public final static String CALL = "call_object"; 908 909 912 public final static String IS_MSG = "isMsg"; 913 914 917 public final static String ATTACHMENTS_DIR = "attachments.directory"; 918 919 923 public final static String ACCEPTMISSINGPARAMS = "acceptMissingParams"; 924 925 929 public final static String WSDLGEN_INTFNAMESPACE = "axis.wsdlgen.intfnamespace"; 930 931 936 public final static String WSDLGEN_SERV_LOC_URL = "axis.wsdlgen.serv.loc.url"; 937 938 942 public final static String WSDLGEN_RESOURCE = "axis.wsdlgen.resource"; 943 944 952 public final static String HTTP_TRANSPORT_VERSION = "axis.transport.version"; 953 954 public static final String SECURITY_PROVIDER = "securityProvider"; 955 956 961 962 965 public String getStrProp(String propName) 966 { 967 return ((String )getProperty(propName)); 968 } 969 970 979 public boolean isPropertyTrue(String propName) 980 { 981 return isPropertyTrue(propName, false); 982 } 983 984 993 public boolean isPropertyTrue(String propName, boolean defaultVal) 994 { 995 return JavaUtils.isTrue(getProperty(propName), defaultVal); 996 } 997 998 1011 public void setProperty(String name, Object value) 1012 { 1013 if (name == null || value == null) 1014 { 1015 return; 1016 } 1019 else if (name.equals(Call.USERNAME_PROPERTY)) 1020 { 1021 if (!(value instanceof String )) 1022 { 1023 throw new IllegalArgumentException (Messages.getMessage("badProp00", new String []{ 1024 name, "java.lang.String", value.getClass().getName()})); 1025 } 1026 setUsername((String )value); 1027 } 1028 else if (name.equals(Call.PASSWORD_PROPERTY)) 1029 { 1030 if (!(value instanceof String )) 1031 { 1032 throw new IllegalArgumentException (Messages.getMessage("badProp00", new String []{ 1033 name, "java.lang.String", value.getClass().getName()})); 1034 } 1035 setPassword((String )value); 1036 } 1037 else if (name.equals(Call.SESSION_MAINTAIN_PROPERTY)) 1038 { 1039 if (!(value instanceof Boolean )) 1040 { 1041 throw new IllegalArgumentException (Messages.getMessage("badProp00", new String [] 1042 {name, 1043 "java.lang.Boolean", 1044 value.getClass().getName()})); 1045 } 1046 setMaintainSession(((Boolean )value).booleanValue()); 1047 } 1048 else if (name.equals(Call.SOAPACTION_USE_PROPERTY)) 1049 { 1050 if (!(value instanceof Boolean )) 1051 { 1052 throw new IllegalArgumentException (Messages.getMessage("badProp00", new String [] 1053 {name, 1054 "java.lang.Boolean", 1055 value.getClass().getName()})); 1056 } 1057 setUseSOAPAction(((Boolean )value).booleanValue()); 1058 } 1059 else if (name.equals(Call.SOAPACTION_URI_PROPERTY)) 1060 { 1061 if (!(value instanceof String )) 1062 { 1063 throw new IllegalArgumentException (Messages.getMessage("badProp00", new String [] 1064 {name, 1065 "java.lang.String", 1066 value.getClass().getName()})); 1067 } 1068 setSOAPActionURI((String )value); 1069 } 1070 else if (name.equals(Call.ENCODINGSTYLE_URI_PROPERTY)) 1071 { 1072 if (!(value instanceof String )) 1073 { 1074 throw new IllegalArgumentException (Messages.getMessage("badProp00", new String [] 1075 {name, 1076 "java.lang.String", 1077 value.getClass().getName()})); 1078 } 1079 setEncodingStyle((String )value); 1080 } 1081 else 1082 { 1083 bag.put(name, value); 1084 } 1085 } 1087 1094 public boolean containsProperty(String name) 1095 { 1096 Object propertyValue = getProperty(name); 1097 return (propertyValue != null); 1098 } 1099 1100 1105 public java.util.Iterator getPropertyNames() 1106 { 1107 return bag.keySet().iterator(); 1108 } 1109 1110 1116 public Object getProperty(String name) 1117 { 1118 if (name != null) 1119 { 1120 if (name.equals(Call.USERNAME_PROPERTY)) 1121 { 1122 return getUsername(); 1123 } 1124 else if (name.equals(Call.PASSWORD_PROPERTY)) 1125 { 1126 return getPassword(); 1127 } 1128 else if (name.equals(Call.SESSION_MAINTAIN_PROPERTY)) 1129 { 1130 return new Boolean (getMaintainSession()); 1131 } 1132 else if (name.equals(Call.OPERATION_STYLE_PROPERTY)) 1133 { 1134 return (getOperationStyle() == null) ? null : getOperationStyle().getName(); 1135 } 1136 else if (name.equals(Call.SOAPACTION_USE_PROPERTY)) 1137 { 1138 return new Boolean (useSOAPAction()); 1139 } 1140 else if (name.equals(Call.SOAPACTION_URI_PROPERTY)) 1141 { 1142 return getSOAPActionURI(); 1143 } 1144 else if (name.equals(Call.ENCODINGSTYLE_URI_PROPERTY)) 1145 { 1146 return getEncodingStyle(); 1147 } 1148 else if (bag == null) 1149 { 1150 return null; 1151 } 1152 else 1153 { 1154 return bag.get(name); 1155 } 1156 } 1157 else 1158 { 1159 return null; 1160 } 1161 } 1162 1163 public void setPropertyParent(Hashtable parent) 1164 { 1165 bag.setParent(parent); 1166 } 1167 1168 1171 public void setUsername(String username) 1172 { 1173 this.username = username; 1174 } 1176 1179 public String getUsername() 1180 { 1181 return username; 1182 } 1184 1187 public void setPassword(String password) 1188 { 1189 this.password = password; 1190 } 1192 1195 public String getPassword() 1196 { 1197 return password; 1198 } 1200 1203 public Style getOperationStyle() 1204 { 1205 if (currentOperation != null) 1206 { 1207 return currentOperation.getStyle(); 1208 } 1209 1210 if (serviceHandler != null) 1211 { 1212 return serviceHandler.getStyle(); 1213 } 1214 1215 return Style.RPC; 1216 } 1218 1221 public Use getOperationUse() 1222 { 1223 if (currentOperation != null) 1224 { 1225 return currentOperation.getUse(); 1226 } 1227 1228 if (serviceHandler != null) 1229 { 1230 return serviceHandler.getUse(); 1231 } 1232 1233 return Use.ENCODED; 1234 } 1236 1239 public void setUseSOAPAction(boolean useSOAPAction) 1240 { 1241 this.useSOAPAction = useSOAPAction; 1242 } 1244 1247 public boolean useSOAPAction() 1248 { 1249 return useSOAPAction; 1250 } 1252 1255 public void setSOAPActionURI(String SOAPActionURI) 1256 throws IllegalArgumentException 1257 { 1258 this.SOAPActionURI = SOAPActionURI; 1259 } 1261 1264 public String getSOAPActionURI() 1265 { 1266 return SOAPActionURI; 1267 } 1269 1274 public void setEncodingStyle(String namespaceURI) 1275 { 1276 if (namespaceURI == null) 1277 { 1278 namespaceURI = Constants.URI_LITERAL_ENC; 1279 } 1280 else if (Constants.isSOAP_ENC(namespaceURI)) 1281 { 1282 namespaceURI = soapConstants.getEncodingURI(); 1283 } 1284 1285 encodingStyle = namespaceURI; 1286 } 1288 1294 public String getEncodingStyle() 1295 { 1296 return encodingStyle; 1297 } 1299 public void removeProperty(String propName) 1300 { 1301 if (bag != null) 1302 { 1303 bag.remove(propName); 1304 } 1305 } 1306 1307 public void reset() 1308 { 1309 if (bag != null) 1310 { 1311 bag.clear(); 1312 } 1313 serviceHandler = null; 1314 havePassedPivot = false; 1315 currentOperation = null; 1316 } 1317 1318 public boolean isHighFidelity() 1319 { 1320 return highFidelity; 1321 } 1322 1323 public void setHighFidelity(boolean highFidelity) 1324 { 1325 this.highFidelity = highFidelity; 1326 } 1327 1328 1341 public String [] getRoles() 1342 { 1343 return null; 1345 } 1346} 1347 | Popular Tags |