游戏,工作,投资,悟禅

工作就是修行

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

xmla 的配置见http://www.activeinterface.com/b2005_11_21.html,但是,如果是通过java去访问XMLA,则会因为用户权限的问题,得不到正确结果。
配置方法是在xmla 的虚拟目录上,把安全性的基本身份验证方式选上,然后在java 代码中,通过 Authenticator 类为验证提供用户和密码。部分代码如下:

用户密码验证提供者

package com.chinadci;

import java.net.*;

public class AuthImpl extends Authenticator {
      
protected PasswordAuthentication getPasswordAuthentication() {
          
            String user 
= "IBMUSERAZ3\\IBMUSER";
            String password
="xxxx";
            
char pass[] = password.toCharArray();
            
return new PasswordAuthentication(user, pass);
        }


}


package com.chinadci;
import java.io.*;
import java.net.*;

public class XMLA {
    
    
private String sXmlaServer;
    
private HttpURLConnection oHttp; 
    
public XMLA() {
        
super();
        
// TODO Auto-generated constructor stub
        sXmlaServer= "http://localhost/olap/msmdpump.dll";    
    }


    
public String  EncloseTag(String sTag, String sValue){
        
return "<" + sTag + ">" + sValue + "</" + sTag + ">";
    }

    
    
public String Discover(String sRequestType,String sRestrictions,String sProps)
    
{
        Authenticator.setDefault(
new AuthImpl());
        
//构造soap 头部
        String  strType = EncloseTag("RequestType",sRequestType);
        String strRestrictions 
= EncloseTag("Restrictions",EncloseTag("RestrictionList",sRestrictions));
        String strProps 
= EncloseTag("Properties",EncloseTag("PropertyList",sProps));
        String sNS 
= " xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi = \"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"";

        String sPayload 
= "<SOAP-ENV:Envelope " + sNS + " >"
        
+ " <SOAP-ENV:Body>"
        
+ " <Discover xmlns=\"urn:schemas-microsoft-com:xml-analysis\" >"
        
+ strType + strRestrictions + strProps
        
+ " </Discover>"
        
+ " </SOAP-ENV:Body>"
        
+ " </SOAP-ENV:Envelope>";

        URL url;
        
try {
            url 
= new URL(sXmlaServer);
            oHttp 
= (HttpURLConnection) url.openConnection();
            oHttp.setRequestMethod(
"POST");
            oHttp.setDoOutput(
true);
            oHttp.setDoInput( 
true);
            oHttp.setRequestProperty(
"Content-Type","text/xml");
            oHttp.setRequestProperty(
"SOAPAction"'"'+ "urn:schemas-microsoft-com:xml-analysis:Discover" + '"' );
            PrintWriter out 
= new PrintWriter(new BufferedWriter(new OutputStreamWriter(oHttp.getOutputStream(),"utf-8")),true);//创建输出流            

            
            
//send the post request 
            out.println(sPayload);
            out.flush() ;
            out.close() ;
            
            
            
//read the response xml
            BufferedReader in
            
= new BufferedReader(new InputStreamReader(oHttp.getInputStream(),"utf-8"));

            String responseMessage 
=oHttp.getResponseMessage();    
            String responseXml 
="";
            
if (responseMessage.equals("OK" ))
            
{
                String line;
                
while ((line = in.readLine()) != null{
                    responseXml 
=responseXml+line;
                }

            }

            
return responseXml;
            
        }
 catch (MalformedURLException e) {
            
// TODO Auto-generated catch block
            e.printStackTrace();
        }
 catch (IOException e) {
            
// TODO Auto-generated catch block
            e.printStackTrace();
        }

        

        
return "";
    }

    
}


测试入口
posted on 2006-11-08 15:05  爱玩游戏的码农  阅读(664)  评论(0编辑  收藏  举报