1 13 package com.tonbeller.jpivot.xmla; 14 15 import java.io.StringWriter ; 16 import java.io.Writer ; 17 import java.net.MalformedURLException ; 18 import java.net.URL ; 19 import java.util.ArrayList ; 20 import java.util.HashMap ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 import java.util.Map ; 24 25 import javax.xml.soap.Detail ; 26 import javax.xml.soap.DetailEntry ; 27 import javax.xml.soap.MessageFactory ; 28 import javax.xml.soap.MimeHeaders ; 29 import javax.xml.soap.Name ; 30 import javax.xml.soap.Node ; 31 import javax.xml.soap.SOAPBody ; 32 import javax.xml.soap.SOAPConnection ; 33 import javax.xml.soap.SOAPConnectionFactory ; 34 import javax.xml.soap.SOAPElement ; 35 import javax.xml.soap.SOAPEnvelope ; 36 import javax.xml.soap.SOAPException ; 37 import javax.xml.soap.SOAPFault ; 38 import javax.xml.soap.SOAPMessage ; 39 import javax.xml.soap.SOAPPart ; 40 import javax.xml.transform.Source ; 41 import javax.xml.transform.Transformer ; 42 import javax.xml.transform.TransformerFactory ; 43 import javax.xml.transform.stream.StreamResult ; 44 45 import org.apache.log4j.Logger; 46 47 import com.tonbeller.jpivot.olap.model.OlapDiscoverer; 48 import com.tonbeller.jpivot.olap.model.OlapException; 49 import com.tonbeller.jpivot.olap.model.OlapItem; 50 import com.tonbeller.jpivot.olap.model.QueryResultHandler; 51 52 55 public class XMLA_SOAP implements OlapDiscoverer { 56 57 static final String MDD_URI = "urn:schemas-microsoft-com:xml-analysis:mddataset"; 58 static final String ROWS_URI = "urn:schemas-microsoft-com:xml-analysis:rowset"; 59 static final String XMLA_URI = "urn:schemas-microsoft-com:xml-analysis"; 60 static final String XSI_URI = "http://www.w3.org/2001/XMLSchema-instance"; 61 62 static Logger logger = Logger.getLogger(XMLA_SOAP.class); 63 64 private SOAPConnectionFactory scf = null; 65 private MessageFactory mf = null; 66 67 private int provider = 0; 68 69 private String uri; 70 private URL url; 71 private String dataSource; 72 73 private String user; 74 private String password; 75 76 interface Rowhandler { 77 void handleRow(SOAPElement eRow, SOAPEnvelope envelope); 78 } 79 80 88 public XMLA_SOAP(String uri, String user, String password) throws OlapException { 89 logger.debug("Constructor: straight DiscoverDS"); 90 init(uri, user, password); 91 92 setProviderAndDataSource(this.discoverDS()); 93 } 94 95 104 public XMLA_SOAP(String uri, String user, String password, String dataSource) 105 throws OlapException { 106 logger.debug("Constructor: given dataSource= " + dataSource); 107 init(uri, user, password); 108 109 this.dataSource = dataSource; 110 provider = determineProvider(dataSource); 111 112 } 113 114 123 public XMLA_SOAP(String uri, String user, String password, int newProvider) throws OlapException { 124 logger.debug("Constructor: given provider= " + newProvider); 125 init(uri, user, password); 126 provider = newProvider; 127 setProviderAndDataSource(discoverDS()); 128 } 129 130 133 private void init(String uri, String user, String password) throws OlapException { 134 try { 135 scf = SOAPConnectionFactory.newInstance(); 136 mf = MessageFactory.newInstance(); 137 } catch (UnsupportedOperationException e) { 138 throw new OlapException(e); 139 } catch (SOAPException e) { 140 throw new OlapException(e); 141 } 142 143 this.uri = uri; 144 this.user = user; 145 this.password = password; 146 try { 147 url = new URL (uri); 148 } catch (MalformedURLException e1) { 149 throw new OlapException(e1); 150 } 151 152 if (user != null && user.length() > 0) { 153 String newUri = url.getProtocol() + "://" + user; 154 if (password != null && password.length() > 0) { 155 newUri += ":" + password; 156 } 157 newUri += "@" + url.getHost() + ":" + url.getPort() + url.getPath(); 158 159 try { 160 url = new URL (newUri); 161 } catch (MalformedURLException e2) { 162 throw new OlapException(e2); 163 } 164 } 165 } 166 167 172 public List discoverCat() throws OlapException { 173 final List cats = new ArrayList (); 174 175 HashMap rHash = new HashMap (); 178 HashMap pHash = new HashMap (); 180 pHash.put("DataSourceInfo", dataSource); 181 pHash.put("Content", "SchemaData"); 182 183 Rowhandler rh = new Rowhandler() { 184 public void handleRow(SOAPElement eRow, SOAPEnvelope envelope) { 185 186 XMLA_OlapItem oi = new XMLA_OlapItem(OlapItem.TYPE_CATALOG); 187 cats.add(oi); 188 Iterator it = eRow.getChildElements(); 189 while (it.hasNext()) { 190 Object o = it.next(); 191 if (!(o instanceof SOAPElement )) 192 continue; 193 SOAPElement e = (SOAPElement ) o; 194 String lname = e.getElementName().getLocalName(); 195 if (lname.equals("CATALOG_NAME")) 196 oi.setName(e.getValue()); 197 else 198 oi.setProperty(lname, e.getValue()); 199 } 200 } 201 }; 202 203 discover("DBSCHEMA_CATALOGS", url, rHash, pHash, rh); 204 logger.debug("DBSCHEMA_CATALOGS: found " + cats.size()); 205 206 return cats; 207 } 208 209 214 public List discoverDSProps() throws OlapException { 215 final List props = new ArrayList (); 216 217 HashMap rHash = new HashMap (); 220 HashMap pHash = new HashMap (); 222 pHash.put("DataSourceInfo", dataSource); 223 pHash.put("Content", "SchemaData"); 224 225 Rowhandler rh = new Rowhandler() { 226 public void handleRow(SOAPElement eRow, SOAPEnvelope envelope) { 227 228 XMLA_OlapItem oi = new XMLA_OlapItem(OlapItem.TYPE_PROPERTY); 229 props.add(oi); 230 Iterator it = eRow.getChildElements(); 231 while (it.hasNext()) { 232 Object o = it.next(); 233 if (!(o instanceof SOAPElement )) 234 continue; 235 SOAPElement e = (SOAPElement ) o; 236 String lname = e.getElementName().getLocalName(); 237 if ( lname.equals("PropertyName") ) 238 oi.setName( e.getValue()); 239 oi.setProperty(lname, e.getValue()); 240 } 241 } 242 }; 243 244 discover("DISCOVER_PROPERTIES", url, rHash, pHash, rh); 245 logger.debug("DISCOVER_PROPERTIES: found " + props.size()); 246 247 return props; 248 } 249 250 255 public List discoverCube(String cat) throws OlapException { 256 final List cubes = new ArrayList (); 257 HashMap rHash = new HashMap (); 259 rHash.put("CATALOG_NAME", cat); 260 261 HashMap pHash = new HashMap (); 263 pHash.put("DataSourceInfo", dataSource); 264 pHash.put("Content", "SchemaData"); 265 pHash.put("Catalog", cat); 267 Rowhandler rh = new Rowhandler() { 268 public void handleRow(SOAPElement eRow, SOAPEnvelope envelope) { 269 270 XMLA_OlapItem oi = new XMLA_OlapItem(OlapItem.TYPE_CUBE); 271 cubes.add(oi); 272 273 Iterator it = eRow.getChildElements(); 274 while (it.hasNext()) { 275 Object o = it.next(); 276 if (!(o instanceof SOAPElement )) 277 continue; 278 SOAPElement e = (SOAPElement ) o; 279 String lname = e.getElementName().getLocalName(); 280 if (lname.equals("CUBE_NAME")) 281 oi.setName(e.getValue()); 282 else 283 oi.setProperty(lname, e.getValue()); 284 } 285 } 286 287 }; 288 discover("MDSCHEMA_CUBES", url, rHash, pHash, rh); 289 logger.debug("MDSCHEMA_CUBES: found " + cubes.size()); 290 return cubes; 291 } 292 293 298 public List discoverDim(String cat, String cube) throws OlapException { 299 final List dims = new ArrayList (); 300 HashMap rHash = new HashMap (); 302 rHash.put("CATALOG_NAME", cat); 303 rHash.put("CUBE_NAME", cube); 304 305 HashMap pHash = new HashMap (); 307 pHash.put("DataSourceInfo", dataSource); 308 pHash.put("Catalog", cat); pHash.put("Content", "SchemaData"); 310 311 Rowhandler rh = new Rowhandler() { 312 public void handleRow(SOAPElement eRow, SOAPEnvelope envelope) { 313 XMLA_OlapItem oi = new XMLA_OlapItem(OlapItem.TYPE_DIMENSION); 314 dims.add(oi); 315 316 Iterator it = eRow.getChildElements(); 317 while (it.hasNext()) { 318 Object o = it.next(); 319 if (!(o instanceof SOAPElement )) 320 continue; 321 SOAPElement e = (SOAPElement ) o; 322 323 String lname = e.getElementName().getLocalName(); 324 if (lname.equals("DIMENSION_UNIQUE_NAME")) { 325 oi.setUniqueName(e.getValue()); 326 } else if (lname.equals("DIMENSION_CAPTION")) { 327 oi.setCaption(e.getValue()); 328 } else if (lname.equals("DIMENSION_NAME")) { 329 oi.setName(e.getValue()); 330 } else { 331 oi.setProperty(lname, e.getValue()); 332 } 333 334 } 335 } 336 337 }; 338 339 discover("MDSCHEMA_DIMENSIONS", url, rHash, pHash, rh); 340 logger.debug("MDSCHEMA_DIMENSIONS: found " + dims.size()); 341 if (dims.size() == 0) { 342 throw new OlapException("No metadata schema dimensions for catalog: " + cat + " and cube: " + cube); 343 } 344 return dims; 345 } 346 347 352 public List discoverHier(String cat, String cube, String dimension) throws OlapException { 353 final List hiers = new ArrayList (); 354 355 HashMap rHash = new HashMap (); 357 rHash.put("CATALOG_NAME", cat); 358 rHash.put("CUBE_NAME", cube); 359 if (dimension != null) 360 rHash.put("DIMENSION_UNIQUE_NAME", dimension); 361 362 HashMap pHash = new HashMap (); 364 pHash.put("DataSourceInfo", dataSource); 365 pHash.put("Catalog", cat); pHash.put("Content", "SchemaData"); 367 368 Rowhandler rh = new Rowhandler() { 369 public void handleRow(SOAPElement eRow, SOAPEnvelope envelope) { 370 XMLA_OlapItem oi = new XMLA_OlapItem(OlapItem.TYPE_HIERARCHY); 371 hiers.add(oi); 372 373 Iterator it = eRow.getChildElements(); 374 while (it.hasNext()) { 375 Object o = it.next(); 376 if (!(o instanceof SOAPElement )) 377 continue; 378 SOAPElement e = (SOAPElement ) o; 379 String lname = e.getElementName().getLocalName(); 380 if (lname.equals("HIERARCHY_UNIQUE_NAME")) { 381 oi.setUniqueName(e.getValue()); 382 } else if (lname.equals("HIERARCHY_CAPTION")) { 383 oi.setCaption(e.getValue()); 384 } else if (lname.equals("HIERARCHY_NAME")) { 385 oi.setName(e.getValue()); 386 } else { 387 oi.setProperty(lname, e.getValue()); 388 } 389 } 390 } 391 392 }; 393 394 discover("MDSCHEMA_HIERARCHIES", url, rHash, pHash, rh); 395 logger.debug("MDSCHEMA_HIERARCHIES: found " + hiers.size()); 396 if (hiers.size() == 0) { 397 throw new OlapException("No metadata schema hierarchies for catalog: " + cat + " and cube: " + cube); 398 } 399 return hiers; 400 } 401 402 407 public List discoverLev(String cat, String cube, String dimension, String hier) 408 throws OlapException { 409 410 final List levels = new ArrayList (); 411 412 HashMap rHash = new HashMap (); 414 rHash.put("CATALOG_NAME", cat); 415 rHash.put("CUBE_NAME", cube); 416 if (dimension != null) 417 rHash.put("DIMENSION_UNIQUE_NAME", dimension); 418 if (hier != null) 419 rHash.put("HIERARCHY_UNIQUE_NAME", dimension); 420 421 HashMap pHash = new HashMap (); 423 pHash.put("DataSourceInfo", dataSource); 424 pHash.put("Catalog", cat); pHash.put("Content", "SchemaData"); 426 427 Rowhandler rh = new Rowhandler() { 428 public void handleRow(SOAPElement eRow, SOAPEnvelope envelope) { 429 430 XMLA_OlapItem oi = new XMLA_OlapItem(OlapItem.TYPE_LEVEL); 431 levels.add(oi); 432 433 Iterator it = eRow.getChildElements(); 434 while (it.hasNext()) { 435 Object o = it.next(); 436 if (!(o instanceof SOAPElement )) 437 continue; 438 SOAPElement e = (SOAPElement ) o; 439 440 String lname = e.getElementName().getLocalName(); 441 if (lname.equals("LEVEL_UNIQUE_NAME")) { 442 oi.setUniqueName(e.getValue()); 443 } else if (lname.equals("LEVEL_CAPTION")) { 444 oi.setCaption(e.getValue()); 445 } else if (lname.equals("LEVEL_NAME")) { 446 oi.setName(e.getValue()); 447 } else { 448 oi.setProperty(lname, e.getValue()); 449 } 450 } 451 } 452 453 }; 454 455 discover("MDSCHEMA_LEVELS", url, rHash, pHash, rh); 456 logger.debug("MDSCHEMA_LEVELS: found " + levels.size()); 457 if (levels.size() == 0) { 458 throw new OlapException("No metadata schema levels for catalog: " + cat + " and cube: " + cube); 459 } 460 return levels; 461 } 462 463 468 public List discoverMem(String cat, String cube, String dimension, String hierarchy, String level) 469 throws OlapException { 470 final List mems = new ArrayList (); 471 472 HashMap rHash = new HashMap (); 474 rHash.put("CATALOG_NAME", cat); 475 rHash.put("CUBE_NAME", cube); 476 if (dimension != null) 477 rHash.put("DIMENSION_UNIQUE_NAME", dimension); 478 if (hierarchy != null) 479 rHash.put("HIERARCHY_UNIQUE_NAME", hierarchy); 480 if (level != null) 481 rHash.put("LEVEL_UNIQUE_NAME", level); 482 483 HashMap pHash = new HashMap (); 485 pHash.put("DataSourceInfo", dataSource); 486 pHash.put("Catalog", cat); pHash.put("Content", "SchemaData"); 488 489 Rowhandler rh = new Rowhandler() { 490 491 public void handleRow(SOAPElement eRow, SOAPEnvelope envelope) { 492 493 XMLA_OlapItem oi = new XMLA_OlapItem(OlapItem.TYPE_MEMBER); 494 mems.add(oi); 495 496 Iterator it = eRow.getChildElements(); 497 while (it.hasNext()) { 498 Object o = it.next(); 499 if (!(o instanceof SOAPElement )) 500 continue; 501 SOAPElement e = (SOAPElement ) o; 502 503 String lname = e.getElementName().getLocalName(); 504 if (lname.equals("MEMBER_UNIQUE_NAME")) { 505 oi.setUniqueName(e.getValue()); 506 } else if (lname.equals("MEMBER_CAPTION")) { 507 oi.setCaption(e.getValue()); 508 } else if (lname.equals("MEMBER_NAME")) { 509 oi.setName(e.getValue()); 510 } else { 511 oi.setProperty(lname, e.getValue()); 512 } 513 } 514 } 515 516 }; 517 518 discover("MDSCHEMA_MEMBERS", url, rHash, pHash, rh); 519 logger.debug("MDSCHEMA_MEMBERS: found " + mems.size()); 520 if (mems.size() == 0) { 521 logger.error("No metadata schema members for catalog: " + cat + " and cube: " + cube); 522 } 523 524 return mems; 525 } 526 527 543 544 public List discoverMemTree(String cat, String cube, String member, int treeop) 545 throws OlapException { 546 final List mems = new ArrayList (); 547 548 HashMap rHash = new HashMap (); 550 rHash.put("CATALOG_NAME", cat); 551 rHash.put("CUBE_NAME", cube); 552 rHash.put("MEMBER_UNIQUE_NAME", member); 553 rHash.put("TREE_OP", String.valueOf(treeop)); 554 555 HashMap pHash = new HashMap (); 557 pHash.put("DataSourceInfo", dataSource); 558 pHash.put("Catalog", cat); pHash.put("Content", "SchemaData"); 560 561 Rowhandler rh = new Rowhandler() { 562 563 public void handleRow(SOAPElement eRow, SOAPEnvelope envelope) { 564 565 XMLA_OlapItem oi = new XMLA_OlapItem(OlapItem.TYPE_MEMBER); 566 mems.add(oi); 567 568 Iterator it = eRow.getChildElements(); 569 while (it.hasNext()) { 570 Object o = it.next(); 571 if (!(o instanceof SOAPElement )) 572 continue; 573 SOAPElement e = (SOAPElement ) o; 574 575 String lname = e.getElementName().getLocalName(); 576 if (lname.equals("MEMBER_UNIQUE_NAME")) { 577 oi.setUniqueName(e.getValue()); 578 } else if (lname.equals("MEMBER_CAPTION")) { 579 oi.setCaption(e.getValue()); 580 } else if (lname.equals("MEMBER_NAME")) { 581 oi.setName(e.getValue()); 582 } else { 583 oi.setProperty(lname, e.getValue()); 584 } 585 } 586 } 587 588 }; 589 590 discover("MDSCHEMA_MEMBERS", url, rHash, pHash, rh); 591 logger.debug("MDSCHEMA_MEMBERS Tree: found " + mems.size()); 592 if (mems.size() == 0) { 593 logger.error("No metadata schema members tree for catalog: " + cat + " and cube: " + cube + 594 ", member unique name: " + member + ", tree operation: " + String.valueOf(treeop)); 595 } 596 return mems; 597 } 598 599 604 public Map discoverDS() throws OlapException { 605 HashMap rHash = new HashMap (); 607 608 HashMap pHash = new HashMap (); 609 pHash.put("Content", "Data"); 610 final Map resultMap = new HashMap (); 611 Rowhandler rh = new Rowhandler() { 612 613 public void handleRow(SOAPElement eRow, SOAPEnvelope envelope) { 614 615 624 Iterator it = eRow.getChildElements(); 625 while (it.hasNext()) { 626 Object o = it.next(); 627 if (!(o instanceof SOAPElement )) 628 continue; SOAPElement e = (SOAPElement ) o; 630 String name = e.getElementName().getLocalName(); 631 String value = e.getValue(); 632 resultMap.put(name, value); 633 } 634 } 635 }; 636 637 discover("DISCOVER_DATASOURCES", url, rHash, pHash, rh); 638 logger.debug("DISCOVER_DATASOURCES: found " + resultMap.size()); 639 return resultMap; 640 641 } 642 643 654 public List discoverProp(String cat, String cube, String dimension, String hierarchy, String level) 655 throws OlapException { 656 final List props = new ArrayList (); 657 658 HashMap rHash = new HashMap (); 660 rHash.put("CATALOG_NAME", cat); 661 rHash.put("CUBE_NAME", cube); 662 if (dimension != null) 663 rHash.put("DIMENSION_UNIQUE_NAME", dimension); 664 if (hierarchy != null) 665 rHash.put("HIERARCHY_UNIQUE_NAME", hierarchy); 666 if (level != null) 667 rHash.put("LEVEL_UNIQUE_NAME", level); 668 669 HashMap pHash = new HashMap (); 671 pHash.put("DataSourceInfo", dataSource); 672 pHash.put("Catalog", cat); pHash.put("Content", "SchemaData"); 674 675 Rowhandler rh = new Rowhandler() { 676 677 public void handleRow(SOAPElement eRow, SOAPEnvelope envelope) { 678 XMLA_OlapItem oi = new XMLA_OlapItem(OlapItem.TYPE_PROPERTY); 679 props.add(oi); 680 681 Iterator it = eRow.getChildElements(); 682 while (it.hasNext()) { 683 Object o = it.next(); 684 if (!(o instanceof SOAPElement )) 685 continue; 686 SOAPElement e = (SOAPElement ) o; 687 688 String lname = e.getElementName().getLocalName(); 689 if (lname.equals("PROPERTY_NAME")) { 690 oi.setName(e.getValue()); 691 } else if (lname.equals("PROPERTY_CAPTION")) { 692 oi.setCaption(e.getValue()); 693 } else { 694 oi.setProperty(lname, e.getValue()); 695 } 696 } 697 698 } 699 }; 700 701 discover("MDSCHEMA_PROPERTIES", url, rHash, pHash, rh); 702 logger.debug("MDSCHEMA_PROPERTIES: found " + props.size()); 703 704 return props; 705 } 706 707 715 public List discoverSapVar(String cat, String cube) throws OlapException { 716 final List props = new ArrayList (); 717 718 HashMap rHash = new HashMap (); 720 rHash.put("CATALOG_NAME", cat); 721 rHash.put("CUBE_NAME", cube); 722 723 HashMap pHash = new HashMap (); 725 pHash.put("DataSourceInfo", dataSource); 726 pHash.put("Catalog", cat); pHash.put("Content", "SchemaData"); 728 729 Rowhandler rh = new Rowhandler() { 730 731 public void handleRow(SOAPElement eRow, SOAPEnvelope envelope) { 732 XMLA_OlapItem oi = new XMLA_OlapItem(OlapItem.TYPE_PROPERTY); 733 props.add(oi); 734 735 Iterator it = eRow.getChildElements(); 736 while (it.hasNext()) { 737 Object o = it.next(); 738 if (!(o instanceof SOAPElement )) 739 continue; 740 SOAPElement e = (SOAPElement ) o; 741 742 String lname = e.getElementName().getLocalName(); 743 if (lname.equals("VARIABLE_NAME")) { 744 oi.setName(e.getValue()); 746 } else if (lname.equals("VARIABLE_CAPTION")) { oi.setCaption(e.getValue()); 748 } else { 749 oi.setProperty(lname, e.getValue()); 750 } 751 } 752 753 } 754 }; 755 756 discover("SAP_VARIABLES", url, rHash, pHash, rh); 757 758 return props; 759 } 760 761 768 public void executeQuery(String query, String catalog, QueryResultHandler handler) 769 throws OlapException { 770 771 SOAPConnection connection = null; 772 SOAPMessage reply = null; 773 774 try { 775 connection = scf.createConnection(); 776 SOAPMessage msg = mf.createMessage(); 777 778 MimeHeaders mh = msg.getMimeHeaders(); 779 mh.setHeader("SOAPAction", "\"urn:schemas-microsoft-com:xml-analysis:Execute\""); 780 781 SOAPPart soapPart = msg.getSOAPPart(); 782 SOAPEnvelope envelope = soapPart.getEnvelope(); 783 SOAPBody body = envelope.getBody(); 784 Name nEx = envelope.createName("Execute", "", XMLA_URI); 785 786 SOAPElement eEx = body.addChildElement(nEx); 787 788 790 Name nCom = envelope.createName("Command", "", XMLA_URI); 795 SOAPElement eCommand = eEx.addChildElement(nCom); 796 Name nSta = envelope.createName("Statement", "", XMLA_URI); 797 SOAPElement eStatement = eCommand.addChildElement(nSta); 798 eStatement.addTextNode(query); 799 800 Map paraList = new HashMap (); 809 paraList.put("DataSourceInfo", dataSource); 810 paraList.put("Catalog", catalog); 811 paraList.put("Format", "Multidimensional"); 812 paraList.put("AxisFormat", "TupleFormat"); 813 addParameterList(envelope, eEx, "Properties", "PropertyList", paraList); 814 msg.saveChanges(); 815 816 reply = connection.call(msg, url); 818 if (logger.isDebugEnabled()) { 819 logger.debug("Reply from Execute"); 820 logSoapMsg(reply); 822 } 823 824 errorCheck(reply); 826 828 SOAPElement eRoot = findExecRoot(reply); 829 830 Name name = envelope.createName("OlapInfo", "", MDD_URI); 832 SOAPElement eOlapInfo = selectSingleNode(eRoot, name); 833 if (eOlapInfo == null) 834 throw new OlapException("Excecute result has no eOlapInfo element"); 835 836 name = envelope.createName("AxesInfo", "", MDD_URI); 837 SOAPElement eAxesInfo = selectSingleNode(eOlapInfo, name); 838 if (eAxesInfo == null) 839 throw new OlapException("Excecute result has no AxesInfo element"); 840 841 name = envelope.createName("AxisInfo", "", MDD_URI); 842 Iterator itAxisInfo = eAxesInfo.getChildElements(name); 843 844 int iOrdinal = 0; 845 AxisInfoLoop: while (itAxisInfo.hasNext()) { 846 SOAPElement eAxisInfo = (SOAPElement ) itAxisInfo.next(); 847 848 name = envelope.createName("name"); 849 String axisName = eAxisInfo.getAttributeValue(name); 850 int axisOrdinal; 851 if (axisName.equals("SlicerAxis")) 852 axisOrdinal = -1; 853 else 854 axisOrdinal = iOrdinal++; 855 856 handler.handleAxisInfo(axisName, axisOrdinal); 857 858 name = envelope.createName("HierarchyInfo", "", MDD_URI); 860 Iterator itHierInfo = eAxisInfo.getChildElements(name); 861 862 int hierNumber = 0; 863 HierInfoLoop: while (itHierInfo.hasNext()) { 864 SOAPElement eHierInfo = (SOAPElement ) itHierInfo.next(); 865 name = envelope.createName("name"); 866 String hierName = eHierInfo.getAttributeValue(name); 867 handler.handleHierInfo(hierName, axisOrdinal, hierNumber++); 868 } 870 } 872 name = envelope.createName("Axes", "", MDD_URI); 874 SOAPElement eAxes = selectSingleNode(eRoot, name); 875 if (eAxes == null) 876 throw new OlapException("Excecute result has no Axes element"); 877 878 name = envelope.createName("Axis", "", MDD_URI); 879 Iterator itAxis = eAxes.getChildElements(name); 880 881 AxisLoop: for (iOrdinal = 0; itAxis.hasNext();) { 882 SOAPElement eAxis = (SOAPElement ) itAxis.next(); 883 name = envelope.createName("name"); 884 String axisName = eAxis.getAttributeValue(name); 885 int axisOrdinal; 886 if (axisName.equals("SlicerAxis")) 887 axisOrdinal = -1; 888 else 889 axisOrdinal = iOrdinal++; 890 891 handler.handleAxis(axisName, axisOrdinal); 892 893 name = envelope.createName("Tuples", "", MDD_URI); 894 SOAPElement eTuples = selectSingleNode(eAxis, name); 895 if (eTuples == null) 896 continue AxisLoop; 898 name = envelope.createName("Tuple", "", MDD_URI); 899 Iterator itTuple = eTuples.getChildElements(name); 900 901 int positionOrdinal = 0; 903 TupleLoop: while (itTuple.hasNext()) { 904 SOAPElement eTuple = (SOAPElement ) itTuple.next(); 905 handler.handleTuple(axisOrdinal, positionOrdinal); 906 907 910 int index = 0; 911 name = envelope.createName("Member", "", MDD_URI); 912 Iterator itMember = eTuple.getChildElements(name); 913 MemberLoop: while (itMember.hasNext()) { 914 SOAPElement eMem = (SOAPElement ) itMember.next(); 915 String uName = null; 917 String caption = null; 918 String levUname = null; 919 String displayInfo = null; 920 Iterator it = eMem.getChildElements(); 921 Map otherProps = new HashMap (); 922 InnerLoop: while (it.hasNext()) { 923 Node n = (Node ) it.next(); 924 if (!(n instanceof SOAPElement )) 925 continue InnerLoop; 926 SOAPElement el = (SOAPElement ) n; 927 String enam = el.getElementName().getLocalName(); 928 if (enam.equals("UName")) 929 uName = el.getValue(); 930 else if (enam.equals("Caption")) 931 caption = el.getValue(); 932 else if (enam.equals("LName")) 933 levUname = el.getValue(); 934 else if (enam.equals("DisplayInfo")) 935 displayInfo = el.getValue(); 936 else 937 otherProps.put(enam, el.getValue()); 938 } 939 handler.handleMember(uName, caption, levUname, displayInfo, otherProps, axisOrdinal, 940 positionOrdinal, index); 941 ++index; 942 } 944 ++positionOrdinal; 945 } } 948 name = envelope.createName("CellData", "", MDD_URI); 950 SOAPElement eCellData = selectSingleNode(eRoot, name); 951 handler.handleCellData(); name = envelope.createName("Cell", "", MDD_URI); 953 Iterator itSoapCell = eCellData.getChildElements(name); 954 CellLoop: while (itSoapCell.hasNext()) { 955 SOAPElement eCell = (SOAPElement ) itSoapCell.next(); 956 name = envelope.createName("CellOrdinal", "", ""); 957 String cellOrdinal = eCell.getAttributeValue(name); 958 int ordinal = Integer.parseInt(cellOrdinal); 959 name = envelope.createName("Value", "", MDD_URI); 960 SOAPElement eValue = selectSingleNode(eCell, name); 961 Object value = null; 962 if (eValue != null) { 963 name = envelope.createName("type", "xsi", XSI_URI); 964 String type = eValue.getAttributeValue(name); 965 988 if ("xsd:int".equals(type)) { 989 value = new Long (eValue.getValue()); 991 } else if ("xsd:double".equals(type)) { 992 value = new Double (eValue.getValue()); 993 } else if("xsd:decimal".equals(type)) { 994 value=new Double (eValue.getValue()); 995 } else { 996 value = eValue.getValue(); 997 } 998 } 999 name = envelope.createName("FmtValue", "", MDD_URI); 1000 SOAPElement eFmtValue = selectSingleNode(eCell, name); 1001 String fmtValue; 1002 if (eFmtValue != null) 1003 fmtValue = eFmtValue.getValue(); 1004 else 1005 fmtValue = ""; 1006 1007 name = envelope.createName("FontSize", "", MDD_URI); 1008 SOAPElement eFontSize = selectSingleNode(eCell, name); 1009 String fontSize = null; 1010 if (eFontSize != null) 1011 fontSize = eFontSize.getValue(); 1012 1013 handler.handleCell(ordinal, value, fmtValue, fontSize); 1014 1015 } 1017 } catch (SOAPException se) { 1018 throw new OlapException(se); 1019 } finally { 1020 if (connection != null) 1021 try { 1022 connection.close(); 1023 } catch (SOAPException e) { 1024 logger.error("?", e); 1026 } 1027 } 1028 1029 } 1030 1031 public void executeDrillQuery(String query, String catalog, QueryResultHandler handler) 1033 throws OlapException { 1034 1035 SOAPConnection connection = null; 1036 SOAPMessage reply = null; 1037 1038 try { 1039 connection = scf.createConnection(); 1040 SOAPMessage msg = mf.createMessage(); 1041 1042 MimeHeaders mh = msg.getMimeHeaders(); 1043 mh.setHeader("SOAPAction", "\"urn:schemas-microsoft-com:xml-analysis:Execute\""); 1044 1045 SOAPPart soapPart = msg.getSOAPPart(); 1046 SOAPEnvelope envelope = soapPart.getEnvelope(); 1047 SOAPBody body = envelope.getBody(); 1048 Name nEx = envelope.createName("Execute", "", XMLA_URI); 1049 1050 SOAPElement eEx = body.addChildElement(nEx); 1051 1052 1054 Name nCom = envelope.createName("Command"); 1059 SOAPElement eCommand = eEx.addChildElement(nCom); 1060 Name nSta = envelope.createName("Statement"); 1061 SOAPElement eStatement = eCommand.addChildElement(nSta); 1062 eStatement.addTextNode(query); 1063 1064 Map paraList = new HashMap (); 1065 paraList.put("DataSourceInfo", dataSource); 1066 paraList.put("Catalog", catalog); 1067 paraList.put("Format", "Tabular"); 1070 addParameterList(envelope, eEx, "Properties", "PropertyList", paraList); 1071 msg.saveChanges(); 1072 1073 reply = connection.call(msg, url); 1074 if (logger.isDebugEnabled()) { 1075 logger.debug("Reply from Execute"); 1076 logSoapMsg(reply); 1078 } 1079 1080 errorCheck(reply); 1082 1084 SOAPElement eRoot = findDrillExecRoot(reply); 1085 1086 1092 Name name = envelope.createName("row", "", ROWS_URI); 1093 SOAPElement columnHeader = selectSingleNode(eRoot, name); 1094 if (columnHeader == null) 1095 throw new OlapException("Excecute result has no rows element"); 1096 1097 Map colNames = new HashMap (); 1098 Iterator columnHeaderIt = columnHeader.getChildElements(); 1099 int colIdx = 0; 1100 RowHeadLoop : while (columnHeaderIt.hasNext()) { 1101 Object columnHeaderObj = columnHeaderIt.next(); 1102 if (columnHeaderObj instanceof SOAPElement ) { 1103 String colName = ((SOAPElement )columnHeaderObj).getElementName().getLocalName(); 1104 colNames.put(colName,new Integer (colIdx)); 1105 colIdx++; 1106 } 1107 } 1108 1109 1111 1112 1114 ArrayList drillRows = new ArrayList (); 1115 name = envelope.createName("row", "", ROWS_URI); 1116 Iterator rowIt = eRoot.getChildElements(name); 1117 while (rowIt.hasNext()) { 1118 SOAPElement rowElement = (SOAPElement ) rowIt.next(); 1119 1120 Iterator rowDataIt = rowElement.getChildElements(); 1122 javax.xml.soap.Text child = (javax.xml.soap.Text )rowDataIt.next(); 1123 SOAPElement columnElement = child.getParentElement(); 1124 Iterator columnIterator = columnElement.getChildElements(); 1125 1126 Map dataRow = new HashMap (); 1127 while (columnIterator.hasNext()) { 1128 Object colObject = columnIterator.next(); 1129 if (colObject instanceof SOAPElement ) { 1130 String colName = ((SOAPElement )colObject).getElementName().getLocalName(); 1131 if (!colNames.containsKey(colName)) { 1132 colNames.put(colName,new Integer (colIdx)); 1133 colIdx++; 1134 } 1135 String colValue = ((SOAPElement )colObject).getValue(); 1136 dataRow.put(colName, colValue ); 1137 } 1138 } 1139 drillRows.add(dataRow); 1140 } 1141 1142 handler.setDrillHeader(colNames); 1143 handler.setDrillRows(drillRows); 1144 1145 1146 } catch (SOAPException se) { 1147 throw new OlapException(se); 1148 } finally { 1149 if (connection != null) 1150 try { 1151 connection.close(); 1152 } catch (SOAPException e) { 1153 logger.error("?", e); 1155 } 1156 } 1157 1158} 1159 1160 1161 1164 public int getProvider() { 1165 return provider; 1166 } 1167 1168 1175 private int determineProvider(String dataSourceString) throws OlapException { 1176 logger.debug("determineProvider from dataSourceString: " + dataSourceString); 1177 if (dataSourceString == null) { 1178 throw new OlapException("No data source given for determining XML/A OLAP provider"); 1179 } 1180 1181 String upperDSString = dataSourceString.toUpperCase(); 1182 if (!upperDSString.startsWith("PROVIDER=")) { 1183 throw new OlapException("Malformed data source given for determining XML/A provider"); 1184 } 1185 1186 if (upperDSString.startsWith("PROVIDER=SAP")) { 1187 logger.debug("Provider is SAP"); 1188 return OlapDiscoverer.PROVIDER_SAP; 1189 } else if (upperDSString.startsWith("PROVIDER=MONDRIAN")) { 1190 logger.debug("Provider is Mondrian"); 1191 return OlapDiscoverer.PROVIDER_MONDRIAN; 1192 } else if (upperDSString.startsWith("PROVIDER=MS")) { logger.debug("Provider is Microsoft"); 1194 return OlapDiscoverer.PROVIDER_MICROSOFT; 1195 } else if (upperDSString.startsWith("PROVIDER=MICROSOFT")) { logger.debug("Provider is Microsoft"); 1197 return OlapDiscoverer.PROVIDER_MICROSOFT; } else { 1199 logger.error("Error determining provider from: " + dataSourceString); 1200 throw new OlapException("Unexpected data source determining XML/A provider"); 1201 } 1202 1203 } 1204 1205 1210 private void setProviderAndDataSource(Map resMap) throws OlapException { 1211 if (resMap == null || resMap.size() == 0) { 1212 logger.error("No resource map from Discover Datasource"); 1213 throw new OlapException("No resource map from Discover Datasource"); 1214 } 1215 1216 String pstr = (String ) resMap.get("ProviderName"); 1217 1218 if (pstr == null) 1222 throw new OlapException("No ProviderName from Discover Datasource"); 1223 1224 provider = determineProvider("Provider=" + pstr); 1225 1227 logger.debug("Provider ID: " + provider); 1228 1229 if (provider == OlapDiscoverer.PROVIDER_SAP) { 1230 String dstr = (String ) resMap.get("DataSourceDescription"); 1231 if (dstr == null) { 1232 throw new OlapException("No DataSourceDescription from Discover Datasource"); 1233 } 1234 dataSource = "Provider=" + pstr + ";DataSource=" + dstr; 1235 } else { 1236 logger.debug("DataSourceName: " + String.valueOf(resMap.get("DataSourceName"))); 1237 logger.debug("DataSourceInfo: " + String.valueOf(resMap.get("DataSourceInfo"))); 1238 1239 dataSource = (String ) resMap.get("DataSourceInfo"); 1243 1244 if (dataSource == null || dataSource.length() < 1) { 1245 dataSource = (String ) resMap.get("DataSourceName"); 1246 } 1247 1248 if (dataSource == null) { 1249 throw new OlapException("No DataSourceName from Discover Datasource"); 1250 } 1251 } 1252 logger.debug("Discover Datasource set: " + dataSource); 1253 1254 } 1255 1256 1264 private int getProviderFromDiscoverResponse(SOAPEnvelope envelope, SOAPElement e) throws OlapException, SOAPException { 1265 Name name = ((SOAPElement ) e).getElementName(); 1266 if (!name.getLocalName().equals("DiscoverResponse")) { 1267 throw new OlapException("Not a DiscoverResponse element. Was: " + name.getLocalName()); 1268 } 1269 1270 1272 SOAPElement walker = getDiscoverReturn(envelope, e); 1273 1274 if (walker == null) { 1275 throw new OlapException("Discover result has no DiscoverResponse/return element"); 1276 } 1277 1278 walker = getDiscoverRoot(envelope, walker); 1279 1280 if (walker == null) { 1281 throw new OlapException("Discover result has no DiscoverResponse/return/root element"); 1282 } 1283 1284 walker = getDiscoverRow(envelope, walker); 1285 1286 if (walker == null) { 1287 throw new OlapException("Discover result has no DiscoverResponse/return/root/row element"); 1288 } 1289 1290 1298 String value = null; 1299 Iterator it = walker.getChildElements(); 1300 while (it.hasNext()) { 1301 Object o = it.next(); 1302 if (!(o instanceof SOAPElement )) 1303 continue; SOAPElement e2 = (SOAPElement ) o; 1305 String nameString = e2.getElementName().getLocalName(); 1306 if (nameString.equals("ProviderName")) { 1307 value = e2.getValue(); 1308 logger.debug("Found ProviderName with value: " + value); 1309 break; 1310 } 1311 } 1312 1313 if (value == null || value.trim().length() == 0) { 1314 throw new OlapException("Discover result has empty DiscoverResponse/return/root/row/ProviderName element"); 1315 } 1316 1317 return determineProvider("Provider=" + value); 1318 } 1319 1320 private SOAPElement getDiscoverReturn(SOAPEnvelope envelope, SOAPElement e) throws OlapException, SOAPException { 1321 1322 Name nReturn; 1323 if (provider == PROVIDER_MICROSOFT) { 1324 nReturn = envelope.createName("return", "m", XMLA_URI); } else { 1326 nReturn = envelope.createName("return", "", XMLA_URI); } 1328 SOAPElement eReturn = selectSingleNode(e, nReturn); 1329 if (eReturn == null) { 1330 nReturn = envelope.createName("return", "", ""); eReturn = selectSingleNode(e, nReturn); 1333 if (eReturn == null) 1334 throw new OlapException("Discover result has no return element"); 1335 } 1336 return eReturn; 1337 } 1338 1339 private SOAPElement getDiscoverRoot(SOAPEnvelope envelope, SOAPElement e) throws OlapException, SOAPException { 1340 1341 Name nRoot = envelope.createName("root", "", ROWS_URI); 1342 SOAPElement eRoot = selectSingleNode(e, nRoot); 1343 if (eRoot == null) { throw new OlapException("Discover result has no root element"); } 1344 return eRoot; 1345 1346 } 1347 1348 private SOAPElement getDiscoverRow(SOAPEnvelope envelope, SOAPElement e) throws OlapException, SOAPException { 1349 1350 Name nRow = envelope.createName("row", "", ROWS_URI); 1351 SOAPElement eRow = selectSingleNode(e, nRow); 1352 if (eRow == null) { throw new OlapException("Discover result has no row element"); } 1353 return eRow; 1354 1355 } 1356 1357 1366 private void discover(String request, URL url, Map restrictions, Map properties, Rowhandler rh) 1367 throws OlapException { 1368 1369 try { 1370 SOAPConnection connection = scf.createConnection(); 1371 1372 SOAPMessage msg = mf.createMessage(); 1373 1374 MimeHeaders mh = msg.getMimeHeaders(); 1375 mh.setHeader("SOAPAction", "\"urn:schemas-microsoft-com:xml-analysis:Discover\""); 1376 1377 SOAPPart soapPart = msg.getSOAPPart(); 1378 SOAPEnvelope envelope = soapPart.getEnvelope(); 1379 SOAPBody body = envelope.getBody(); 1380 Name nDiscover = envelope 1381 .createName("Discover", "", XMLA_URI); 1382 1383 SOAPElement eDiscover = body.addChildElement(nDiscover); 1384 1385 Name nPara = envelope.createName("RequestType", "", XMLA_URI); 1386 SOAPElement eRequestType = eDiscover.addChildElement(nPara); 1387 eRequestType.addTextNode(request); 1388 1389 if (restrictions != null) 1391 addParameterList(envelope, eDiscover, "Restrictions", "RestrictionList", restrictions); 1392 addParameterList(envelope, eDiscover, "Properties", "PropertyList", properties); 1393 1394 msg.saveChanges(); 1395 1396 if (logger.isDebugEnabled()) { 1397 logger.debug("Discover Request for " + request); 1398 logSoapMsg(msg); 1399 } 1400 1401 SOAPMessage reply = connection.call(msg, url); 1403 1404 if (logger.isDebugEnabled()) { 1405 logger.debug("Discover Response for " + request); 1406 logSoapMsg(reply); 1407 } 1408 1409 errorCheck(reply); 1410 1411 SOAPElement eRoot = findDiscoverRoot(reply); 1412 1413 Name nRow = envelope.createName("row", "", ROWS_URI); Iterator itRow = eRoot.getChildElements(nRow); 1415 RowLoop: while (itRow.hasNext()) { 1416 1417 SOAPElement eRow = (SOAPElement ) itRow.next(); 1418 rh.handleRow(eRow, envelope); 1419 1420 } 1422 connection.close(); 1423 } catch (UnsupportedOperationException e) { 1424 throw new OlapException(e); 1425 } catch (SOAPException e) { 1426 throw new OlapException(e); 1427 } 1428 1429 } 1430 1431 1434 private void addParameterList(SOAPEnvelope envelope, SOAPElement eParent, String typeName, 1435 String listName, Map params) throws SOAPException { 1436 Name nPara = envelope.createName(typeName, "", XMLA_URI); 1437 SOAPElement eType = eParent.addChildElement(nPara); 1438 nPara = envelope.createName(listName, "", XMLA_URI); 1439 SOAPElement eList = eType.addChildElement(nPara); 1440 if (params == null) 1441 return; 1442 Iterator it = params.keySet().iterator(); 1443 while (it.hasNext()) { 1444 String tag = (String ) it.next(); 1445 String value = (String ) params.get(tag); 1446 nPara = envelope.createName(tag, "", XMLA_URI); 1447 SOAPElement eTag = eList.addChildElement(nPara); 1448 eTag.addTextNode(value); 1449 } 1450 } 1451 1452 private void errorCheck(SOAPMessage reply) throws SOAPException , OlapException { 1454 String [] strings = new String [4]; 1455 if (soapFault(reply, strings)) { 1456 String faultString = "Soap Fault code=" + strings[0] + " fault string=" + strings[1] 1457 + " fault actor=" + strings[2]; 1458 if (strings[3] != null) 1459 faultString += "\ndetail:" + strings[3]; 1460 throw new OlapException(faultString); 1461 } 1462 } 1463 1464 1469 private SOAPElement selectSingleNode(SOAPElement contextNode, Name childName) { 1470 1471 Iterator it = contextNode.getChildElements(childName); 1472 if (it.hasNext()) 1473 return (SOAPElement ) it.next(); 1474 else 1475 return null; 1476 } 1477 1478 1481 private SOAPElement findDiscoverRoot(SOAPMessage reply) throws SOAPException , OlapException { 1482 1483 SOAPPart sp = reply.getSOAPPart(); 1484 SOAPEnvelope envelope = sp.getEnvelope(); 1485 SOAPBody body = envelope.getBody(); 1486 Name childName; 1487 SOAPElement eResponse = null; 1488 if (provider == 0) { 1489 Iterator itBody = body.getChildElements(); 1491 while (itBody.hasNext()) { 1492 Node n = (Node ) itBody.next(); 1493 if (!(n instanceof SOAPElement )) 1494 continue; 1495 Name name = ((SOAPElement ) n).getElementName(); 1496 if (name.getLocalName().equals("DiscoverResponse")) { 1497 eResponse = (SOAPElement ) n; 1498 provider = getProviderFromDiscoverResponse(envelope, eResponse); 1499 break; 1505 } 1506 } 1507 if (eResponse == null) { 1508 throw new OlapException("Discover result has no DiscoverResponse element"); 1509 } 1510 1511 } else { 1512 if (provider == PROVIDER_MICROSOFT) { 1513 childName = envelope.createName("DiscoverResponse", "m", XMLA_URI); 1515 } else if (provider == PROVIDER_SAP || provider == PROVIDER_MONDRIAN) { 1516 childName = envelope.createName("DiscoverResponse", "", XMLA_URI); 1518 } else { 1519 throw new IllegalArgumentException ("no a valid provider specification"); 1520 } 1521 eResponse = selectSingleNode(body, childName); 1522 if (eResponse == null) { 1523 throw new OlapException("Discover result has no DiscoverResponse element"); 1524 } 1525 } 1526 1527 SOAPElement eReturn = getDiscoverReturn(envelope, eResponse); 1528 if (eReturn == null) 1529 throw new OlapException("Discover result has no return element"); 1530 1531 SOAPElement eRoot = getDiscoverRoot(envelope, eReturn); 1532 if (eRoot == null) 1533 throw new OlapException("Discover result has no root element"); 1534 return eRoot; 1535 } 1536 1537 1540 private void logSoapMsg(SOAPMessage msg) { 1541 1542 1557 try { 1559 Writer writer = new StringWriter (); 1560 TransformerFactory tFact = TransformerFactory.newInstance(); 1561 Transformer transformer = tFact.newTransformer(); 1562 Source src = msg.getSOAPPart().getContent(); 1563 StreamResult result = new StreamResult (writer); 1564 transformer.transform(src, result); 1565 logger.debug(writer.toString()); 1566 } catch (Exception e) { 1567 logger.error("?", e); 1569 } 1570 } 1571 1572 1577 private boolean soapFault(SOAPMessage reply, String [] faults) throws SOAPException { 1578 SOAPPart sp = reply.getSOAPPart(); 1579 SOAPEnvelope envelope = sp.getEnvelope(); 1580 SOAPBody body = envelope.getBody(); 1581 if (!body.hasFault()) 1582 return false; 1583 SOAPFault fault = body.getFault(); 1584 1585 faults[0] = fault.getFaultCode(); 1586 faults[1] = fault.getFaultString(); 1587 faults[2] = fault.getFaultActor(); 1588 1589 Detail detail = fault.getDetail(); 1591 if (detail == null) 1592 return true; 1593 String detailMsg = ""; 1594 Iterator it = detail.getDetailEntries(); 1595 for (; it.hasNext();) { 1596 DetailEntry det = (DetailEntry ) it.next(); 1597 Iterator ita = det.getAllAttributes(); 1598 for (boolean cont = false; ita.hasNext(); cont = true) { 1599 Name name = (Name ) ita.next(); 1600 if (cont) 1601 detailMsg += "; "; 1602 detailMsg += name.getLocalName(); 1603 detailMsg += " = "; 1604 detailMsg += det.getAttributeValue(name); 1605 } 1606 } 1607 faults[3] = detailMsg; 1608 1609 return true; 1610 } 1611 1612 1615 private SOAPElement findExecRoot(SOAPMessage reply) throws SOAPException , OlapException { 1616 SOAPPart sp = reply.getSOAPPart(); 1617 SOAPEnvelope envelope = sp.getEnvelope(); 1618 SOAPBody body = envelope.getBody(); 1619 1620 Name name; 1621 if (provider == PROVIDER_SAP) { 1622 name = envelope.createName("ExecuteResponse", "", XMLA_URI); 1623 } else { 1625 name = envelope.createName("ExecuteResponse", "m", XMLA_URI); 1626 } 1628 SOAPElement eResponse = selectSingleNode(body, name); 1629 if (eResponse == null) 1630 throw new OlapException("Excecute result has no ExecuteResponse element"); 1631 1632 if (provider == PROVIDER_SAP) { 1633 name = envelope.createName("return", "", XMLA_URI); 1634 } else { 1636 name = envelope.createName("return", "m", XMLA_URI); 1639 } 1640 SOAPElement eReturn = selectSingleNode(eResponse, name); 1641 if (eReturn == null) { 1642 name = envelope.createName("return", "", ""); eReturn = selectSingleNode(eResponse, name); 1645 if (eReturn == null) 1646 throw new OlapException("Excecute result has no ExecuteResponse element"); 1647 } 1648 1649 name = envelope.createName("root", "", MDD_URI); 1650 SOAPElement eRoot = selectSingleNode(eReturn, name); 1651 if (eRoot == null) { throw new OlapException("Excecute result has no root element"); } 1652 return eRoot; 1653 } 1654 1655 private SOAPElement findDrillExecRoot(SOAPMessage reply) throws SOAPException , OlapException { 1657 SOAPPart sp = reply.getSOAPPart(); 1659 SOAPEnvelope envelope = sp.getEnvelope(); 1660 SOAPBody body = envelope.getBody(); 1661 1662 Name name; 1663 if (provider == PROVIDER_SAP) { 1664 name = envelope.createName("ExecuteResponse", "", XMLA_URI); 1665 } else { 1667 name = envelope.createName("ExecuteResponse", "m", XMLA_URI); 1668 } 1670 SOAPElement eResponse = selectSingleNode(body, name); 1671 if (eResponse == null) { 1672 throw new OlapException("Excecute result has no ExecuteResponse element"); 1673 } 1674 1675 if (provider == PROVIDER_SAP) { 1676 name = envelope.createName("return", "", XMLA_URI); 1677 } else { 1679 name = envelope.createName("return", "m", XMLA_URI); 1682 } 1683 SOAPElement eReturn = selectSingleNode(eResponse, name); 1684 if (eReturn == null) { 1685 throw new OlapException("Excecute result has no return element"); 1686 } 1687 1688 name = envelope.createName("root", "", ROWS_URI); 1689 SOAPElement eRoot = selectSingleNode(eReturn, name); 1690 if (eRoot == null) { 1691 throw new OlapException("Excecute result has no root element"); 1692 } 1693 return eRoot; 1694 } 1695 1696} | Popular Tags |