Author: tyrell
Date: Sun Jan 13 23:35:47 2008
New Revision: 12190
Log:
Adding service creation functionality using the new Mashup Editor. Fixed
MASHUP-504 as a result of this new workflow.
Modified:
trunk/mashup/java/modules/coreservices/servicemetadatalister/src/org/wso2/mashup/coreservices/servicemetadatalister/ServiceMetaDataListerService.java
trunk/mashup/java/modules/www/editor.jsp
trunk/mashup/java/modules/www/js/mashup-utils.js
trunk/mashup/java/modules/www/js/services.js
Modified:
trunk/mashup/java/modules/coreservices/servicemetadatalister/src/org/wso2/mashup/coreservices/servicemetadatalister/ServiceMetaDataListerService.java
==============================================================================
---
trunk/mashup/java/modules/coreservices/servicemetadatalister/src/org/wso2/mashup/coreservices/servicemetadatalister/ServiceMetaDataListerService.java
(original)
+++
trunk/mashup/java/modules/coreservices/servicemetadatalister/src/org/wso2/mashup/coreservices/servicemetadatalister/ServiceMetaDataListerService.java
Sun Jan 13 23:35:47 2008
@@ -376,200 +376,43 @@
}
- public String createNewServiceSkeleton(String serviceName, String
userName) {
- String success = "An error occured, failed to create the service
skeleton.";
- String decodedServiceName = "";
- boolean serviceNameValidated = false;
+ public String isPossibleToCreate(String servicePath) {
+ String success = "OK";
+
+ String decodedServicePath = "";
+ String serviceName = "";
+
+ //Validating the service name
try {
- decodedServiceName = URIEncoderDecoder.decode(serviceName);
- MashupUtils.validateName(decodedServiceName, "ServiceName");
- serviceNameValidated = true;
+ decodedServicePath = URIEncoderDecoder.decode(servicePath);
+
+ //Extracting the real path from the registry path provided
+ String[] pathContents = decodedServicePath.split("/");
+ decodedServicePath = "";
+ for (int x = 2; x < pathContents.length; x++) {
+ decodedServicePath = decodedServicePath + "/" +
pathContents[x];
+ }
+
+ serviceName = pathContents[3];
+ MashupUtils.validateName(serviceName, "ServiceName");
} catch (MashupFault e) {
success = e.getMessage();
} catch (UnsupportedEncodingException e) {
success = e.getMessage();
}
- if (serviceNameValidated) {
- MessageContext messageContext =
MessageContext.getCurrentMessageContext();
- URL repository =
-
messageContext.getConfigurationContext().getAxisConfiguration().getRepository();
-
- if (repository != null) {
- try {
- File repo = new File(repository.getFile());
- File scriptsFolder;
- if (userName != null) {
- scriptsFolder = new File(repo, "scripts/" + userName);
- } else {
- //Keeping this for backward compatibility todo: remove
after migration
- scriptsFolder = new File(repo, "scripts");
- }
-
- //Creating the folder if necessary
- if (!scriptsFolder.exists()) {
- scriptsFolder.mkdirs();
- }
-
- //Creating the new service js file
- File newService = new File(scriptsFolder,
decodedServiceName + ".js");
-
- //The skeleton
- String serviceSkeleton = "/*\n" +
- "* Copyright 2005-2007 WSO2, Inc.
http://www.wso2.org\n" +
- "*\n" +
- "* Licensed under the Apache License, Version 2.0
(the \"License\");\n" +
- "* you may not use this file except in compliance
with the License.\n" +
- "* You may obtain a copy of the License at\n" +
- "*\n" +
- "* http://www.apache.org/licenses/LICENSE-2.0\n" +
- "*\n" +
- "* Unless required by applicable law or agreed to
in writing, software\n" +
- "* distributed under the License is distributed on
an \"AS IS\" BASIS,\n" +
- "* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied.\n" +
- "* See the License for the specific language
governing permissions and\n" +
- "* limitations under the License.\n" +
- "*/\n" +
- "this.serviceName = \"" + decodedServiceName +
"\";\n" +
- "this.documentation = \"TODO: Add service level
documentation here\" ;\n" +
- "\n" +
- "toString.documentation = \"TODO: Add operation
level documentation here\" ;\n" +
- "toString.inputTypes = { /* TODO: Add input types
of this operation */ };\n" +
- "toString.outputType = \"String\"; /* TODO: Add
output type here */ \n" +
- "function toString()\n" +
- "{\n" +
- " //TODO: Add function code here\n" +
- " return \"Hi, my name is " + decodedServiceName
+ "\";\n" +
- "}\n";
-
-
- BufferedWriter out = new BufferedWriter(new
FileWriter(newService));
- out.write(serviceSkeleton);
- out.flush();
- out.close();
-
- //Creating the Custom UI
- String uiSkeleton = "<!--\n" +
- " ~ Copyright 2005-2007 WSO2, Inc.
http://www.wso2.org\n" +
- " ~\n" +
- " ~ Licensed under the Apache License, Version
2.0 (the \"License\");\n" +
- " ~ you may not use this file except in
compliance with the License.\n" +
- " ~ You may obtain a copy of the License at\n" +
- " ~\n" +
- " ~ http://www.apache.org/licenses/LICENSE-2.0\n"
+
- " ~\n" +
- " ~ Unless required by applicable law or agreed
to in writing, software\n" +
- " ~ distributed under the License is distributed
on an \"AS IS\" BASIS,\n" +
- " ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied.\n" +
- " ~ See the License for the specific language
governing permissions and\n" +
- " ~ limitations under the License.\n" +
- " -->\n" +
- "\n" +
- "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01
Transitional//EN\">\n" +
- "<html>\n" +
- "<head>\n" +
- "\n" +
- " <meta content=\"text/html;
charset=ISO-8859-1\" http-equiv=\"content-type\">\n" +
- " <title>Welcome to " + decodedServiceName +
"</title>\n" +
- " \n" +
- " <style type=\"text/css\">\n" +
- " body {font: 75%/1.5 \"Lucida
Grande\",\"Lucida Sans\",\"Microsoft Sans Serif\", \"Lucida Sans
Unicode\",verdana,sans-serif,\"trebuchet ms\"; color: #111; }\n" +
- " img {margin-bottom: 0.5em}\n" +
- " span {font-weight: bold}\n" +
- " .template {margin-left:1em;
margin-bottom:1em; font-size:125%}\n" +
- " #console {color:red; font-weight:bold}\n" +
- " </style>\n" +
- " <script type=\"text/javascript\"
src=\"/js/wso2/WSRequest.js\"></script>\n" +
- " <script type=\"text/javascript\" src=\"../" +
decodedServiceName +
- "?stub\"></script>\n" +
- " \n" +
- " <script type=\"text/javascript\"
language=\"javascript\">\n" +
- "\n" +
- "\t\t //Calls the toString operation of the '" +
decodedServiceName +
- "' Mashup \n" +
- " function callMashup() { \n" +
- "\n" +
- " " + decodedServiceName +
".setAddress(" +
- decodedServiceName + ".endpoint, \"services/" +
decodedServiceName +
- "\");\n" +
- " " + decodedServiceName +
- ".toString.onError = handleError;\n" +
- " " + decodedServiceName +
- ".toString.callback = function (response) {\n" +
- " fillData(response);\n" +
- " }\n" +
- " " + decodedServiceName +
".toString();\n" +
- " }\n" +
- " \n" +
- " //Handles and error by displaying the
reason in a dialog\n" +
- " function handleError(error) {\n" +
- " var console =
document.getElementById(\"error-console\");" +
- " log (console, \"Fault: \" +
error.reason + \"\\n\\n\" + error.detail);\n" +
- " }\n" +
- "\n" +
- "\t\t //Writes the received response to the
DIV\n" +
- " function fillData(response)\n" +
- " { \n" +
- " var responseDiv =
document.getElementById(\"reponse-text\");\n" +
- " responseDiv.innerHTML = '<p>' +
response + '</p>'; \n" +
- " } \n" +
- " \n" +
- " function log(console, data) {\n" +
- " var browser =
WSRequest.util._getBrowser();\n" +
- " if (browser == \"ie\" || browser ==
\"ie7\")\n" +
- " console.innerText = data;\n" +
- " else\n" +
- " console.textContent = data;\n" +
- " }" +
- " \n" +
- " </script>\n" +
- " \n" +
- "</head>\n" +
- "\n" +
- "<body onload='callMashup();'>\n" +
- "<img alt=\"WSO2 Mashup Server logo\"
src=\"/images/wso2_mashup_logo.gif\"/>" +
- "\n" +
- "\t<div id=\"reponse-text\"> \n" +
- "\t<!-- This div will contain the text returned as
response to the service call -->\n" +
- "\t</div>\n" +
- "<div>Access all the operations of the " +
decodedServiceName +
- " service through the <a href=\"../" +
decodedServiceName +
- "?tryit\">Try-it page</a>.</div>" +
- "\n" +
- "<div id=\"error-console\"></div>" +
- " \n" +
- "</body>\n" +
- "</html>";
-
- //Creating the www directory inside the .resources
directory
- File wwwDirectory =
- new File(scriptsFolder, decodedServiceName +
".resources/www");
- if (!wwwDirectory.exists()) {
- wwwDirectory.mkdirs();
- }
-
- //Creating the html file
- File skeletonHtmlFile = new File(wwwDirectory,
"index.html");
-
- //Writing skeleton UI code
- out = new BufferedWriter(new FileWriter(skeletonHtmlFile));
- out.write(uiSkeleton);
- out.flush();
- out.close();
-
- //Setting the flag indicating operation success
- success = "OK";
- } catch (IOException e) {
- success = success + ". " + e.getMessage();
- }
- }
- }
+ //Validating the possibility to create a new service file.
+ ServerManager serverManager = ServerManager.getInstance();
+ ConfigurationContext configContext = serverManager.configContext;
- try {
- return URIEncoderDecoder.quoteIllegal(success, "");
- } catch (UnsupportedEncodingException e) {
- return e.getMessage();
+ File serviceJs = new
File(configContext.getRealPath(configContext.getContextRoot()) +
+ "/scripts/" + decodedServicePath + ".js");
+
+ if(serviceJs.exists()){
+ success = "A service with the name you specified (" + serviceName
+ ") already exists. Please use a new name or use the 'edit' option to edit the
existing service.";
}
+
+ return success;
}
Modified: trunk/mashup/java/modules/www/editor.jsp
==============================================================================
--- trunk/mashup/java/modules/www/editor.jsp (original)
+++ trunk/mashup/java/modules/www/editor.jsp Sun Jan 13 23:35:47 2008
@@ -26,6 +26,8 @@
response.setHeader("Pragma", "no-cache"); //HTTP 1.0
response.setDateHeader("Expires", 0); //prevents caching at the proxy
server
+ String currentReferer = request.getHeader("Referer");
+
Registry registry = RegistryUtils.getRegistry(request);
String bounceback = request.getParameter("bounceback");
@@ -73,8 +75,24 @@
} else if ((action.equalsIgnoreCase("new")) && (mashup == null)) {
throw new Exception(
"Sorry. A request was made to create a mashup without
providing a valid name.");
- }else if ((action.equalsIgnoreCase("new")) && (mashup != null)) {
+ } else if ((action.equalsIgnoreCase("new")) && (mashup != null)) {
author = currentUser;
+
+ //Restricting new mashup creation for particular referer pages
+ String[] validReferers = { "user.jsp", "mashup.jsp" };
+ boolean validReferer = false;
+
+ for (int x = 0; x < validReferers.length; x++) {
+ if (currentReferer.contains(validReferers[x])) {
+ validReferer = true;
+ }
+ }
+
+ if (!validReferer) {
+ throw new Exception(
+ "Sorry. Unable to launch the editor. Please try using the
links provided in the ui to create a new service.");
+ }
+
}
%>
<html>
Modified: trunk/mashup/java/modules/www/js/mashup-utils.js
==============================================================================
--- trunk/mashup/java/modules/www/js/mashup-utils.js (original)
+++ trunk/mashup/java/modules/www/js/mashup-utils.js Sun Jan 13 23:35:47 2008
@@ -343,7 +343,7 @@
*/
WSO2.MashupUtils.showCreateMashupDialog = function(userName) {
- //Showing a dialog to get the new Mashup's name
+ //Creating a dialog to get the new Mashup's name
var parent = document.createElement("div");
parent.setAttribute("id", "MashupCreationDialog");
@@ -366,114 +366,68 @@
lblStatusMessages.setAttribute("id", "lblStatus");
parent.appendChild(lblStatusMessages);
+ var cmdSubmit = document.createElement("input");
+ cmdSubmit.setAttribute("type", "button");
+ cmdSubmit.setAttribute("id", "cmdSubmit");
+ cmdSubmit.value = "Create";
+ cmdSubmit.setAttribute("onclick",
"WSO2.MashupUtils.makeServiceNameValidationRequest('" +
+ userName + "');");
+ cmdSubmit.setAttribute("style", "float: right;");
+ parent.appendChild(cmdSubmit);
+
YAHOO.util.Event.onContentReady('doc3', function() {
// Instantiate the Dialog
- var browser = WSRequest.util._getBrowser();
- var mashupCreationDialog = "";
+ WSO2.MashupUtils.dialog("Create a new mashup", parent.innerHTML, 100,
100);
+ });
+};
+
+
+WSO2.MashupUtils.makeServiceNameValidationRequest = function(userName) {
+
+ function submitServiceCallback() {
+ var response ;
+ var browser = WSRequest.util._getBrowser();
if (browser == "ie" || browser == "ie7") {
- mashupCreationDialog = new
YAHOO.widget.Dialog("MashupCreationDialog",
- {
- width : "500px",
- x:YAHOO.util.Dom.getViewportWidth() /
- 8, //Manual fix for getting rubbish viewport dimensions in IE
- y:100,
- draggable:true,
- visible : false,
- modal:true,
- close:false,
- buttons : [ { id: "cmdSubmit", text:"Submit",
handler:handleSubmit, isDefault:true },
- { text:"Cancel", handler:handleCancel } ]
- });
+ response =
+
this.req.responseXML.getElementsByTagName("ns:return")[0].firstChild.nodeValue;
} else {
- mashupCreationDialog = new
YAHOO.widget.Dialog("MashupCreationDialog",
- { width : "500px",
- fixedcenter : true,
- draggable:true,
- visible : false,
- constraintoviewport : true,
- modal:true,
- close:false,
- buttons : [ { id: "cmdSubmit", text:"Submit",
handler:handleSubmit, isDefault:true },
- { text:"Cancel", handler:handleCancel } ]
- });
+ response =
+
this.req.responseXML.getElementsByTagName("return")[0].firstChild.nodeValue;
}
+ if (response == "OK") {
+ //Redirecting to the actual editor
+ window.location = "editor.jsp?action=new&mashup=" + this.params[1]
+ } else {
+ this.params[0].innerHTML = response;
+ }
+ }
- var strCreationDialogHeader = '<table border="0" width="100%"
cellpadding="0" cellspacing="0">' +
- '<tr>' +
- '<td><img
src="images/w_small_top_left_edit.gif"/></td>' +
- '<td class="mashup-editer-hd" >Create a
new Mashup skeleton</td>' +
- '<td><img
src="images/w_top_right_edit.gif"/></td>' +
- '</tr>' +
- '</table>';
-
- mashupCreationDialog.setHeader(strCreationDialogHeader);
- mashupCreationDialog.setBody(parent);
- mashupCreationDialog.render("content");
- mashupCreationDialog.show();
- document.getElementById("txtMashupName").focus();
-
- WSO2.MashupUtils.currentActiveModelDialog = mashupCreationDialog;
-
- function handleSubmit() {
- var labelElement = document.getElementById("lblStatus");
- var mashupName = document.getElementById("txtMashupName").value;
-
- if (!(WSO2.MashupUtils.trim(mashupName) == "")) {
-
- //Encoding to escape special characters
- mashupName = encodeURI(mashupName);
-
- labelElement.innerHTML = "";
- labelElement.appendChild(document.createTextNode("Contacting
backend services. Please wait..."));
-
- wso2.mashup.services.createMashupSkeleton(mashupName,
userName, submitServiceCallback, labelElement);
- mashupCreationDialog.cancel();
- clearDom();
- }
- else {
- labelElement.innerHTML = "";
- labelElement.appendChild(document.createTextNode("Please enter
a valid service name"));
- }
- }
+ var labelElement = document.getElementById("lblStatus");
+ var mashupName = document.getElementById("txtMashupName").value;
- function submitServiceCallback() {
+ if (!(WSO2.MashupUtils.trim(mashupName) == "")) {
- var response ;
+ //Encoding to escape special characters
+ var mashupPath = encodeURI("/mashups/" + userName + "/" + mashupName);
- var browser = WSRequest.util._getBrowser();
- if (browser == "ie" || browser == "ie7") {
- response =
-
this.req.responseXML.getElementsByTagName("ns:return")[0].firstChild.nodeValue;
- } else {
- response =
-
this.req.responseXML.getElementsByTagName("return")[0].firstChild.nodeValue;
- }
+ labelElement.innerHTML = "";
+ labelElement.appendChild(document.createTextNode("Contacting backend
services for validation. Please wait..."));
- if (response == "OK") {
- wso2.wsf.Util.alertMessage("The Mashup was successfully
created. It will be listed under your Mashups list shortly.");
- } else {
- wso2.wsf.Util.alertMessage("Mashup creation failed at the
server side. " +
- decodeURI(response), "warnicon");
- }
+ var params = new Array();
+ params[0] = labelElement;
+ params[1] = mashupName;
- }
+ wso2.mashup.services.isPossibleToCreate(mashupPath,
submitServiceCallback, params);
- function handleCancel() {
- this.cancel();
- clearDom();
- WSO2.MashupUtils.currentActiveModelDialog = null;
- }
+ }
+ else {
+ labelElement.innerHTML = "";
+ labelElement.appendChild(document.createTextNode("Please enter a name
for your new mashup."));
+ }
- function clearDom() {
- var dialogMask =
document.getElementById("MashupCreationDialog_mask");
- dialogMask.parentNode.removeChild(dialogMask);
- var dialogResedue =
document.getElementById("MashupCreationDialog_c");
- dialogResedue.parentNode.removeChild(dialogResedue);
- }
- });
};
@@ -784,7 +738,7 @@
var y = (document.body.clientHeight - height) / 2;
x = (x > 0) ? x : 0;
y = (y > 0) ? y : 0;
-
+
document.body.innerHTML +=
'<div id="lyrDialog" style="position:absolute; left:' + x + 'px; top:'
+ y +
'px; width:' + width + 'px; z-index:1">' +
Modified: trunk/mashup/java/modules/www/js/services.js
==============================================================================
--- trunk/mashup/java/modules/www/js/services.js (original)
+++ trunk/mashup/java/modules/www/js/services.js Sun Jan 13 23:35:47 2008
@@ -257,21 +257,21 @@
/**
- * @description Method used to create a skeleton js service and deploy in the
Mashup Server
+ * @description Validates a given service path
* @method createMashupSkeleton
+ * @param {String} mashupPath A path to a new mashup
* @param {callback} callBack User-defined callback function or object
* @param {callback} params Parameters to be set in the callback
*/
-wso2.mashup.services.createMashupSkeleton = function (newServiceName,
userName, callback, params) {
+wso2.mashup.services.isPossibleToCreate = function (mashupPath, callback,
params) {
var callURL = serverURL + "/" + "ServiceMetaDataLister" + "/" ;
- var body_xml = '<req:createNewServiceSkeletonRequest
xmlns:req="http://servicemetadatalister.coreservices.mashup.wso2.org/xsd">\n' +
- ' <req:serviceName>' + newServiceName +
'</req:serviceName>\n' +
- ' <req:userName>' + userName + '</req:userName>\n' +
- ' </req:createNewServiceSkeletonRequest>\n';
+ var body_xml = '<req:isPossibleToCreateRequest
xmlns:req="http://servicemetadatalister.coreservices.mashup.wso2.org/xsd">\n' +
+ ' <req:servicePath>' + mashupPath + '</req:servicePath>\n'
+
+ ' </req:isPossibleToCreateRequest>\n';
- new wso2.wsf.WSRequest(callURL, "createNewServiceSkeleton", body_xml,
callback, params, wso2.mashup.services.defaultErrHandler);
+ new wso2.wsf.WSRequest(callURL, "isPossibleToCreate", body_xml, callback,
params, wso2.mashup.services.defaultErrHandler);
};
_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev