-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- ExternalProcessAsciidoctorJServerLauncher provides now possibility to show server output or not - because of race condition problems different testclasses are now using different ports - Added another example code snippet and linked it inside documentation and README.md
- Loading branch information
Showing
12 changed files
with
147 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
asp-doc/src/test/java/de/jcup/asp/example/ExternalProcessWithDebugOutputExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package de.jcup.asp.example; | ||
|
||
import java.awt.Desktop; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import de.jcup.asp.api.Response; | ||
import de.jcup.asp.client.AspClient; | ||
import de.jcup.asp.core.OutputHandler; | ||
import de.jcup.asp.server.asciidoctorj.launcher.ExternalProcessAsciidoctorJServerLauncher; | ||
|
||
public class ExternalProcessWithDebugOutputExample { | ||
|
||
|
||
public static void main(String[] args) throws Exception { | ||
Path adocfile = createExampleAsciidocFile(); | ||
String pathToServerJar = ensurePathToServerDistJar(); | ||
OutputHandler launcherOutputHandler = new OutputHandler() { | ||
|
||
@Override | ||
public void output(String message) { | ||
System.out.println("LAUNCHER: "+message); | ||
} | ||
}; | ||
OutputHandler clientOutputHandler = new OutputHandler() { | ||
|
||
@Override | ||
public void output(String message) { | ||
System.out.println("CLIENT: "+message); | ||
} | ||
}; | ||
// tag::launcherExample[] | ||
ExternalProcessAsciidoctorJServerLauncher launcher = new ExternalProcessAsciidoctorJServerLauncher(pathToServerJar, 4449); // <1> | ||
launcher.setOutputHandler(launcherOutputHandler); | ||
launcher.setShowServerOutput(true); | ||
try { | ||
/* launch server*/ | ||
String serverSecret = launcher.launch(30); // <2> | ||
|
||
/* create client with secret from server for encrypted communication */ | ||
AspClient client = new AspClient(serverSecret); // <3> | ||
client.setPortNumber(4449); | ||
client.setOutputHandler(clientOutputHandler); | ||
client.setShowCommunication(true); | ||
|
||
/* now convert Asciidoc to HTML by ASP client */ | ||
Map<String, Object> options = new HashMap<String, Object>(); | ||
options.put("backend", "html");// <4> | ||
|
||
/* get the result and show it inside browser:*/ | ||
Response response = client.convertFile(adocfile, options, null);// <5> | ||
Path resultFile = response.getResultFilePath(); | ||
|
||
Desktop.getDesktop().open(resultFile.toFile()); | ||
}finally { | ||
launcher.stopServer(); //<6> | ||
} | ||
// end::launcherExample[] | ||
|
||
|
||
} | ||
|
||
private static Path createExampleAsciidocFile() throws IOException { | ||
Path adocfile = Files.createTempFile("asp_test", ".adoc"); | ||
Files.write(adocfile, (":toc:\n== Headline1\nSome text...\n\n== Headline2\nThis is just an example content for ASP...").getBytes()); | ||
return adocfile; | ||
} | ||
|
||
private static String ensurePathToServerDistJar() { | ||
String pathToServerJar= System.getProperty("user.home")+ "/.m2/repository/de/jcup/asp/asp-server-asciidoctorj/0.3.0/asp-server-asciidoctorj-0.3.0-dist.jar"; | ||
if (! new File(pathToServerJar).exists()) { | ||
throw new RuntimeException("Distribution jar missing - please download server distribution into your local maven repository"); | ||
} | ||
return pathToServerJar; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
asp-integrationtest/src/test/java/de/jcup/asp/integrationtest/TestConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package de.jcup.asp.integrationtest; | ||
|
||
public class TestConstants { | ||
|
||
public static final int EXTERNAL_PROCESS_PORT=4447; | ||
public static final int EMBEDDED_TESTSERVER_PORT=4448; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters