Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defensive API: Killing Processes and Future/ Watchdog Implementation. #21

Open
hsyed opened this issue Aug 14, 2015 · 1 comment
Open

Comments

@hsyed
Copy link

hsyed commented Aug 14, 2015

I'm writing a Java OSGi wrapper via sPDF and i'd like to guard against denial of server and bugs in wkhtmltopdf. I think the there should be some defensive elements to the API.

The PDF Class could do with a run method that returns a handle to the Process object to enable a watchdog to kill the process.

Additionally Future and watchdog implementations would be handy.

@hsyed
Copy link
Author

hsyed commented Aug 14, 2015

Having a method that constructs the ProcessBuilder without executing it should be a simple enough change.

  /**
   * Runs the conversion tool to convert sourceDocument HTML into
   * destinationDocument PDF.
   */
  def run[A, B](sourceDocument: A, destinationDocument: B)(implicit sourceDocumentLike: SourceDocumentLike[A], destinationDocumentLike: DestinationDocumentLike[B]): Int = {
    processBuilder(sourceDocument, destinationDocument).!
  }

  /**
   * constructs a processBuilder geared for different execution scenarios. 
   */
  def processBuilder[A, B](sourceDocument: A, destinationDocument: B)(implicit sourceDocumentLike: SourceDocumentLike[A], destinationDocumentLike: DestinationDocumentLike[B]): scala.sys.process.ProcessBuilder = {
    val commandLine = toCommandLine(sourceDocument, destinationDocument)
    println(commandLine.mkString(" "))
    val process = Process(commandLine)
    def source = sourceDocumentLike.sourceFrom(sourceDocument) _
    def sink = destinationDocumentLike.sinkTo(destinationDocument) _

    (sink compose source)(process)
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants