SharePoint 2010 Web服务上的Java JBoss 401错误 [英] Java JBoss 401 Error on SharePoint 2010 Web Service

查看:102
本文介绍了SharePoint 2010 Web服务上的Java JBoss 401错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码在Eclipse IDE中进行测试时成功运行.

My code runs successfully when tested within the Eclipse IDE.

我正在使用生成的Copy.wsdl通过Web服务连接到MS SharePoint 2010

I'm connecting to MS SharePoint 2010 via Web Services using the generated Copy.wsdl

当我在JBoss服务器(运行Adobe LifeCycle)上部署代码时,我的代码收到401错误.

When I deploy my code on the JBoss server (Running Adobe LifeCycle) my code receives a 401 Error.

错误:

Caused by: org.jboss.ws.WSException: Invalid HTTP server response [401] - Unauthorized
at org.jboss.ws.core.soap.SOAPMessageUnMarshallerHTTP.read(SOAPMessageUnMarshallerHTTP.java:75)
at org.jboss.remoting.transport.http.HTTPClientInvoker.readResponse(HTTPClientInvoker.java:608)
at org.jboss.remoting.transport.http.HTTPClientInvoker.useHttpURLConnection(HTTPClientInvoker.java:402)
at org.jboss.remoting.transport.http.HTTPClientInvoker.makeInvocation(HTTPClientInvoker.java:253)
... 156 more

现在,如果我故意通过IDE使用错误的登录名,则会出现此错误:

Now if I purposely use the wrong login via the IDE I get this error:

com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 401: Unauthorized

更新:

因此,经过更多的研究,原来是对NTLM的完全缺乏J2EE支持.到目前为止,我已经尝试了几种解决方案,但均无济于事.

So after more research it turns out J2EE support, well lack of, with NTLM is the cause. I've tried several solutions to no avail as of yet.

代码:

protected void initialize(String username, String password) throws Exception {
    System.out.println("initialize()...");
    java.net.CookieManager cm = new java.net.CookieManager();
    java.net.CookieHandler.setDefault(cm);
    Authenticator.setDefault(new SharepointAuthenticator(username, password));
}

身份验证器

public class SharepointAuthenticator extends Authenticator {

private String username = "";
private String password = "";

public SharepointAuthenticator(String username, String password) {
    this.username = username;
    this.password = password;
    System.out.println("Initializing Authentication");
}

@Override
public PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication(username, password.toCharArray());
}
}

获取SOAP

protected CopySoap getCopySoap(String username, String password, String wsdl, String endpoint) throws Exception {
    System.out.println("Creating a CopySoap instance...");
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    Copy service = new Copy(new URL(wsdl), new QName("http://schemas.microsoft.com/sharepoint/soap/", "Copy"));
    System.out.println("CopySoap 2");

    CopySoap copySoap = service.getCopySoap();

    System.out.println(endpoint + "\n" + wsdl);

    BindingProvider bp = (BindingProvider) copySoap;  
    bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
    bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
    return copySoap;
}

致电上传文件:

    // make the call to upload
    port.copyIntoItems("null", destinationUrlCollection, metadata, byteArray, longHolder, resultHolder);

推荐答案

我正在使用 CXF 框架来创建港口.它将处理所有类型的身份验证.它也在JBoss中工作.

I am using CXF framework to create port. It will take care of all type of authentication. It is working in JBoss also.

实现起来很简单.添加CXF依赖项,并使用以下代码创建端口.

It is simple to implement. Add CXF dependencies and use the following code to create port.

示例代码:

InvocationHandlerImpl.java

public class InvocationHandlerImpl implements InvocationHandler
{
    CopySoap port;

    public InvocationHandlerImpl(CopySoap copySoap) {
        port = copySoap;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return method.invoke(port, args);
    }

}

TrustingX509TrustManager.java

TrustingX509TrustManager.java

public class TrustingX509TrustManager implements X509TrustManager
{
    /**
     * @see javax.net.ssl.X509TrustManager#getAcceptedIssuers()
     */
    @Override
    public X509Certificate[] getAcceptedIssuers() {
        // return null will let jsse accept all certificates!
        return null;
    }

    /**
     * @see javax.net.ssl.X509TrustManager#checkClientTrusted(X509Certificate[],String authType)
     */
    @Override
    public void checkClientTrusted(X509Certificate[] certs, String authType) {
    }

    /**
     * @see javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[],String authType)
     */
    @Override
    public void checkServerTrusted(X509Certificate[] certs, String authType) {
    }
}

SPCopyDriver.java

public class SPCopyDriver
{

    public static void main(String[] args) {

        JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
        proxyFactory.setServiceClass(CopySoap.class);
        proxyFactory.setUsername("domain\\username");
        proxyFactory.setPassword("password");
        proxyFactory.setAddress("https://<<IP>>/_vti_bin/Copy.asmx");

        HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
        httpClientPolicy.setAutoRedirect(true);
        httpClientPolicy.setAllowChunking(false);

        Object port = proxyFactory.create();
        Client client = ClientProxy.getClient(port);
        HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
        httpConduit.setClient(httpClientPolicy);

        TLSClientParameters tls = new TLSClientParameters();
        tls.setDisableCNCheck(true);
        tls.setTrustManagers(new TrustManager[] { new TrustingX509TrustManager() });
        httpConduit.setTlsClientParameters(tls);

        port = Proxy.newProxyInstance(SPCopyDriver.class.getClassLoader(), new Class[] { CopySoap.class }, new InvocationHandlerImpl((CopySoap) port));

        CopySoap copySoap = (CopySoap) port;

    }

}

这篇关于SharePoint 2010 Web服务上的Java JBoss 401错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆