AnsweredAssumed Answered

Not able to create site programmatically

Question asked by nancyaggarwal on Mar 3, 2016
Latest reply on Apr 18, 2016 by nancyaggarwal

Hi ,

I trying to create a site in alfresco share using a webscript in java and this i am doing with the help of below code:

HttpClient client = new HttpClient();


          PostMethod  httpPost = new PostMethod ("http://localhost:8080/share/service/modules/create-site?authority="+username+"&alf_ticket="+alf_tkt);


           JSONObject site = new JSONObject();
           try {
               site.put("shortName", "java_test");
               site.put("Visiblity", "Public");
               site.put("sitePreset", "site-dashboard");
               site.put("title", "java_test");
               site.put("description", "test");
               httpPost.setDoAuthentication(true);
               httpPost.setRequestHeader("Content-Type", "application/json");
               httpPost.setRequestEntity( new StringRequestEntity(site.toString(), "application/json", "UTF-8"));


               int status1 = client.executeMethod(httpPost);

               if (status1 != HttpStatus.SC_OK) {
               System.err.println("Method failed: " + httpPost.getStatusLine());
               }



          } catch (JSONException e1) {
               // TODO Auto-generated catch block
               e1.printStackTrace();
          }

It is giving me the error as HTTP/1.1 401 Unauthorized.

Please help me in this.

Regards,
Nancy

Outcomes