Source:
public void uploadBundle ( HttpServletRequest request, HttpServletResponse response ) throws FileUploadException, IOException{ try { if(!APILocator.getLayoutAPI().doesUserHaveAccessToPortlet("publishing-queue", getUser())){ response.sendError(401); return; } } catch (DotDataException e1) { Logger.error(RemotePublishAjaxAction.class,e1.getMessage(),e1); response.sendError(401); return; } FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload( factory ); PrintWriter out = response.getWriter(); PublishAuditStatus status; String bundleName = null; try { @SuppressWarnings ("unchecked") List<FileItem> items = (List<FileItem>) upload.parseRequest( request ); InputStream bundle = items.get( 0 ).getInputStream(); bundleName = sanitizeBundleName(items.get(0).getName()); String bundlePath = ConfigUtils.getBundlePath() + File.separator; String bundleFolder = bundleName.substring( 0, bundleName.indexOf( ".tar.gz" ) ); String endpointId = getUser().getUserId(); response.setContentType( "text/html; charset=utf-8" ); status = PublishAuditAPI.getInstance().updateAuditTable( endpointId, endpointId, bundleFolder ); FileUtil.writeToFile( bundle, bundlePath + bundleName ); if ( !status.getStatus().equals( Status.PUBLISHING_BUNDLE ) ) { new Thread( new PublishThread( bundleName, null, endpointId, status ) ).start(); } out.print( "<html><head><script>isLoaded = true;</script></head><body><textarea>{'status':'success'}</textarea></body></html>" ); } catch ( DotPublisherException e ) { Logger.error(this, String.format("An error occurred when uploading bundle '%s'", bundleName), e); out.print( "<html><head><script>isLoaded = true;</script></head><body><textarea>{'status':'error'}</textarea></body></html>" ); } }

Target:
public void uploadBundle ( HttpServletRequest request, HttpServletResponse response ) throws FileUploadException, IOException{ try { if(!APILocator.getLayoutAPI().doesUserHaveAccessToPortlet("publishing-queue", getUser())){ response.sendError(401); return; } } catch (DotDataException e1) { Logger.error(RemotePublishAjaxAction.class,e1.getMessage(),e1); response.sendError(401); return; } FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload( factory ); PrintWriter out = response.getWriter(); PublishAuditStatus status; String bundleName = null; try { @SuppressWarnings ("unchecked") List<FileItem> items = upload.parseRequest( request ); InputStream bundle = items.get( 0 ).getInputStream(); bundleName = BundlerUtil.sanitizeBundleName(items.get(0).getName()); String bundlePath = ConfigUtils.getBundlePath() + File.separator; String bundleFolder = bundleName.substring( 0, bundleName.indexOf( ".tar.gz" ) ); String endpointId = getUser().getUserId(); response.setContentType( "text/html; charset=utf-8" ); status = PublishAuditAPI.getInstance().updateAuditTable( endpointId, endpointId, bundleFolder ); FileUtil.writeToFile( bundle, bundlePath + bundleName ); if ( !status.getStatus().equals( Status.PUBLISHING_BUNDLE ) ) { new Thread( new PublishThread( bundleName, null, endpointId, status ) ).start(); } out.print( "<html><head><script>isLoaded = true;</script></head><body><textarea>{'status':'success'}</textarea></body></html>" ); } catch ( DotPublisherException e ) { Logger.error(this, String.format("An error occurred when uploading bundle '%s'", bundleName), e); out.print( "<html><head><script>isLoaded = true;</script></head><body><textarea>{'status':'error'}</textarea></body></html>" ); } }