webscript call from share

cancel
Showing results for 
Search instead for 
Did you mean: 
rekhaahir
Active Member

webscript call from share

Jump to solution

i want to call repo webscript from share means 8081 to 8080 port's web script.in which i used get method in form submit to pass data .but in actual  web script i used action tag. in script i used ajax to call repo url .after this i cant get error msg or not even output.

help me to solve it.

thank you..

1 Solution

Accepted Solutions
abhinavmishra14
Advanced

Re: webscript call from share

Jump to solution

It is still not clear what issue you are facing. Can you please check the logs and see if you are seeing any run time errors? Looking at your java code, there are several run time exception cases. 

I don't see you are passing the parameters. Whereas you are expecting some parameters on web-script.

function callGet() {

var date = document.getElementById('date').value;
var name = document.getElementById('name').value;
var email = document.getElementById('email').value;
var des = document.getElementById('des').value;

var add = document.getElementById('add').value;
Alfresco.util.Ajax.request({
url:Alfresco.constants.PROXY_URI +'/tutorials1/ofltr',

method:Alfresco.util.Ajax.GET,
dataObj:
{
},
successCallback:
{ 
fn: this.success, 
scope:this

},
failureCallback:
{
fn: this.failure, 
scope:this
}
});
alert(date);
}

The nodeRef you are trying to create already exists in the system ? if not your code will fail on the next line itself.

NodeRef parent = new NodeRef("workspace://SpacesStore/9edf7607-0e2c-4643-a156-5fd22975ffba");

There will be a NullPointerException on the line where you are trying to put null value of "mname" which is basically null as you are not passing any values in the parameter. 

writer.putContent(mname);

please cleanup your code and try again.

~Abhinav
(ACSCE, AWS SAA, Azure Admin)

View solution in original post

6 Replies
abhinavmishra14
Advanced

Re: webscript call from share

Jump to solution

Can you please explain properly? Share step by step code and error if possible. 

Ideally you should be able to call the repository webscript from share and consume the response. See the example below where i am trying to call membership service:

var siteShortName = "test-site";
var userName = "admin";

Alfresco.util.Ajax.jsonGet({
  url : Alfresco.constants.PROXY_URI+ "api/sites/" + siteShortName+ "/memberships/" + userName,
  successCallback : {
  fn : function(response) {
  var responseJson = response.json;
  //DO SOMETHING WITH RESPONSE....
  },
  scope : this
  }
});

~Abhinav
(ACSCE, AWS SAA, Azure Admin)
rekhaahir
Active Member

Re: webscript call from share

Jump to solution

Thank you 

i also try this same 

so,this is dashlet to get data .ftl file to share side.

<#-- JavaScript Dependencies
<@markup id="js">
</@>
-->

<#-- Stylesheet Dependencies
<@markup id="css">
</@>
-->

<#-- Surf Widget creation
<@markup id="widgets">
<@createWidgets group="dashlets"/>
</@>
-->

<@markup id="html">
<@uniqueIdDiv>
<#assign id = args.htmlid?html>
<#assign dashboardconfig=config.scoped['Dashboard']['dashboard']>

<div class="dashlet">
<div class="title">Custom Dashlet</div>
<div id="${id}-memberdir" class="body">
<script type="text/javascript">

function callGet() {

var date = document.getElementById('date').value;
var name = document.getElementById('name').value;
var email = document.getElementById('email').value;
var des = document.getElementById('des').value;

var add = document.getElementById('add').value;
Alfresco.util.Ajax.request({
url:Alfresco.constants.PROXY_URI +'/tutorials1/ofltr',method:Alfresco.util.Ajax.GET,
dataObj:
{
},
successCallback:
{
fn: this.success,
scope:this

},
failureCallback:
{
fn: this.failure,
scope:this
}
});
alert(date);
}
</script>

<div class="toolbar">
<div class="actions">
<form name="input"
action=""
method="get">
${msg("Name")}: <input type="text" id="name" name="mname" /><br/>
${msg("Designation")}: <select name="des" id="des">
<option value="hr" >hr</option>
<option value="s/w engg">s/w engg</option>
<option value="h/w engg">h/w engg</option>

</select><br/>
${msg("Joining Date")}: <input type="date" id="date" name="date" /><br/>
${msg("Email")}: <input type="email" id="email" /><br/>
${msg("Address")}: <textarea name="add" id="add" cols="50" rows="3" maxlength="10"></textarea><br/>


<button onClick="callGet()">create</button>
</form>

2. this is repo side webscripts desc file.

<webscript>
<shortname>ofltr</shortname>
<description>Returns metadata as </description>
<url>/tutorials1/ofltr</url>
<authentication>user</authentication>
<args>
<arg>
<name>mname</name>
</arg>
<arg>
<name>des</name>
</arg>
<arg>
<name>date</name>
</arg>
<arg>
<name>email</name>
</arg>
<arg>
<name>add</name>
</arg>

</args>
</webscript>

3. this is repo side java class in which i send data to another ftl file .

package com.sdk3_repo.platformsample;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;

public class offer extends DeclarativeWebScript {
@Autowired
ServiceRegistry serviceRegistry;

protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {

String mname = req.getParameter("mname");
String date = req.getParameter("date");
String email = req.getParameter("email");
String des = req.getParameter("des");
Map<String, Object> model = new HashMap<String, Object>();



model.put("mname", mname);
model.put("date", date);
model.put("email", email);
model.put("des", des);

Map<QName, Serializable> props = new HashMap<QName, Serializable>();
props.put(ContentModel.PROP_NAME,mname);

NodeRef parent = new NodeRef("workspace://SpacesStore/9edf7607-0e2c-4643-a156-5fd22975ffba");
// use the node service to create a new node
NodeRef node = serviceRegistry.getNodeService().createNode(parent, ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, new Date().getTime()+""), ContentModel.TYPE_CONTENT, props)
.getChildRef();
try {
ContentWriter writer = serviceRegistry.getContentService().getWriter(node, ContentModel.PROP_CONTENT, true);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
// writer.putContent(mname +""+date+""+email+""+des);
writer.putContent(mname);

} catch (Exception e) {
e.printStackTrace();
}
// response.sendRedirect(request.getContextPath() + "/page/site/" + URLEncoder.encode(siteName) + "/dashboard");
return model ;

}
}

this is repo side final ftl file for output.

${mname}
${date}
${email}
${des}

now if i give the url of the webscript the same page is rendered .you can see that url in first .ftl file.

abhinavmishra14
Advanced

Re: webscript call from share

Jump to solution

It is still not clear what issue you are facing. Can you please check the logs and see if you are seeing any run time errors? Looking at your java code, there are several run time exception cases. 

I don't see you are passing the parameters. Whereas you are expecting some parameters on web-script.

function callGet() {

var date = document.getElementById('date').value;
var name = document.getElementById('name').value;
var email = document.getElementById('email').value;
var des = document.getElementById('des').value;

var add = document.getElementById('add').value;
Alfresco.util.Ajax.request({
url:Alfresco.constants.PROXY_URI +'/tutorials1/ofltr',

method:Alfresco.util.Ajax.GET,
dataObj:
{
},
successCallback:
{ 
fn: this.success, 
scope:this

},
failureCallback:
{
fn: this.failure, 
scope:this
}
});
alert(date);
}

The nodeRef you are trying to create already exists in the system ? if not your code will fail on the next line itself.

NodeRef parent = new NodeRef("workspace://SpacesStore/9edf7607-0e2c-4643-a156-5fd22975ffba");

There will be a NullPointerException on the line where you are trying to put null value of "mname" which is basically null as you are not passing any values in the parameter. 

writer.putContent(mname);

please cleanup your code and try again.

~Abhinav
(ACSCE, AWS SAA, Azure Admin)
rekhaahir
Active Member

Re: webscript call from share

Jump to solution

thanks for the help

now i can call webscript using this url and also able to pass parameter .

thanks and Regards,

abhinavmishra14
Advanced

Re: webscript call from share

Jump to solution

Good to hear..

~Abhinav
(ACSCE, AWS SAA, Azure Admin)
rekhaahir
Active Member

Re: csrf error

Jump to solution

hello,

i m stuck at csrf error..

I get CSRF Token "Possible CSRF attack noted when comparing token in session and request parameter" Error  when Multipart/formdata is passed in parameter to send file .

  1. Request URL:
    http://localhost:8081/share/proxy/alfresco/save-form/create-document?Alfresco-CSRFToken=9%2fc9f96gScXccigFrNuLobmnbX%2bUWGRJPzwZZB1zCws%3d
  2. Cookie:
    JSESSIONID=3044806F0BB456CE1CCFA8D188E2BE03; alfUsername3=admin; alfLogin=1572000318; Alfresco-CSRFToken=9%2fc9f96gScXccigFrNuLobmnbX%2bUWGRJPzwZZB1zCws%3d; _alfTest=_alfTest; JSESSIONID=26AEB117F34C2231A07461D05F934C53

still it gives error!!!