AnsweredAssumed Answered

Create a share site with a program

Question asked by anita.platos on Nov 28, 2013
Latest reply on Nov 28, 2013 by yogeshpj
I have created a site with a Java program. It creates OK the site but it is unaccessible.
This is the java program:

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.json.JSONObject;
public class CreateSiteTest
{
   public static final String HOSTNAME="localhost";
   public static final String USER="admin";
   public static final String PASSWORD=USER;
   public static final Integer PORT=8080;
   public static final String APIURL="http://localhost:8080/alfresco/service/api/sites";
   public static final String SHORTNAME="mysite";
   public static final String VISIBILITY="PUBLIC";
   public static final String SITEPRESET="site-dashboard";
   public static final String CONTENT_TYPE="application/json";
   public void crearNuevoSitio ()
   {
      System.out.println("SHORTNAME= "+ SHORTNAME);
      HttpClient client = new HttpClient();
      client.getState().setCredentials(
                     new AuthScope(HOSTNAME, PORT, "Alfresco"),
                     new UsernamePasswordCredentials(USER, PASSWORD));
      String apiurl ="http://localhost:8080/alfresco/service/api/sites";
      PostMethod post = new PostMethod(apiurl);
      try
      {
         JSONObject site=new JSONObject ();
         site.put("description", SHORTNAME);
         site.put("shortName", SHORTNAME);
         site.put("visibility", VISIBILITY);
         site.put("sitePreset", SITEPRESET);
         site.put("title", SHORTNAME);
         site.put("description", SHORTNAME);
         System.out.println(site.toString());
         post.setDoAuthentication(true);
         post.setRequestHeader("Content-Type", CONTENT_TYPE);
         post.setRequestEntity(new StringRequestEntity(site.toString(), CONTENT_TYPE, "UTF-8"));
         int status = client.executeMethod(post);
         if (status != HttpStatus.SC_OK)
         {
            System.err.println("Method failed: " + post.getStatusLine());
         }
         String resultString = post.getResponseBodyAsString();
         System.out.println(resultString);
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }
      finally
      {
         post.releaseConnection();
      }
      
   }//void
}//class

The problem is that when I try to access to the site in the Share, it appears an error in the explorer interface telling this:

A server error has occured.
There are a number of reasons why this could have happened:
You have attempted to access a page that does not exist - check the URL in the address bar.
You have attempted to access a page that is not accessable to you, such as a private Site dashboard.
A valid page has been requested but the server was unable to render it due to an internal error -  contact your administrator.
Return to your dashboard page
Alfresco Software Inc. © 2005-2012 All rights reserved.

The exception in the log is:

javax.servlet.ServletException: Could not resolve view with name 'site/mysite/dashboard' in servlet with name 'Spring Surf Dispatcher Servlet'
   at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1029)
   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
   at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
   at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
   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.alfresco.web.site.servlet.MTAuthenticationFilter.doFilter(MTAuthenticationFilter.java:74)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.alfresco.web.site.servlet.SSOAuthenticationFilter.doFilter(SSOAuthenticationFilter.java:355)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   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.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   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:293)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
   at java.lang.Thread.run(Thread.java:662)

Moreover, in the application console browser I can see that normal sites created in the web interface  contain inside the folder "cm:surf-config", but my site created with the program doesn´t contain it. Somebody knows how can I create a site accessible with a program as I created using the Share inteface?

Outcomes