AnsweredAssumed Answered

from jsp to alfresco with web service

Question asked by rufatina on Nov 28, 2008
Latest reply on Nov 20, 2009 by maqsood
Please help me to solve my problem

In WebServicesSamples I found simple examples how to connect to Alfresco from console and search some Nodes and some useful things also and modify it.If you want you can see this code below. 

package org.alfresco.sample.webservice;

import org.alfresco.service.namespace.QName;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.webservice.repository.UpdateResult;
import org.alfresco.webservice.types.CML;
import org.alfresco.webservice.types.CMLCreate;
import org.alfresco.webservice.types.ContentFormat;
import org.alfresco.webservice.types.NamedValue;
import org.alfresco.webservice.types.ParentReference;
import org.alfresco.webservice.types.Predicate;
import org.alfresco.webservice.types.Reference;
import org.alfresco.webservice.types.Store;
import org.alfresco.webservice.util.Constants;
import org.alfresco.webservice.util.Utils;
import org.alfresco.webservice.util.WebServiceFactory;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

import javax.xml.rpc.ServiceException;
import org.alfresco.webservice.repository.QueryResult;
import org.alfresco.webservice.repository.RepositoryFault;
import org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub;
import org.alfresco.webservice.types.NamedValue;
import org.alfresco.webservice.types.Query;
import org.alfresco.webservice.types.Reference;
import org.alfresco.webservice.types.ResultSet;
import org.alfresco.webservice.types.ResultSetRow;
import org.alfresco.webservice.util.AuthenticationUtils;
import org.alfresco.webservice.util.Constants;
import org.alfresco.webservice.util.WebServiceFactory;


import com.azeriland.models.supremeModel;

public class JoinTwoClass {
   
    public static void main(String[] args)
    throws Exception
{
    // Start the session
    AuthenticationUtils.startSession(USERNAME, PASSWORD);
   
    try
    {       
        // Make sure smaple data has been created
      //  createSampleData();
       
        // Execute the search sample
        executeSearch();       
    }
    finally
    {
        // End the session
        AuthenticationUtils.endSession();
    }
}
   
   
   private boolean useComlainers = true;
   private boolean useAdditonalPersons = false;
   private boolean useComplainer = false;
   private boolean useAdditinalPerson = false;
   
   protected static final String USERNAME = "RRR";
   protected static final String PASSWORD = "rrr";
   
   protected static final Store STORE = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
   //protected static final Reference SAMPLE_FOLDER = new Reference(STORE,null, "/sup:legalproc");
   
/*   protected static void createSampleData() throws Exception
   {
       try
       {
           // Check to see if the sample folder has already been created or not
           WebServiceFactory.getRepositoryService().get(new Predicate(new Reference[]{SAMPLE_FOLDER}, STORE, null));
       }
       catch (Exception exception)
       {
           // Create parent reference to company home
           ParentReference parentReference = new ParentReference(
                   STORE,
                   null,
                   "/sup:legalproc",
                   Constants.ASSOC_CONTAINS,
                   Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, "sample_folder"));
       }
   
}*/
      public static Reference executeSearch() throws ServiceException, RemoteException, RepositoryFault
       {
           Reference parentReference = null;
          
           // Get a reference to the respository web service
           RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();        
          
           // Create a query object, looking for all items with alfresco in the name of text
         String searchPath =  "PATH:\"/app:company_home/cm:Archive//*\"";
                searchPath = searchPath + " AND TYPE:\"{http://www.com.azerland/model/supremecourt/1.0}legalproc\"";
         
           //String propStr =  "\\@" + Repository.escapeQName(supremeModel.PROPERTY_PROCID) + ":AM*";
         String propStr =  "\\@" + Repository.escapeQName(supremeModel.PROPERTY_PROCID) + ":AM*";      
         String searchString = searchPath + " AND (" + propStr + ")";
         
           Query query = new Query(Constants.QUERY_LANG_LUCENE,searchString);
                                // Execute the query
           QueryResult queryResult = repositoryService.query(STORE, query, false);
          
           // Display the results
           ResultSet resultSet = queryResult.getResultSet();
           ResultSetRow[] rows = resultSet.getRows();
           if (rows == null)
           {
               System.out.println("No query results found.");
           }
           else
           {
               System.out.println("Results from query:");
               outputResultSet(rows);
              
               // Get the id of the first result
               String firstResultId = rows[0].getNode().getId();
               Reference reference = new Reference(STORE, firstResultId, null);
              
               // Get the parent(s) of the first result
               QueryResult parentQueryResult = repositoryService.queryParents(reference);
              
               // Get the parent of the first result
               ResultSet parentResultSet = parentQueryResult.getResultSet();
               ResultSetRow[] parentRows = parentResultSet.getRows();
           }
          
           return parentReference;   
       }
     
       public static void outputResultSet(ResultSetRow[] rows)
       {
           if (rows != null)
           {
               for (int x = 0; x < rows.length; x++)
               {
                   ResultSetRow row = rows[x];
                  
                   System.out.println("—————————–");
                  
                   System.out.println("id node = "+row.getColumns(5).getName() + " – " + "Node value = "+ row.getColumns(5).getValue());
          
                 
                  
               }
           }
       }
}

But I need create some web page (jsp) to connect Alfresco and do some search with Lucene I am very new in Alfresco and haven't any experience in web service
I modify code that in above like that

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<%@page import="org.alfresco.webservice.repository.UpdateResult"%>
<%@page import="org.alfresco.webservice.types.CML"%>
<%@page import="org.alfresco.webservice.types.CMLCreate"%>
<%@page import="org.alfresco.webservice.types.ContentFormat"%>
<%@page import="org.alfresco.webservice.types.NamedValue"%>
<%@page import="org.alfresco.webservice.types.ParentReference"%>
<%@page import="org.alfresco.webservice.types.Predicate"%>
<%@page import="org.alfresco.webservice.types.Reference"%>
<%@page import="org.alfresco.webservice.types.Store"%>
<%@page import="org.alfresco.webservice.util.Constants"%>
<%@page import="org.alfresco.webservice.util.Utils"%>
<%@page import="org.alfresco.webservice.util.WebServiceFactory"%>
<%@page import="java.rmi.RemoteException"%>
<%–@page import="javax.xml.rpc.ServiceException"–%>
<%@page import="org.alfresco.webservice.repository.QueryResult"%>
<%@page import="org.alfresco.webservice.repository.RepositoryFault"%>
<%@page import="org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub"%>
<%@page import="org.alfresco.webservice.types.Query"%>
<%@page import="org.alfresco.webservice.types.ResultSet"%>
<%@page import="org.alfresco.webservice.types.ResultSetRow"%>
<%@page import="org.alfresco.webservice.util.AuthenticationUtils"%>


   

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<%!
protected static final String USERNAME = "admin";
protected static final String PASSWORD = "admin";

protected static final Store STORE = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
protected static final Reference SAMPLE_FOLDER = new Reference(STORE,null, "/app:company_home/cm:Intranet");





public static Reference executeSearch() throws  RemoteException, RepositoryFault
{
try   
{
    Reference parentReference = null;
   
    // Get a reference to the respository web service
    RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();        
   
    // Create a query object, looking for all items with alfresco in the name of text
    Query query = new Query(Constants.QUERY_LANG_LUCENE, "@cm\\:name:EE*");
   
    // Execute the query
    QueryResult queryResult = repositoryService.query(STORE, query, false);
   
    // Display the results
    ResultSet resultSet = queryResult.getResultSet();
    ResultSetRow[] rows = resultSet.getRows();
    if (rows == null)
    {
        System.out.println("No query results found.");
    }
    else
    {
        System.out.println("Results from query:");
        outputResultSet(rows);
       
        // Get the id of the first result
        String firstResultId = rows[0].getNode().getId();
        Reference reference = new Reference(STORE, firstResultId, null);
       
        // Get the parent(s) of the first result
        QueryResult parentQueryResult = repositoryService.queryParents(reference);
       
        // Get the parent of the first result
        ResultSet parentResultSet = parentQueryResult.getResultSet();
        ResultSetRow[] parentRows = parentResultSet.getRows();

    }
   
}
    catch(ServiceException ee){}
   
    return parentReference;   
}
public static void outputResultSet(ResultSetRow[] rows)
{
    if (rows != null)
    {
        for (int x = 0; x < rows.length; x++)
        {
            ResultSetRow row = rows[x];
           
           // NamedValue[] columns = row.getColumns();
           System.out.println("——————————-");
           System.out.println("id node = "+row.getColumns(5).getName() + " – " + "Node value = "+ row.getColumns(5).getValue() );
       }
    }
}
%>

<%
    AuthenticationUtils.startSession(USERNAME, PASSWORD);
try
{   
   
    // Make sure smaple data has been created
  
   
    // Execute the search sample
    executeSearch();       
}
catch(RemoteException  e1){
   
   
}

catch(Exception  e){
   
   
}

finally
{
    // End the session
    AuthenticationUtils.endSession();
}
%>

</body>
</html>

but this return me some exceptions like

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 1 in the generated java file
The type org.apache.axis.AxisFault cannot be resolved. It is indirectly referenced from required .class files

An error occurred at line: 19 in the generated java file
Only a type can be imported. javax.xml.rpc.ServiceException resolves to a package

An error occurred at line: 27 in the generated java file
Only a type can be imported. javax.xml.rpc.soap.SOAPFaultException resolves to a package

An error occurred at line: 52 in the jsp file: /First.jsp
Type mismatch: cannot convert from RepositoryFault to Throwable
49: // Check to see if the sample folder has already been created or not
50: WebServiceFactory.getRepositoryService().get(new Predicate(new Reference[]{SAMPLE_FOLDER}, STORE, null));
51: }
52: catch(RepositoryFault ex1){
53:
54:
55: }


An error occurred at line: 60 in the jsp file: /First.jsp
SOAPFaultException cannot be resolved to a type
57:
58:
59: }
60: catch(SOAPFaultException ex3){
61:
62:
63: }


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

Anybody help me please  :(  to solve it.or if  you have some jsp examples with Alfresco and web service please send me or put it there

Sorry my English isn't good but I am hope you understand me

Outcomes