├── .dockerignore ├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── lambdacontainer └── Dockerfile ├── package-lock.json ├── package.json ├── pom.xml ├── sam-deploy.sh ├── serverless.yml ├── serverlessrepo ├── README.md └── serverlessrepo-publish.sh ├── src └── main │ ├── java │ ├── com │ │ └── nitor │ │ │ └── plantuml │ │ │ ├── DiagramTypeUtil.java │ │ │ ├── PlantUmlUtil.java │ │ │ └── lambda │ │ │ ├── DiagramType.java │ │ │ ├── LambdaBase.java │ │ │ ├── MapHandler.java │ │ │ ├── PngHandler.java │ │ │ ├── SvgHandler.java │ │ │ ├── SyntaxCheckResult.java │ │ │ ├── SyntaxHandler.java │ │ │ ├── TxtHandler.java │ │ │ ├── UIHandler.java │ │ │ ├── UmlHandler.java │ │ │ └── exception │ │ │ ├── BadRequestException.java │ │ │ └── StatusCodeException.java │ └── net │ │ └── sourceforge │ │ └── plantuml │ │ └── servlet │ │ └── utility │ │ └── UmlExtractor.java │ └── resources │ ├── bg.png │ ├── bg.sh │ ├── log4j-dev.properties │ ├── log4j-plantuml.properties │ ├── log4j-prod.properties │ └── ui │ └── umlsource.html ├── template.yml ├── test.html └── ui ├── build └── build.js ├── index.html └── package-lock.json /.dockerignore: -------------------------------------------------------------------------------- 1 | **/node_modules 2 | bin 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .serverless 3 | *.iml 4 | 5 | ## File-based project format: 6 | *.iws 7 | 8 | ## Plugin-specific files: 9 | 10 | # IntelliJ 11 | /out/ 12 | 13 | # mpeltonen/sbt-idea plugin 14 | .idea_modules/ 15 | 16 | # JIRA plugin 17 | atlassian-ide-plugin.xml 18 | 19 | aws 20 | target 21 | *reduced-pom.xml 22 | 23 | #macOS 24 | .DS_Store 25 | 26 | node_modules 27 | bin 28 | 29 | #UI 30 | ui/dist 31 | 32 | #dot 33 | dot/build 34 | 35 | .classpath 36 | .project 37 | .settings/ 38 | 39 | .vscode/ 40 | .sts4-cache/ 41 | 42 | .aws-sam/ 43 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | *.class 2 | target 3 | 4 | # Package Files 5 | *.jar 6 | *.war 7 | *.ear 8 | 9 | # Serverless directories 10 | .serverless -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Render PlantUML diagrams with AWS Lambda 2 | 3 | A serverless UI + API to render [PlantUML](http://plantuml.com) diagrams. 4 | 5 | ## Drop in replacement for official PlantUML server 6 | 7 | This can be used as a drop in replacement for scenarios 8 | where http://www.plantuml.com/plantuml is used as a rendering endpoint. You can avoid sending the diagram source to a server outside your control and use an encrypted HTTPS endpoint for the diagram traffic. 9 | 10 | This doesn't support everything the official PlantUML server does but should be good for most intents and purposes (PNG, SVG and TXT rendering). 11 | 12 | For example, to have Visual Studio Code PlantUML plugin render using your own serverless deployment, set the following properties in vscode for the plugin: 13 | 14 | ```json 15 | "plantuml.render": "PlantUMLServer", 16 | "plantuml.server": "https://your-endpoint-here" 17 | ``` 18 | 19 | Use `"plantuml.server": "https://plantuml.nitorio.us"` if you'd like to try before you deploy your own. 20 | 21 | ## Demo 22 | 23 | ### PNG Diagram 24 | 25 | ![Rendered PNG diagram should be here](https://plantuml.nitorio.us/png/Kt8goYylJYrIKj2rKr1o3F1KS4yiIIrFh5IoKWZ8ALOeIirBIIrIACd8B5Oeo4dCAodDpU52KGVMw9EOcvIIgE1McfTSafcVfwI0JpU6Of09C6czhCGYlDgnwBVHrSKq80YiEJL58IKpCRqeCHVDrM0zM9oDgGqUGc0jg464hXe0) 26 | 27 | ### SVG Diagram 28 | 29 | ![Rendered SVG diagram should be here](https://plantuml.nitorio.us/svg/Kt8goYylJYrIKj2rKr1o3F1KS4yiIIrFh5IoKWZ8ALOeIirBIIrIACd8B5Oeo4dCAodDpU52KGVMw9EOcvIIgE1McfTSafcVfwI0JpU6Of09C6czhCGYlDgnwBVHrSKq80YiEJL58IKpCRqeCHVDrM0zM9oDgGqUGc0jg464hXe0) 30 | 31 | ### TXT Diagram 32 | 33 | https://plantuml.nitorio.us/txt/Kt8goYylJYrIKj2rKr1o3F1KS4yiIIrFh5IoKWZ8ALOeIirBIIrIACd8B5Oeo4dCAodDpU52KGVMw9EOcvIIgE1McfTSafcVfwI0JpU6Of09C6czhCGYlDgnwBVHrSKq80YiEJL58IKpCRqeCHVDrM0zM9oDgGqUGc0jg464hXe0 34 | 35 | ## Build 36 | 37 | - `npm ci` 38 | - `mvn clean package` 39 | 40 | ## Deploy 41 | 42 | You can deploy with Serverless framework or AWS SAM. 43 | 44 | This used to be available on the AWS Serverless Application Repository, but currently that's not possible because it 45 | doesn't appear to support lambda functions packaged as container images. 46 | 47 | ### Serverless framework: 48 | 49 | - Edit `serverless.yml` to replace `custom.domains.dev` and `custom.domains.prod` with your own domain names. 50 | * If you don't want a custom domain name, remove or comment out the `serverless-domain-manager` plugin from the plugins list and skip 51 | the `sls create-cert` and `sls create_domain` commands. 52 | - Run `sls create-cert` to create an ACM certificate for your domain as configured in `custom.customCertificate`. 53 | - Run `sls create_domain` to create an API Gateway custom domain as configured in `custom.customDomain`. 54 | - Run `sls deploy`. 55 | 56 | The above steps deploy the default `dev` stage. To deploy the `prod` stage, add `--stage prod` to each command. 57 | 58 | ### AWS SAM 59 | 60 | - Run `sam-deploy.sh` 61 | 62 | The SAM deployment doesn't include custom domains currently. 63 | -------------------------------------------------------------------------------- /lambdacontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM public.ecr.aws/lambda/java:11 AS dotbuild 2 | 3 | RUN mkdir build 4 | RUN yum install -y curl tar gzip 5 | RUN curl https://www2.graphviz.org/Packages/stable/portable_source/graphviz-2.42.3.tar.gz -o build/graphviz-2.42.3.tar.gz 6 | RUN tar zxvf build/graphviz-2.42.3.tar.gz -C build 7 | RUN yum groupinstall -y 'Development Tools' 8 | RUN yum install -y expat-devel 9 | RUN cd build/graphviz-2.42.3 && pwd && ./configure --enable-static=yes --with-expat=yes && make 10 | 11 | FROM public.ecr.aws/lambda/java:11 12 | 13 | RUN yum install -y fontconfig && yum clean all 14 | 15 | # Copy function code and runtime dependencies from Maven layout 16 | COPY --from=dotbuild /var/task/build/graphviz-2.42.3/cmd/dot/dot_static /opt/dot_static 17 | COPY target/classes ${LAMBDA_TASK_ROOT} 18 | COPY target/dependency/* ${LAMBDA_TASK_ROOT}/lib/ 19 | 20 | # Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile) 21 | #CMD [ "com.example.LambdaHandler::handleRequest" ] 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "plantuml-serverless", 3 | "version": "0.0.7-SNAPSHOT", 4 | "description": "Render PlantUML diagrams", 5 | "main": "index.js", 6 | "dependencies": { 7 | "html-minifier": "^4.0.0", 8 | "serverless": "^2.70.0" 9 | }, 10 | "devDependencies": { 11 | "serverless-certificate-creator": "^1.6.0", 12 | "serverless-domain-manager": "^5.2.0" 13 | }, 14 | "scripts": { 15 | "test": "echo \"Error: no test specified\" && exit 1" 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "git+https://github.com/mmajis/plantuml-serverless.git" 20 | }, 21 | "keywords": [ 22 | "plantuml", 23 | "serverless" 24 | ], 25 | "author": "Mika Majakorpi", 26 | "license": "GPL-3.0", 27 | "bugs": { 28 | "url": "https://github.com/mmajis/plantuml-serverless/issues" 29 | }, 30 | "homepage": "https://github.com/mmajis/plantuml-serverless#readme" 31 | } 32 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.nitor 6 | plantuml-serverless 7 | jar 8 | static 9 | PlantUML Serverless API 10 | 11 | 12 | 11 13 | 11 14 | 1.2021.16 15 | 16 | 17 | 18 | 19 | com.amazonaws 20 | aws-lambda-java-core 21 | 1.2.1 22 | 23 | 24 | com.amazonaws 25 | aws-lambda-java-events 26 | 3.11.0 27 | 28 | 29 | com.amazonaws 30 | aws-lambda-java-log4j 31 | 1.0.1 32 | 33 | 34 | 35 | net.sourceforge.plantuml 36 | plantuml 37 | ${plantuml.version} 38 | 39 | 40 | 41 | org.scilab.forge 42 | jlatexmath 43 | 1.0.7 44 | 45 | 46 | org.apache.xmlgraphics 47 | batik-all 48 | 1.14 49 | 50 | 51 | 52 | org.apache.cxf 53 | cxf-rt-frontend-jaxrs 54 | 3.5.0 55 | 56 | 57 | 58 | com.googlecode.json-simple 59 | json-simple 60 | 1.1.1 61 | 62 | 63 | 64 | com.google.code.gson 65 | gson 66 | 2.8.9 67 | 68 | 69 | 70 | org.apache.httpcomponents 71 | httpcore 72 | 4.4.15 73 | 74 | 75 | 76 | 77 | 78 | 79 | org.codehaus.mojo 80 | exec-maven-plugin 81 | 3.0.0 82 | 83 | 84 | Minify UI 85 | 86 | exec 87 | 88 | process-resources 89 | 90 | node 91 | 92 | ui/build/build.js 93 | 94 | 95 | 96 | 97 | 98 | 99 | org.apache.maven.plugins 100 | maven-dependency-plugin 101 | 3.2.0 102 | 103 | 104 | copy-dependencies 105 | package 106 | 107 | copy-dependencies 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /sam-deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Note! This needs an ECR repo created like this: 3 | # aws ecr create-repository --repository-name plantuml-sam \ 4 | # --image-tag-mutability IMMUTABLE --image-scanning-configuration scanOnPush=true 5 | 6 | set -eo pipefail 7 | readonly basedir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 8 | usage() { 9 | cat >&2 < [ -s ] [ -p ] [ -p ] 11 | Options 12 | -b | --bucket (Required) The S3 bucket to upload artifacts to. 13 | -s | --stack-name The name of the CloudFormation stack to create. 14 | (default: plantuml-sam) 15 | -p | --profile Specify an AWS profile 16 | -r | --region Specify an AWS region 17 | -a | --account Specify container image repository account id 18 | -i | --image-repo) Specify container image repository name 19 | (default: plantuml-sam) 20 | -h | --help Print this usage message and exit 21 | EOUSAGE 22 | } 23 | awsProfile=() 24 | rawRegion="" 25 | awsRegion=() 26 | s3bucket="" 27 | stackName="plantuml-sam" 28 | repoName="plantuml-sam" 29 | accountId="" 30 | while [[ $# -gt 0 ]]; do 31 | opt="$1" 32 | shift 33 | case "$opt" in 34 | -h|--help) usage; exit;; 35 | -p|--profile) awsProfile=(--profile "$1"); shift;; 36 | -r|--region) rawRegion="$1"; awsRegion=(--region "$1"); shift;; 37 | -b|--bucket) s3bucket="$1"; shift;; 38 | -s|--stack-name) stackName="$1"; shift;; 39 | -a|--account) accountId="$1"; shift;; 40 | -i|--image-repo) repoName="$1"; shift;; 41 | *) echo "Unknown option $opt"; usage; exit 1;; 42 | esac 43 | done 44 | 45 | if [[ "$rawRegion" == "" ]]; then 46 | rawRegion="$(aws ${awsProfile[*]} ec2 describe-availability-zones --output text --query 'AvailabilityZones[0].[RegionName]')" 47 | awsRegion=(--region "$rawRegion") 48 | fi 49 | 50 | if [[ "$accountId" == "" ]]; then 51 | accountId="$(aws ${awsProfile[*]} sts get-caller-identity --query Account --output text)" 52 | fi 53 | 54 | if [[ "$s3bucket" == "" ]]; then 55 | echo "please provide an S3 bucket name with -b" >&2 56 | exit 1 57 | fi 58 | 59 | if [[ "$stackName" == "" ]]; then 60 | echo "please provide a name for the CFN stack with -s" >&2 61 | exit 1 62 | fi 63 | 64 | pushd "${basedir}" 2>/dev/null 65 | codeUri="$(ls target/plantuml-serverless-*.jar | head -n 1)" 66 | if [[ ! -f "$codeUri" ]]; then 67 | echo "missing plantuml-serverless-*.jar. please run 'mvn clean package'." >&2 68 | exit 1 69 | fi 70 | 71 | sam build --cached 72 | 73 | # Edit the AWS account id and region in the repo URL here 74 | aws ecr get-login-password | docker login --username AWS \ 75 | --password-stdin "${accountId}.dkr.ecr.${rawRegion}.amazonaws.com" 76 | 77 | # Replace image-repository with your own 78 | sam deploy "${awsProfile[@]}" "${awsRegion[@]}" \ 79 | --stack-name "${stackName}" \ 80 | --capabilities CAPABILITY_IAM \ 81 | --image-repository "${accountId}.dkr.ecr.${rawRegion}.amazonaws.com/${repoName}" \ 82 | --s3-bucket "${s3bucket}" 83 | 84 | #These would be for serverless application repository, but it doesn't support container based lambdas at the moment. 85 | #aws ${awsProfile[@]} s3 cp LICENSE s3://"${s3bucket}"/LICENSE 86 | #aws ${awsProfile[@]} s3 cp serverlessrepo/README.md s3://"${s3bucket}"/README.md 87 | -------------------------------------------------------------------------------- /serverless.yml: -------------------------------------------------------------------------------- 1 | service: plantuml-serverless 2 | 3 | frameworkVersion: ">=2.46.0 <3.0.0" 4 | variablesResolutionMode: 20210326 5 | 6 | provider: 7 | name: aws 8 | region: eu-west-1 9 | stage: dev 10 | timeout: 30 11 | logRetentionInDays: 30 12 | lambdaHashingVersion: 20201221 13 | environment: 14 | stage: ${self:custom.stage} 15 | ecr: 16 | scanOnPush: true 17 | images: 18 | lambdacontainer: 19 | path: ./ 20 | file: lambdacontainer/Dockerfile 21 | 22 | plugins: 23 | - serverless-certificate-creator 24 | - serverless-domain-manager 25 | 26 | custom: 27 | stage: ${opt:stage, self:provider.stage} 28 | domains: 29 | prod: plantuml.nitorio.us 30 | dev: plantuml-dev.nitorio.us 31 | customCertificate: 32 | certificateName: ${self:custom.domains.${self:custom.stage}} 33 | idempotencyToken: "plantumlserverless" 34 | hostedZoneIds: "Z2N6543C2MYFH4" 35 | region: us-east-1 # us-east-1 required for edge type CloudFront endpoint 36 | # optional, default false. this is useful if you managed to delete your certificate but the dns validation records still exist 37 | rewriteRecords: true 38 | customDomain: 39 | domainName: ${self:custom.domains.${self:custom.stage}} 40 | certificateName: ${self:custom.domains.${self:custom.stage}} 41 | basePath: '' 42 | stage: "${self:custom.stage}" 43 | createRoute53Record: true 44 | endpointType: edge 45 | 46 | functions: 47 | ui: 48 | events: 49 | - http: 50 | path: / 51 | method: get 52 | integration: lambda-proxy 53 | cors: true 54 | image: 55 | name: lambdacontainer 56 | command: 57 | - com.nitor.plantuml.lambda.UIHandler::handleRequest 58 | uml: 59 | events: 60 | - http: 61 | path: uml/{encodedUml} 62 | method: get 63 | integration: lambda-proxy 64 | cors: true 65 | image: 66 | name: lambdacontainer 67 | command: 68 | - com.nitor.plantuml.lambda.UmlHandler::handleRequest 69 | png: 70 | events: 71 | - http: 72 | path: png/{encodedUml} 73 | method: get 74 | integration: lambda-proxy 75 | cors: true 76 | response: 77 | contentHandling: CONVERT_TO_BINARY 78 | image: 79 | name: lambdacontainer 80 | command: 81 | - com.nitor.plantuml.lambda.PngHandler::handleRequest 82 | img: 83 | events: 84 | - http: 85 | path: img/{encodedUml} 86 | method: get 87 | integration: lambda-proxy 88 | cors: true 89 | response: 90 | contentHandling: CONVERT_TO_BINARY 91 | image: 92 | name: lambdacontainer 93 | command: 94 | - com.nitor.plantuml.lambda.PngHandler::handleRequest 95 | svg: 96 | events: 97 | - http: 98 | path: svg/{encodedUml} 99 | method: get 100 | integration: lambda-proxy 101 | cors: true 102 | image: 103 | name: lambdacontainer 104 | command: 105 | - com.nitor.plantuml.lambda.SvgHandler::handleRequest 106 | txt: 107 | events: 108 | - http: 109 | path: txt/{encodedUml} 110 | method: get 111 | integration: lambda-proxy 112 | cors: true 113 | image: 114 | name: lambdacontainer 115 | command: 116 | - com.nitor.plantuml.lambda.TxtHandler::handleRequest 117 | map: 118 | events: 119 | - http: 120 | path: map/{encodedUml} 121 | method: get 122 | integration: lambda-proxy 123 | cors: true 124 | response: 125 | contentHandling: CONVERT_TO_BINARY 126 | image: 127 | name: lambdacontainer 128 | command: 129 | - com.nitor.plantuml.lambda.MapHandler::handleRequest 130 | check: 131 | events: 132 | - http: 133 | path: check/{encodedUml} 134 | method: get 135 | integration: lambda-proxy 136 | cors: true 137 | image: 138 | name: lambdacontainer 139 | command: 140 | - com.nitor.plantuml.lambda.SyntaxHandler::handleRequest 141 | 142 | resources: 143 | Description: PlantUML Serverless 144 | -------------------------------------------------------------------------------- /serverlessrepo/README.md: -------------------------------------------------------------------------------- 1 | # PlantUML Serverless 2 | 3 | An API Gateway + Lambda service for rendering PlantUML diagrams. 4 | 5 | Try here before you deploy: 6 | 7 | To try your own deployment, see the stack outputs after deploying for UI and example diagram links. 8 | 9 | A basic UI is provided at the root path: https://{apigw endpoint}/plantuml/. 10 | 11 | ## Drop in replacement for official PlantUML server 12 | 13 | This can be used as a drop in replacement for scenarios 14 | where http://www.plantuml.com/plantuml is used a a rendering endpoint. You can avoid sending the diagram source to a server outisde your control and use an encrypted HTTPS endpoint for the diagram traffic. 15 | 16 | This doesn't support everything the official PlantUML server does but should be good for most intents and purposes (PNG, SVG and TXT rendering). 17 | 18 | For example, to have Visual Studio Code PlantUML plugin render using your own serverless deployment, set the following properties in vscode for the plugin: 19 | 20 | ```json 21 | "plantuml.render": "PlantUMLServer", 22 | "plantuml.server": "https://your-endpoint-here" 23 | ``` 24 | 25 | Use `"plantuml.server": "https://plantuml.nitorio.us"` if you'd like to try before you deploy your own. 26 | 27 | ## Details for API usage 28 | 29 | The plantuml text to render needs to be encoded as described here: . The UI does the encoding and you can see the encoded source in the URL for the rendered diagram. Also, have a look at to encode with a CLI. 30 | 31 | Make requests like this: https://{apigw endpoint}/png/{encoded plantuml} 32 | 33 | ## Example Diagrams 34 | 35 | Example PNG diagram at : 36 | 37 | ![Example PNG diagram](https://plantuml.nitorio.us/png/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000 "Example PNG diagram") 38 | 39 | SVG format is also supported: 40 | 41 | ![Example SVG diagram](https://plantuml.nitorio.us/svg/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000 "Example SVG diagram") 42 | 43 | Made with ❤️ by [@mmajis](https://twitter.com/mmajis) at [@NitorCreations](https://twitter.com/NitorCreations). Available on the [AWS Serverless Application Repository](https://aws.amazon.com/serverless) 44 | 45 | ## License 46 | 47 | GNU General Public License v3.0 only (GPL-3.0) -------------------------------------------------------------------------------- /serverlessrepo/serverlessrepo-publish.sh: -------------------------------------------------------------------------------- 1 | aws --region us-east-1 serverlessrepo create-application-version --application-id arn:aws:serverlessrepo:us-east-1:293246570391:applications/plantuml-render --semantic-version 0.0.8 --source-code-url https://github.com/mmajis/plantuml-serverless/releases/tag/v0.0.9 --template-body file://.aws-sam/build/template.yaml 2 | #maybe this could be the future: 3 | #sam publish --region us-east-1 --template .aws-sam/build/template.yaml --semantic-version 0.0.9 4 | 5 | # The issue here is that serverless application repository doesn't appear to support lambdas with PackageType: Image (containers) 6 | -------------------------------------------------------------------------------- /src/main/java/com/nitor/plantuml/DiagramTypeUtil.java: -------------------------------------------------------------------------------- 1 | package com.nitor.plantuml; 2 | 3 | import com.nitor.plantuml.lambda.DiagramType; 4 | import net.sourceforge.plantuml.FileFormat; 5 | import org.apache.log4j.Logger; 6 | 7 | class DiagramTypeUtil { 8 | 9 | private static Logger logger = Logger.getLogger(DiagramTypeUtil.class); 10 | 11 | static FileFormat asFileFormat(DiagramType diagramType) { 12 | switch (diagramType) { 13 | case IMAGE_PNG: 14 | return FileFormat.PNG; 15 | case IMAGE_SVG_XML: 16 | return FileFormat.SVG; 17 | case TEXT_PLAIN: 18 | return FileFormat.UTXT; 19 | default: 20 | logger.debug("Defaulting to PNG diagram"); 21 | return FileFormat.PNG; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/nitor/plantuml/PlantUmlUtil.java: -------------------------------------------------------------------------------- 1 | package com.nitor.plantuml; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.GsonBuilder; 5 | import com.nitor.plantuml.lambda.DiagramType; 6 | import com.nitor.plantuml.lambda.SyntaxCheckResult; 7 | import com.nitor.plantuml.lambda.exception.BadRequestException; 8 | import net.sourceforge.plantuml.FileFormat; 9 | import net.sourceforge.plantuml.FileFormatOption; 10 | import net.sourceforge.plantuml.LineLocation; 11 | import net.sourceforge.plantuml.SourceStringReader; 12 | import net.sourceforge.plantuml.code.AsciiEncoder; 13 | import net.sourceforge.plantuml.servlet.utility.UmlExtractor; 14 | import net.sourceforge.plantuml.syntax.SyntaxChecker; 15 | import net.sourceforge.plantuml.syntax.SyntaxResult; 16 | import net.sourceforge.plantuml.version.Version; 17 | import org.apache.log4j.Logger; 18 | 19 | import java.io.ByteArrayOutputStream; 20 | import java.io.IOException; 21 | import java.nio.charset.StandardCharsets; 22 | import java.security.MessageDigest; 23 | import java.util.ArrayList; 24 | import java.util.Arrays; 25 | import java.util.regex.Pattern; 26 | 27 | public class PlantUmlUtil { 28 | 29 | private static final Logger logger = Logger.getLogger(PlantUmlUtil.class); 30 | public static final String DIAGRAM_TYPE_UNKNOWN = "UNKNOWN"; 31 | public static final String NOETAG = "NOETAG"; 32 | 33 | public SourceStringReader readDiagram(String encodedUml) { 34 | String uml = decodeUml(encodedUml); 35 | return new SourceStringReader(uml); 36 | } 37 | 38 | public String getEtag(String encodedUml, String typeIdentifier) { 39 | String uml = decodeUml(encodedUml); 40 | if (Pattern.compile("!include(_many|_once)?\\s*https?://").matcher(uml).find()) { 41 | return NOETAG; 42 | } 43 | String baseEtag = typeIdentifier + Version.etag(); 44 | try { 45 | final AsciiEncoder coder = new AsciiEncoder(); 46 | final MessageDigest msgDigest = MessageDigest.getInstance("MD5"); 47 | msgDigest.update(uml.getBytes(StandardCharsets.UTF_8)); 48 | final byte[] digest = msgDigest.digest(); 49 | return baseEtag + coder.encode(digest); 50 | } catch (Exception e) { 51 | logger.error("failed to digest uml", e); 52 | return NOETAG; 53 | } 54 | } 55 | 56 | public ByteArrayOutputStream renderDiagram(SourceStringReader reader, DiagramType diagramType) throws IOException { 57 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 58 | reader.outputImage(baos, new FileFormatOption(DiagramTypeUtil.asFileFormat(diagramType), true)); 59 | return baos; 60 | } 61 | 62 | public String renderImageMap(SourceStringReader reader) throws IOException { 63 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 64 | return reader.outputImage(baos, new FileFormatOption(FileFormat.PNG, true)).getDescription(); 65 | } 66 | 67 | public SyntaxCheckResult checkSyntax(String encodedUml) throws IOException { 68 | String uml = decodeUml(encodedUml); 69 | SyntaxResult syntaxResult = SyntaxChecker.checkSyntax(uml); 70 | if (logger.isDebugEnabled()) { 71 | Gson gson = new GsonBuilder().create(); 72 | String json = gson.toJson(syntaxResult); 73 | logger.debug(json); 74 | } 75 | String diagramType = syntaxResult.getUmlDiagramType() != null ? syntaxResult.getUmlDiagramType().name() : DIAGRAM_TYPE_UNKNOWN; 76 | LineLocation lineLoc = syntaxResult.getLineLocation(); 77 | int lineLocationPos = -1; 78 | if (lineLoc != null) { 79 | lineLocationPos = lineLoc.getPosition(); 80 | } 81 | SyntaxCheckResult result = new SyntaxCheckResult(syntaxResult.isError(), diagramType, 82 | String.valueOf(lineLocationPos), new ArrayList(syntaxResult.getErrors())); 83 | return result; 84 | } 85 | 86 | public String decodeUml(String encodedUml) { 87 | logger.debug(String.format("Got encoded uml: %s", encodedUml)); 88 | try { 89 | if (encodedUml.length() > 10) { 90 | int period = encodedUml.indexOf('.'); 91 | if (period > encodedUml.length() - 10) { 92 | encodedUml = encodedUml.substring(0, period); 93 | } 94 | } 95 | String decodedUml = UmlExtractor.getUmlSource(encodedUml); 96 | logger.debug(String.format("Decoded uml: %s", decodedUml)); 97 | return decodedUml; 98 | } catch (IllegalArgumentException iae) { 99 | SyntaxCheckResult result = new SyntaxCheckResult(true, DIAGRAM_TYPE_UNKNOWN, "0", 100 | Arrays.asList(String.format("Could not decode UML from request path: %s", encodedUml))); 101 | Gson gson = new GsonBuilder().create(); 102 | String json = gson.toJson(result); 103 | throw new BadRequestException(json, iae); 104 | } 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/com/nitor/plantuml/lambda/DiagramType.java: -------------------------------------------------------------------------------- 1 | package com.nitor.plantuml.lambda; 2 | 3 | public enum DiagramType { 4 | 5 | IMAGE_PNG("image/png"), IMAGE_SVG_XML("image/svg+xml;charset=UTF-8"), TEXT_PLAIN("text/plain;charset=UTF-8"), 6 | IMAGEMAP("text/plain;charset=UTF-8"); 7 | 8 | private String mimeType; 9 | 10 | DiagramType(String mimeType) { 11 | this.mimeType = mimeType; 12 | } 13 | 14 | public String getMimeType() { 15 | return mimeType; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/nitor/plantuml/lambda/LambdaBase.java: -------------------------------------------------------------------------------- 1 | package com.nitor.plantuml.lambda; 2 | 3 | import com.nitor.plantuml.PlantUmlUtil; 4 | import com.nitor.plantuml.lambda.exception.StatusCodeException; 5 | import org.apache.http.HttpStatus; 6 | import org.apache.log4j.LogManager; 7 | import org.apache.log4j.Logger; 8 | import org.apache.log4j.PropertyConfigurator; 9 | import org.json.simple.JSONObject; 10 | import org.json.simple.parser.JSONParser; 11 | 12 | import java.awt.*; 13 | import java.io.BufferedReader; 14 | import java.io.File; 15 | import java.io.IOException; 16 | import java.io.InputStream; 17 | import java.io.InputStreamReader; 18 | import java.io.OutputStream; 19 | import java.io.OutputStreamWriter; 20 | import java.net.URL; 21 | import java.nio.file.FileSystems; 22 | import java.nio.file.Files; 23 | import java.nio.file.StandardCopyOption; 24 | import java.nio.file.attribute.PosixFilePermissions; 25 | import java.util.Base64; 26 | import java.util.Collections; 27 | import java.util.HashMap; 28 | import java.util.Map; 29 | import java.util.Optional; 30 | import java.util.Properties; 31 | 32 | import static com.nitor.plantuml.PlantUmlUtil.NOETAG; 33 | 34 | class LambdaBase { 35 | 36 | private static final String ENV_VAR_KEY_STAGE = "stage"; 37 | private static final String DEFAULT_STAGE = "dev"; 38 | private static final String GRAPHVIZ_DOT = "GRAPHVIZ_DOT"; 39 | static final String LAMBDA_TASK_ROOT = "LAMBDA_TASK_ROOT"; 40 | private static final String DOT_PATH = "/opt/dot_static"; 41 | static final long DEFAULT_MAX_AGE = 3600; 42 | 43 | private static final Logger logger = Logger.getLogger(LambdaBase.class); 44 | 45 | static { 46 | String stage = Optional.ofNullable(System.getenv(ENV_VAR_KEY_STAGE)).orElse(DEFAULT_STAGE); 47 | URL logPropsUrl = LambdaBase.class.getResource(String.format("/log4j-%s.properties", stage)); 48 | if (logPropsUrl != null) { 49 | LogManager.resetConfiguration(); 50 | PropertyConfigurator.configure(logPropsUrl); 51 | } 52 | 53 | if (System.getenv(LAMBDA_TASK_ROOT) == null) { 54 | logger.error(String.format("%s environment variable is not set. Rendering without graphviz dot!", LAMBDA_TASK_ROOT)); 55 | } else { 56 | System.setProperty(GRAPHVIZ_DOT, DOT_PATH); 57 | } 58 | logger.debug(String.format("GRAPHVIZ_DOT system property: %s", System.getProperty(GRAPHVIZ_DOT))); 59 | } 60 | 61 | Map getCacheHeaders(String etag, long maxAge) { 62 | if (NOETAG.equals(etag)) { 63 | return Collections.emptyMap(); 64 | } else { 65 | Map headers = new HashMap<>(); 66 | headers.put("ETag", etag); 67 | headers.put("Cache-Control", "public, max-age=" + maxAge); 68 | return headers; 69 | } 70 | } 71 | 72 | boolean isMatchingEtag(JSONObject event, String expectedEtag) { 73 | logger.debug(String.format("expected etag %s -> event: %s", expectedEtag, event.toJSONString())); 74 | return expectedEtag != null && !NOETAG.equals(expectedEtag) && getJSONObject(event, "headers") 75 | .entrySet().stream().anyMatch(pair -> 76 | "if-none-match".equalsIgnoreCase(pair.getKey()) && expectedEtag.equals(pair.getValue())); 77 | } 78 | 79 | @SuppressWarnings("unchecked") 80 | void send304Response(OutputStream outputStream, Map headers) throws IOException { 81 | JSONObject responseJson = new JSONObject(); 82 | 83 | JSONObject headerJson = new JSONObject(); 84 | headerJson.putAll(headers); 85 | headerJson.put("Access-Control-Allow-Origin", "*"); 86 | 87 | responseJson.put("statusCode", "304"); 88 | responseJson.put("headers", headerJson); 89 | 90 | internalSendResponse(outputStream, responseJson); 91 | } 92 | 93 | void sendOKDiagramResponse(OutputStream outputStream, String base64Response, DiagramType diagramType) throws IOException { 94 | sendOKDiagramResponse(outputStream, base64Response, diagramType, Collections.emptyMap()); 95 | } 96 | 97 | void sendOKDiagramResponse(OutputStream outputStream, String base64Response, 98 | DiagramType diagramType, Map headers) throws IOException { 99 | sendDiagramResponse(outputStream, base64Response, diagramType, String.valueOf(HttpStatus.SC_OK), headers); 100 | } 101 | 102 | void sendDiagramResponse(OutputStream outputStream, String base64Response, DiagramType diagramType, 103 | String statusCode) throws IOException { 104 | sendDiagramResponse(outputStream, base64Response, diagramType, statusCode, Collections.emptyMap()); 105 | } 106 | 107 | @SuppressWarnings("unchecked") 108 | void sendDiagramResponse(OutputStream outputStream, String base64Response, DiagramType diagramType, 109 | String statusCode, Map headers) throws IOException { 110 | JSONObject responseJson = new JSONObject(); 111 | 112 | JSONObject headerJson = new JSONObject(); 113 | headerJson.putAll(headers); 114 | headerJson.put("Access-Control-Allow-Origin", "*"); 115 | headerJson.put("Content-Type", diagramType.getMimeType()); 116 | 117 | responseJson.put("statusCode", statusCode); 118 | responseJson.put("headers", headerJson); 119 | responseJson.put("body", base64Response); 120 | responseJson.put("isBase64Encoded", true); 121 | 122 | internalSendResponse(outputStream, responseJson); 123 | } 124 | 125 | void sendOKJSONResponse(OutputStream outputStream, String base64Response) throws IOException { 126 | sendOKJSONResponse(outputStream, base64Response, Collections.emptyMap()); 127 | } 128 | 129 | @SuppressWarnings("unchecked") 130 | void sendOKJSONResponse(OutputStream outputStream, String base64Response, Map headers) throws IOException { 131 | sendJSONResponse(outputStream, base64Response, String.valueOf(HttpStatus.SC_OK), headers); 132 | } 133 | 134 | void sendExceptionResponse(OutputStream outputStream, StatusCodeException statusCodeException) throws IOException { 135 | sendExceptionResponse(outputStream, statusCodeException, Collections.emptyMap()); 136 | } 137 | 138 | void sendExceptionResponse(OutputStream outputStream, StatusCodeException statusCodeException, 139 | Map headers) throws IOException { 140 | String base64Response = Base64.getEncoder().encodeToString(statusCodeException.getMessage().getBytes()); 141 | sendJSONResponse(outputStream, base64Response, statusCodeException.getStatusCode(), headers); 142 | } 143 | 144 | void sendJSONResponse(OutputStream outputStream, String base64Response, String statusCode) throws IOException { 145 | sendJSONResponse(outputStream, base64Response, statusCode, Collections.emptyMap()); 146 | } 147 | 148 | void sendJSONResponse(OutputStream outputStream, String base64Response, 149 | String statusCode, Map headers) throws IOException { 150 | JSONObject responseJson = new JSONObject(); 151 | 152 | JSONObject headerJson = new JSONObject(); 153 | headerJson.putAll(headers); 154 | headerJson.put("Access-Control-Allow-Origin", "*"); 155 | headerJson.put("Content-Type", "application/json"); 156 | 157 | responseJson.put("statusCode", statusCode); 158 | responseJson.put("headers", headerJson); 159 | responseJson.put("body", base64Response); 160 | responseJson.put("isBase64Encoded", true); 161 | 162 | internalSendResponse(outputStream, responseJson); 163 | } 164 | 165 | void sendHTMLResponse(OutputStream outputStream, String htmlResponse, String statusCode) throws IOException { 166 | sendHTMLResponse(outputStream, htmlResponse, statusCode, Collections.emptyMap()); 167 | } 168 | 169 | void sendHTMLResponse(OutputStream outputStream, String htmlResponse, 170 | String statusCode, Map headers) throws IOException { 171 | JSONObject responseJson = new JSONObject(); 172 | 173 | JSONObject headerJson = new JSONObject(); 174 | headerJson.putAll(headers); 175 | headerJson.put("Access-Control-Allow-Origin", "*"); 176 | headerJson.put("Content-Type", "text/html"); 177 | 178 | responseJson.put("statusCode", statusCode); 179 | responseJson.put("headers", headerJson); 180 | responseJson.put("body", htmlResponse); 181 | responseJson.put("isBase64Encoded", false); 182 | 183 | internalSendResponse(outputStream, responseJson); 184 | } 185 | 186 | void sendRedirectResponse(OutputStream outputStream, String redirectPath) throws IOException { 187 | sendRedirectResponse(outputStream, redirectPath, Collections.emptyMap()); 188 | } 189 | 190 | void sendRedirectResponse(OutputStream outputStream, String redirectPath, 191 | Map headers) throws IOException { 192 | JSONObject responseJson = new JSONObject(); 193 | 194 | JSONObject headerJson = new JSONObject(); 195 | headerJson.putAll(headers); 196 | headerJson.put("Access-Control-Allow-Origin", "*"); 197 | headerJson.put("Location", redirectPath); 198 | 199 | responseJson.put("statusCode", HttpStatus.SC_MOVED_PERMANENTLY); 200 | responseJson.put("headers", headerJson); 201 | responseJson.put("isBase64Encoded", false); 202 | 203 | internalSendResponse(outputStream, responseJson); 204 | } 205 | 206 | private void internalSendResponse(OutputStream outputStream, JSONObject responseJson) throws IOException { 207 | logger.debug(responseJson.toJSONString()); 208 | OutputStreamWriter writer = new OutputStreamWriter(outputStream, "UTF-8"); 209 | writer.write(responseJson.toJSONString()); 210 | writer.close(); 211 | } 212 | 213 | @SuppressWarnings("unchecked") 214 | Map getJSONObject(JSONObject parent, String key) { 215 | Object value = parent.get(key); 216 | Map map = new HashMap<>(); 217 | if (value instanceof JSONObject) { 218 | map.putAll((JSONObject) value); 219 | } 220 | return map; 221 | } 222 | 223 | String getEncodedUml(JSONObject event) throws IOException { 224 | if (event.get("pathParameters") != null) { 225 | JSONObject pps = (JSONObject) event.get("pathParameters"); 226 | if (pps.get("encodedUml") == null) { 227 | handleInputError(null); 228 | } 229 | return (String) pps.get("encodedUml"); 230 | } 231 | return null; 232 | } 233 | 234 | boolean isNitorStyle(JSONObject event) { 235 | JSONObject qsp; 236 | if ((event == null) || (qsp = (JSONObject) event.get("queryStringParameters")) == null) { 237 | return false; 238 | } 239 | return qsp.get("nitorStyle") != null; 240 | } 241 | 242 | JSONObject parseEvent(InputStream inputStream) { 243 | BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); 244 | final JSONParser parser = new JSONParser(); 245 | try { 246 | JSONObject event = (JSONObject) parser.parse(reader); 247 | logger.debug(event.toJSONString()); 248 | return event; 249 | } catch (Exception e) { 250 | handleInputError(e); 251 | } 252 | return null; 253 | } 254 | 255 | private void handleInputError(Exception e) { 256 | throw new IllegalArgumentException("Could not parse parameters", e); 257 | } 258 | } -------------------------------------------------------------------------------- /src/main/java/com/nitor/plantuml/lambda/MapHandler.java: -------------------------------------------------------------------------------- 1 | package com.nitor.plantuml.lambda; 2 | 3 | import com.amazonaws.services.lambda.runtime.Context; 4 | import com.amazonaws.services.lambda.runtime.RequestStreamHandler; 5 | import com.nitor.plantuml.PlantUmlUtil; 6 | import com.nitor.plantuml.lambda.exception.StatusCodeException; 7 | import net.sourceforge.plantuml.SourceStringReader; 8 | import org.apache.http.HttpStatus; 9 | import org.json.simple.JSONObject; 10 | 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | import java.io.OutputStream; 14 | import java.util.Base64; 15 | import java.util.Collections; 16 | 17 | public class MapHandler extends LambdaBase implements RequestStreamHandler { 18 | 19 | private static final String TYPE_IDENTIFIER = "map"; 20 | private final PlantUmlUtil plantUmlUtil = new PlantUmlUtil(); 21 | 22 | @Override 23 | public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException { 24 | JSONObject event = parseEvent(inputStream); 25 | String encodedUml = getEncodedUml(event); 26 | final String etag = plantUmlUtil.getEtag(encodedUml, TYPE_IDENTIFIER); 27 | if (isMatchingEtag(event, etag)) { 28 | send304Response(outputStream, Collections.emptyMap()); 29 | return; 30 | } 31 | try { 32 | SourceStringReader reader = plantUmlUtil.readDiagram(encodedUml); 33 | String imageMap = plantUmlUtil.renderImageMap(reader); 34 | String base64Response = Base64.getEncoder().encodeToString(imageMap.getBytes()); 35 | SyntaxCheckResult syntaxCheckResult = plantUmlUtil.checkSyntax(encodedUml); 36 | if (!syntaxCheckResult.isError()) { 37 | sendOKDiagramResponse(outputStream, base64Response, DiagramType.IMAGEMAP, 38 | getCacheHeaders(etag, DEFAULT_MAX_AGE)); 39 | } else { 40 | sendDiagramResponse(outputStream, base64Response, DiagramType.IMAGEMAP, 41 | String.valueOf(HttpStatus.SC_UNPROCESSABLE_ENTITY)); 42 | } 43 | } catch (StatusCodeException sce) { 44 | sendExceptionResponse(outputStream, sce); 45 | } 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /src/main/java/com/nitor/plantuml/lambda/PngHandler.java: -------------------------------------------------------------------------------- 1 | package com.nitor.plantuml.lambda; 2 | 3 | import com.amazonaws.services.lambda.runtime.Context; 4 | import com.amazonaws.services.lambda.runtime.RequestStreamHandler; 5 | import com.nitor.plantuml.PlantUmlUtil; 6 | import com.nitor.plantuml.lambda.exception.StatusCodeException; 7 | import net.sourceforge.plantuml.SourceStringReader; 8 | import org.apache.http.HttpStatus; 9 | import org.apache.log4j.Logger; 10 | import org.json.simple.JSONObject; 11 | 12 | import java.io.ByteArrayOutputStream; 13 | import java.io.IOException; 14 | import java.io.InputStream; 15 | import java.io.OutputStream; 16 | import java.nio.file.Files; 17 | import java.nio.file.Path; 18 | import java.nio.file.Paths; 19 | import java.nio.file.attribute.PosixFilePermission; 20 | import java.nio.file.attribute.PosixFilePermissions; 21 | import java.util.Base64; 22 | import java.util.Collections; 23 | import java.util.Set; 24 | import java.util.concurrent.TimeUnit; 25 | 26 | public class PngHandler extends LambdaBase implements RequestStreamHandler { 27 | private static final Logger logger = Logger.getLogger(PngHandler.class); 28 | private static final String TYPE_IDENTIFIER = "png"; 29 | private final PlantUmlUtil plantUmlUtil = new PlantUmlUtil(); 30 | 31 | @Override 32 | public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException { 33 | JSONObject event = parseEvent(inputStream); 34 | String encodedUml = getEncodedUml(event); 35 | final String etag = plantUmlUtil.getEtag(encodedUml, TYPE_IDENTIFIER); 36 | if (isMatchingEtag(event, etag)) { 37 | send304Response(outputStream, Collections.emptyMap()); 38 | return; 39 | } 40 | 41 | try { 42 | SourceStringReader reader = plantUmlUtil.readDiagram(encodedUml); 43 | ByteArrayOutputStream baos = plantUmlUtil.renderDiagram(reader, DiagramType.IMAGE_PNG); 44 | if (isNitorStyle(event)) { 45 | baos = applyBackground(baos); 46 | } 47 | byte[] bytes = baos.toByteArray(); 48 | String base64Response = Base64.getEncoder().encodeToString(bytes); 49 | SyntaxCheckResult syntaxCheckResult = plantUmlUtil.checkSyntax(encodedUml); 50 | if (!syntaxCheckResult.isError()) { 51 | sendOKDiagramResponse(outputStream, base64Response, DiagramType.IMAGE_PNG, 52 | getCacheHeaders(etag, DEFAULT_MAX_AGE)); 53 | } else { 54 | sendDiagramResponse(outputStream, base64Response, DiagramType.IMAGE_PNG, 55 | String.valueOf(HttpStatus.SC_UNPROCESSABLE_ENTITY)); 56 | } 57 | } catch (StatusCodeException sce) { 58 | sendExceptionResponse(outputStream, sce); 59 | } 60 | } 61 | 62 | private ByteArrayOutputStream applyBackground(ByteArrayOutputStream diagramImage) { 63 | byte[] originalDiagramBytes = diagramImage.toByteArray(); 64 | try { 65 | if (!Files.exists(Paths.get(System.getenv(LAMBDA_TASK_ROOT), "bg.png"))) { 66 | logger.error("Background image not found!"); 67 | return bytesToByteArrayOutputStream(originalDiagramBytes); 68 | } 69 | Path pathToTmp = Paths.get("/tmp"); 70 | Set perms = PosixFilePermissions.fromString("rwx------"); 71 | Path diagramImageFile = Files.createTempFile(pathToTmp, null, null); 72 | Files.write(diagramImageFile, originalDiagramBytes); 73 | Path diagramWithBackgroundFile = Files.createTempFile(Paths.get("/tmp"), null, null); 74 | Path tempBackgroundFile = Files.createTempFile(Paths.get("/tmp"), null, null); 75 | Path bgFile = Paths.get(System.getenv(LAMBDA_TASK_ROOT), "bg.png"); 76 | Path script = Paths.get(System.getenv(LAMBDA_TASK_ROOT), "bg.sh"); 77 | 78 | Process p = new ProcessBuilder("/bin/sh", "-x", script.toString(), diagramImageFile.toString(), 79 | bgFile.toString(), tempBackgroundFile.toString(), diagramWithBackgroundFile.toString()) 80 | .redirectOutput(ProcessBuilder.Redirect.INHERIT) 81 | .redirectError(ProcessBuilder.Redirect.INHERIT) 82 | .start(); 83 | p.waitFor(5, TimeUnit.SECONDS); 84 | if (p.exitValue() == 0) { 85 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 86 | baos.write(Files.readAllBytes(diagramWithBackgroundFile)); 87 | return baos; 88 | } 89 | } catch (IOException e) { 90 | e.printStackTrace(); 91 | } catch (InterruptedException e) { 92 | e.printStackTrace(); 93 | } 94 | 95 | logger.error(String.format("Problem with background apply")); 96 | 97 | return bytesToByteArrayOutputStream(originalDiagramBytes); 98 | } 99 | 100 | private ByteArrayOutputStream bytesToByteArrayOutputStream(byte[] bytes) { 101 | ByteArrayOutputStream originalImageData = new ByteArrayOutputStream(); 102 | try { 103 | originalImageData.write(bytes); 104 | } catch (IOException e) { 105 | e.printStackTrace(); 106 | } 107 | return originalImageData; 108 | } 109 | 110 | } -------------------------------------------------------------------------------- /src/main/java/com/nitor/plantuml/lambda/SvgHandler.java: -------------------------------------------------------------------------------- 1 | package com.nitor.plantuml.lambda; 2 | 3 | import com.amazonaws.services.lambda.runtime.Context; 4 | import com.amazonaws.services.lambda.runtime.RequestStreamHandler; 5 | import com.nitor.plantuml.PlantUmlUtil; 6 | import com.nitor.plantuml.lambda.exception.StatusCodeException; 7 | import net.sourceforge.plantuml.SourceStringReader; 8 | import org.apache.http.HttpStatus; 9 | import org.json.simple.JSONObject; 10 | 11 | import java.io.ByteArrayOutputStream; 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | import java.io.OutputStream; 15 | import java.util.Base64; 16 | import java.util.Collections; 17 | 18 | public class SvgHandler extends LambdaBase implements RequestStreamHandler { 19 | private static final String TYPE_IDENTIFIER = "svg"; 20 | private final PlantUmlUtil plantUmlUtil = new PlantUmlUtil(); 21 | 22 | @Override 23 | public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException { 24 | JSONObject event = parseEvent(inputStream); 25 | String encodedUml = getEncodedUml(event); 26 | final String etag = plantUmlUtil.getEtag(encodedUml, TYPE_IDENTIFIER); 27 | if (isMatchingEtag(event, etag)) { 28 | send304Response(outputStream, Collections.emptyMap()); 29 | return; 30 | } 31 | 32 | try { 33 | SourceStringReader reader = plantUmlUtil.readDiagram(encodedUml); 34 | ByteArrayOutputStream baos = plantUmlUtil.renderDiagram(reader, DiagramType.IMAGE_SVG_XML); 35 | byte[] bytes = baos.toByteArray(); 36 | String base64Response = Base64.getEncoder().encodeToString(bytes); 37 | SyntaxCheckResult syntaxCheckResult = plantUmlUtil.checkSyntax(encodedUml); 38 | if (!syntaxCheckResult.isError()) { 39 | sendOKDiagramResponse(outputStream, base64Response, DiagramType.IMAGE_SVG_XML, 40 | getCacheHeaders(etag, DEFAULT_MAX_AGE)); 41 | } else { 42 | sendDiagramResponse(outputStream, base64Response, 43 | DiagramType.IMAGE_SVG_XML, String.valueOf(HttpStatus.SC_UNPROCESSABLE_ENTITY)); 44 | } 45 | } catch (StatusCodeException sce) { 46 | sendExceptionResponse(outputStream, sce); 47 | } 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /src/main/java/com/nitor/plantuml/lambda/SyntaxCheckResult.java: -------------------------------------------------------------------------------- 1 | package com.nitor.plantuml.lambda; 2 | 3 | import java.util.List; 4 | 5 | public class SyntaxCheckResult { 6 | 7 | private final boolean isError; 8 | private final List errors; 9 | private final String diagramType; 10 | private final String errorLocation; 11 | 12 | public SyntaxCheckResult(boolean isError, String diagramType, String errorLocation, List errors) { 13 | this.isError = isError; 14 | this.diagramType = diagramType; 15 | this.errorLocation = errorLocation; 16 | this.errors = errors; 17 | } 18 | 19 | public boolean isError() { 20 | return isError; 21 | } 22 | 23 | public List getErrors() { 24 | return errors; 25 | } 26 | 27 | public String getDiagramType() { 28 | return diagramType; 29 | } 30 | 31 | public String getErrorLocation() { 32 | return errorLocation; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/nitor/plantuml/lambda/SyntaxHandler.java: -------------------------------------------------------------------------------- 1 | package com.nitor.plantuml.lambda; 2 | 3 | import com.amazonaws.services.lambda.runtime.Context; 4 | import com.amazonaws.services.lambda.runtime.RequestStreamHandler; 5 | import com.google.gson.Gson; 6 | import com.google.gson.GsonBuilder; 7 | import com.nitor.plantuml.PlantUmlUtil; 8 | import com.nitor.plantuml.lambda.exception.StatusCodeException; 9 | import org.apache.http.HttpStatus; 10 | import org.json.simple.JSONObject; 11 | 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | import java.io.OutputStream; 15 | import java.util.Base64; 16 | 17 | public class SyntaxHandler extends LambdaBase implements RequestStreamHandler { 18 | 19 | private final PlantUmlUtil plantUmlUtil = new PlantUmlUtil(); 20 | 21 | @Override 22 | public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException { 23 | try { 24 | JSONObject event = parseEvent(inputStream); 25 | String encodedUml = getEncodedUml(event); 26 | SyntaxCheckResult syntaxCheckResult = plantUmlUtil.checkSyntax(encodedUml); 27 | Gson gson = new GsonBuilder().create(); 28 | String json = gson.toJson(syntaxCheckResult); 29 | String base64Response = Base64.getEncoder().encodeToString(json.getBytes()); 30 | if (!syntaxCheckResult.isError()) { 31 | sendOKJSONResponse(outputStream, base64Response); 32 | } else { 33 | sendJSONResponse(outputStream, base64Response, String.valueOf(HttpStatus.SC_UNPROCESSABLE_ENTITY)); 34 | } 35 | } catch (StatusCodeException sce) { 36 | sendExceptionResponse(outputStream, sce); 37 | } 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /src/main/java/com/nitor/plantuml/lambda/TxtHandler.java: -------------------------------------------------------------------------------- 1 | package com.nitor.plantuml.lambda; 2 | 3 | import com.amazonaws.services.lambda.runtime.Context; 4 | import com.amazonaws.services.lambda.runtime.RequestStreamHandler; 5 | import com.nitor.plantuml.PlantUmlUtil; 6 | import com.nitor.plantuml.lambda.exception.StatusCodeException; 7 | import net.sourceforge.plantuml.SourceStringReader; 8 | import org.apache.http.HttpStatus; 9 | import org.json.simple.JSONObject; 10 | 11 | import java.io.ByteArrayOutputStream; 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | import java.io.OutputStream; 15 | import java.util.Base64; 16 | import java.util.Collections; 17 | 18 | public class TxtHandler extends LambdaBase implements RequestStreamHandler { 19 | 20 | private static final String TYPE_IDENTIFIER = "txt"; 21 | private final PlantUmlUtil plantUmlUtil = new PlantUmlUtil(); 22 | 23 | @Override 24 | public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException { 25 | JSONObject event = parseEvent(inputStream); 26 | String encodedUml = getEncodedUml(event); 27 | final String etag = plantUmlUtil.getEtag(encodedUml, TYPE_IDENTIFIER); 28 | if (isMatchingEtag(event, etag)) { 29 | send304Response(outputStream, Collections.emptyMap()); 30 | return; 31 | } 32 | try { 33 | SourceStringReader reader = plantUmlUtil.readDiagram(encodedUml); 34 | ByteArrayOutputStream baos = plantUmlUtil.renderDiagram(reader, DiagramType.TEXT_PLAIN); 35 | byte[] bytes = baos.toByteArray(); 36 | String base64Response = Base64.getEncoder().encodeToString(bytes); 37 | SyntaxCheckResult syntaxCheckResult = plantUmlUtil.checkSyntax(encodedUml); 38 | if (!syntaxCheckResult.isError()) { 39 | sendOKDiagramResponse(outputStream, base64Response, DiagramType.TEXT_PLAIN, 40 | getCacheHeaders(etag, DEFAULT_MAX_AGE)); 41 | } else { 42 | sendDiagramResponse(outputStream, base64Response, DiagramType.TEXT_PLAIN, 43 | String.valueOf(HttpStatus.SC_UNPROCESSABLE_ENTITY)); 44 | } 45 | } catch (StatusCodeException sce) { 46 | sendExceptionResponse(outputStream, sce); 47 | } 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /src/main/java/com/nitor/plantuml/lambda/UIHandler.java: -------------------------------------------------------------------------------- 1 | package com.nitor.plantuml.lambda; 2 | 3 | import com.amazonaws.services.lambda.runtime.Context; 4 | import com.amazonaws.services.lambda.runtime.RequestStreamHandler; 5 | import org.apache.http.HttpStatus; 6 | import org.apache.log4j.Logger; 7 | import org.json.simple.JSONObject; 8 | 9 | import java.io.*; 10 | import java.util.stream.Stream; 11 | 12 | public class UIHandler extends LambdaBase implements RequestStreamHandler { 13 | 14 | private static final Logger logger = Logger.getLogger(UIHandler.class); 15 | private static final String CONTENT_CLASSPATH = "/ui/index.html"; 16 | 17 | @Override 18 | public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException { 19 | JSONObject event = parseEvent(inputStream); 20 | String path = (String)((JSONObject)event.get("requestContext")).get("path"); 21 | logger.debug("Path: " + path); 22 | if (path != null && !path.endsWith("/")) { 23 | sendRedirectResponse(outputStream, path + "/"); 24 | return; 25 | } 26 | 27 | InputStream content = this.getClass().getResourceAsStream(CONTENT_CLASSPATH); 28 | BufferedReader br = new BufferedReader(new InputStreamReader((content))); 29 | StringBuffer sb = new StringBuffer(); 30 | 31 | Stream stream = br.lines(); 32 | stream.forEach(l -> sb.append(l)); 33 | 34 | sendHTMLResponse(outputStream, sb.toString(), String.valueOf(HttpStatus.SC_OK)); 35 | content.close(); 36 | } 37 | } -------------------------------------------------------------------------------- /src/main/java/com/nitor/plantuml/lambda/UmlHandler.java: -------------------------------------------------------------------------------- 1 | package com.nitor.plantuml.lambda; 2 | 3 | import com.amazonaws.services.lambda.runtime.Context; 4 | import com.amazonaws.services.lambda.runtime.RequestStreamHandler; 5 | import com.nitor.plantuml.PlantUmlUtil; 6 | import com.nitor.plantuml.lambda.exception.StatusCodeException; 7 | import org.apache.http.HttpStatus; 8 | import org.json.simple.JSONObject; 9 | 10 | import java.io.BufferedReader; 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | import java.io.InputStreamReader; 14 | import java.io.OutputStream; 15 | import java.util.Collections; 16 | import java.util.Optional; 17 | import java.util.stream.Stream; 18 | 19 | public class UmlHandler extends LambdaBase implements RequestStreamHandler { 20 | private static final String TYPE_IDENTIFIER = "uml"; 21 | private static final String CONTENT_CLASSPATH = "/ui/umlsource.html"; 22 | private final PlantUmlUtil plantUmlUtil = new PlantUmlUtil(); 23 | 24 | @Override 25 | public void handleRequest(final InputStream inputStream, 26 | final OutputStream outputStream, 27 | final Context context) throws IOException { 28 | JSONObject event = parseEvent(inputStream); 29 | String encodedUml = Optional.ofNullable(getEncodedUml(event)).orElse(""); 30 | final String etag = plantUmlUtil.getEtag(encodedUml, TYPE_IDENTIFIER); 31 | if (isMatchingEtag(event, etag)) { 32 | send304Response(outputStream, Collections.emptyMap()); 33 | return; 34 | } 35 | 36 | String decodedUml = plantUmlUtil.decodeUml(encodedUml) 37 | .replace("&", "&") 38 | .replace("<", "<") 39 | .replace(">", ">"); 40 | String editorUrl="../../"; 41 | try(InputStream content = this.getClass().getResourceAsStream(CONTENT_CLASSPATH); 42 | BufferedReader br = new BufferedReader(new InputStreamReader(content))) { 43 | StringBuffer sb = new StringBuffer(); 44 | Stream stream = br.lines(); 45 | stream.forEach(l -> sb.append(l.replace("{{uml_source}}", decodedUml) 46 | .replace("{{editor_url}}", editorUrl))); 47 | sendHTMLResponse(outputStream, sb.toString(), String.valueOf(HttpStatus.SC_OK), 48 | getCacheHeaders(etag, DEFAULT_MAX_AGE)); 49 | } catch (StatusCodeException sce) { 50 | sendExceptionResponse(outputStream, sce); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/nitor/plantuml/lambda/exception/BadRequestException.java: -------------------------------------------------------------------------------- 1 | package com.nitor.plantuml.lambda.exception; 2 | 3 | public class BadRequestException extends StatusCodeException { 4 | 5 | private final static String STATUS_CODE = "400"; 6 | 7 | public BadRequestException() { 8 | super(); 9 | } 10 | 11 | public BadRequestException(String message) { 12 | super(message); 13 | } 14 | 15 | public BadRequestException(String message, Throwable cause) { 16 | super(message, cause); 17 | } 18 | 19 | public String getStatusCode() { 20 | return STATUS_CODE; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/nitor/plantuml/lambda/exception/StatusCodeException.java: -------------------------------------------------------------------------------- 1 | package com.nitor.plantuml.lambda.exception; 2 | 3 | public abstract class StatusCodeException extends RuntimeException { 4 | 5 | public StatusCodeException() { 6 | super(); 7 | } 8 | 9 | public StatusCodeException(String message) { 10 | super(message); 11 | } 12 | 13 | public StatusCodeException(String message, Throwable cause) { 14 | super(message, cause); 15 | } 16 | 17 | public abstract String getStatusCode(); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/net/sourceforge/plantuml/servlet/utility/UmlExtractor.java: -------------------------------------------------------------------------------- 1 | /* ======================================================================== 2 | * PlantUML : a free UML diagram generator 3 | * ======================================================================== 4 | * 5 | * Project Info: http://plantuml.sourceforge.net 6 | * 7 | * This file is part of PlantUML. 8 | * 9 | * PlantUML is free software; you can redistribute it and/or modify it 10 | * under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * PlantUML distributed in the hope that it will be useful, but 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17 | * License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | */ 24 | package net.sourceforge.plantuml.servlet.utility; 25 | 26 | import java.io.IOException; 27 | import java.io.UnsupportedEncodingException; 28 | import java.net.URLDecoder; 29 | 30 | import net.sourceforge.plantuml.code.Transcoder; 31 | import net.sourceforge.plantuml.code.TranscoderUtil; 32 | 33 | /** 34 | * Utility class to extract the UML source from the compressed UML source contained in the end part 35 | * of the requested URI. 36 | */ 37 | public class UmlExtractor { 38 | 39 | /** 40 | * Build the complete UML source from the compressed source extracted from the HTTP URI. 41 | * 42 | * @param source 43 | * the last part of the URI containing the compressed UML 44 | * @return the textual UML source 45 | */ 46 | static public String getUmlSource(String source) { 47 | 48 | // build the UML source from the compressed part of the URL 49 | String text; 50 | try { 51 | text = URLDecoder.decode(source, "UTF-8"); 52 | } catch (UnsupportedEncodingException uee) { 53 | text = "' invalid encoded string"; 54 | } 55 | Transcoder transcoder = TranscoderUtil.getDefaultTranscoder(); 56 | try { 57 | text = transcoder.decode(text); 58 | } catch (IOException ioe) { 59 | text = "' unable to decode string"; 60 | } 61 | 62 | // encapsulate the UML syntax if necessary 63 | String uml; 64 | if (text.startsWith("@start")) { 65 | uml = text; 66 | } else { 67 | StringBuilder plantUmlSource = new StringBuilder(); 68 | plantUmlSource.append("@startuml\n"); 69 | plantUmlSource.append(text); 70 | if (text.endsWith("\n") == false) { 71 | plantUmlSource.append("\n"); 72 | } 73 | plantUmlSource.append("@enduml"); 74 | uml = plantUmlSource.toString(); 75 | } 76 | return uml; 77 | } 78 | 79 | protected UmlExtractor() { 80 | // prevents calls from subclass 81 | throw new UnsupportedOperationException(); 82 | } 83 | 84 | } -------------------------------------------------------------------------------- /src/main/resources/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmajis/plantuml-serverless/bf5c4a666696b72fff7e348dcc614aefc045a85b/src/main/resources/bg.png -------------------------------------------------------------------------------- /src/main/resources/bg.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Grid background script starting" 4 | 5 | diagram=$1 6 | tile=$2 7 | background=$3 8 | output=$4 9 | dim=$(identify -format "%[fx:w]x%[fx:h]" $diagram) 10 | 11 | composite -tile $tile -size $dim xc:none png:- | convert - -negate $background 12 | 13 | convert $background $diagram -flatten $output 14 | -------------------------------------------------------------------------------- /src/main/resources/log4j-dev.properties: -------------------------------------------------------------------------------- 1 | log = . 2 | log4j.rootLogger = DEBUG, LAMBDA 3 | 4 | #Define the LAMBDA appender 5 | log4j.appender.LAMBDA=com.amazonaws.services.lambda.runtime.log4j.LambdaAppender 6 | log4j.appender.LAMBDA.layout=org.apache.log4j.PatternLayout 7 | log4j.appender.LAMBDA.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss} <%X{AWSRequestId}> %-5p %c{1}:%L - %m%n -------------------------------------------------------------------------------- /src/main/resources/log4j-plantuml.properties: -------------------------------------------------------------------------------- 1 | log = . 2 | log4j.rootLogger = INFO, LAMBDA 3 | 4 | #Define the LAMBDA appender 5 | log4j.appender.LAMBDA=com.amazonaws.services.lambda.runtime.log4j.LambdaAppender 6 | log4j.appender.LAMBDA.layout=org.apache.log4j.PatternLayout 7 | log4j.appender.LAMBDA.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss} <%X{AWSRequestId}> %-5p %c{1}:%L - %m%n -------------------------------------------------------------------------------- /src/main/resources/log4j-prod.properties: -------------------------------------------------------------------------------- 1 | log = . 2 | log4j.rootLogger = INFO, LAMBDA 3 | 4 | #Define the LAMBDA appender 5 | log4j.appender.LAMBDA=com.amazonaws.services.lambda.runtime.log4j.LambdaAppender 6 | log4j.appender.LAMBDA.layout=org.apache.log4j.PatternLayout 7 | log4j.appender.LAMBDA.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss} <%X{AWSRequestId}> %-5p %c{1}:%L - %m%n -------------------------------------------------------------------------------- /src/main/resources/ui/umlsource.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Reveal UML Source 5 | 6 | 7 | 16 |
{{uml_source}}
17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /template.yml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: AWS::Serverless-2016-10-31 3 | Description: PlantUML Serverless API 4 | 5 | Globals: 6 | Function: 7 | Timeout: 30 8 | MemorySize: 512 9 | 10 | Metadata: 11 | AWS::ServerlessRepo::Application: 12 | Name: plantuml-render 13 | Description: PlantUML Serverless API and UI 14 | Author: mmajis 15 | SpdxLicenseId: GPL-3.0-only 16 | LicenseUrl: s3://plantuml-serverlessrepo/LICENSE 17 | ReadmeUrl: s3://plantuml-serverlessrepo/README.md 18 | Labels: ['plantuml'] 19 | HomePageUrl: https://github.com/mmajis/plantuml-serverless 20 | SemanticVersion: 0.1.1 21 | SourceCodeUrl: https://github.com/mmajis/plantuml-serverless/releases/tag/v0.1.1 22 | 23 | Resources: 24 | PlantUMLAPI: 25 | Type: AWS::Serverless::Api 26 | Properties: 27 | StageName: plantuml 28 | DefinitionBody: 29 | swagger: 2.0 30 | info: 31 | title: 32 | Ref: AWS::StackName 33 | paths: 34 | "/": 35 | get: 36 | x-amazon-apigateway-integration: 37 | responses: 38 | default: 39 | statusCode: 200 40 | uri: 41 | Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${UIFunction.Arn}/invocations" 42 | httpMethod: POST 43 | type: aws_proxy 44 | "/uml/{encodedUml}": 45 | get: 46 | x-amazon-apigateway-integration: 47 | responses: 48 | default: 49 | statusCode: 200 50 | uri: 51 | Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${UmlFunction.Arn}/invocations" 52 | httpMethod: POST 53 | type: aws_proxy 54 | "/png/{encodedUml}": 55 | get: 56 | x-amazon-apigateway-integration: 57 | responses: 58 | default: 59 | statusCode: 200 60 | uri: 61 | Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${PngFunction.Arn}/invocations" 62 | httpMethod: POST 63 | type: aws_proxy 64 | contentHandling: CONVERT_TO_BINARY 65 | "/img/{encodedUml}": 66 | get: 67 | x-amazon-apigateway-integration: 68 | responses: 69 | default: 70 | statusCode: 200 71 | uri: 72 | Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImgFunction.Arn}/invocations" 73 | httpMethod: POST 74 | type: aws_proxy 75 | contentHandling: CONVERT_TO_BINARY 76 | "/svg/{encodedUml}": 77 | get: 78 | x-amazon-apigateway-integration: 79 | responses: 80 | default: 81 | statusCode: 200 82 | uri: 83 | Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${SvgFunction.Arn}/invocations" 84 | httpMethod: POST 85 | type: aws_proxy 86 | contentHandling: CONVERT_TO_BINARY 87 | "/txt/{encodedUml}": 88 | get: 89 | x-amazon-apigateway-integration: 90 | responses: 91 | default: 92 | statusCode: 200 93 | uri: 94 | Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${TxtFunction.Arn}/invocations" 95 | httpMethod: POST 96 | type: aws_proxy 97 | contentHandling: CONVERT_TO_BINARY 98 | "/map/{encodedUml}": 99 | get: 100 | x-amazon-apigateway-integration: 101 | responses: 102 | default: 103 | statusCode: 200 104 | uri: 105 | Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MapFunction.Arn}/invocations" 106 | httpMethod: POST 107 | type: aws_proxy 108 | contentHandling: CONVERT_TO_BINARY 109 | "/check/{encodedUml}": 110 | get: 111 | x-amazon-apigateway-integration: 112 | responses: 113 | default: 114 | statusCode: 200 115 | uri: 116 | Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${SyntaxFunction.Arn}/invocations" 117 | httpMethod: POST 118 | type: aws_proxy 119 | contentHandling: CONVERT_TO_BINARY 120 | x-amazon-apigateway-binary-media-types: 121 | - "*/*" 122 | UIFunction: 123 | Type: AWS::Serverless::Function 124 | Properties: 125 | Timeout: 30 126 | PackageType: Image 127 | ImageConfig: 128 | Command: [ "com.nitor.plantuml.lambda.UIHandler::handleRequest" ] 129 | Events: 130 | GetResource: 131 | Type: Api 132 | Properties: 133 | Path: / 134 | Method: get 135 | RestApiId: !Ref PlantUMLAPI 136 | Metadata: 137 | DockerTag: lambdacontainer-sam 138 | DockerContext: ./ 139 | Dockerfile: lambdacontainer/Dockerfile 140 | 141 | UmlFunction: 142 | Type: AWS::Serverless::Function 143 | Properties: 144 | Timeout: 30 145 | PackageType: Image 146 | ImageConfig: 147 | Command: [ "com.nitor.plantuml.lambda.UmlHandler::handleRequest" ] 148 | Events: 149 | GetResource: 150 | Type: Api 151 | Properties: 152 | Path: /uml/{encodedUml} 153 | Method: get 154 | RestApiId: !Ref PlantUMLAPI 155 | Metadata: 156 | DockerTag: lambdacontainer-sam 157 | DockerContext: ./ 158 | Dockerfile: lambdacontainer/Dockerfile 159 | 160 | PngFunction: 161 | Type: AWS::Serverless::Function 162 | Properties: 163 | Timeout: 30 164 | PackageType: Image 165 | ImageConfig: 166 | Command: [ "com.nitor.plantuml.lambda.PngHandler::handleRequest" ] 167 | Events: 168 | GetResource: 169 | Type: Api 170 | Properties: 171 | Path: /png/{encodedUml} 172 | Method: get 173 | RestApiId: !Ref PlantUMLAPI 174 | Metadata: 175 | DockerTag: lambdacontainer-sam 176 | DockerContext: ./ 177 | Dockerfile: lambdacontainer/Dockerfile 178 | 179 | ImgFunction: 180 | Type: AWS::Serverless::Function 181 | Properties: 182 | Timeout: 30 183 | PackageType: Image 184 | ImageConfig: 185 | Command: [ "com.nitor.plantuml.lambda.PngHandler::handleRequest" ] 186 | Events: 187 | GetResource: 188 | Type: Api 189 | Properties: 190 | Path: /img/{encodedUml} 191 | Method: get 192 | RestApiId: !Ref PlantUMLAPI 193 | Metadata: 194 | DockerTag: lambdacontainer-sam 195 | DockerContext: ./ 196 | Dockerfile: lambdacontainer/Dockerfile 197 | 198 | SvgFunction: 199 | Type: AWS::Serverless::Function 200 | Properties: 201 | Timeout: 30 202 | PackageType: Image 203 | ImageConfig: 204 | Command: [ "com.nitor.plantuml.lambda.SvgHandler::handleRequest" ] 205 | Events: 206 | GetResource: 207 | Type: Api 208 | Properties: 209 | Path: /svg/{encodedUml} 210 | Method: get 211 | RestApiId: !Ref PlantUMLAPI 212 | Metadata: 213 | DockerTag: lambdacontainer-sam 214 | DockerContext: ./ 215 | Dockerfile: lambdacontainer/Dockerfile 216 | 217 | TxtFunction: 218 | Type: AWS::Serverless::Function 219 | Properties: 220 | Timeout: 30 221 | PackageType: Image 222 | ImageConfig: 223 | Command: [ "com.nitor.plantuml.lambda.TxtHandler::handleRequest" ] 224 | Events: 225 | GetResource: 226 | Type: Api 227 | Properties: 228 | Path: /txt/{encodedUml} 229 | Method: get 230 | RestApiId: !Ref PlantUMLAPI 231 | Metadata: 232 | DockerTag: lambdacontainer-sam 233 | DockerContext: ./ 234 | Dockerfile: lambdacontainer/Dockerfile 235 | 236 | MapFunction: 237 | Type: AWS::Serverless::Function 238 | Properties: 239 | Timeout: 30 240 | PackageType: Image 241 | ImageConfig: 242 | Command: [ "com.nitor.plantuml.lambda.MapHandler::handleRequest" ] 243 | Events: 244 | GetResource: 245 | Type: Api 246 | Properties: 247 | Path: /map/{encodedUml} 248 | Method: get 249 | RestApiId: !Ref PlantUMLAPI 250 | Metadata: 251 | DockerTag: lambdacontainer-sam 252 | DockerContext: ./ 253 | Dockerfile: lambdacontainer/Dockerfile 254 | 255 | SyntaxFunction: 256 | Type: AWS::Serverless::Function 257 | Properties: 258 | Timeout: 30 259 | PackageType: Image 260 | ImageConfig: 261 | Command: [ "com.nitor.plantuml.lambda.SyntaxHandler::handleRequest" ] 262 | Events: 263 | GetResource: 264 | Type: Api 265 | Properties: 266 | Path: /check/{encodedUml} 267 | Method: get 268 | RestApiId: !Ref PlantUMLAPI 269 | Metadata: 270 | DockerTag: lambdacontainer-sam 271 | DockerContext: ./ 272 | Dockerfile: lambdacontainer/Dockerfile 273 | 274 | Outputs: 275 | ApiUrl: 276 | Description: URL of your API endpoint 277 | Value: !Sub "https://${PlantUMLAPI}.execute-api.${AWS::Region}.amazonaws.com/plantuml" 278 | ExampleDiagram: 279 | Description: Example URL to render a PlantUML diagram 280 | Value: !Sub "https://${PlantUMLAPI}.execute-api.${AWS::Region}.amazonaws.com/plantuml/png/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000" 281 | -------------------------------------------------------------------------------- /test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 |

PNG Sequence Diagram

9 | 10 |

SVG Component Diagram

11 | 12 |

TXT Class Diagram

13 |

14 | 
15 | 
21 | 
22 | 

Image map

23 | 24 | 25 |
26 | 32 | -------------------------------------------------------------------------------- /ui/build/build.js: -------------------------------------------------------------------------------- 1 | const minify = require('html-minifier').minify; 2 | const fs = require('fs'); 3 | const path = require('path'); 4 | 5 | const srcDir = 'ui'; 6 | const targetDir = 'target' + path.sep + 'classes' + path.sep + 'ui'; 7 | 8 | var html = fs.readFileSync(srcDir + path.sep + 'index.html', 'utf8'); 9 | var result = minify(html, { 10 | removeAttributeQuotes: true, 11 | collapseWhitespace: true, 12 | conservativeCollapse: true, 13 | minifyCSS: true, 14 | minifyJS: true, 15 | removeComments: true 16 | }); 17 | if (!fs.existsSync(targetDir)){ 18 | fs.mkdirSync(targetDir); 19 | } 20 | fs.writeFileSync(targetDir + path.sep + 'index.html', result); -------------------------------------------------------------------------------- /ui/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 1690 | 1733 | 1837 | 1840 | 1841 | 1845 | 1846 | 1847 | 1848 | 1849 | 1850 | 1920 | 1921 | 1968 | 1969 | PlantUML Serverless 1970 | 1971 | 1972 | 1973 | 1980 |
1981 |
1982 | 1983 |
1984 | 1989 | 1990 |
1991 |
1992 |
1993 |
1994 |

1995 |     
1996 |
1997 |
1998 | 2002 |
2003 |
2004 |
2005 | 2006 | 2019 | 2020 | 2021 | 2022 | -------------------------------------------------------------------------------- /ui/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "plantuml-previewer", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "camel-case": { 8 | "version": "3.0.0", 9 | "resolved": "https://registry.npmjs.org/camel-case/-/camel-case-3.0.0.tgz", 10 | "integrity": "sha1-yjw2iKTpzzpM2nd9xNy8cTJJz3M=", 11 | "dev": true, 12 | "requires": { 13 | "no-case": "^2.2.0", 14 | "upper-case": "^1.1.1" 15 | } 16 | }, 17 | "clean-css": { 18 | "version": "4.1.11", 19 | "resolved": "https://registry.npmjs.org/clean-css/-/clean-css-4.1.11.tgz", 20 | "integrity": "sha1-Ls3xRaujj1R0DybO/Q/z4D4SXWo=", 21 | "dev": true, 22 | "requires": { 23 | "source-map": "0.5.x" 24 | } 25 | }, 26 | "commander": { 27 | "version": "2.15.1", 28 | "resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz", 29 | "integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==", 30 | "dev": true 31 | }, 32 | "he": { 33 | "version": "1.1.1", 34 | "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", 35 | "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", 36 | "dev": true 37 | }, 38 | "html-minifier": { 39 | "version": "3.5.12", 40 | "resolved": "https://registry.npmjs.org/html-minifier/-/html-minifier-3.5.12.tgz", 41 | "integrity": "sha512-+N778qLf0RWBscD0TPGoYdeGNDZ0s76/0pQhY1/409EOudcENkm9IbSkk37RDyPdg/09GVHTKotU4ya93RF1Gg==", 42 | "dev": true, 43 | "requires": { 44 | "camel-case": "3.0.x", 45 | "clean-css": "4.1.x", 46 | "commander": "2.15.x", 47 | "he": "1.1.x", 48 | "ncname": "1.0.x", 49 | "param-case": "2.1.x", 50 | "relateurl": "0.2.x", 51 | "uglify-js": "3.3.x" 52 | } 53 | }, 54 | "lower-case": { 55 | "version": "1.1.4", 56 | "resolved": "https://registry.npmjs.org/lower-case/-/lower-case-1.1.4.tgz", 57 | "integrity": "sha1-miyr0bno4K6ZOkv31YdcOcQujqw=", 58 | "dev": true 59 | }, 60 | "ncname": { 61 | "version": "1.0.0", 62 | "resolved": "https://registry.npmjs.org/ncname/-/ncname-1.0.0.tgz", 63 | "integrity": "sha1-W1etGLHKCShk72Kwse2BlPODtxw=", 64 | "dev": true, 65 | "requires": { 66 | "xml-char-classes": "^1.0.0" 67 | } 68 | }, 69 | "no-case": { 70 | "version": "2.3.2", 71 | "resolved": "https://registry.npmjs.org/no-case/-/no-case-2.3.2.tgz", 72 | "integrity": "sha512-rmTZ9kz+f3rCvK2TD1Ue/oZlns7OGoIWP4fc3llxxRXlOkHKoWPPWJOfFYpITabSow43QJbRIoHQXtt10VldyQ==", 73 | "dev": true, 74 | "requires": { 75 | "lower-case": "^1.1.1" 76 | } 77 | }, 78 | "param-case": { 79 | "version": "2.1.1", 80 | "resolved": "https://registry.npmjs.org/param-case/-/param-case-2.1.1.tgz", 81 | "integrity": "sha1-35T9jPZTHs915r75oIWPvHK+Ikc=", 82 | "dev": true, 83 | "requires": { 84 | "no-case": "^2.2.0" 85 | } 86 | }, 87 | "relateurl": { 88 | "version": "0.2.7", 89 | "resolved": "https://registry.npmjs.org/relateurl/-/relateurl-0.2.7.tgz", 90 | "integrity": "sha1-VNvzd+UUQKypCkzSdGANP/LYiKk=", 91 | "dev": true 92 | }, 93 | "source-map": { 94 | "version": "0.5.7", 95 | "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", 96 | "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", 97 | "dev": true 98 | }, 99 | "uglify-js": { 100 | "version": "3.3.16", 101 | "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.3.16.tgz", 102 | "integrity": "sha512-FMh5SRqJRGhv9BbaTffENIpDDQIoPDR8DBraunGORGhySArsXlw9++CN+BWzPBLpoI4RcSnpfGPnilTxWL3Vvg==", 103 | "dev": true, 104 | "requires": { 105 | "commander": "~2.15.0", 106 | "source-map": "~0.6.1" 107 | }, 108 | "dependencies": { 109 | "source-map": { 110 | "version": "0.6.1", 111 | "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", 112 | "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", 113 | "dev": true 114 | } 115 | } 116 | }, 117 | "upper-case": { 118 | "version": "1.1.3", 119 | "resolved": "https://registry.npmjs.org/upper-case/-/upper-case-1.1.3.tgz", 120 | "integrity": "sha1-9rRQHC7EzdJrp4vnIilh3ndiFZg=", 121 | "dev": true 122 | }, 123 | "xml-char-classes": { 124 | "version": "1.0.0", 125 | "resolved": "https://registry.npmjs.org/xml-char-classes/-/xml-char-classes-1.0.0.tgz", 126 | "integrity": "sha1-ZGV4SKIP/F31g6Qq2KJ3tFErvE0=", 127 | "dev": true 128 | } 129 | } 130 | } 131 | --------------------------------------------------------------------------------