Create user with CUrl and JSON
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2014 08:46 AM
Hi,
we are using a custom webscript similar to the /alfresco/service/api/people webscript in order to create users passing a JSON argument with CUrl:
The problem is that if the JSON happens to be not well formed the script crashes with a stack without making us capable to catch any exception.
In fact, using the debugger, it seems that the check on the passed JSON is performed before entering the script.
Is it possible to intercept this error in order to preliminarly check the content of the passed JSON?
Regards,
Andrea
we are using a custom webscript similar to the /alfresco/service/api/people webscript in order to create users passing a JSON argument with CUrl:
curl -X POST -uadmin:admin http://localhost:8080/alfresco/service/api/people -H"content-type: application/json" -d@creaDOCADM.json
The problem is that if the JSON happens to be not well formed the script crashes with a stack without making us capable to catch any exception.
In fact, using the debugger, it seems that the check on the passed JSON is performed before entering the script.
Is it possible to intercept this error in order to preliminarly check the content of the passed JSON?
Regards,
Andrea
Labels:
- Labels:
-
Archive
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2014 12:06 PM
Before entering javascript controller ,webscript framework will first parse request content and try to convert it to JSON using org.json.JSONObject class.
If it can't be converted to json object ,an exception with "Failed to convert request to JSON" will be thrown,and you still can get http response with exception information like below
If it can't be converted to json object ,an exception with "Failed to convert request to JSON" will be thrown,and you still can get http response with exception information like below
{ "status" : { "code" : 500, "name" : "Internal Error", "description" : "An error inside the HTTP server which prevented it from fulfilling the request." }, "message" : "05050018 Failed to convert request to JSON", "exception" : "org.springframework.extensions.webscripts.WebScriptException -05050018 Failed to convert request to JSON", "callstack" : [ "" ,"org.json.JSONException: Expected a ',' or '}' at character 66" ,"org.json.JSONTokener.syntaxError(JSONTokener.java:413)" ,"org.json.JSONObject.<init>(JSONObject.java:223)" ,"org.json.JSONObject.<init>(JSONObject.java:420)" ,"org.springframework.extensions.webscripts.json.JSONReader.read(JSONReader.java:77)" ,"org.springframework.extensions.webscripts.json.JSONReader.createScriptParameters(JSONReader.java:93)" ,"org.springframework.extensions.webscripts.AbstractWebScript.createScriptParameters(AbstractWebScript.java:725)" ,"org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:81)" ,"org.alfresco.repo.web.scripts.RepositoryContainer$3.execute(RepositoryContainer.java:433)" ,"org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:454)" ,"org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:495)" ,"org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:553)" ,"org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:343)" ,"org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:378)" ,"org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)" ,"org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)" ,"javax.servlet.http.HttpServlet.service(HttpServlet.java:728)" ,"org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)" ,"org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)" ,"org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61)" ,"org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)" ,"org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)" ,"org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)" ,"org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)" ,"org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)" ,"org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)" ,"org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)" ,"org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)" ,"org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)" ,"org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)" ,"org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)" ,"org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)" ,"org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)" ,"java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)" ,"java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)" ,"java.lang.Thread.run(Thread.java:724)" ,"org.springframework.extensions.webscripts.WebScriptException: 05050018 Failed to convert request to JSON" ,"org.springframework.extensions.webscripts.json.JSONReader.read(JSONReader.java:82)" ], "server" : "Community v4.3.0 (r70508) schema 7,003", "time" : "2014-6-5 23:53:51"}
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2014 05:50 AM
Hi,
for me it is still unclear how can I intercept this exception since all I have is my post webscript.
Do you mean I should put this code between a try/catch clause?
How did you managed to get the exception you're showing in the post?
Regards,
Andrea
for me it is still unclear how can I intercept this exception since all I have is my post webscript.
Do you mean I should put this code between a try/catch clause?
How did you managed to get the exception you're showing in the post?
Regards,
Andrea
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2014 09:22 AM
It is just common response ,only it's content is filled with integer status code and exception detail information instead of node data.
The response body is llegal json format ,you can parse the json string and get integer status code,if it is other than 200,then something wrong happens.
The response body is llegal json format ,you can parse the json string and get integer status code,if it is other than 200,then something wrong happens.
