Forums de discussion
How to send more than one actionId to a JSON service
Cesar Quinteiro, modifié il y a 11 années.
How to send more than one actionId to a JSON service
Junior Member Publications: 34 Date d'inscription: 18/10/11 Publications récentes
I have the following code that works fine:
the problem is that I don’t found the correct way to send more than one actionId I try with:
How can you send more than one Id for one RoleID?
public static void setPermision() 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/resourcepermission/set-individual-resource-permissions");
List<namevaluepair> params = new ArrayList<namevaluepair>();
params.add(new BasicNameValuePair("groupId", "10179"));
params.add(new BasicNameValuePair("companyId","10153")); //@@ ADAPT
params.add(new BasicNameValuePair("name", "com.liferay.portlet.documentlibrary.model.DLFileEntry"));
params.add(new BasicNameValuePair("primKey", "19503"));
// 10169 es el rol "site member" por defecto, si esto cambiara adaptar en consecuencia
params.add(new BasicNameValuePair("roleIdsToActionIds", "{10169:ADD_DISCUSSION}"));//,10169:DELETE_DISCUSSION}"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
post.setEntity(entity);
HttpResponse resp = httpclient.execute(targetHost, post, ctx);
System.out.println(resp.getStatusLine());
OutputStream respuesta = new ByteArrayOutputStream();
resp.getEntity().writeTo(respuesta);
System.err.println("contenido respuestas" +respuesta.toString());
httpclient.getConnectionManager().shutdown();
}</namevaluepair></namevaluepair>
the problem is that I don’t found the correct way to send more than one actionId I try with:
params.add(new BasicNameValuePair("roleIdsToActionIds", "{10169:ADD_DISCUSSION,10169:DELETE_DISCUSSION}")); ---> I get duplicate Key error
params.add(new BasicNameValuePair("roleIdsToActionIds", "{10169:ADD_DISCUSSION, VIEW}")); ---> I get :{"exception":"Expected a ':' after a key at character 27”}
params.add(new BasicNameValuePair("roleIdsToActionIds", "{10169:[ADD_DISCUSSION, VIEW]}")); ---> I get : respuestas{"exception":"com.liferay.portal.NoSuchResourceActionException: com.liferay.portlet.documentlibrary.model.dlfileentry#[add_discussion”}
How can you send more than one Id for one RoleID?