cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with rootgroup api

laurent_hever
Champ in-the-making
Champ in-the-making
Hi,

I'm trying to add a new rootgroup to my alfresco with the rootgroup api function.
I'm trying this from a java webapp. Here's my code.


public boolean createRootGroup(String groupShortName) {
        getLog().info("Adding group " + groupShortName);
        HttpClient httpClient = new DefaultHttpClient();
        String alfrescoUrl = ResourceBundle.getBundle("pchCommonsWebAlfresco").getString("alfrescoServer");
        try {
            String url = alfrescoUrl + "/alfresco/service/api/rootgroups/" + groupShortName +
                    "?alf_ticket=" + getAlfResource().getTicket();
            getLog().info("Url: " + url);
            HttpPost request = new HttpPost(url);
            request.addHeader("content-type", "application/json");
            HttpResponse result = httpClient.execute(request);
            log.info(result.toString());
            if (result.getStatusLine().getStatusCode() == 200)
                return true;
            String json = EntityUtils.toString(result.getEntity(), "UTF-8");
            JSONParser parser = new JSONParser();
            JSONObject resultObject = (JSONObject) parser.parse(json);
            String exception = (String) resultObject.get("exception");
            getLog().severe("Could not add group " + groupShortName);
            getLog().severe("Exception: " + exception);
            return false;
        } catch (Exception e) {
            getLog().severe("Could not add group " + groupShortName + "(" + e.toString() +": " + e.getMessage() + ")");
            return false;
        }
    }


On the alfresco side, I receive this message. The shortname is a simple string with some "_" but nothing special.


2015-05-13 08:14:31,360  ERROR [extensions.webscripts.AbstractRuntime] [http-apr-8080-exec-495] Exception from executeScript - redirecting to status template error: 04131264 Failed to convert request to JSON
org.springframework.extensions.webscripts.WebScriptException: 04131264 Failed to convert request to JSON
        at org.springframework.extensions.webscripts.json.JSONReader.read(JSONReader.java:82)
        at org.springframework.extensions.webscripts.json.JSONReader.createScriptParameters(JSONReader.java:93)
        at org.springframework.extensions.webscripts.AbstractWebScript.createScriptParameters(AbstractWebScript.java:663)
        at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:81)
        at org.alfresco.repo.web.scripts.RepositoryContainer$3.execute(RepositoryContainer.java:433)
        at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:454)
        at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:495)
        at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:563)
        at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:343)
        at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:378)
        at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)
        at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
        at org.apache.tomcat.util.net.AprEndpoint$SocketWithOptionsProcessor.run(AprEndpoint.java:2378)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:724)
Caused by: org.json.JSONException: A JSONObject text must begin with '{' at character 0
        at org.json.JSONTokener.syntaxError(JSONTokener.java:413)
        at org.json.JSONObject.<init>(JSONObject.java:180)
        at org.json.JSONObject.<init>(JSONObject.java:420)
        at org.springframework.extensions.webscripts.json.JSONReader.read(JSONReader.java:77)
        … 34 more


Does someone know a solution for this?

best regards,
Laurent
3 REPLIES 3

mrogers
Star Contributor
Star Contributor
You have forgotten to post anything!    You have got as far as saying you are posting JSON but there's no body.

Oh.
I didn't know that I works that way, I thought I should only POST the request, but you were right. With the json attached to the request it works just as expected.

many thanks.

sujaypillai
Confirmed Champ
Confirmed Champ
If I do the same with CURL I use the below command -

curl -X POST -H "Content-Type: application/json" -d '{data:{shortName:"test22"}}' -u admin:admin http://localhost:8080/alfresco/service/api/rootgroups/test22




{
   "data":{
         "authorityType": "GROUP",
         "shortName": "test22",
         "fullName": "GROUP_test22",
         "displayName": "test22",
         "url": "/api/groups/test22"
           ,"zones":
           [
              "APP.DEFAULT",
              "AUTH.ALF"
           ]
}

}


Make sure you are passing the JSON object correctly as shown above.

Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.