geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdam...@apache.org
Subject svn commit: r594107 - in /geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/remote: FileUploadClient.java FileUploadProgress.java FileUploadServletClient.java RemoteDeployUtil.java
Date Mon, 12 Nov 2007 13:20:16 GMT
Author: gdamour
Date: Mon Nov 12 05:20:15 2007
New Revision: 594107

URL: http://svn.apache.org/viewvc?rev=594107&view=rev
Log:
Put the servlet upload implementation behind an interface so that it is 
easier to test and re-use from other part of the system.

Added:
    geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/remote/FileUploadClient.java
    geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/remote/FileUploadProgress.java
    geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/remote/FileUploadServletClient.java
Modified:
    geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/remote/RemoteDeployUtil.java

Added: geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/remote/FileUploadClient.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/remote/FileUploadClient.java?rev=594107&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/remote/FileUploadClient.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/remote/FileUploadClient.java
Mon Nov 12 05:20:15 2007
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.deployment.plugin.remote;
+
+import java.io.File;
+import java.net.URL;
+
+import org.apache.geronimo.kernel.Kernel;
+
+/**
+ *
+ * @version $Rev:$ $Date:$
+ */
+public interface FileUploadClient {
+    URL getRemoteDeployUploadURL(Kernel kernel);
+    
+    void uploadFilesToServer(URL uploadURL,
+        String username,
+        String password,
+        File[] files,
+        FileUploadProgress progress);
+}

Added: geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/remote/FileUploadProgress.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/remote/FileUploadProgress.java?rev=594107&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/remote/FileUploadProgress.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/remote/FileUploadProgress.java
Mon Nov 12 05:20:15 2007
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.deployment.plugin.remote;
+
+/**
+ *
+ * @version $Rev:$ $Date:$
+ */
+public interface FileUploadProgress {
+    void updateStatus(String message);
+
+    void fail(String message);
+
+    void fail(Exception exception);
+}

Added: geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/remote/FileUploadServletClient.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/remote/FileUploadServletClient.java?rev=594107&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/remote/FileUploadServletClient.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/remote/FileUploadServletClient.java
Mon Nov 12 05:20:15 2007
@@ -0,0 +1,270 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.deployment.plugin.remote;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.util.encoders.Base64;
+
+/**
+ *
+ * @version $Rev:$ $Date:$
+ */
+public class FileUploadServletClient implements FileUploadClient {
+    private static final Log log = LogFactory.getLog(FileUploadServletClient.class);
+
+    /** Note:  The below versions should be kept in sync with those in FileUploadServlet.java
**/
+    // Starting RemoteDeploy datastream versions
+    public static final int REMOTE_DEPLOY_REQUEST_VER_0 = 0;
+    public static final int REMOTE_DEPLOY_RESPONSE_VER_0 = 0;
+    // Current RemoteDeploy datastream versions
+    public static final int REMOTE_DEPLOY_REQUEST_VER = 0;
+    public static final int REMOTE_DEPLOY_RESPONSE_VER = 0;
+
+    public URL getRemoteDeployUploadURL(Kernel kernel) {
+        AbstractName deployerName = getDeployerName(kernel);
+        String remoteDeployUpload;
+        try {
+            remoteDeployUpload = (String) kernel.getAttribute(deployerName, "remoteDeployUploadURL");
+            return new URL(remoteDeployUpload);
+        } catch (Exception e) {
+            throw new AssertionError(e);
+        }
+     }
+
+    protected AbstractName getDeployerName(Kernel kernel) {
+        Set<AbstractName> deployerNames = kernel.listGBeans(new AbstractNameQuery("org.apache.geronimo.deployment.Deployer"));
+        if (1 != deployerNames.size()) {
+            throw new IllegalStateException("No Deployer GBean present in running Geronimo
server. " +
+                 "This usually indicates a serious problem with the configuration of " +
+                 "your running Geronimo server.  If " +
+                 "the deployer is present but not started, the workaround is to run " +
+                 "a deploy command like 'start geronimo/geronimo-gbean-deployer/1.0/car'.
 " +
+                 "If the deployer service is not present at all (it was undeployed) then
" +
+                 "you need to either re-install Geronimo or get a deployment plan for the
" +
+                 "runtime deployer and distribute it while the server is not running and
" +
+                 "then start the server with a command like the above.  For help on this,
" +
+                 "write to user@geronimo.apache.org and include the contents of your " +
+                 "var/config/config.xml file.");
+        }
+        return deployerNames.iterator().next();
+    }
+
+    public void uploadFilesToServer(URL uploadURL,
+            String username,
+            String password,
+            File[] files,
+            FileUploadProgress progress) {
+        if(files == null) {
+            return;
+        }
+        
+        List valid = new LinkedList();
+        for(int i=0; i<files.length; i++) {
+            if(files[i] == null) {
+                continue;
+            }
+            File file = files[i];
+            if(!file.exists() || !file.canRead()) {
+                continue;
+            }
+            valid.add(new Integer(i));
+        }
+        
+        if(valid.size() > 0) {
+            progress.updateStatus("Uploading "+valid.size()+" file(s) to server");
+            if (log.isDebugEnabled()) {
+                log.debug("Uploading "+valid.size()+" file(s) to server");
+            }
+            try {
+                URLConnection con = connectToServer(uploadURL, username, password);
+                writeRequest(con, files, valid, progress);
+                readResponse(con, files, valid, progress);
+            } catch (Exception e) {
+                progress.fail(e);
+            }
+        }
+    }
+
+    protected void readResponse(URLConnection con, File[] files, List valid, FileUploadProgress
progress)
+            throws IOException {
+        /* ---------------------
+         * RemoteDeploy Response
+         * ---------------------
+         *
+         * Note:  The below code has to match FileUploadServlet.java
+         *
+         * RemoteDeployer response stream format:
+         *   It returns a serialized stream containing:
+         *   0) an int, the version of this datastream format - REMOTE_DEPLOY_RESPONSE_VER
+         *   1) a UTF string, the status (should be "OK")
+         *   2) an int, the number of files received
+         *   3) for each file:
+         *     3.1) a UTF String, the path to the file as saved to the server's filesystem
+         *   x) new data would be added here
+         *
+         *   The file positions in the response will be the same as in the request.
+         *   That is, a name for upload file #2 will be in response position #2.
+         */
+        DataInputStream in = new DataInputStream(new BufferedInputStream(con.getInputStream()));
+        // 0) an int, the version of this datastream format - REMOTE_DEPLOY_RESPONSE_VER
+        int rspVer = in.readInt();
+        // whenever we update the stream version, the next line needs to
+        // be changed to just - (rspVer >= REMOTE_DEPLOY_RESPONSE_VER_0)
+        // but until then, be more restrictive so we can handle old servers
+        // that don't send a version as the first thing, but UTF instead...
+        if ((rspVer >= REMOTE_DEPLOY_RESPONSE_VER_0) && (rspVer <= REMOTE_DEPLOY_RESPONSE_VER))
{
+            // 1) a UTF string, the status (should be "OK")
+            String status = in.readUTF();
+            if(!status.equals("OK")) {
+                progress.fail("Unable to upload files to server.  Server returned status="+status);
+                log.error("Unable to upload files to server.  Server returned status="+status);
+                return;
+            }
+            progress.updateStatus("File upload complete (Server status="+status+")");
+            if (log.isDebugEnabled()) {
+                log.debug("File upload complete (Server status="+status+")");
+            }
+            // 2) an int, the number of files received
+            int count = in.readInt();
+            if(count != valid.size()) {
+                progress.fail("Server only received "+count+" of "+valid.size()+" files");
+                log.warn("Server only received "+count+" of "+valid.size()+" files");
+            }
+            // 3) for each file:
+            for (Iterator it = valid.iterator(); it.hasNext();) {
+                Integer index = (Integer) it.next();
+                // 3.1) a UTF String, the path to the file as saved to the server's filesystem
+                String serverFileName = in.readUTF();
+                if (serverFileName != null) {
+                    files[index.intValue()] = new File(serverFileName);
+                } else {
+                    log.error("Received an invalid filename from the server");
+                    files[index.intValue()] = null;
+                }
+                if (log.isDebugEnabled()) {
+                    log.debug("Server created file="+serverFileName);
+                }
+            }
+            // x) new data would be added here
+            if (rspVer > REMOTE_DEPLOY_RESPONSE_VER_0) {
+                // additions in later datastream versions would be handled here
+
+                if (rspVer > REMOTE_DEPLOY_RESPONSE_VER) {
+                    // if the server is sending a newer version than we know about
+                    // just ignore it and warn the user about the mismatch
+                    log.warn("Received a newer server response ("+rspVer+") than expected
("+REMOTE_DEPLOY_RESPONSE_VER+").  Ignoring any additional server response data.");
+                }
+            }
+        } else {
+            // should never happen, but handle it anyway
+            progress.fail("Received unknown server response version="+rspVer);
+            log.warn("Received unknown server response version="+rspVer);
+        }
+        in.close();
+        progress.updateStatus("File(s) transferred to server.  Resuming deployment operation.");
+    }
+
+    protected void writeRequest(URLConnection con, File[] files, List valid, FileUploadProgress
progress)
+            throws IOException, FileNotFoundException {
+        /* --------------------
+         * RemoteDeploy Request
+         * --------------------
+         *
+         * Note:  The below code has to match FileUploadServlet.java
+         *
+         * RemoteDeployer data stream format:
+         *   0) an int, the version of this datastream format - REMOTE_DEPLOY_REQUEST_VER
+         *   1) an int, the number of files being uploaded
+         *   2) for each file:
+         *     2.0) a UTF String, the filename of the file being uploaded
+         *     2.1) a long, the length of the file in bytes
+         *     2.2) byte[], byte count equal to the number above for the file
+         */
+        DataOutputStream out = new DataOutputStream(new BufferedOutputStream(con.getOutputStream()));
+        // 0) an int, the version of this datastream format - REMOTE_DEPLOY_REQUEST_VER
+        out.writeInt(REMOTE_DEPLOY_REQUEST_VER);
+        // 1) an int, the number of files being uploaded
+        out.writeInt(valid.size());
+        byte[] buf = new byte[1024];
+        int size;
+        long total, length, threshold, next;
+        // 2) for each file:
+        for (Iterator it = valid.iterator(); it.hasNext();) {
+            Integer index = (Integer) it.next();
+            File file = files[index.intValue()];
+            // 2.0) a UTF String, the filename of the file being uploaded
+            out.writeUTF(file.getName().trim());
+            // 2.1) a long, the length of the file in bytes
+            out.writeLong(length = file.length());
+            threshold = Math.max(length / 100, (long)10240);
+            next = threshold;
+            BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
+            if (log.isDebugEnabled()) {
+                log.debug("Uploading "+file.getName());
+            }
+            total = 0;
+            // 2.2) raw bytes, equal to the number above for the file
+            while((size = in.read(buf)) > -1) {
+                out.write(buf, 0, size);
+                total += size;
+                if(total > next) {
+                    progress.updateStatus("Uploading "+file.getName()+": "+(total/1024)+"
KB");
+                    while(total > next) next += threshold;
+                }
+            }
+            in.close();
+        }
+        out.flush();
+        out.close();
+    }
+
+    protected URLConnection connectToServer(URL url, String username, String password) throws
IOException {
+        URLConnection con = url.openConnection();
+        String auth = username + ":" + password;
+        byte[] data = auth.getBytes();
+        String s = new String(Base64.encode(data));
+        while(s.length() % 4 != 0) s += "=";
+        con.setRequestProperty("Authorization", "Basic "+s);
+        con.setDoInput(true);
+        con.setDoOutput(true);
+        con.connect();
+        return con;
+    }
+
+}

Modified: geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/remote/RemoteDeployUtil.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/remote/RemoteDeployUtil.java?rev=594107&r1=594106&r2=594107&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/remote/RemoteDeployUtil.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/remote/RemoteDeployUtil.java
Mon Nov 12 05:20:15 2007
@@ -16,23 +16,9 @@
  */
 package org.apache.geronimo.deployment.plugin.remote;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.geronimo.deployment.plugin.local.AbstractDeployCommand;
-import org.apache.geronimo.util.encoders.Base64;
-
 import java.io.File;
-import java.io.IOException;
-import java.io.DataOutputStream;
-import java.io.BufferedInputStream;
-import java.io.FileInputStream;
-import java.io.BufferedOutputStream;
-import java.io.DataInputStream;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Iterator;
+
+import org.apache.geronimo.deployment.plugin.local.AbstractDeployCommand;
 
 /**
  * Knows how to upload files to a server
@@ -41,183 +27,37 @@
  */
 public class RemoteDeployUtil {
 
-    private static final Log log = LogFactory.getLog(RemoteDeployUtil.class);
-
-    /** Note:  The below versions should be kept in sync with those in FileUploadServlet.java
**/
-    // Starting RemoteDeploy datastream versions
-    public static final int REMOTE_DEPLOY_REQUEST_VER_0 = 0;
-    public static final int REMOTE_DEPLOY_RESPONSE_VER_0 = 0;
-    // Current RemoteDeploy datastream versions
-    public static final int REMOTE_DEPLOY_REQUEST_VER = 0;
-    public static final int REMOTE_DEPLOY_RESPONSE_VER = 0;
+    public static void uploadFilesToServer(File[] files, AbstractDeployCommand command) {
+        FileUploadClient uploadServletClient = new FileUploadServletClient();
+        try {
+            uploadServletClient.uploadFilesToServer(command.getRemoteDeployUploadURL(), 
+                command.getCommandContext().getUsername(),
+                command.getCommandContext().getPassword(),
+                files,
+                new FileUploadServletProgressAdapter(command));
+        } catch (Exception e) {
+            command.doFail(e);
+        }
+    }
 
+    protected static class FileUploadServletProgressAdapter implements FileUploadProgress
{
+        private final AbstractDeployCommand command;
+        
+        public FileUploadServletProgressAdapter(AbstractDeployCommand command) {
+            this.command = command;
+        }
 
-    public static void uploadFilesToServer(File[] files, AbstractDeployCommand progress)
{
-        if(files == null) {
-            return;
+        public void fail(String message) {
+            command.fail(message);
         }
-        List valid = new LinkedList();
-        for(int i=0; i<files.length; i++) {
-            if(files[i] == null) {
-                continue;
-            }
-            File file = files[i];
-            if(!file.exists() || !file.canRead()) {
-                continue;
-            }
-            valid.add(new Integer(i));
+
+        public void fail(Exception exception) {
+            command.doFail(exception);
         }
-        if(valid.size() > 0) {
-            progress.updateStatus("Uploading "+valid.size()+" file(s) to server");
-            if (log.isDebugEnabled()) {
-                log.debug("Uploading "+valid.size()+" file(s) to server");
-            }
-            try {
-                /* --------------------
-                 * RemoteDeploy Request
-                 * --------------------
-                 *
-                 * Note:  The below code has to match FileUploadServlet.java
-                 *
-                 * RemoteDeployer data stream format:
-                 *   0) an int, the version of this datastream format - REMOTE_DEPLOY_REQUEST_VER
-                 *   1) an int, the number of files being uploaded
-                 *   2) for each file:
-                 *     2.0) a UTF String, the filename of the file being uploaded
-                 *     2.1) a long, the length of the file in bytes
-                 *     2.2) byte[], byte count equal to the number above for the file
-                 */
-                URL url = progress.getRemoteDeployUploadURL();
-                URLConnection con = connectToServer(url, progress.getCommandContext().getUsername(),
progress.getCommandContext().getPassword());
-                DataOutputStream out = new DataOutputStream(new BufferedOutputStream(con.getOutputStream()));
-                // 0) an int, the version of this datastream format - REMOTE_DEPLOY_REQUEST_VER
-                out.writeInt(REMOTE_DEPLOY_REQUEST_VER);
-                // 1) an int, the number of files being uploaded
-                out.writeInt(valid.size());
-                byte[] buf = new byte[1024];
-                int size;
-                long total, length, threshold, next;
-                // 2) for each file:
-                for (Iterator it = valid.iterator(); it.hasNext();) {
-                    Integer index = (Integer) it.next();
-                    File file = files[index.intValue()];
-                    // 2.0) a UTF String, the filename of the file being uploaded
-                    out.writeUTF(file.getName().trim());
-                    // 2.1) a long, the length of the file in bytes
-                    out.writeLong(length = file.length());
-                    threshold = Math.max(length / 100, (long)10240);
-                    next = threshold;
-                    BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
-                    if (log.isDebugEnabled()) {
-                        log.debug("Uploading "+file.getName());
-                    }
-                    total = 0;
-                    // 2.2) raw bytes, equal to the number above for the file
-                    while((size = in.read(buf)) > -1) {
-                        out.write(buf, 0, size);
-                        total += size;
-                        if(total > next) {
-                            progress.updateStatus("Uploading "+file.getName()+": "+(total/1024)+"
KB");
-                            while(total > next) next += threshold;
-                        }
-                    }
-                    in.close();
-                }
-                out.flush();
-                out.close();
-
-                /* ---------------------
-                 * RemoteDeploy Response
-                 * ---------------------
-                 *
-                 * Note:  The below code has to match FileUploadServlet.java
-                 *
-                 * RemoteDeployer response stream format:
-                 *   It returns a serialized stream containing:
-                 *   0) an int, the version of this datastream format - REMOTE_DEPLOY_RESPONSE_VER
-                 *   1) a UTF string, the status (should be "OK")
-                 *   2) an int, the number of files received
-                 *   3) for each file:
-                 *     3.1) a UTF String, the path to the file as saved to the server's filesystem
-                 *   x) new data would be added here
-                 *
-                 *   The file positions in the response will be the same as in the request.
-                 *   That is, a name for upload file #2 will be in response position #2.
-                 */
-
-                DataInputStream in = new DataInputStream(new BufferedInputStream(con.getInputStream()));
-                // 0) an int, the version of this datastream format - REMOTE_DEPLOY_RESPONSE_VER
-                int rspVer = in.readInt();
-                // whenever we update the stream version, the next line needs to
-                // be changed to just - (rspVer >= REMOTE_DEPLOY_RESPONSE_VER_0)
-                // but until then, be more restrictive so we can handle old servers
-                // that don't send a version as the first thing, but UTF instead...
-                if ((rspVer >= REMOTE_DEPLOY_RESPONSE_VER_0) && (rspVer <=
REMOTE_DEPLOY_RESPONSE_VER)) {
-                    // 1) a UTF string, the status (should be "OK")
-                    String status = in.readUTF();
-                    if(!status.equals("OK")) {
-                        progress.fail("Unable to upload files to server.  Server returned
status="+status);
-                        log.error("Unable to upload files to server.  Server returned status="+status);
-                        return;
-                    }
-                    progress.updateStatus("File upload complete (Server status="+status+")");
-                    if (log.isDebugEnabled()) {
-                        log.debug("File upload complete (Server status="+status+")");
-                    }
-                    // 2) an int, the number of files received
-                    int count = in.readInt();
-                    if(count != valid.size()) {
-                        progress.fail("Server only received "+count+" of "+valid.size()+"
files");
-                        log.warn("Server only received "+count+" of "+valid.size()+" files");
-                    }
-                    // 3) for each file:
-                    for (Iterator it = valid.iterator(); it.hasNext();) {
-                        Integer index = (Integer) it.next();
-                        // 3.1) a UTF String, the path to the file as saved to the server's
filesystem
-                        String serverFileName = in.readUTF();
-                        if (serverFileName != null) {
-                            files[index.intValue()] = new File(serverFileName);
-                        } else {
-                            log.error("Received an invalid filename from the server");
-                            files[index.intValue()] = null;
-                        }
-                        if (log.isDebugEnabled()) {
-                            log.debug("Server created file="+serverFileName);
-                        }
-                    }
-                    // x) new data would be added here
-                    if (rspVer > REMOTE_DEPLOY_RESPONSE_VER_0) {
-                        // additions in later datastream versions would be handled here
-
-                        if (rspVer > REMOTE_DEPLOY_RESPONSE_VER) {
-                            // if the server is sending a newer version than we know about
-                            // just ignore it and warn the user about the mismatch
-                            log.warn("Received a newer server response ("+rspVer+") than
expected ("+REMOTE_DEPLOY_RESPONSE_VER+").  Ignoring any additional server response data.");
-                        }
-                    }
-                } else {
-                    // should never happen, but handle it anyway
-                    progress.fail("Received unknown server response version="+rspVer);
-                    log.warn("Received unknown server response version="+rspVer);
-                }
-                in.close();
-                progress.updateStatus("File(s) transferred to server.  Resuming deployment
operation.");
-            } catch (Exception e) {
-                progress.doFail(e);
-            }
+
+        public void updateStatus(String message) {
+            command.updateStatus(message);
         }
-    }
 
-    private static URLConnection connectToServer(URL url, String username, String password)
throws IOException {
-        URLConnection con = url.openConnection();
-        String auth = username + ":" + password;
-        byte[] data = auth.getBytes();
-        String s = new String(Base64.encode(data));
-        while(s.length() % 4 != 0) s += "=";
-        con.setRequestProperty("Authorization", "Basic "+s);
-        con.setDoInput(true);
-        con.setDoOutput(true);
-        con.connect();
-        return con;
     }
 }



Mime
View raw message