2012-11-15 3 views
4

여기에서 나는 셰어 포인트 목록을 읽으려고합니다. 이를 위해 나는 다음을 수행했습니다 : WSDL 파일을 다운로드 받았는데 다음 URL에서 보았습니다 : sharepointsite.com/_vti_bin/Lists.asmx?WSDL. 디렉토리에있는 클래스를 생성하기 위해 다음 명령을 실행했습니다. "C : \ Program Files \ Java \ jdk1.6.0_12 \ bin \ wsimport.exe"-p com.microsoft.schemas.sharepoint.soap -keep - 확장 Lists.wsdl. Eclipse Java IDE 응용 프로그램에서 해당 클래스를 가져 왔습니다.자바를 사용하여 SharePoint 목록을 읽을 수 없습니다.

와 나는

/* 주어진 SharePoint 웹 서비스에 연결된 포트를 작성합니다 다음 코드를 작성했습니다.

* Authentication is done here. It also prints the authentication details 

* in the console. 

* @param userName SharePoint username 

* @param password SharePoint password 

* @return port ListsSoap port, connected with SharePoint 

* @throws Exception in case of invalid parameters or connection error. 

*/ 

public static ListsSoap sharePointListsAuth(String userName, String password) throws Exception { 

    ListsSoap port = null; 

    if (userName != null && password != null) { 

     try { 

      Lists service = new Lists(); 

      port = service.getListsSoap(); 

      System.out.println("Web Service Auth Username: " + userName); 

      ((BindingProvider) port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userName); 

      ((BindingProvider) port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password); 

     } catch (Exception e) { 

      throw new Exception("Error: " + e.toString()); 

     } 

    } else { 

     throw new Exception("Couldn't authenticate: Invalid connection details given."); 

    } 

    return port; 

} 
/** 

* Creates a string from an XML file with start and end indicators 

* @param docToString document to convert 

* @return string of the xml document 

*/ 

public static String xmlToString(Document docToString) { 

    String returnString = "\n-------------- XML START --------------\n"; 

    try { 

     //create string from xml tree 

     //Output the XML 

     //set up a transformer 

     TransformerFactory transfac = TransformerFactory.newInstance(); 

     Transformer trans; 

     trans = transfac.newTransformer(); 

     trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); 

     trans.setOutputProperty(OutputKeys.INDENT, "yes"); 

     StringWriter sw = new StringWriter(); 

     StreamResult streamResult = new StreamResult(sw); 

     DOMSource source = new DOMSource(docToString); 

     trans.transform(source, streamResult); 

     String xmlString = sw.toString(); 

     //print the XML 

     returnString = returnString + xmlString; 

    } catch (TransformerException ex) { 

     Logger.getLogger(Manager.class.getName()).log(Level.SEVERE, null, ex); 

    } 

    returnString = returnString + "-------------- XML END --------------"; 

    return returnString; 

} 
/** 
02 
* Connects to a SharePoint Lists Web Service through the given open port, 
03 
* and reads all the elements of the given list. Only the ID and the given 
04 
* attributes (column names) are displayed, as well as a dump of the SOAP 
05 
* response from the Web Service (for debugging purposes). 
06 
* @param port an already authentificated SharePoint Online SOAP port 
07 
* @param listName original name of the Sharepoint list that is going to be read 
08 
* @param listColumnNames arraylist containing the various names of the Columns 
09 
* of the SharePoint list that are going to be read. If the column name isn't 
10 
* found, then an exception will be thrown 
11 
* @param rowLimit limits the number of rows (list items) that are going to 
12 
* be returned 
13 
* @throws Exception 
14 
*/ 

public static void displaySharePointList(ListsSoap port, String listName, ArrayList<String> listColumnNames, String rowLimit) throws Exception { 

    if (port != null && listName != null && listColumnNames != null && rowLimit != null) { 

     try { 



      //Here are additional parameters that may be set 

      String viewName = ""; 

      GetListItems.ViewFields viewFields = null; 

      GetListItems.Query query = null; 

      GetListItems.QueryOptions queryOptions = null; 

      String webID = ""; 



      //Calling the List Web Service 

      GetListItemsResponse.GetListItemsResult result = port.getListItems(listName, viewName, query, viewFields, rowLimit, queryOptions, webID); 

      Object listResult = result.getContent().get(0); 

      if ((listResult != null) && (listResult instanceof ElementNSImpl)) { 

       ElementNSImpl node = (ElementNSImpl) listResult; 



       //Dumps the retrieved info in the console 

       Document document = node.getOwnerDocument(); 

       System.out.println("SharePoint Online Lists Web Service Response:" + Manager.xmlToString(document)); 



       //selects a list of nodes which have z:row elements 

       NodeList list = node.getElementsByTagName("z:row"); 

       System.out.println("=> " + list.getLength() + " results from SharePoint Online"); 



       //Displaying every result received from SharePoint, with its ID 

       for (int i = 0; i < list.getLength(); i++) { 


        //Gets the attributes of the current row/element 

        NamedNodeMap attributes = list.item(i).getAttributes(); 

        System.out.println("******** Item ID: " + attributes.getNamedItem("ows_ID").getNodeValue()+" ********"); 



        //Displays all the attributes of the list item that correspond to the column names given 

        for (String columnName : listColumnNames) { 

         String internalColumnName = "ows_" + columnName; 

         if (attributes.getNamedItem(internalColumnName) != null) { 

          System.out.println(columnName + ": " + attributes.getNamedItem(internalColumnName).getNodeValue()); 

         } else { 

          throw new Exception("Couldn't find the '" + columnName + "' column in the '" + listName + "' list in SharePoint.\n"); 

         } 

        } 

       } 

      } else { 

       throw new Exception(listName + " list response from SharePoint is either null or corrupt\n"); 

      } 

     } catch (Exception ex) { 

      throw new Exception("Exception. See stacktrace." + ex.toString() + "\n"); 

     } 

    } 
} 
public static void main(String[] args) { 

     try { 



      //Authentication parameters 

      String userName = "domain\\username"; 

      String password = "pass"; 



      //Opening the SOAP port of the Lists Web Service 

      ListsSoap port = Manager.sharePointListsAuth(userName, password); 



      /* 

      * Lists Web service parameters 

      * The list names below must be the *original* names of the list. 

      * if a list or column was renamed from SharePoint afterwards, 

      * these parameters don't change. 

      */ 

      String listName = "listname"; 

      String rowLimit = "2"; 

      ArrayList<String> listColumnNames = new ArrayList<String>(); 

      listColumnNames.add("Name"); 

      listColumnNames.add("ID"); 

      //Displays the lists items in the console 

      Manager.displaySharePointList(port, listName, listColumnNames, rowLimit); 

     } catch (Exception ex) { 

      System.err.println(ex); 

     } 

    } 

나는 다음과 같은 예외를 얻고있다 :

웹 서비스 인증 아이디 : "도메인 \ 사용자 이름" 의 java.lang.Exception : 예외입니다. stacktrace.javax.xml.ws.soap.SOAPFaultException : 'Microsoft.SharePoint.SoapServer.SoapServerException'유형의 예외가 발생했습니다.

new BasicAuthentication(userName,password).authenticate(); 

내 BasicAuthentication 선택 클래스 : 여전히

import java.net.Authenticator; 
import java.net.PasswordAuthentication; 

public class BasicAuthentication extends Authenticator 
{ 
    private String username; 
    private String password; 

    public BasicAuthentication(String username, String password) 
    { 
     this.username = username; 
     this.password = password; 
    } 

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

    public void authenticate() 
    { 
     Authenticator.setDefault(this); 
    } 
} 

답변

1

가 나는 인증 자와 시도, 같은 문제가 있었다 Colin
+0

인증 성공을 얻지 못하고, 그 같은 오류 (401)는, @Mathieu 도움이 필요

It would be helpfull if i get the specific exception from the server.With this expection i am unable to track my pgm. I dont know where did i go wrong? am i missing anything ? any configuration is required ? Thanks in advance for your help 

+0

SharePoint 서버가 구성된 인증 유형을 알고 있습니까? Windows 인증을 선택하면 BasicAuth가 작동하지 않으며 Kerberos를 사용할 수있는 경우 MS 구현 외부에서 NTLM보다 작동하는 것이 일반적으로 더 쉽습니다. –

관련 문제