Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


As with other integration server-to-server calls, the call to the tool adapter servlet will require a hash containing the timestamp, user, server id and secret server key. View the integrations page for more information on this.


No Format

 * Export the XML fragment for the tool's content, along with any files
 * needed for the content.
 * @throws DataMissingException
 *             if no tool content matches the toolSessionId
 * @throws ToolException
 *             if any other error occurs

public void exportToolContent(Long toolContentId, String rootPath)
		throws DataMissingException, ToolException {

	MdlForum mdlForum = mdlForumDAO.getByContentId(toolContentId);
	if (mdlForum == null) {
		mdlForum = getDefaultContent();
	if (mdlForum == null)
		throw new DataMissingException("Unable to find default content for the mdlForum tool");

	// If no external content was found, export empty mdlForum
	// Otherwise, call the external servlet to get the export file
	if (mdlForum.getExtToolContentId() == null)

		try {
					mdlForum, mdlForumToolContentHandler, rootPath);
		} catch (ExportToolContentException e) {
			throw new ToolException(e);

		URLConnection conn = null;
			// Create the directory to store the export file
			String toolPath = FileUtil.getFullPath(rootPath,toolContentId.toString());

			String exportServletUrl = mdlForumConfigItemDAO.getConfigItemByKey(MdlForumConfigItem.KEY_EXTERNAL_TOOL_SERVLET).getConfigValue();

			// setting these to arbitrary values since they are only used to construct the hash

			HashMap<String, String> params = this.getRequiredExtServletParams(mdlForum);
			params.put(EXT_SERVER_PARAM_EXT_TOOL_CONTENT_ID, mdlForum.getExtToolContentId().toString());

			// Get the reponse stream from the external server (hopefully containing the export file
			InputStream in = WebUtility.getResponseInputStreamFromExternalServer(exportServletUrl, params);

			// Get the output stream to write the file for extport
			OutputStream out = new BufferedOutputStream(new FileOutputStream(toolPath + "/ext_tool.txt"));

			byte[] buffer = new byte[1024];
			int numRead;
			long numWritten = 0;
			while ((numRead = != -1)
				out.write(buffer, 0, numRead);
				numWritten += numRead;
			logger.debug("Path to mdlForum export content: " + toolPath + "/ext_tool.txt");

		catch (Exception e)
			logger.error("Problem exporting data from external .LRN servlet", e);

 Import Learning Design

Once you have handled the export correctly, you must handle the import. For this, the exported files that are stored on the user's hard drive will have to be transported in a multi-part post to the external server. Again, here we will need to set up an action in the external tool adapter servlet. When a tool adapter tool is called to import tool content, it will be sent the path to a file, and the customCSV parameter. The customCSV parameter is included here because it is often the case that to create a new instance of an external tool, the course and user information is required. With this parameters you can construct the multipart request using the file used for tool adapters.