private void pumpItOut(AdminCommandContext context) { String fileName = file_name != null && !file_name.isEmpty() ? file_name : getDefaultBundleName(); File localFile = new File(fileName.replace('\\', '/')); Properties props = new Properties(); File parent = localFile.getParentFile(); if (parent == null) { parent = localFile; } props.setProperty("file-xfer-root", parent.getPath().replace('\\', '/')); URI parentURI = parent.toURI(); try { context.getOutboundPayload().attachFile( "application/octet-stream", parentURI.relativize(localFile.toURI()), "sync-bundle", props, syncBundleExport); } catch (IOException ex) { setError(Strings.get("export.sync.bundle.retrieveFailed", ex.getLocalizedMessage())); if (logger.isLoggable(Level.FINER)) { logger.finer("fileURI: " + parentURI.relativize(localFile.toURI())); logger.finer("file-xfer-root: " + parent.getPath().replace('\\', '/')); logger.finer("file: " + syncBundleExport.getAbsolutePath()); } } }
/** * Send a request to the client to remove the specified file. * The file is named by mt.name, relative to base. The name * used in the response will be relative to root. */ private void removeFile(URI root, File base, ModTime mt, Payload.Outbound payload) throws URISyntaxException { File f = fileOf(base, mt.name); if (logger.isLoggable(Level.FINEST)) logger.finest("ServerSynchronizer: file " + mt.name + " removed from client"); try { logger.fine("ServerSynchronizer: removing file " + f + " because it does not exist on the DAS"); payload.requestFileRemoval( root.relativize(f.toURI()), "configChange", null); } catch (IOException ioex) { logger.fine("ServerSynchronizer: IOException removing file: " + f); logger.fine(ioex.toString()); } }
" because it doesn't exist on the instance": " because it was out of date")); payload.requestFileReplacement("application/octet-stream", root.relativize(f.toURI()), "configChange", null, f, true);
logger.log(Level.FINE, "About to download artifact {0}", uriPair.getFull()); outboundPayload.attachFile("application/octet-stream", uriPair.getPart(),"files",props, new File(uriPair.getFull().getSchemeSpecificPart())); outboundPayload.writeTo(targetStream); targetStream.flush();
final Properties reportProps = new Properties(); reportProps.setProperty("data-request-type", "report"); outboundPayload.addPart(0, report.getContentType(), "report", reportProps, bais); res.setContentType(outboundPayload.getContentType()); String commandName = req.getRequestURI().substring(getContextRoot().length() + 1); res.addHeader(SET_COOKIE_HEADER, getCookieHeader(req)); outboundPayload.writeTo(res.getOutputStream()); res.getOutputStream().flush(); res.finish();
outboundPayload.attachFile( "application/octet-stream", sourceDir.toURI().relativize(file.toURI()), outboundPayload.writeTo(targetStream); targetStream.flush(); targetStream.close();
logger.finer("Uploading file"); try { outboundPayload.attachFile(FILE_PAYLOAD_MIME_TYPE, URI.create(optionName + "/" + f.getName() + (f.isDirectory() ? "/" : "")), optionName,
outboundPayload.attachFile(FILE_PAYLOAD_MIME_TYPE, URI.create(optionName + "/" + f.getName() + (f.isDirectory() ? "/" : "")), optionName,
Iterator<Part> parts = payload.parts(); while (parts.hasNext()) { writePayloadPart(writer, os, boundary, parts.next());
logger.log(Level.FINE, "About to download artifact {0}", uriPair.getFull()); outboundPayload.attachFile("application/octet-stream", uriPair.getPart(),"files",props, new File(uriPair.getFull().getSchemeSpecificPart()));
logger.fine("ServerSynchronizer: sending file " + f + " because it was out of date"); payload.requestFileReplacement("application/octet-stream", root.relativize(f.toURI()), "configChange", null, f, true);
private void write() { OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(syncBundleExport)); payload.writeTo(out); } catch (IOException ex) { setError(Strings.get("export.sync.bundle.exportFailed", syncBundleExport.getAbsolutePath(), ex.getLocalizedMessage())); } finally { if (out != null) { try { out.close(); } catch (IOException ex) { logger.warning(Strings.get("export.sync.bundle.closeStreamFailed", syncBundleExport.getAbsolutePath(), ex.getLocalizedMessage())); } } } if (!isRetrieve) { if (syncBundleExport.isFile()) { report.setMessage(Strings.get("export.sync.bundle.success", syncBundleExport.getAbsolutePath())); } else { setError(Strings.get("export.sync.bundle.fail", syncBundleExport.getAbsolutePath())); } } }
/** * Send a request to the client to remove the specified file. * The file is named by mt.name, relative to base. The name * used in the response will be relative to root. */ private void removeFile(URI root, File base, ModTime mt, Payload.Outbound payload) throws URISyntaxException { File f = fileOf(base, mt.name); if (logger.isLoggable(Level.FINEST)) logger.finest("ServerSynchronizer: file " + mt.name + " removed from client"); try { if (logger.isLoggable(Level.FINE)) logger.fine("ServerSynchronizer: removing file " + f + " because it does not exist on the DAS"); payload.requestFileRemoval( root.relativize(f.toURI()), "configChange", null); } catch (IOException ioex) { if (logger.isLoggable(Level.FINE)) { logger.fine("ServerSynchronizer: IOException removing file: " + f); logger.fine(ioex.toString()); } } }
private void write() { OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(syncBundleExport)); payload.writeTo(out); } catch (IOException ex) { setError(Strings.get("export.sync.bundle.exportFailed", syncBundleExport.getAbsolutePath(), ex.getLocalizedMessage())); } finally { if (out != null) { try { out.close(); } catch (IOException ex) { logger.warning(Strings.get("export.sync.bundle.closeStreamFailed", syncBundleExport.getAbsolutePath(), ex.getLocalizedMessage())); } } } if (!isRetrieve) { if (syncBundleExport.isFile()) { report.setMessage(Strings.get("export.sync.bundle.success", syncBundleExport.getAbsolutePath())); } else { setError(Strings.get("export.sync.bundle.fail", syncBundleExport.getAbsolutePath())); } } }
private void pumpItOut(AdminCommandContext context) { String fileName = file_name != null && !file_name.isEmpty() ? file_name : getDefaultBundleName(); File localFile = new File(fileName.replace('\\', '/')); Properties props = new Properties(); File parent = localFile.getParentFile(); if (parent == null) { parent = localFile; } props.setProperty("file-xfer-root", parent.getPath().replace('\\', '/')); URI parentURI = parent.toURI(); try { context.getOutboundPayload().attachFile( "application/octet-stream", parentURI.relativize(localFile.toURI()), "sync-bundle", props, syncBundleExport); } catch (IOException ex) { setError(Strings.get("export.sync.bundle.retrieveFailed", ex.getLocalizedMessage())); logger.finer("fileURI: " + parentURI.relativize(localFile.toURI())); logger.finer("file-xfer-root: " + parent.getPath().replace('\\', '/')); logger.finer("file: " + syncBundleExport.getAbsolutePath()); } }
@Override public void execute(AdminCommandContext context) { final ActionReport report = context.getActionReport(); final Payload.Outbound outboundPayload = context.getOutboundPayload(); final File instanceRoot = env.getInstanceRoot(); try { for (File f : bootstrappedFiles) { outboundPayload.attachFile( DOWNLOADED_FILE_MIME_TYPE, instanceRoot.toURI().relativize(f.toURI()), DOWNLOAD_DATA_REQUEST_NAME, f); } report.setActionExitCode(ActionReport.ExitCode.SUCCESS); } catch (IOException ex) { report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(ex); } } }
@Override public void prepareConnection(final HttpURLConnection urlConnection) throws IOException { if (doUpload) { /* * If we are uploading anything then set the content-type * and add the uploaded part(s) to the payload. */ urlConnection.setChunkedStreamingMode(0); // use default value urlConnection.setRequestProperty("Content-Type", outboundPayload.getContentType()); } // add any user-specified headers for (Header h : requestHeaders) { urlConnection.addRequestProperty(h.getName(), h.getValue()); } if (doUpload) { outboundPayload.writeTo(urlConnection.getOutputStream()); } }
@Override public void execute(AdminCommandContext context) { final ActionReport report = context.getActionReport(); final Payload.Outbound outboundPayload = context.getOutboundPayload(); final File instanceRoot = env.getInstanceRoot(); try { for (File f : bootstrappedFiles) { outboundPayload.attachFile( DOWNLOADED_FILE_MIME_TYPE, instanceRoot.toURI().relativize(f.toURI()), DOWNLOAD_DATA_REQUEST_NAME, f); } report.setActionExitCode(ActionReport.ExitCode.SUCCESS); } catch (IOException ex) { report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(ex); } } }