Author: tyrell Date: Tue Jul 15 11:15:32 2008 New Revision: 19348 URL: http://wso2.org/svn/browse/wso2?view=rev&revision=19348
Log: Adding faulty Data Service handling. Modified: trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupDataServiceAdmin.java trunk/mashup/java/modules/www/faulty_mashup.jsp Modified: trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupDataServiceAdmin.java URL: http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupDataServiceAdmin.java?rev=19348&r1=19347&r2=19348&view=diff ============================================================================== --- trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupDataServiceAdmin.java (original) +++ trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupDataServiceAdmin.java Tue Jul 15 11:15:32 2008 @@ -19,25 +19,45 @@ import org.apache.axiom.om.OMAttribute; import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.axiom.om.util.StAXUtils; import org.apache.axis2.AxisFault; import org.apache.axis2.context.MessageContext; import org.apache.axis2.context.ServiceGroupContext; +import org.apache.axis2.context.ConfigurationContext; import org.apache.axis2.description.AxisService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.wsas.admin.service.util.DataServiceInfo; import org.wso2.wsas.admin.service.util.DBServerData; +import org.wso2.wsas.ServerManager; +import org.wso2.wsas.util.WsasUtils; import org.wso2.ws.dataservice.DBConstants; import org.wso2.mashup.MashupConstants; +import org.wso2.mashup.MashupFault; +import org.wso2.registry.jdbc.EmbeddedRegistry; +import org.wso2.registry.RegistryConstants; +import org.wso2.registry.exceptions.RegistryException; +import org.wso2.registry.session.UserRegistry; +import org.wso2.javascript.rhino.JavaScriptEngineConstants; +import org.wso2.utils.ServerConfiguration; import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; import java.util.Iterator; import java.io.File; import java.io.IOException; import java.io.BufferedWriter; import java.io.FileWriter; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.ByteArrayInputStream; public class MashupDataServiceAdmin extends org.wso2.wsas.admin.service.DataServiceAdmin { + private static final Log log = LogFactory.getLog(MashupDataServiceAdmin.class); + public void saveDataServiceContents(OMElement dataWrapper) throws AxisFault { String serviceId; @@ -135,13 +155,108 @@ } public DataServiceInfo getDSMetaData(String init) throws AxisFault { - return super.getDSMetaData( - init); + if (init == null || init.length() == 0) { + //Call for new one DS. + String axis2Repo = ServerConfiguration.getInstance(). + getFirstProperty(ServerConfiguration.AXIS2_CONFIG_REPO_LOCATION); + if (WsasUtils.isURL(axis2Repo)) { + throw new AxisFault("WSAS is running from a URL repository " + axis2Repo + + ". Cannot create Data Services for URL repositories"); + } else { + OMFactory fac = OMAbstractFactory.getOMFactory(); + OMElement dwEle = fac.createOMElement(new QName(null, "dataWrapper")); + OMElement dataEle = fac.createOMElement(new QName(null, "data")); + OMElement configEle = fac.createOMElement(new QName(null, "config")); + dataEle.addChild(configEle); + dwEle.addChild(dataEle); + DataServiceInfo dataServiceInfo = new DataServiceInfo(); + dataServiceInfo.setDataWrapper(dwEle); + dataServiceInfo.setDbServerData(getDatabaseUrlDriverList()); + return dataServiceInfo; + } + + } else { + //call for the existing + DataServiceInfo dataServiceInfo = new DataServiceInfo(); + OMElement dataEle = getDataServiceContents(init); + dataEle.build(); + dataEle.detach(); + OMFactory fac = OMAbstractFactory.getOMFactory(); + OMElement dwEle = fac.createOMElement(new QName(null, "dataWrapper")); + dwEle.addChild(dataEle); + dataServiceInfo.setDataWrapper(dwEle); + dataServiceInfo.setDbServerData(getDatabaseUrlDriverList()); + return dataServiceInfo; + } } public OMElement getDataServiceContents(String serviceId) throws AxisFault { - return super.getDataServiceContents( - serviceId); + OMElement returnEle = null; + + String fileParth = null; + + AxisService axisService = getAxisConfig().getService(serviceId); + + if (axisService != null) { + fileParth = + (String) axisService.getParameter(DBConstants.DB_SERVICE_CONFIG_FILE) + .getValue(); + } else { + // This might be a faulty service let's get the file manually + //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 { + // Figuruing out the registry path from the service id provided + String[] contents = serviceId.split("-"); + String path = "/mashups/" + contents[0] + "/" + contents[1]; + + UserRegistry systemRegistry = embeddedRegistry.getSystemRegistry(); + fileParth = + systemRegistry.get(path).getProperty(DBConstants.DB_SERVICE_CONFIG_FILE); + } catch (RegistryException e) { + log.error("Failed to read mashup from disk.", e); + } + } + + if (fileParth == null) { + throw new MashupFault("Failed to read the Data Service Config file from disk."); + } else { + StringBuffer fileContents = new StringBuffer(); + try { + BufferedReader in = new BufferedReader(new FileReader(fileParth)); + String str; + while ((str = in.readLine()) != null) { + fileContents.append(str); + } + in.close(); + } catch (IOException e) { + throw new AxisFault( + "Error while reading the contents from the service config file for service " + + serviceId, e); + } + + + try { + XMLStreamReader xmlSR = + StAXUtils.createXMLStreamReader( + new ByteArrayInputStream(fileContents.toString().getBytes())); + + returnEle = new StAXOMBuilder(xmlSR).getDocumentElement(); + // new BufferedReader(new InputStreamReader( + } catch (Exception e) { + throw new AxisFault( + "Error while converting the contents of the configuration file into and OMElement for service " + + serviceId, e); + } + } + + + return returnEle; } public DBServerData[] getDatabaseUrlDriverList() { Modified: trunk/mashup/java/modules/www/faulty_mashup.jsp URL: http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/www/faulty_mashup.jsp?rev=19348&r1=19347&r2=19348&view=diff ============================================================================== --- trunk/mashup/java/modules/www/faulty_mashup.jsp (original) +++ trunk/mashup/java/modules/www/faulty_mashup.jsp Tue Jul 15 11:15:32 2008 @@ -111,7 +111,23 @@ } </script> - You may use the <a href="editor.jsp?action=edit&author=<%=mashupOwner%>&mashup=<%=mashup%>">mashup editor</a> to + You may use the + <% + + String mediaType = userRegistry.get(path).getMediaType(); + if (mediaType.equals(MashupConstants.MASHUP_MEDIA_TYPE)){ + %> + <a href="editor.jsp?action=edit&mashup=<%=mashup%>&author=<%=author%>&bounceback=<%=URLEncoder.encode(thisPage, "UTF-8")%>">Mashup Editor</a> + <% +}else if (mediaType.equals(MashupConstants.DATA_SERVICE_MEDIA_TYPE)){ +%> + <a href="edit_ds.jsp?serviceName=<%=author + "-" + mashup%>&bounceback=<%=URLEncoder.encode(thisPage, "UTF-8")%>">Data Service Editor</a> + + <% + +} + %> + to fix the source code of this mashup. You can also <a href="#" onclick="deleteMashup();">delete</a> this mashup from the system. _______________________________________________ Mashup-dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/mashup-dev
