DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Sharepoint java integration through web services returns (401)Unauthorized error

  1. #1
    Join Date
    Aug 2007
    Posts
    1

    Exclamation Sharepoint java integration through web services returns (401)Unauthorized error

    Hi All,

    I am trying to connect Microsoft Sharepoint services through its web services from java client. I am setting domain/username and password at system as well as application level. Every time it is returning (401)Unauthorized error.
    I am able to connect the web services through 4 different processes. All are returning same error code.
    I am pasting below the code for your reference.
    Any comments/ ideas will be highly appreciated.
    Exception thrown:
    (401)Unauthorized
    at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:630)
    at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:131)
    at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:71)
    at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:156)
    at org.apache.axis.SimpleChain.invoke(SimpleChain.java:126)
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:182)
    at org.apache.axis.client.Call.invokeEngine(Call.java:2113)
    at org.apache.axis.client.Call.invoke(Call.java:2102)
    at org.apache.axis.client.Call.invoke(Call.java:1851)
    at org.apache.axis.client.Call.invoke(Call.java:1777)
    at org.apache.axis.client.Call.invoke(Call.java:1315)
    at Sharepoint.main(Sharepoint.java:58

    Best Regards,
    Ranjanlal

    Code:

    First Process:


    File file = new File("C:/axis.bat");
    BufferedInputStream bis = new BufferedInputStream(new
    FileInputStream(file));
    byte b[] = new byte[bis.available()];
    bis.read(b);
    Object data[] = new Object[4];
    data[0] = "First";
    data[1] = "Second";
    data[2] = "abcd.doc";
    data[3] = b;
    String endpoint = "http://server/_vti_bin/lists.asmx";
    Service service = new Service();
    Call call = (Call) service.createCall();
    call.setTargetEndpointAddress( new java.net.URL(endpoint) );
    call.setOperationName(new QName("AddAttachment"));
    call.setUsername("DOMAIN\\username");
    call.setPassword("password");
    String ret = (String) call.invoke(data);
    System.out.println(ret);


    Second Process:


    ListsSoapStub stub;
    ListsLocator locator = new ListsLocator();
    URL url = new URL("http://server/_vti_bin/lists.asmx");
    stub = (ListsSoapStub)locator.getListsSoap(url);
    stub.setUsername("DOMAIN\\username");
    stub.setPassword("password");
    stub._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY, "DOMAIN\username");
    stub._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY, "password");
    stub._setProperty("http.username", "DOMAIN\\username");
    stub._setProperty("http.password", "password");
    File file = new File("C:/axis.bat");
    BufferedInputStream bis = new BufferedInputStream(new
    FileInputStream(file));
    byte b[] = new byte[bis.available()];
    bis.read(b);
    System.out.println(b.length);
    Object data[] = new Object[4];
    data[0] = "First";
    data[1] = "Second";
    data[2] = "abcd.doc";
    data[3] = b;
    stub.addAttachment("First", "Second", "axis.bat", b);


    Third process:


    Service service = new Service();
    File file = new File("C:/axis.bat");
    BufferedInputStream bis = new BufferedInputStream(new
    FileInputStream(file));
    byte b[] = new byte[bis.available()];
    bis.read(b);
    System.out.println(b.length);
    Object data[] = new Object[4];
    data[0] = "First";
    data[1] = "Second";
    data[2] = "abcd.doc";
    data[3] = b;
    ListsLocator lc = new ListsLocator();
    ListsSoap ls = lc.getListsSoap();
    ((ListsSoapStub)ls).setPassword("password");
    ((ListsSoapStub)ls).setUsername("DOMAIN\\username");
    ls.addAttachment("First", "Second", "axis.bat", b);


    Fourth Process:


    System.setProperty("http.username", "DOMAIN/username");
    System.setProperty("http.password", "password");
    String endpoint = "http://servername/_vti_bin/lists.asmx";
    Service service = new Service();
    Call call = (Call) service.createCall();
    call.setUsername("DOMAIN/username");
    call.setPassword("password");
    call.setTargetEndpointAddress( new java.net.URL(endpoint) );
    call.setOperationName(new QName("AddAttachment"));
    call.setUseSOAPAction(true);
    call.setUsername("DOMAIN/username");
    call.setPassword("password");
    call.addParameter("listName", org.apache.axis.Constants.SOAP_STRING, ParameterMode.IN);
    call.addParameter("listItemID", org.apache.axis.Constants.SOAP_STRING, ParameterMode.IN);
    call.addParameter("fileName", org.apache.axis.Constants.SOAP_STRING, ParameterMode.IN);
    call.addParameter("attachment", org.apache.axis.Constants.SOAP_BASE64, ParameterMode.IN);
    call.setReturnType(org.apache.axis.Constants.SOAP_STRING);
    File file = new File("C:/axis.bat");
    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
    byte b[] = new byte[bis.available()];
    bis.read(b);
    Object data[] = new Object[4];
    data[0] = "First";
    data[1] = "Second";
    data[2] = "abcd.doc";
    data[3] = b;
    Object greet = (Object)call.invoke(data);
    System.out.println(greet.getClass().getName());
    System.out.println(greet.toString());

  2. #2
    Join Date
    Aug 2009
    Posts
    1

    Jar file having Call and Service methods

    Hi,

    I tried to execute your code. While executing, I got some compilation errors. may I know in which jar file the Call and Service class are there. I downloaded "axis-jaxrpc-1.4.jar", but there Call and Service are Interface, not Class. So when I instantiate Service class using
    Service service = new Service();
    I get compilation error since Service is a Class not an Interface.
    Please let me know which jar file you are using for this purpose.


    Thanks
    Aditya Aery

Similar Threads

  1. Replies: 0
    Last Post: 03-31-2007, 08:40 AM
  2. Link error
    By Shar in forum C++
    Replies: 5
    Last Post: 12-19-2006, 07:07 AM
  3. Question on .NET remoting
    By kgoff@worldnet.att.net in forum .NET
    Replies: 2
    Last Post: 01-07-2003, 02:06 PM
  4. Web Services before .NET - Don't Miss the Point
    By Aaron Sevivas in forum .NET
    Replies: 0
    Last Post: 05-29-2002, 07:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center