3

the code are as follows:

private static EndpointReference targetEPR = new EndpointReference(  
            "http://sharepoint01/_vti_bin/lists.asmx");  
ServiceClient sender = new ServiceClient();

List authSchema = new ArrayList(); 
HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
auth.setDomain(""); 
auth.setUsername("");
auth.setPassword(""); 
auth.setHost("");
auth.setPort(80);
List authPrefs = new ArrayList(1); 
authPrefs.add(AuthPolicy.NTLM); 
auth.setAuthSchemes(authPrefs);
sender.getOptions()
      .setAction("http://schemas.microsoft.com/sharepoint/soap/CheckOutFile");
sender.getOptions().setTo(targetEPR); 
sender.getOptions().setTimeOutInMilliSeconds(1000000); 
sender.getOptions()
      .setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth); 
sender.getOptions()
      .setProperty (HTTPConstants.HTTP_PROTOCOL_VERSION, HTTPConstants.HEADER_PROTOCOL_10);

OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://schemas.microsoft.com/sharepoint/soap/", "");
OMElement data = fac.createOMElement("CheckOutFile", omNs);
OMElement inner = fac.createOMElement("pageUrl", omNs);
inner.setText("http://sharepoint01/Shared Documents/fpga.doc");
OMElement inner1 = fac.createOMElement("checkoutToLocal", omNs);
inner.setText("true"); OMElement inner2 = fac.createOMElement("lastmodified", omNs);
inner.setText(""); data.addChild(inner); data.addChild(inner1); data.addChild(inner2);

OMElement result = sender.sendReceive;

and the error code is

Exception in thread "main" org.apache.axis2.AxisFault: Transport error: 401 Error: Unauthorized at org.apache.axis2.transport.http.HTTPSender.handleResponse(HTTPSender.java:311) at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:200) at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:76) at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:400) at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:225) at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:438) at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:402) at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229) at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165) at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:540) at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:521) at test01.getResult(test01.java:113) at test01.main(test01.java:182)

Anatoly Mironov
  • 5,750
  • 2
  • 29
  • 56
user10510
  • 31
  • 1
  • 2
  • Take a look in the IIS logs, to see what kind of 401 is thrown (401.1, 401.2, ...). This is maybe a server configuration issue. Also, please explains what kind of authentication you have set up on the SharePoint farm, especially if you have setup the web application to use claims authentication – Steve B Dec 12 '12 at 13:47

1 Answers1

1

Not a Java expert but you are not setting the domain, username and password when making the connection. TherefOre the request is sent anonymously and is not authenticated and you get a 401 error

Simon Doy
  • 1,666
  • 1
  • 10
  • 13
  • Many thanks for you quick reply. So you mean the setting in my code is invalid ? And do you know how to setting the domain, username and password exactly? And could you give me some example code? – user10510 Sep 05 '12 at 01:46
  • I believe in Java you have to ask for the credentials. In '.net you can use a default set which users the current users login details. I found this post http://docs.oracle.com/javase/6/docs/technotes/guides/net/http-auth.html I can see from your code that you have calls to setusername() setdomain and setpassword() I would try populating those to get it working and then look at how you could get the credentials from the user in a nice way. – Simon Doy Sep 05 '12 at 22:09