For code based on JavaScript (Surf) :
To call Alfresco from Share side in Java you need first write class:
And then setup Spring Bean for this class:
// set url to call var url = "/url/to/some/webscript"; // get connector var connector = remote.connect("alfresco"); // do HTTP get request var result = connector.get(url); // check success of call if (result.status.code == status.STATUS_OK) { // parse response to object var obj = eval("(" + result.response + ")"); // set some value to property of the model model.someProp = obj.someProp; } else { // do something }
To call Alfresco from Share side in Java you need first write class:
import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.json.JSONException; import org.json.JSONObject; import org.springframework.extensions.surf.WebFrameworkServiceRegistry; import org.springframework.extensions.webscripts.ScriptRemote; import org.springframework.extensions.webscripts.connector.Response; /** * Created by s.palyukh on 07.09.15. */ public class CallAlfresco { private static Log logger = LogFactory.getLog(CallAlfresco.class); protected WebFrameworkServiceRegistry serviceRegistry = null; public JSONObject jsonGet(String uri) { ScriptRemote scriptRemote = serviceRegistry.getScriptRemote(); Response response = scriptRemote.connect().get(uri); if (response.getStatus().getCode() == 200) { try { return new JSONObject(response.getResponse()); } catch (JSONException e) { if (logger.isErrorEnabled()) { logger.error("An error occurred when parsing response to json from the uri '" + uri + "': " + e.getMessage()); } } } return null; } public void setServiceRegistry(WebFrameworkServiceRegistry serviceRegistry) { this.serviceRegistry = serviceRegistry; } }
And then setup Spring Bean for this class:
Комментариев нет :
Отправить комментарий