2

我正在学习教程“将 Java 与 Microsoft SQL Server Reporting Services 2005/2008 集成”。我正在使用以下设置:

  • SQL Server 2012 商业智能
  • Windows 7家庭高级版
  • http客户端3.1

在eclipse中执行代码时出现错误:

使用 NTLM 进行身份验证失败

尝试过本文提到的JCIFS解决方案,也看过很多其他的帖子、论坛、教程、博客,但问题还是没有解决。

对于我使用内置帐户的服务帐户:NT Authority\Network Service. 我可以通过网络浏览器访问我的网络服务,但不能通过 Eclipse。

这是输出的完整堆栈:

Nov 19, 2012 3:44:48 AM org.apache.axis.utils.JavaUtils isAttachmentSupported
WARNING: Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
Nov 19, 2012 3:44:49 AM org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme
INFO: ntlm authentication scheme selected
Nov 19, 2012 3:44:49 AM org.apache.commons.httpclient.HttpMethodDirector processWWWAuthChallenge
INFO: Failure authenticating with NTLM <any realm>@yappkahowe-pc:80
AxisFault
 faultCode: {http://xml.apache.org/axis/}HTTP
 faultSubcode: 
 faultString: (401)Unauthorized
 faultActor: 
 faultNode: 
 faultDetail: 
    {}:return code:  401

    {http://xml.apache.org/axis/}HttpErrorCode:401

(401)Unauthorized
    at org.apache.axis.transport.http.CommonsHTTPSender.invoke(CommonsHTTPSender.java:218)
    at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
    at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
    at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
    at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
    at org.apache.axis.client.Call.invoke(Call.java:2767)
    at org.apache.axis.client.Call.invoke(Call.java:2443)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at com.microsoft.schemas.sqlserver._2005._06._30.reporting.reportingservices.ReportExecutionServiceSoapStub.loadReport(ReportExecutionServiceSoapStub.java:886)
    at test.Test.<init>(Test.java:30)
    at test.Test.main(Test.java:70)

我的代码如下:

package test;

import java.net.URL;

import javax.xml.rpc.holders.ByteArrayHolder;
import javax.xml.rpc.holders.StringHolder;
import javax.xml.soap.SOAPException;

import org.apache.axis.EngineConfiguration;
import org.apache.axis.message.SOAPHeaderElement;
import org.apache.commons.httpclient.auth.AuthPolicy;

import com.microsoft.schemas.sqlserver._2005._06._30.reporting.reportingservices.ExecutionInfo;
import com.microsoft.schemas.sqlserver._2005._06._30.reporting.reportingservices.ParameterValue;
import com.microsoft.schemas.sqlserver._2005._06._30.reporting.reportingservices.ReportExecutionServiceLocator;
import com.microsoft.schemas.sqlserver._2005._06._30.reporting.reportingservices.ReportExecutionServiceSoapStub;
import com.microsoft.schemas.sqlserver._2005._06._30.reporting.reportingservices.holders.ArrayOfStringHolder;
import com.microsoft.schemas.sqlserver._2005._06._30.reporting.reportingservices.holders.ArrayOfWarningHolder;

public class Test {
    public static final String USERNAME = "NT AUTHORITY\\NETWORKSERVICE";
    public static final String PASSWORD = "";
public Test() {
    AuthPolicy.registerAuthScheme(AuthPolicy.NTLM, JCIFS_NTLMScheme.class);
    ReportExecutionServiceSoapStub service = getService();
    ParameterValue[] parameters = new ParameterValue[0];

    try {
        ExecutionInfo info = service.loadReport("/Tutorial/Members", null); // Load report
        setExecutionId(service, info.getExecutionID()); // You must set the session id before continuing
        service.setExecutionParameters(parameters, "en-us"); // Set report parameters

        String format = "HTML4.0"; // Valid options are HTML4.0, MHTML, EXCEL, CSV, PDF, etc
        String deviceInfo = "<DeviceInfo><Toolbar>False</Toolbar><HTMLFragment>True</HTMLFragment></DeviceInfo>"; // Only generate an HTML fragment
        ByteArrayHolder result = new ByteArrayHolder();
        StringHolder extension = new StringHolder();
        StringHolder mimeType = new StringHolder();
        StringHolder encoding = new StringHolder();
        ArrayOfWarningHolder warnings = new ArrayOfWarningHolder();
        ArrayOfStringHolder streamIDs = new ArrayOfStringHolder();
        service.render(format, deviceInfo, result, extension, mimeType, encoding, warnings, streamIDs); // Render report to HTML

        System.out.println(new String(result.value)); // Prints the report HTML; this could be embedded in a JSP
    } catch (Exception e) {
        e.printStackTrace();
    }
}

public static void main(String[] arg) {
    new Test();
}

public static void setExecutionId(ReportExecutionServiceSoapStub service, String id) throws SOAPException {
    SOAPHeaderElement sessionHeader = new SOAPHeaderElement("http://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices",
            "ExecutionHeader");
    sessionHeader.addChildElement("ExecutionID").addTextNode(id);
    service.setHeader(sessionHeader);
}

public static ReportExecutionServiceSoapStub getService() {
    try {
        String endpoint = "http://127.0.0.1/reportserver/ReportExecution2005.asmx";
        ReportExecutionServiceSoapStub service = (ReportExecutionServiceSoapStub) new ReportExecutionServiceLocator(getEngineConfiguration())
                .getReportExecutionServiceSoap(new URL(endpoint));
        service.setUsername(USERNAME);
        service.setPassword(PASSWORD);
        return service;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}

public static EngineConfiguration getEngineConfiguration() {
    java.lang.StringBuffer sb = new java.lang.StringBuffer();

    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
    sb.append("<deployment name=\"defaultClientConfig\"\r\n");
    sb.append("xmlns=\"http://xml.apache.org/axis/wsdd/\"\r\n");
    sb.append("xmlns:java=\"http://xml.apache.org/axis/wsdd/providers/java\">\r\n");
    sb.append("<globalConfiguration>\r\n");
    sb.append("<parameter name=\"disablePrettyXML\" value=\"true\"/>\r\n");
    sb.append("<parameter name=\"enableNamespacePrefixOptimization\" value=\"true\"/>\r\n");
    sb.append("</globalConfiguration>\r\n");
    sb.append("<transport name=\"http\" pivot=\"java:org.apache.axis.transport.http.CommonsHTTPSender\"/>\r\n");
    sb.append("<transport name=\"local\" pivot=\"java:org.apache.axis.transport.local.LocalSender\"/>\r\n");
    sb.append("<transport name=\"java\" pivot=\"java:org.apache.axis.transport.java.JavaSender\"/>\r\n");
    sb.append("</deployment>\r\n");

    return new org.apache.axis.configuration.XMLStringProvider(sb.toString());
}
4

0 回答 0