Author: tyrell Date: Mon Jun 9 03:37:42 2008 New Revision: 18210 URL: http://wso2.org/svn/browse/wso2?view=rev&revision=18210
Log: Fixing MASHUP-818 Modified: trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupAdminService.java trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java trunk/mashup/java/modules/www/editor.jsp trunk/mashup/java/modules/www/js/services.js trunk/mashup/java/modules/www/js/utils.js trunk/mashup/java/modules/www/mashup.jsp Modified: trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupAdminService.java URL: http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupAdminService.java?rev=18210&r1=18209&r2=18210&view=diff ============================================================================== --- trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupAdminService.java (original) +++ trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupAdminService.java Mon Jun 9 03:37:42 2008 @@ -129,7 +129,8 @@ return Boolean.valueOf(success); } - public Boolean saveUiSource(String path, String modifiedSource) throws MashupFault { + public Boolean saveUiSource(String path, String modifiedSource, String type) + throws MashupFault { boolean success; try { @@ -170,15 +171,16 @@ wwwDir.mkdirs(); } - //Getting the html file - File uiHtmlFile = new File(wwwDir, "index.htm"); - - if (!uiHtmlFile.exists()) { - uiHtmlFile = new File(wwwDir, "index.html"); + //Getting the ui file depending on the type + File uiSourceFile; + if (type.equals("gadget")) { + uiSourceFile = new File(wwwDir, "gadget.xml"); + } else { + uiSourceFile = new File(wwwDir, "index.htm"); } //Writing the file with the source provided - BufferedWriter out = new BufferedWriter(new FileWriter(uiHtmlFile)); + BufferedWriter out = new BufferedWriter(new FileWriter(uiSourceFile)); out.write(modifiedSource); out.flush(); out.close(); @@ -518,76 +520,76 @@ boolean success = false; if (transportName == null || transportName.trim().length() == 0) { - return Boolean.valueOf(success); - } + return Boolean.valueOf(success); + } ServerManager serverManager = ServerManager.getInstance(); ConfigurationContext configContext = serverManager.configContext; AxisService axisService = configContext.getAxisConfiguration().getService(serviceName); - if (axisService.isExposedTransport(transportName)) { - return Boolean.valueOf(success); - } - - ServiceDO serviceDO = pm.getService(axisService.getName(), - ServiceIdentifierDO.EMPTY_SERVICE_VERSION); - if (serviceDO.getIsUTAuthEnabled()) { - if (!transportName - .equalsIgnoreCase(ServerConstants.HTTPS_TRANSPORT)) { - throw new AxisFault( - "Cannot add non-HTTPS transport binding for Service [" - + serviceName - + "] since a security scenario which requires the " - + "service to contain only the HTTPS transport binding" - + " has been applied to this service."); - } - } - - if (!axisService.isEnableAllTransports()) { - axisService.addExposedTransport(transportName); - } else { - return Boolean.valueOf(success); - } - - TransportDO transportDO = pm.getTransport(transportName); - if (transportDO != null) { - serviceDO.setIsExposedOnAllTransports(false); - serviceDO.addTransport(transportDO); - - try { - pm.updateService(serviceDO); - pm.updateEntity(transportDO); - } catch (ServiceNotFoundException e) { - String msg = "Service with name " + serviceName + " not found."; - log.error(msg); - throw new AxisFault(msg, e); - } - } + if (axisService.isExposedTransport(transportName)) { + return Boolean.valueOf(success); + } - success = true; + ServiceDO serviceDO = pm.getService(axisService.getName(), + ServiceIdentifierDO.EMPTY_SERVICE_VERSION); + if (serviceDO.getIsUTAuthEnabled()) { + if (!transportName + .equalsIgnoreCase(ServerConstants.HTTPS_TRANSPORT)) { + throw new AxisFault( + "Cannot add non-HTTPS transport binding for Service [" + + serviceName + + "] since a security scenario which requires the " + + "service to contain only the HTTPS transport binding" + + " has been applied to this service."); + } + } + + if (!axisService.isEnableAllTransports()) { + axisService.addExposedTransport(transportName); + } else { + return Boolean.valueOf(success); + } + + TransportDO transportDO = pm.getTransport(transportName); + if (transportDO != null) { + serviceDO.setIsExposedOnAllTransports(false); + serviceDO.addTransport(transportDO); + + try { + pm.updateService(serviceDO); + pm.updateEntity(transportDO); + } catch (ServiceNotFoundException e) { + String msg = "Service with name " + serviceName + " not found."; + log.error(msg); + throw new AxisFault(msg, e); + } + } + + success = true; return Boolean.valueOf(success); } public Boolean disableServiceTransport(String serviceName, String transportName) throws AxisFault { boolean success = false; - + ServerManager serverManager = ServerManager.getInstance(); ConfigurationContext configContext = serverManager.configContext; AxisService axisService = configContext.getAxisConfiguration().getService(serviceName); - ServiceDO serviceDO = pm.getService(axisService.getName(), - ServiceIdentifierDO.EMPTY_SERVICE_VERSION); - if (serviceDO.getIsUTAuthEnabled()) { - if (transportName - .equalsIgnoreCase(ServerConstants.HTTPS_TRANSPORT)) { - throw new AxisFault( - "HTTPS transport binding for Service [" - + serviceName - + "] cannot be removed since a security scenario which requires" - + " HTTPS has been applied to this service."); - } - } + ServiceDO serviceDO = pm.getService(axisService.getName(), + ServiceIdentifierDO.EMPTY_SERVICE_VERSION); + if (serviceDO.getIsUTAuthEnabled()) { + if (transportName + .equalsIgnoreCase(ServerConstants.HTTPS_TRANSPORT)) { + throw new AxisFault( + "HTTPS transport binding for Service [" + + serviceName + + "] cannot be removed since a security scenario which requires" + + " HTTPS has been applied to this service."); + } + } TransportDO transportDO = pm.getTransport(transportName); if (!axisService.isEnableAllTransports()) { @@ -611,21 +613,21 @@ } } - serviceDO.setIsExposedOnAllTransports(false); - try { - pm.updateService(serviceDO); - } catch (ServiceNotFoundException e) { - String msg = "Service with name " + serviceName + " not found."; - log.error(msg); - throw new AxisFault(msg, e); - } + serviceDO.setIsExposedOnAllTransports(false); + try { + pm.updateService(serviceDO); + } catch (ServiceNotFoundException e) { + String msg = "Service with name " + serviceName + " not found."; + log.error(msg); + throw new AxisFault(msg, e); + } - success = true; + success = true; return Boolean.valueOf(success); } - + public Boolean importCert(String userName, String alias, DataHandler cert) throws MashupFault { try { InputStream certIn = cert.getDataSource().getInputStream(); Modified: trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java URL: http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java?rev=18210&r1=18209&r2=18210&view=diff ============================================================================== --- trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java (original) +++ trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java Mon Jun 9 03:37:42 2008 @@ -422,8 +422,7 @@ * @return serviceSource The source code contents of the service js file */ public static String readServiceUiSource(String path) { - String serviceUiSource = - "The custom UI code for the specified mashup was not found on the server."; + String serviceUiSource = "404"; //Extracting the real path from the registry path provided ServerManager serverManager = ServerManager.getInstance(); @@ -479,6 +478,53 @@ return serviceUiSource; } + + + /** + * Reads a given JS service's Google Gadget UI source directly from the physical file. This ensures the availability + * of the service UI source even when the service is faulty and not deployed. + * + * @param path The path of the mashup + * @return serviceSource The source code contents of the service js file + */ + public static String readGadgetUiSource(String path) { + String gadgetSource = "404"; + + //Extracting the real path from the registry path provided + ServerManager serverManager = ServerManager.getInstance(); + ConfigurationContext configContext = serverManager.configContext; + EmbeddedRegistry embeddedRegistry = + (EmbeddedRegistry) configContext.getAxisConfiguration().getParameterValue( + RegistryConstants.REGISTRY); + + try { + UserRegistry systemRegistry = embeddedRegistry.getSystemRegistry(); + File gadgetCodeFile = + new File(systemRegistry.get(path) + .getProperty(JavaScriptEngineConstants.RESOURCES_FOLDER) + + "/www/gadget.xml"); + + if (gadgetCodeFile.exists()) { + + StringBuffer fileData = new StringBuffer(1000); + BufferedReader reader = new BufferedReader(new FileReader(gadgetCodeFile)); + char[] buf = new char[1024]; + int numRead; + while ((numRead = reader.read(buf)) != -1) { + fileData.append(buf, 0, numRead); + } + reader.close(); + + gadgetSource = fileData.toString(); + } + } catch (IOException e) { + log.error("Failed to read the mashup's gadget ui from disk.", e); + } catch (RegistryException e) { + log.error("Failed to read the mashup's gadget ui from disk.", e); + } + + return gadgetSource; + } public static void login(String username, String password, String cookieString, String contextPath) Modified: trunk/mashup/java/modules/www/editor.jsp URL: http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/www/editor.jsp?rev=18210&r1=18209&r2=18210&view=diff ============================================================================== --- trunk/mashup/java/modules/www/editor.jsp (original) +++ trunk/mashup/java/modules/www/editor.jsp Mon Jun 9 03:37:42 2008 @@ -96,6 +96,8 @@ } else { throw new MashupUiFault("Not enough data provided to fulfil this request"); } + + String httpUrl = MashupUtils.getServerURL(request.getServerName()); %> <html> <head> @@ -131,7 +133,7 @@ type="text/javascript">userLoggedOn = <%=RegistryUtils.isLoggedIn(userRegistry) %>;</script> <script language="JavaScript" type="text/javascript"> -var panels = new Array('mashup_code', 'ui_code'); +var panels = new Array('mashup_code', 'ui_code', 'gadget_code'); var selectedTab = null; function showPanel(tab, name) { @@ -144,7 +146,7 @@ } selectedTab = tab; selectedTab.style.color = 'black'; - // selectedTab.style.fontWeight = 'bold'; + // selectedTab.style.fontWeight = 'bold'; selectedTab.style.textDecoration = 'none'; for (var i = 0; i < panels.length; i++) @@ -235,18 +237,18 @@ %> } -function saveUiSource(newSource, isRedirect) { +function saveUiSource(newSource, isRedirect, type) { var params = new Array(); params[0] = "ui_save_status"; params[1] = isRedirect; <% if(action.equalsIgnoreCase("edit")){ %> - wso2.mashup.services.saveUiSource('<%=mashup%>', newSource, saveSourceCallback, params); + wso2.mashup.services.saveUiSource('<%=mashup%>', newSource, saveSourceCallback, params, type); <% }else if(action.equalsIgnoreCase("new")){ %> - wso2.mashup.services.saveUiSource('<%="/mashups/" + currentUser + "/" + mashup%>', newSource, saveSourceCallback, params); + wso2.mashup.services.saveUiSource('<%="/mashups/" + currentUser + "/" + mashup%>', newSource, saveSourceCallback, params, type); <% } %> @@ -256,6 +258,45 @@ window.location = "<%=bounceback%>"; } +function generateNewUi(uiType){ + var url = ""; + if(uiType == "gadget"){ + url = "<%=mashupServerURL%><%=author%>/<%=mashup%>?template&flavor=googlegadget"; + }else{ + url = "<%=mashupServerURL%><%=author%>/<%=mashup%>?template&flavor=html"; + } + + var request = createXmlHttpRequest(); + + //Make sure the XMLHttpRequest object was instantiated + if (request) + { + //Check for requested web-accesible artifact (e.g. index.html, gadget.xml) + request.open("GET", url, true); + + request.onreadystatechange = function () { + if (request.readyState == 4) { + + try { + if (request.status == 200) { + if (uiType == 'gadget') { + gadget_code_text.setCode(request.responseText); + } else { + ui_code_text.setCode(request.responseText); + } + } else { + wso2.wsf.Util.alertMessage(request.responseText); + } + } catch(ex) { + + } + } + } + + request.send(null); + } +} + </script> </head> <body onload="init();"> @@ -291,6 +332,10 @@ onmousedown="return event.returnValue = showPanel(this, 'ui_code');" onclick="return false;">Custom UI Code</a></li> <li class="tab-right"><img src="images/blank.gif" width="8"/></li> + <li class="tab"><a href="" + onmousedown="return event.returnValue = showPanel(this, 'gadget_code');" + onclick="return false;">Gadget UI Code</a></li> + <li class="tab-right"><img src="images/blank.gif" width="8"/></li> </ul> </div> @@ -346,103 +391,11 @@ </div> <div class="panel" id="ui_code" style="display: block"> <% - String uiSource = ""; - if (action.equalsIgnoreCase("new")) { - uiSource = - "<!--\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 " + mashup + "</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=\"../" + mashup + - "?stub\"></script>\n" + - " \n" + - " <script type=\"text/javascript\" language=\"javascript\">\n" + - "\n" + - "\t\t //Calls the toString operation of the '" + mashup + - "' Mashup \n" + - " function callMashup() { \n" + - "\n" + - " " + mashup + ".setAddress(" + - mashup + ".endpoint, \"services/" + mashup + - "\");\n" + - " " + mashup + - ".toString.onError = handleError;\n" + - " " + mashup + - ".toString.callback = function (response) {\n" + - " fillData(response);\n" + - " }\n" + - " " + mashup + ".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 " + mashup + - " service through the <a href=\"../" + mashup + - "?tryit\">Try-it page</a>.</div>" + - "\n" + - "<div id=\"error-console\"></div>" + - " \n" + - "</body>\n" + - "</html>"; - } else if (action.equalsIgnoreCase("edit")) { - uiSource = MashupUtils.readServiceUiSource(mashup); - } + String uiSource = MashupUtils.readServiceUiSource(mashup); + + if (uiSource.equals("404")) { + uiSource = "A custom UI was not found for this mashup. You can use the 'Generate Template' button below to generate a sample."; + } %> <textarea id="ui_code_text" rows="" cols="" class="codepress html" style="width: 100%; height: 94%; *height:628px"><%=uiSource%> @@ -453,9 +406,34 @@ use the button on the right to save changes.</label> <span style="float:right"> + <input type="button" value="Generate Template" onclick="generateNewUi('custom_ui');" /> + <input type="button" value="Discard changes" onclick="discardChanges();" /> + <input type="button" value="Apply changes" onclick="saveUiSource(ui_code_text.getCode(),false, 'html');" /> + <input type="button" value="Save changes" onclick="saveUiSource(ui_code_text.getCode(),true, 'html');" /> + </span> +</div> +</div> +<div class="panel" id="gadget_code" style="display: block"> +<% + String gadgetSource = MashupUtils.readGadgetUiSource(mashup); + + if (gadgetSource.equals("404")) { + gadgetSource = "A gadget UI was not found for this mashup. You can use the 'Generate New' button below to generate a sample."; + } +%> +<textarea id="gadget_code_text" rows="" cols="" class="codepress html" + style="width: 100%; height: 94%; *height:628px"><%=gadgetSource%> +</textarea> +<br> + +<div style="padding-top: 10px;"><label id="gadget_save_status" style="float: left;">Tip: You can + use the button on + the right to save changes.</label> + <span style="float:right"> + <input type="button" value="Generate Template" onclick="generateNewUi('gadget');" /> <input type="button" value="Discard changes" onclick="discardChanges();" /> - <input type="button" value="Apply changes" onclick="saveUiSource(ui_code_text.getCode(),false);" /> - <input type="button" value="Save changes" onclick="saveUiSource(ui_code_text.getCode(),true);" /> + <input type="button" value="Apply changes" onclick="saveUiSource(gadget_code_text.getCode(),false, 'gadget');" /> + <input type="button" value="Save changes" onclick="saveUiSource(gadget_code_text.getCode(),true, 'gadget');" /> </span> </div> </div> Modified: trunk/mashup/java/modules/www/js/services.js URL: http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/www/js/services.js?rev=18210&r1=18209&r2=18210&view=diff ============================================================================== --- trunk/mashup/java/modules/www/js/services.js (original) +++ trunk/mashup/java/modules/www/js/services.js Mon Jun 9 03:37:42 2008 @@ -421,7 +421,7 @@ * @param {callback} callBack User-defined callback function or object * @param {callback} params Parameters to be set in the callback */ -wso2.mashup.services.saveUiSource = function (path, modifiedSource, callback, params) { +wso2.mashup.services.saveUiSource = function (path, modifiedSource, callback, params, type) { var callURL = mashupServerURL + "/" + "MashupAdminService" + "/" ; var serviceSource = Base64.encode(modifiedSource); @@ -429,6 +429,7 @@ var body_xml = '<req:saveUiSource xmlns:req="http://service.admin.mashup.wso2.org/xsd">\n' + ' <req:path>' + path + '</req:path>\n' + ' <req:modifiedSource>' + serviceSource + '</req:modifiedSource>\n' + + ' <req:type>' + type + '</req:type>\n' + ' </req:saveUiSource>\n'; new wso2.wsf.WSRequest(callURL, "saveUiSource", body_xml, callback, params, wso2.mashup.services.defaultErrHandler); Modified: trunk/mashup/java/modules/www/js/utils.js URL: http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/www/js/utils.js?rev=18210&r1=18209&r2=18210&view=diff ============================================================================== --- trunk/mashup/java/modules/www/js/utils.js (original) +++ trunk/mashup/java/modules/www/js/utils.js Mon Jun 9 03:37:42 2008 @@ -21,7 +21,7 @@ if (xmlHttpRequest4ui) { //Check for requested web-accesible artifact (e.g. index.html, gadget.xml) - xmlHttpRequest4ui.open("GET", serviceLocation, true); + xmlHttpRequest4ui.open("GET", serviceLocation + "/index.html", true); xmlHttpRequest4ui.onreadystatechange = function () { if (xmlHttpRequest4ui.readyState == 4) { @@ -33,7 +33,7 @@ } } else { //Check for index.htm - xmlHttpRequest4ui.open("GET", serviceLocation, true); + xmlHttpRequest4ui.open("GET", serviceLocation + "/index.htm", true); xmlHttpRequest4ui.onreadystatechange = function () { if (xmlHttpRequest4ui.readyState == 4) { @@ -61,6 +61,34 @@ } } +function isGadgetAvailable(serviceLocation, callback) { + var xmlHttpRequest4ui = createXmlHttpRequest(); + + //Make sure the XMLHttpRequest object was instantiated + if (xmlHttpRequest4ui) + { + //Check for requested web-accesible artifact (e.g. index.html, gadget.xml) + xmlHttpRequest4ui.open("GET", serviceLocation + "/gadget.xml", true); + + xmlHttpRequest4ui.onreadystatechange = function () { + if (xmlHttpRequest4ui.readyState == 4) { + + try { + if (xmlHttpRequest4ui.status == 200) { + if (typeof callback != 'undefined') { + callback.call(this); + } + } + } catch(ex) { + isGadgetAvailable(serviceLocation, callback); + } + } + } + + xmlHttpRequest4ui.send(null); + } +} + function createXmlHttpRequest() { var request; Modified: trunk/mashup/java/modules/www/mashup.jsp URL: http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/www/mashup.jsp?rev=18210&r1=18209&r2=18210&view=diff ============================================================================== --- trunk/mashup/java/modules/www/mashup.jsp (original) +++ trunk/mashup/java/modules/www/mashup.jsp Mon Jun 9 03:37:42 2008 @@ -475,7 +475,7 @@ 'View the custom <a href="<%=httpUrl%><%=mashupServerURL%><%=author%>/<%= mashup %>/" target="_blank">HTML Interface</a> to this service.'; } - isCustomUiAvailable('<%=mashupServerURL%><%=author%>/<%= mashup %>/index.html', customUiCallback); + isCustomUiAvailable('<%=mashupServerURL%><%=author%>/<%= mashup %>', customUiCallback); </script> <li><a href="<%=httpUrl%><%=mashupServerURL%><%=author%>/<%= mashup %>?tryit" @@ -493,7 +493,7 @@ document.getElementById("custom_gadget_link").style.display = "list-item"; } - isCustomUiAvailable('<%=mashupServerURL%><%=author%>/<%= mashup %>/gadget.xml', customGadgetCallback); + isGadgetAvailable('<%=mashupServerURL%><%=author%>/<%= mashup %>', customGadgetCallback); </script> <li><a href="<%=httpUrl%><%=mashupServerURL%><%=author%>/<%= mashup %>?gadget" _______________________________________________ Mashup-dev mailing list [email protected] http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev
