私はチュートリアル「Java を Microsoft SQL Server Reporting Services 2005/2008 と統合する」を行っています。次のセットアップを使用しています。
- SQL Server 2012 ビジネス インテリジェンス
- Windows 7 ホーム プレミアム
- HTTP クライアント 3.1
Eclipse でコードを実行するとエラーが発生します。
NTLM による認証の失敗
この記事に記載されている JCIFS ソリューションを試し、他の多くの投稿、フォーラム、チュートリアル、ブログを見てきましたが、問題はまだ解決されていません。
サービス アカウントについては、ビルトイン アカウントを使用しています: NT Authority\Network Service
. Web ブラウザからは Web サービスにアクセスできますが、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());
}