留言板
Liferay 6.1 jsonws example
In my blog post from last June, I gave 3 examples of using Liferay's built-in JSON web services to query and post new content to Liferay. It was based on 6.0, and a couple of you noticed that it doesn't work in 6.1, so I re-did the 3rd example to demonstrate how to achieve the same thing using 6.1's new jsonws services. Below you will find the addArticle() and removeArticle() from the 3rd example of my blog post, re-written to work with Liferay 6.1 GA1.
You will notice a couple of changes:
Similar changes are needed to make the other 2 examples work, but they should be straightforward based on the example above.
Enjoy!
private static void addArticle() throws Exception {
HttpHost targetHost = new HttpHost("localhost", 8080, "http");
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(targetHost.getHostName(), targetHost.getPort()),
new UsernamePasswordCredentials("bruno@7cogs.com", "bruno"));
// Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local
// auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
// Add AuthCache to the execution context
BasicHttpContext ctx = new BasicHttpContext();
ctx.setAttribute(ClientContext.AUTH_CACHE, authCache);
HttpPost post = new HttpPost("/api/secure/jsonws/journalarticle/add-article");
Calendar yesterday = Calendar.getInstance();
yesterday.add(Calendar.DAY_OF_YEAR, -1);
Calendar nextWeek = Calendar.getInstance();
nextWeek.add(Calendar.WEEK_OF_YEAR, 1);
List<namevaluepair> params = new ArrayList<namevaluepair>();
params.add(new BasicNameValuePair("groupId", "10180"));
params.add(new BasicNameValuePair("classNameId", "0"));
params.add(new BasicNameValuePair("classPK", "0"));
params.add(new BasicNameValuePair("articleId", "60000"));
params.add(new BasicNameValuePair("autoArticleId", "false"));
params.add(new BasicNameValuePair("titleMap", "{\"en_US\":\"Test JSON Article\"}"));
params.add(new BasicNameValuePair("descriptionMap", "{\"en_US\":\"Test JSON Description\"}"));
params.add(new BasicNameValuePair("content", "<!--?xml version='1.0' encoding='UTF-8'?--><root available-locales="\"en_US\"" default-locale="\"en_US\""><static-content language-id="\"en_US\""><p>\n" +
"\ttest content</p></static-content></root>"));
params.add(new BasicNameValuePair("type", "general"));
params.add(new BasicNameValuePair("structureId", ""));
params.add(new BasicNameValuePair("templateId", ""));
params.add(new BasicNameValuePair("layoutUuid", ""));
params.add(new BasicNameValuePair("displayDateMonth", "" + (1 + yesterday.get(Calendar.MONTH))));
params.add(new BasicNameValuePair("displayDateDay", "" + yesterday.get(Calendar.DAY_OF_MONTH)));
params.add(new BasicNameValuePair("displayDateYear", "" + yesterday.get(Calendar.YEAR)));
params.add(new BasicNameValuePair("displayDateHour", "" + yesterday.get(Calendar.HOUR_OF_DAY)));
params.add(new BasicNameValuePair("displayDateMinute", "" + yesterday.get(Calendar.MINUTE)));
params.add(new BasicNameValuePair("expirationDateMonth", "" + (1 + nextWeek.get(Calendar.MONTH))));
params.add(new BasicNameValuePair("expirationDateDay", "" + nextWeek.get(Calendar.DAY_OF_MONTH)));
params.add(new BasicNameValuePair("expirationDateYear", "" + nextWeek.get(Calendar.YEAR)));
params.add(new BasicNameValuePair("expirationDateHour", "" + nextWeek.get(Calendar.HOUR_OF_DAY)));
params.add(new BasicNameValuePair("expirationDateMinute", "" + nextWeek.get(Calendar.MINUTE)));
params.add(new BasicNameValuePair("neverExpire", "false"));
params.add(new BasicNameValuePair("reviewDateMonth", "" + (1 + nextWeek.get(Calendar.MONTH))));
params.add(new BasicNameValuePair("reviewDateDay", "" + nextWeek.get(Calendar.DAY_OF_MONTH)));
params.add(new BasicNameValuePair("reviewDateYear", "" + nextWeek.get(Calendar.YEAR)));
params.add(new BasicNameValuePair("reviewDateHour", "" + nextWeek.get(Calendar.HOUR_OF_DAY)));
params.add(new BasicNameValuePair("reviewDateMinute", "" + nextWeek.get(Calendar.MINUTE)));
params.add(new BasicNameValuePair("neverReview", "false"));
params.add(new BasicNameValuePair("indexable", "true"));
params.add(new BasicNameValuePair("articleURL", "articleURL"));
params.add(new BasicNameValuePair("serviceContext", "{}"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
post.setEntity(entity);
HttpResponse resp = httpclient.execute(targetHost, post, ctx);
System.out.println(resp.getStatusLine());
resp.getEntity().writeTo(System.out);
httpclient.getConnectionManager().shutdown();
}
public static void removeArticle() throws Exception {
HttpHost targetHost = new HttpHost("localhost", 8080, "http");
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(targetHost.getHostName(), targetHost.getPort()),
new UsernamePasswordCredentials("bruno@7cogs.com", "bruno"));
// Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local
// auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
// Add AuthCache to the execution context
BasicHttpContext ctx = new BasicHttpContext();
ctx.setAttribute(ClientContext.AUTH_CACHE, authCache);
HttpPost post = new HttpPost("/api/secure/jsonws/journalarticle/delete-article");
List<namevaluepair> params = new ArrayList<namevaluepair>();
params.add(new BasicNameValuePair("groupId", "10180"));
params.add(new BasicNameValuePair("articleId", "60000"));
params.add(new BasicNameValuePair("articleURL", "articleURL"));
params.add(new BasicNameValuePair("serviceContext", "{}"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
post.setEntity(entity);
HttpResponse resp = httpclient.execute(targetHost, post, ctx);
System.out.println(resp.getStatusLine());
resp.getEntity().writeTo(System.out);
httpclient.getConnectionManager().shutdown();
}
</namevaluepair></namevaluepair></namevaluepair></namevaluepair>
You will notice a couple of changes:
- The path to the jsonws resource has changed (no longer need tunnel-web). It is now /api/secure/jsonws/<service>/<method>. You can read more about these services in the official development documentation.
- There are a couple of new parameters needed for addArticle(), and they are of type java.util.Map - these can be passed by forming a serialized representation of the map using json notation. e.g. {"en_US":"Some Title in US English"}
- There are also new parameters for classNameID, classPK, and layoutId - all can be set to 0 when creating a new article. These new parameters are used for storing default values for content (see LPS-16960) and for setting the default display page (see LPS-15035).
Similar changes are needed to make the other 2 examples work, but they should be straightforward based on the example above.
Enjoy!
Hi James:
I have JSON services working in 6.1 but it's not secured. I can access my test service using url http://localhost:8080/DataSourceTest-portlet/api/secure/jsonws/training/get-my-training/myparam/myparamvalue
Only problem is I can not secure access using user id and pass. What does this mean when we have api/secure/jsonws in the url?
Thanks.
Mohammad
I have JSON services working in 6.1 but it's not secured. I can access my test service using url http://localhost:8080/DataSourceTest-portlet/api/secure/jsonws/training/get-my-training/myparam/myparamvalue
Only problem is I can not secure access using user id and pass. What does this mean when we have api/secure/jsonws in the url?
Thanks.
Mohammad
I have JSON services working in 6.1 but it's not secured. I can access my test service using url http://localhost:8080/DataSourceTest-portlet/api/secure/jsonws/training/get-my-training/myparam/myparamvalue
Only problem is I can not secure access using user id and pass. What does this mean when we have api/secure/jsonws in the url?
Check the following security patch.
http://www.liferay.com/community/security-team/known-vulnerabilities/-/asset_publisher/T8Ei/content/cst-sa-lps-26935-all-json-web-services-are-accessible-without-authentication-?redirect=http%3A%2F%2Fwww.liferay.com%2Fcommunity%2Fsecurity-team%2Fknown-vulnerabilities%3Fp_p_id%3D101_INSTANCE_T8Ei%26p_p_lifecycle%3D0%26p_p_state%3Dnormal%26p_p_mode%3Dview%26p_p_col_id%3Dcolumn-5%26p_p_col_count%3D1
Doesn't work with 6.1 EE
Pass value 0 to classNameId parameter.
I get the following exception
com.liferay.portal.NoSuchGroupException: No Group exists with the primary key 0
So I changed classNameId to a positive value.
The article gets added but is not being displayed in the liferay webcontent list.
I had to manually update the classNameId to 0 in JournalArticle table in the DB for the newly added article to appear in the web content list
Please reply
Pass value 0 to classNameId parameter.
I get the following exception
com.liferay.portal.NoSuchGroupException: No Group exists with the primary key 0
So I changed classNameId to a positive value.
The article gets added but is not being displayed in the liferay webcontent list.
I had to manually update the classNameId to 0 in JournalArticle table in the DB for the newly added article to appear in the web content list
Please reply
KARTHIK VENKATARAMAN:
Doesn't work with 6.1 EE
Pass value 0 to classNameId parameter.
I get the following exception
com.liferay.portal.NoSuchGroupException: No Group exists with the primary key 0
So I changed classNameId to a positive value.
The article gets added but is not being displayed in the liferay webcontent list.
I had to manually update the classNameId to 0 in JournalArticle table in the DB for the newly added article to appear in the web content list
Please reply
I'm getting the same Error with LR 6.1.1 CE GA2. I already tried to submit a serviceContext with the scopeGroupId, but it's still the same error. Is there no possible solution?
Hi Karthik, J W
I have debugged the code and following are my findings -
Above exception has nothing to do with classNameId parameter; Its because of following code in the JournalArticleWorkflowHandler class
Here serviceContext.getScopeGroupId() returns 0 that results in com.liferay.portal.NoSuchGroupException exception in PortalImpl class
When we pass classNameId parameter a value >0 then this flow is bypassed so we do not get this exceprion.
HTH
Regards
I have debugged the code and following are my findings -
com.liferay.portal.NoSuchGroupException: No Group exists with the primary key 0
Above exception has nothing to do with classNameId parameter; Its because of following code in the JournalArticleWorkflowHandler class
ServiceContext serviceContext = (ServiceContext)workflowContext.get(
"serviceContext");
String articleURL = PortalUtil.getControlPanelFullURL(
serviceContext.getScopeGroupId(), PortletKeys.JOURNAL, null);
Here serviceContext.getScopeGroupId() returns 0 that results in com.liferay.portal.NoSuchGroupException exception in PortalImpl class
public String getControlPanelFullURL(
long scopeGroupId, String ppid, Map<string, string[]> params)
throws PortalException, SystemException {
StringBundler sb = new StringBundler(6);
Group group = GroupLocalServiceUtil.getGroup(scopeGroupId); // at this line
</string,>
When we pass classNameId parameter a value >0 then this flow is bypassed so we do not get this exceprion.
if (classNameId == 0) {
WorkflowHandlerRegistryUtil.startWorkflowInstance(
user.getCompanyId(), groupId, userId,
JournalArticle.class.getName(), article.getId(), article,
serviceContext);
if (serviceContext.getWorkflowAction() !=
WorkflowConstants.ACTION_PUBLISH) {
// Indexer
Indexer indexer = IndexerRegistryUtil.getIndexer(
JournalArticle.class);
indexer.reindex(article);
}
}
else {
updateStatus(
userId, article, WorkflowConstants.STATUS_APPROVED, null,
serviceContext);
}
HTH
Regards
To get this fixed pass scopeGroupId within serviceContext -
params.add(new BasicNameValuePair("serviceContext.scopeGroupId", "10180"));
Hi
first of all thanks for your post,
I was try your sample 1) and after adapting is working fine. But I want to invoke a service (DLFileEntry or DLApp) and in both cases i get the same error:
the last code I test (for DLApp):
.
first of all thanks for your post,
I was try your sample 1) and after adapting is working fine. But I want to invoke a service (DLFileEntry or DLApp) and in both cases i get the same error:
java.lang.RuntimeException: No JSON web service action associated with path /dlapp/add-file-entry and method POST for /
the last code I test (for DLApp):
.
......
String sTRgroupId = groupId+"";
String sTRfolderId = folderId+"";
String sTRfileEntryTypeId = fileEntryTypeId+"";
String sTRfieldsMap = JsonWriter.objectToJson(fieldsMap);
String sTRfile = JsonWriter.objectToJson(file);;
String sTRis = JsonWriter.objectToJson(is);;
String sTRsize =size+"";
String sTRscopeGroupId = scopeGroupId+"";
addFileEntry(sTRgroupId, sTRfolderId , title, description, sTRfileEntryTypeId , sTRfieldsMap, sTRfile, sTRis , sTRsize, sTRscopeGroupId );
public static void addFileEntry(String groupId, String folderId, String title, String description, String fileEntryTypeId, String fieldsMap, String file, String is, String size, String scopeGroupId) throws Exception {
HttpHost targetHost = new HttpHost("localhost",8080,"http");
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(targetHost.getHostName(), targetHost.getPort()),
new UsernamePasswordCredentials("test@liferay.com", “****"));
// Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local
// auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
// Add AuthCache to the execution context
BasicHttpContext ctx = new BasicHttpContext();
ctx.setAttribute(ClientContext.AUTH_CACHE, authCache);
// HttpPost post = new HttpPost("/api/secure/jsonws/dlfileentry/add-file-entry");
HttpPost post = new HttpPost("/api/secure/jsonws/dlapp/add-file-entry");
List<namevaluepair> params = new ArrayList<namevaluepair>();
// params.add(new BasicNameValuePair("serviceClassName", "com.liferay.portlet.documentlibrary.service.DLFileEntryServiceUtil"));
params.add(new BasicNameValuePair("serviceClassName", "com.liferay.portlet.documentlibrary.service.DLAppServiceUtil"));
params.add(new BasicNameValuePair("serviceMethodName", "addFileEntry"));
// dlapp params.add(new BasicNameValuePair("serviceParameters", "[groupId,repositoryId,folderId,sourceFileName,mimeType,title,description,changeLog,is,size,serviceContext]"));
// dlapp params.add(new BasicNameValuePair("serviceParameterTypes", "[long,long,long,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.io.InputStream,long,com.liferay.portal.service.ServiceContext]"));
// params.add(new BasicNameValuePair("serviceParameters", "[groupId,repositoryId,folderId,sourceFileName,mimeType,title,description,changeLog,fileEntryTypeId,fieldsMap,file,is,size,serviceContext]"));
// params.add(new BasicNameValuePair("serviceParameterTypes", "[long,long,long,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,long,java.util.Map,java.io.File,java.io.InputStream,long,com.liferay.portal.service.ServiceContext]"));
params.add(new BasicNameValuePair("groupId", groupId));
params.add(new BasicNameValuePair("repositoryId", "0"));
params.add(new BasicNameValuePair("folderId", folderId));
params.add(new BasicNameValuePair("title",title));
params.add(new BasicNameValuePair("description", description));
params.add(new BasicNameValuePair("changeLog", ""));
// params.add(new BasicNameValuePair("fileEntryTypeId", fileEntryTypeId));
// params.add(new BasicNameValuePair("fieldsMap", fieldsMap));
// params.add(new BasicNameValuePair("file", file));
params.add(new BasicNameValuePair("is", is));
params.add(new BasicNameValuePair("size", size));
params.add(new BasicNameValuePair("serviceContext", "{}"));
// params.add(new BasicNameValuePair("serviceContext.scopeGroupId", scopeGroupId));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
post.setEntity(entity);
HttpResponse resp = httpclient.execute(targetHost, post, ctx);
System.out.println(resp.getStatusLine());
resp.getEntity().writeTo(System.out);
httpclient.getConnectionManager().shutdown();
}</namevaluepair></namevaluepair>
I was able to create a DlFileEntry , with the following code: But it works only with empty “bytes” you get a record create but with a cero bytes, I try many diferents ways to convert the bytes into Json string, but any works I always get the error:
what is the correct way to fill up that param “bytes” in a /dlapp/add-file-entry
Here is the code I was trying :
{"exception":"Unable to convert to type: [B\njodd.typeconverter.TypeConversionException: Unable to convert value: JVBERi0xLjQKJeLjz9MKNSAwIG9iago8
what is the correct way to fill up that param “bytes” in a /dlapp/add-file-entry
Here is the code I was trying :
public static void main(String[] args) throws Exception {
long folderId = 13713;
long groupId = 10179;
String scopeGroupId ="10179";
String mimeType = "application/pdf";
long fileEntryTypeId = 0;
File file = new File("temp"+"sourceFileName");
String url = "http://localhost:8080/pdfs/ACTANum126.pdf";
System.err.println("URL A conectar" + url);
URLConnection conn;
try {
conn = new URL(url).openConnection();
conn.connect();
InputStream is = conn.getInputStream();
byte[] bytes = IOUtils.toByteArray(is);
Base64 base64 = new Base64();
byte[] buffer = new byte[(int) file.length() + 100];
int length = is.read(buffer);
String sTRBytes = Base64.encodeBase64URLSafeString(bytes);
// String sTRBytes = JsonWriter.objectToJson(bytes);
// String sTRBytes = JsonWriter.toJson(bytes);
is.close();
addDLFileEntry(sTRgroupId, sTRfolderId , "titlessaasss", "description", sTRfileEntryTypeId , sTRfile, sTRis , sTRsize, sTRscopeGroupId, mimeType,sTRBytes );
public static void addDLFileEntry(String groupId, String folderId, String title, String description, String fileEntryTypeId, String file, String is, String size, String scopeGroupId, String mimeType,String sTRBytes) throws Exception {
HttpHost targetHost = new HttpHost("localhost",8080,"http");
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(targetHost.getHostName(), targetHost.getPort()),
new UsernamePasswordCredentials("test@liferay.com", "brasin"));
// Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local
// auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
// Add AuthCache to the execution context
BasicHttpContext ctx = new BasicHttpContext();
ctx.setAttribute(ClientContext.AUTH_CACHE, authCache);
HttpPost post = new HttpPost("/api/secure/jsonws/dlapp/add-file-entry");
List<namevaluepair> params = new ArrayList<namevaluepair>();
params.add(new BasicNameValuePair("repositoryId", "10179"));
params.add(new BasicNameValuePair("folderId",folderId));
params.add(new BasicNameValuePair("sourceFileName", "/Applications/Liferay/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/webapps/pdfs/ACTANum126.pdf"));
params.add(new BasicNameValuePair("mimeType", mimeType));
params.add(new BasicNameValuePair("title", title));
params.add(new BasicNameValuePair("description", "description"));
params.add(new BasicNameValuePair("changeLog", "file"));
params.add(new BasicNameValuePair("bytes", sTRBytes));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
post.setEntity(entity);
HttpResponse resp = httpclient.execute(targetHost, post, ctx);
System.out.println(resp.getStatusLine());
resp.getEntity().writeTo(System.out);
httpclient.getConnectionManager().shutdown();
}
</namevaluepair></namevaluepair>
Finally I found the solution:
what the param need is just a list of values that represents the data by example : 23,34,35,12….
as String sTRBytes = JsonWriter.objectToJson(bytes); returns
{"@type":"B","@items”:[23,34,35,12…..]}
you just have to take off what is not need
sTRBytes = sTRBytes.substring(24,sTRBytes.length()-2);
(or any other way to get the content of a Byte[] as a string of a list of numbers)
then with :
params.add(new BasicNameValuePair("bytes", sTRBytes));
you will your data upload a attached to the DLFileEntry Row
what the param need is just a list of values that represents the data by example : 23,34,35,12….
as String sTRBytes = JsonWriter.objectToJson(bytes); returns
{"@type":"B","@items”:[23,34,35,12…..]}
you just have to take off what is not need
sTRBytes = sTRBytes.substring(24,sTRBytes.length()-2);
(or any other way to get the content of a Byte[] as a string of a list of numbers)
then with :
params.add(new BasicNameValuePair("bytes", sTRBytes));
you will your data upload a attached to the DLFileEntry Row
Hi
I created a JSON Webservice in liferay without authentication.
I build a simple java client that access with that GET call:
Then I mount JSONObject with response obtained. It's a simple http get call.
My problem is encoding. By default I received with ISO-8859-1. I changed the InputStreamReader call , with charset UTF-8 but does not works. The special chars are broken by thuis way.
Any help please?
I created a JSON Webservice in liferay without authentication.
I build a simple java client that access with that GET call:
URLConnection conn = null;
try {
conn = url.openConnection ();
} catch (IOException e) {
e.printStackTrace();
}
BufferedReader rd = null;
try {
rd = new BufferedReader(new InputStreamReader(conn.getInputStream(),Charset.forName("UTF-8")));
} catch (IOException e) {
e.printStackTrace();
}
StringBuffer sb = new StringBuffer();
String line;
try {
while ((line = rd.readLine()) != null) {sb.append(line); }
} catch (IOException e) {
e.printStackTrace();
}
Then I mount JSONObject with response obtained. It's a simple http get call.
My problem is encoding. By default I received with ISO-8859-1. I changed the InputStreamReader call , with charset UTF-8 but does not works. The special chars are broken by thuis way.
Any help please?
Hi James,
We are trying to create announcement through json service using httpClient in Liferay 6.1.
JSON URL: http://localhost:8080/api/secure/jsonws/announcements/add-entry We got below exception
ERROR [JSONWebServiceServiceAction:84] java.lang.RuntimeException: No JSON web service action associated with path /announcements/add-entry and method POST for /
java.lang.RuntimeException: No JSON web service action associated with path /announcements/add-entry and method POST for /
at com.liferay.portal.jsonwebservice.JSONWebServiceActionsManagerImpl.getJSONWebServiceAction(JSONWebServiceActionsManagerImpl.java:100)
at com.liferay.portal.kernel.jsonwebservice.JSONWebServiceActionsManagerUtil.getJSONWebServiceAction(JSONWebServiceActionsManagerUtil.java:31)
at com.liferay.portal.jsonwebservice.JSONWebServiceServiceAction.getJSON(JSONWebServiceServiceAction.java:71)
at com.liferay.portal.struts.JSONAction.execute(JSONAction.java:60)
at com.liferay.portal.servlet.JSONServlet.service(JSONServlet.java:64)
Then I have tried with http://localhost:8080/api/secure/json and passing serviceclassname and method as parameter. we got below exception
ERROR [JSONServiceAction:465] No method found for class class com.liferay.portlet.announcements.service.AnnouncementsEntryServiceUtil, method addEntry, and parameters
Thanks,
Ram
We are trying to create announcement through json service using httpClient in Liferay 6.1.
JSON URL: http://localhost:8080/api/secure/jsonws/announcements/add-entry We got below exception
ERROR [JSONWebServiceServiceAction:84] java.lang.RuntimeException: No JSON web service action associated with path /announcements/add-entry and method POST for /
java.lang.RuntimeException: No JSON web service action associated with path /announcements/add-entry and method POST for /
at com.liferay.portal.jsonwebservice.JSONWebServiceActionsManagerImpl.getJSONWebServiceAction(JSONWebServiceActionsManagerImpl.java:100)
at com.liferay.portal.kernel.jsonwebservice.JSONWebServiceActionsManagerUtil.getJSONWebServiceAction(JSONWebServiceActionsManagerUtil.java:31)
at com.liferay.portal.jsonwebservice.JSONWebServiceServiceAction.getJSON(JSONWebServiceServiceAction.java:71)
at com.liferay.portal.struts.JSONAction.execute(JSONAction.java:60)
at com.liferay.portal.servlet.JSONServlet.service(JSONServlet.java:64)
Then I have tried with http://localhost:8080/api/secure/json and passing serviceclassname and method as parameter. we got below exception
ERROR [JSONServiceAction:465] No method found for class class com.liferay.portlet.announcements.service.AnnouncementsEntryServiceUtil, method addEntry, and parameters
Thanks,
Ram
has you send all the params that the JSON Service needs?
you can see in http://localhost:8080/api/jsonws?signature=/announcementsentry/add-entry-19-plid-classNameId-classPK-title-content-url-type-displayDateMonth-displayDateDay-displayDateYear-displayDateHour-displayDateMinute-expirationDateMonth-expirationDateDay-expirationDateYear-expirationDateHour-expirationDateMinute-priority-alert
If you don’t fill that params, then you get the error :
No JSON web service action associated with path /announcements/add-entry and method POST for /
you can see in http://localhost:8080/api/jsonws?signature=/announcementsentry/add-entry-19-plid-classNameId-classPK-title-content-url-type-displayDateMonth-displayDateDay-displayDateYear-displayDateHour-displayDateMinute-expirationDateMonth-expirationDateDay-expirationDateYear-expirationDateHour-expirationDateMinute-priority-alert
If you don’t fill that params, then you get the error :
No JSON web service action associated with path /announcements/add-entry and method POST for /
Cesar Quinteiro:
has you send all the params that the JSON Service needs?
you can see in http://localhost:8080/api/jsonws?signature=/announcementsentry/add-entry-19-plid-classNameId-classPK-title-content-url-type-displayDateMonth-displayDateDay-displayDateYear-displayDateHour-displayDateMinute-expirationDateMonth-expirationDateDay-expirationDateYear-expirationDateHour-expirationDateMinute-priority-alert
If you don’t fill that params, then you get the error :
No JSON web service action associated with path /announcements/add-entry and method POST for /
Thank you for the suggestion. But I have filled all the params. Please find below.
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("plid", PropertiesUtil.getProperty("announce_plid")));
params.add(new BasicNameValuePair("classNameId", PropertiesUtil.getProperty("announce_classNameId")));
params.add(new BasicNameValuePair("classPK", PropertiesUtil.getProperty("announce_classPK")));
params.add(new BasicNameValuePair("title", subject));
params.add(new BasicNameValuePair("content", content));
params.add(new BasicNameValuePair("url", PropertiesUtil.getProperty("announce_URL")));
params.add(new BasicNameValuePair("type", PropertiesUtil.getProperty("announce_Type")));
params.add(new BasicNameValuePair("displayDateMonth", ""+(displayStart.get(Calendar.MONTH))));
params.add(new BasicNameValuePair("displayDateDay", ""+(displayStart.get(Calendar.DAY_OF_MONTH))));
params.add(new BasicNameValuePair("displayDateYear", ""+(displayStart.get(Calendar.YEAR))));
params.add(new BasicNameValuePair("displayDateHour", ""+(displayStart.get(Calendar.HOUR_OF_DAY))));
params.add(new BasicNameValuePair("displayDateMinute", ""+(displayStart.get(Calendar.MINUTE))));
params.add(new BasicNameValuePair("expirationDateMonth", ""+(displayEnd.get(Calendar.MONTH))));
params.add(new BasicNameValuePair("expirationDateDay", ""+(displayEnd.get(Calendar.DAY_OF_MONTH))));
params.add(new BasicNameValuePair("expirationDateYear", ""+(displayEnd.get(Calendar.YEAR))));
params.add(new BasicNameValuePair("expirationDateHour", ""+(displayEnd.get(Calendar.HOUR_OF_DAY))));
params.add(new BasicNameValuePair("expirationDateMinute", ""+(displayEnd.get(Calendar.MINUTE))));
params.add(new BasicNameValuePair("priority", PropertiesUtil.getProperty("announce_Priority")));
params.add(new BasicNameValuePair("alert", PropertiesUtil.getProperty("announce_alert")));
I have similar problem with /api/secure/jsonws/dlfileentry/add-file-entry and wasn’t able to resolve it even I was sending all the params, I was getting the same error:
finally I used /api/secure/jsonws/dlapp/add-file-entry and then it works,
I don’t know If exists equivalent for announcementsentry, I didn’t found,
Any way I don’t see any mistake in your code and after my case where I was double checking my params, and I was getting always the error , my conclusion is that the JSON service is wrong documented, in your case and also in my case, I hope that somebody from Liferay develoment team clarify this point.
Please If you finally found the solution post it here.
finally I used /api/secure/jsonws/dlapp/add-file-entry and then it works,
I don’t know If exists equivalent for announcementsentry, I didn’t found,
Any way I don’t see any mistake in your code and after my case where I was double checking my params, and I was getting always the error , my conclusion is that the JSON service is wrong documented, in your case and also in my case, I hope that somebody from Liferay develoment team clarify this point.
Please If you finally found the solution post it here.
I had similar error messages and it was solved by using hints on the JSON calls, that helps the web-server to match the correct method
for example, the below JSON call is working,
using a hint = 10
(I am using "api/secure/jsonws/invoke ", Liferay 6.1 GA2)
using a hint = 10
(I am using "api/secure/jsonws/invoke ", Liferay 6.1 GA2)
JSONObject _command = new JSONObject();
JSONObject serviceContext = new JSONObject();
JSONArray files = new JSONArray();
try {
JSONObject _params = new JSONObject();
_params.put("groupId", GROUP_ID);
_params.put("categoryId", CATEGORY_ID);
_params.put("subject", "test 15");
_params.put("body", "test 15");
_params.put("format", "bbcode");
_params.put("inputStreamOvPs", files);
_params.put("anonymous", false);
_params.put("priority", 0);
_params.put("allowPingbacks", false);
_params.put("serviceContext", serviceContext);
_params.put("serviceContext.addGroupPermissions", true);
_params.put("serviceContext.assetTagNames", "vegetables, water");
_command.put("/mbmessage/add-message.10", _params);
Hello, and thank you for the great informative post!!
I am having trouble executing via JSONWS at http://localhost:8080/api/jsonws
Specifically the add-article method. I am receiving the following message when I invoke: "com.liferay.portlet.journal.ArticleTitleException"
Here is the parameter/value list. Any thoughts?
I am having trouble executing via JSONWS at http://localhost:8080/api/jsonws
Specifically the add-article method. I am receiving the following message when I invoke: "com.liferay.portlet.journal.ArticleTitleException"
Here is the parameter/value list. Any thoughts?
Liferay.Service(
'/journalarticle/add-article',
{
groupId: 10184,
folderId: 12211,
classNameId: 0,
classPK: 0,
articleId: '60000',
autoArticleId: false,
titleMap: {"en_us":"Some Title in US English"},
descriptionMap: {"en_us":"Some desc in US English"},
content: 'This is my test content.',
type: 'general',
ddmStructureKey: '0',
ddmTemplateKey: '0',
layoutUuid: '0',
displayDateMonth: 02,
displayDateDay: 25,
displayDateYear: 2014,
displayDateHour: 12,
displayDateMinute: 12,
expirationDateMonth: 12,
expirationDateDay: 12,
expirationDateYear: 2015,
expirationDateHour: 12,
expirationDateMinute: 12,
neverExpire: true,
reviewDateMonth: 12,
reviewDateDay: 12,
reviewDateYear: 2014,
reviewDateHour: 12,
reviewDateMinute: 12,
neverReview: true,
indexable: true,
articleURL: 'testURL'
},
function(obj) {
console.log(obj);
}
);
Well, I figured out that exception. I didn't have my content wrapped in XML.
Now I am getting the following...any thoughts?
"No DDMStructure exists with the key {groupId=10197, classNameId=10109, structureKey=0}"
Now I am getting the following...any thoughts?
"No DDMStructure exists with the key {groupId=10197, classNameId=10109, structureKey=0}"
Vijay Aravind Rajagopalan,修改在9 年前。
RE: Liferay 6.1 jsonws example
New Member 发布: 1 加入日期: 14-8-21 最近的帖子
I am getting the same error. I am using the /api/jsonws/invoke
"No DDMStructure exists with the key {groupId=10197, classNameId=10109, structureKey=11680}"
Any help and pointers is greatly appreciated.
"No DDMStructure exists with the key {groupId=10197, classNameId=10109, structureKey=11680}"
Any help and pointers is greatly appreciated.