[mashup-dev] svn commit r4603 -
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils
svn at wso2.org
svn at wso2.org
Sun Jul 1 22:27:10 PDT 2007
Author: thilina
Date: Sun Jul 1 22:27:00 2007
New Revision: 4603
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupArchiveManupulator.java
Log:
adding methods to support mashup downloading, more refactorings
Modified: trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupArchiveManupulator.java
==============================================================================
--- trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupArchiveManupulator.java (original)
+++ trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupArchiveManupulator.java Sun Jul 1 22:27:00 2007
@@ -19,6 +19,7 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.net.URL;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@@ -27,13 +28,17 @@
import javax.activation.FileDataSource;
import javax.xml.namespace.QName;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMText;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.Parameter;
+import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.wso2.javascript.rhino.JavaScriptEngineConstants;
import org.wso2.mashup.MashupFault;
@@ -57,7 +62,8 @@
* @return the DataHandler containing the archived Mashup Service
* @throws IOException
*/
- public DataHandler createMashupArchiveDataHandler(AxisService mashupService, ConfigurationContext configCtx) throws IOException {
+ public DataHandler createMashupArchiveDataHandler(AxisService mashupService,
+ ConfigurationContext configCtx) throws IOException {
File serviceJS = null;
File serviceResourceFolder = null;
// Get the service js file for the given service
@@ -99,10 +105,13 @@
}
/**
- * Upload a archived mashupService included in the dataHanlder to a remote Mashup Server
- * donated by the destinationServerAddress.
- * @param destinationServerAddress - remote mashup server address (eg: http://mashup.wso2.org:9762)
- * @param dataHandler - contains the archived mashup service
+ * Upload a archived mashupService included in the dataHanlder to a remote
+ * Mashup Server donated by the destinationServerAddress.
+ *
+ * @param destinationServerAddress -
+ * remote mashup server address (eg: http://mashup.wso2.org:9762)
+ * @param dataHandler -
+ * contains the archived mashup service
* @param configCtx
* @param serviceJsFileName
* @param mashupServiceName
@@ -110,7 +119,7 @@
*/
public void uploadMashupService(String destinationServerAddress, DataHandler dataHandler,
ConfigurationContext configCtx, String serviceJsFileName, String mashupServiceName)
- throws AxisFault{
+ throws AxisFault {
// We use the RPCClient to call the sharing service
RPCServiceClient serviceClient = new RPCServiceClient(configCtx, null);
@@ -130,9 +139,8 @@
options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
QName opAddEntry = new QName("http://service.share.mashup.wso2.org/xsd", "shareMashup");
- // parameters to the service
- // ServiceName string, service file name, dataHandler of the bundled
- // archive
+ // parameters to the service ServiceName string, service file name,
+ // dataHandler of the bundled archive
Object[] opAddEntryArgs = new Object[] { mashupServiceName, serviceJsFileName, dataHandler };
serviceClient.invokeRobust(opAddEntry, opAddEntryArgs);
}
@@ -166,4 +174,108 @@
zipDir(resourcesDir, zos);
zos.close();
}
+
+ /**
+ * Downloads the MashupService denoted by the serviceName from the
+ * remoteServer and deploys it in this server.
+ *
+ * @param remoteServer -
+ * Shared Server
+ * @param serviceName
+ * @param messageContext
+ * @param axisConfiguration
+ * @throws AxisFault
+ * @throws IOException
+ * @throws FileNotFoundException
+ */
+ public void downloadMashupService(String remoteServer, String serviceName,
+ MessageContext messageContext, AxisConfiguration axisConfiguration) throws AxisFault,
+ IOException, FileNotFoundException {
+ // We use the RPCClient to call the download service
+ RPCServiceClient serviceClient = new RPCServiceClient(messageContext
+ .getConfigurationContext(), null);
+ Options options = serviceClient.getOptions();
+ EndpointReference remoteSharingServiceEPR;
+ // Check whether used has given the HostAdress with or without the
+ // trailing '/'
+ if (remoteServer.endsWith("/")) {
+ remoteSharingServiceEPR = new EndpointReference(remoteServer
+ + "services/MashupSharingService/getMashup");
+ } else {
+ remoteSharingServiceEPR = new EndpointReference(remoteServer
+ + "/services/MashupSharingService/getMashup");
+ }
+
+ options.setTo(remoteSharingServiceEPR);
+ QName opAddEntry = new QName("http://service.share.mashup.wso2.org/xsd", "getMashup");
+
+ Object[] opAddEntryArgs = new Object[] { serviceName };
+
+ // There is a bug in Axis2 which prevents us from using
+ // invokeBlocking(opAddEntry, opAddEntryArgs,class[]);
+ // Axis2 fails on handling the DataHandler responses in the RPCClient.So
+ // we use OMElements
+ OMElement response = serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs);
+
+ if (response != null) {
+ OMElement responseElement = response.getFirstElement();
+ if (responseElement != null) {
+ OMElement archiveElement = responseElement.getFirstChildWithName(new QName(
+ "http://utils.mashup.wso2.org/xsd", "mashupArchive"));
+ if (archiveElement != null) {
+ OMText textNode = (OMText) archiveElement.getFirstOMChild();
+ textNode.setBinary(true);
+ DataHandler dataHandler = (DataHandler) textNode.getDataHandler();
+ OMElement fileNameElement = responseElement.getFirstChildWithName(new QName(
+ "http://utils.mashup.wso2.org/xsd", "serviceJSFileName"));
+ if (fileNameElement != null) {
+ String fileName = fileNameElement.getText();
+ System.out.println(fileName + dataHandler);
+ deploySharedService(fileName, dataHandler, axisConfiguration);
+ return;
+ }
+ }
+ }
+ }
+ throw new MashupFault("Malformed response from the remote Mashup server.");
+ }
+
+ /**
+ * Extracts the content in the DataHandler to the scripts folder of this
+ * Mashup Server.
+ *
+ * @param fileName -
+ * filename of the service js file (to validate whether a file
+ * with same name exists)
+ * @param dataHandler -
+ * archived mashup service Js & the resources
+ * @param axisConfiguration
+ * @throws AxisFault
+ * @throws IOException
+ * @throws FileNotFoundException
+ * @throws MashupFault
+ */
+ public void deploySharedService(String fileName, DataHandler dataHandler,
+ AxisConfiguration axisConfiguration) throws AxisFault, IOException,
+ FileNotFoundException, MashupFault {
+ URL repository = axisConfiguration.getRepository();
+ if (repository != null) {
+ // Access the scripts deployment folder
+ File repo = new File(repository.getFile());
+ File scriptsFolder = new File(repo, "scripts");
+
+ // Checking whether a file with the same name exists
+ File file = new File(scriptsFolder, fileName);
+ if (file.exists()) {
+ throw new AxisFault(
+ "A Service JavaScript file with the same name already exists in the remote Mashup Server.");
+ }
+ MashupArchiveManupulator archiveManupulator = new MashupArchiveManupulator();
+ // Extract the uploaded mashup archive to the scripts folder.
+ archiveManupulator.extractFromStream(dataHandler.getInputStream(), scriptsFolder
+ .getAbsolutePath());
+ } else {
+ throw new MashupFault("Cannot find the repository in the Mashup server.");
+ }
+ }
}
More information about the Mashup-dev
mailing list