How to send request to plantuml server from java code?

0 votes
asked Jan 11, 2015 in To be sorted by anonymous
Hello! Our team is now building open-source application, that will generate PlantUML Code and Diagrams from java code, however, some of our users, might not have installed GraphViz or something. So, we want to add a button in the application "Open in PlantUML site", which will copy all PlantUML code from application, and automatically will load it and open it in Is it possible? Thanks! With respect, team of Java2UML.

1 Answer

0 votes
answered Jan 12, 2015 by plantuml (195,460 points)

What you can do, is to build an URL that encodes your diagram text.
Then send this URL so the server using a standard GET HTTP request, and retrieve the HTTP answer with the image.

Building an URL is not very difficult, for example, you have an snippet in PHP here:
In Java, you can using this:
This is also possible in Javascript, or in other languages.

Which development language are you using ?
commented Jan 12, 2015 by anonymous
Hello, thanks for the answer! We're using java. Can URL address become too big? Some projects could have far more than fifty classes in them, and some libraries include even bigger classes number. So, there will be huuuuge sheet of PlantUML code, that we'll need to transfer to your server.
commented Jan 12, 2015 by anonymous
About your API. Yeah, we're already using it to generate images of diagram in our application, but we want to have ability to use also site-version of generator, by sending PlantUML code to it, and opening a diagram on your site, because our users may not have computers that fast and powerful enough, to handle and generate diagram from big projects, like libraries, or projects that have many classes.
commented Jan 12, 2015 by plantuml (195,460 points)
From Java, you can easily generate the URL using the following code (assuming that your are using plantuml.jar)

        Transcoder t = TranscoderUtil.getDefaultTranscoder();
        String s = "Alice->Bob: hello1\nAlice->Bob: hello2\n";
        String url = t.encode(s);

This code only generates the URL, it does not do any image generation, and does not depend on Graphviz/dot.
About URL length, there is a limit, but it's difficult to have it precisly, because encoding is using text compression.
commented Jan 12, 2015 by anonymous
Thanks, that was really helpful.