Pdf2SwfPageConverter is now using NuProcess library instead of the native Java Process.

This commit is contained in:
Ghazi Triki 2015-11-24 16:47:24 +01:00
parent dc39a89986
commit ce31bdd369
5 changed files with 205 additions and 61 deletions

View File

@ -43,18 +43,19 @@ repositories {
dependencies {
//redis
compile "redis.clients:jedis:2.7.2"
compile 'org.apache.commons:commons-pool2:2.3'
compile 'redis.clients:jedis:2.7.2'
compile 'org.apache.commons:commons-pool2:2.3'
compile 'commons-lang:commons-lang:2.5'
compile 'commons-io:commons-io:2.4'
compile 'com.google.code.gson:gson:1.7.1'
compile 'commons-httpclient:commons-httpclient:3.1'
compile 'com.zaxxer:nuprocess:1.0.4'
compile 'org.bigbluebutton:bbb-common-message:0.0.13'
// Logging
// Commenting out as it results in build failure (ralam - may 11, 2014)
// Commenting out as it results in build failure (ralam - may 11, 2014)
//compile 'ch.qos.logback:logback-core:1.0.9@jar'
//compile 'ch.qos.logback:logback-classic:1.0.9@jar'
//compile 'org.slf4j:log4j-over-slf4j:1.7.2@jar'
@ -64,7 +65,7 @@ dependencies {
//junit
compile 'junit:junit:4.8.2'
// Logging
/**** UNCOMMENT WHEN you want to run gradle test
compile 'ch.qos.logback:logback-core:1.0.13@jar'

View File

@ -0,0 +1,81 @@
/**
* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
*
* Copyright (c) 2015 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*
*/
package org.bigbluebutton.presentation.handlers;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.StandardCharsets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.zaxxer.nuprocess.NuAbstractProcessHandler;
import com.zaxxer.nuprocess.NuProcess;
public abstract class AbstractPageConverterHandler extends
NuAbstractProcessHandler {
private static Logger log = LoggerFactory
.getLogger(AbstractPageConverterHandler.class);
private NuProcess nuProcess;
private int exitCode;
final private StringBuilder stdoutBuilder = new StringBuilder();
final private StringBuilder stderrBuilder = new StringBuilder();
@Override
public void onPreStart(NuProcess nuProcess) {
this.nuProcess = nuProcess;
}
@Override
public void onStart(NuProcess nuProcess) {
super.onStart(nuProcess);
}
@Override
public void onStdout(ByteBuffer buffer, boolean closed) {
if (buffer != null) {
CharBuffer charBuffer = StandardCharsets.UTF_8.decode(buffer);
stdoutBuilder.append(charBuffer);
}
log.debug("Conversion success\n" + stdoutBuilder.toString());
}
@Override
public void onStderr(ByteBuffer buffer, boolean closed) {
if (buffer != null) {
CharBuffer charBuffer = StandardCharsets.UTF_8.decode(buffer);
stderrBuilder.append(charBuffer);
}
log.debug("Conversion error\n" + stderrBuilder.toString());
}
@Override
public void onExit(int statusCode) {
exitCode = statusCode;
log.debug("Conversion process exited with status=" + exitCode);
}
protected Boolean stdoutContains(String value) {
return stdoutBuilder.indexOf(value) > -1;
}
public abstract Boolean isConversionSuccessfull();
}

View File

@ -0,0 +1,34 @@
/**
* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
*
* Copyright (c) 2015 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*
*/
package org.bigbluebutton.presentation.handlers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Pdf2SwfPageConverterHandler extends AbstractPageConverterHandler {
private static Logger log = LoggerFactory
.getLogger(Pdf2SwfPageConverterHandler.class);
@Override
public Boolean isConversionSuccessfull() {
return true;
}
}

View File

@ -1,65 +1,93 @@
/**
* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
*
* Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*
*/
* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
*
* Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*
*/
package org.bigbluebutton.presentation.imp;
import java.io.File;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import org.bigbluebutton.presentation.PageConverter;
import org.bigbluebutton.presentation.handlers.Pdf2SwfPageConverterHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.zaxxer.nuprocess.NuProcess;
import com.zaxxer.nuprocess.NuProcessBuilder;
public class Pdf2SwfPageConverter implements PageConverter {
private static Logger log = LoggerFactory.getLogger(Pdf2SwfPageConverter.class);
private String SWFTOOLS_DIR;
private String fontsDir;
public boolean convert(File presentation, File output, int page) {
String source = presentation.getAbsolutePath();
String dest = output.getAbsolutePath();
String AVM2SWF = "-T9";
String COMMAND = SWFTOOLS_DIR + File.separator + "pdf2swf " + AVM2SWF + " -F " + fontsDir + " -p " + page + " " + source + " -o " + dest;
private static Logger log = LoggerFactory
.getLogger(Pdf2SwfPageConverter.class);
boolean done = new ExternalProcessExecutor().exec(COMMAND, 60000);
File destFile = new File(dest);
if (done && destFile.exists()) {
return true;
} else {
COMMAND = SWFTOOLS_DIR + File.separator + "pdf2swf " + AVM2SWF + " -s poly2bitmap -F " + fontsDir + " -p " + page + " " + source + " -o " + dest;
done = new ExternalProcessExecutor().exec(COMMAND, 60000);
if (done && destFile.exists()){
return true;
} else {
log.warn("Failed to convert: " + dest + " does not exist.");
return false;
}
}
}
private String SWFTOOLS_DIR;
private String fontsDir;
public void setSwfToolsDir(String dir) {
SWFTOOLS_DIR = dir;
}
public void setFontsDir(String dir) {
fontsDir = dir;
}
public boolean convert(File presentation, File output, int page) {
String source = presentation.getAbsolutePath();
String dest = output.getAbsolutePath();
String AVM2SWF = "-T9";
NuProcessBuilder pb = new NuProcessBuilder(Arrays.asList(SWFTOOLS_DIR
+ File.separator + "pdf2swf", "-v", AVM2SWF, "-F", fontsDir, "-p",
String.valueOf(page), source, "-o", "dest"));
Pdf2SwfPageConverterHandler pHandler = new Pdf2SwfPageConverterHandler();
pb.setProcessListener(pHandler);
NuProcess process = pb.start();
try {
process.waitFor(60, TimeUnit.SECONDS);
} catch (InterruptedException e) {
log.error(e.getMessage());
}
boolean done = pHandler.isConversionSuccessfull();
File destFile = new File(dest);
if (done && destFile.exists()) {
return true;
} else {
NuProcessBuilder pbBmp = new NuProcessBuilder(Arrays.asList(SWFTOOLS_DIR
+ File.separator, "pdf2swf", "-v", AVM2SWF, "-s", "poly2bitmap",
"-F", fontsDir, "-p", String.valueOf(page), source, "-o", dest));
Pdf2SwfPageConverterHandler pBmpHandler = new Pdf2SwfPageConverterHandler();
pb.setProcessListener(pBmpHandler);
NuProcess processBmp = pbBmp.start();
try {
processBmp.waitFor(60, TimeUnit.SECONDS);
} catch (InterruptedException e) {
log.error(e.getMessage());
}
boolean doneBmp = pBmpHandler.isConversionSuccessfull();
if (doneBmp && destFile.exists()) {
return true;
} else {
log.warn("Failed to convert: " + dest + " does not exist.");
return false;
}
}
}
public void setSwfToolsDir(String dir) {
SWFTOOLS_DIR = dir;
}
public void setFontsDir(String dir) {
fontsDir = dir;
}
}

View File

@ -33,13 +33,13 @@ import java.util.concurrent.TimeUnit;
import org.bigbluebutton.presentation.ConversionMessageConstants;
import org.bigbluebutton.presentation.ConversionUpdateMessage;
import org.bigbluebutton.presentation.ConversionUpdateMessage.MessageBuilder;
import org.bigbluebutton.presentation.PageConverter;
import org.bigbluebutton.presentation.PdfToSwfSlide;
import org.bigbluebutton.presentation.SvgImageCreator;
import org.bigbluebutton.presentation.TextFileCreator;
import org.bigbluebutton.presentation.ThumbnailCreator;
import org.bigbluebutton.presentation.UploadedPresentation;
import org.bigbluebutton.presentation.ConversionUpdateMessage.MessageBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -152,12 +152,12 @@ public class PdfToSwfSlidesGenerationService {
slidesCompleted++;
notifier.sendConversionUpdateMessage(slidesCompleted, pres);
} else {
log.warn("Timedout waiting for page to finish conversion. meetingId=" + pres.getMeetingId() + " presId=" + pres.getId() + " presName=" + pres.getName() );
log.warn("Timedout waiting for page to finish conversion. meetingId=" + pres.getMeetingId() + " presId=" + pres.getId() + " presName=[" + pres.getName() + "]");
}
} catch (InterruptedException e) {
log.error("InterruptedException while creating slide. meetingId=" + pres.getMeetingId() + " presId=" + pres.getId() + " name=[" + pres.getName());
log.error("InterruptedException while creating slide. meetingId=" + pres.getMeetingId() + " presId=" + pres.getId() + " presName=[" + pres.getName() + "]");
} catch (ExecutionException e) {
log.error("ExecutionException while creating slide. meetingId=" + pres.getMeetingId() + " presId=" + pres.getId() + " name=[" + pres.getName());
log.error("ExecutionException while creating slide. meetingId=" + pres.getMeetingId() + " presId=" + pres.getId() + " presName=[" + pres.getName() + "]");
}
}