cancel
Showing results for 
Search instead for 
Did you mean: 

from jsp to alfresco with web service

rufatina
Champ in-the-making
Champ in-the-making
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  Smiley Sad  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
2 REPLIES 2

cdifulco
Champ in-the-making
Champ in-the-making
Hi rufatina,
I'm facing the same problem of your post and I'd like to know if you solved it.

I'm trying to include a custom jar library that uses Alfresco's API in my web application, but when I try to open the jsp page on the browser it returns an error.

This is the jsp code:


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

<%@ page import= "d2b.simpleClient.SearchService_v2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</head>
<body>
   
   <br/>
   <h1>Risultato della Ricerca: </h1>
   
   <%
      
      SearchService_v2 scdq = new SearchService_v2();
      
      out.println(scdq.ciao());
   %>
</body>
</html>

And this is the full error message:

 GRAVE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 20 in the jsp file: /principale.jsp
SearchService_v2 cannot be resolved to a type
17:    
18:    <%
19:       
20:       SearchService_v2 scdq = new SearchService_v2();
21:       
22:       out.println(scdq.ciao());
23:    %>


An error occurred at line: 20 in the jsp file: /principale.jsp
SearchService_v2 cannot be resolved to a type
17:    
18:    <%
19:       
20:       SearchService_v2 scdq = new SearchService_v2();
21:       
22:       out.println(scdq.ciao());
23:    %>


Stacktrace:
   at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
   at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
   at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
   at org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)
   at org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
   at org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
   at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
   at java.lang.Thread.run(Thread.java:619)

please help me if you solved your problem!

thanks

maqsood
Confirmed Champ
Confirmed Champ
include alfresco-web-service-client.jar and other required jars in your project library