mmajis / plantuml-serverless

Serverless PlantUML diagram rendering
GNU General Public License v3.0
48 stars 22 forks source link

Setup instructions and example calling the service? #1

Closed jamestharpe closed 6 years ago

jamestharpe commented 6 years ago

Hi!

I've deployed the service, but whenever I attempt to generate a diagram I get gibberish as a response. For example:

https://XXX.execute-api.us-east-1.amazonaws.com/dev/txt/%40startuml%0ABob%20-%3E%20Alice%20%3A%20hello%0A%40enduml

Returns:

eyJpc0Vycm9yIjp0cnVlLCJlcnJvcnMiOlsiQ291bGQgbm90IGRlY29kZSBVTUwgZnJvbSByZXF1ZXN0IHBhdGg6ICU0MHN0YXJ0dW1sJTBBQm9iJTIwLSUzRSUyMEFsaWNlJTIwJTNBJTIwaGVsbG8lMEElNDBlbmR1bWwiXSwiZGlhZ3JhbVR5cGUiOiJVTktOT1dOIiwiZXJyb3JMb2NhdGlvbiI6IjAiLCJzdWdnZXN0aW9ucyI6W119

Which, when decoded, reads:

{"isError":true,"errors":["Could not decode UML from request path: %40startuml%0ABob%20-%3E%20Alice%20%3A%20hello%0A%40enduml"],"diagramType":"UNKNOWN","errorLocation":"0","suggestions":[]}

I also tried a bas64 encoded string:

https://XXX.execute-api.us-east-1.amazonaws.com/dev/txt/QHN0YXJ0dW1sDQpCb2IgLT4gQWxpY2UgOiBoZWxsbw0KQGVuZHVtbA==

Which returns:

QHN0YXJ0dW1sICAgICAgICAgICAgICAgIAonIHVuYWJsZSB0byBkZWNvZGUgc3RyaW5nCl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl4KIEVtcHR5IGRlc2NyaXB0aW9uICAgICAgIAogU3ludGF4IEVycm9yPyAgICAgICAgICAgCg==

Which decodes to:

@startuml                
' unable to decode string
^^^^^^^^^^^^^^^^^^^^^^^^^
 Empty description       
 Syntax Error?           

So I'm not sure how to call the service via a URL.

If I try to run the service from the command line, I get an error:

$ sls invoke -f txt -d "%40startuml%0ABob%20-%3E%20Alice%20%3A%20hello%0A%40enduml"
{
    "errorMessage": "Could not parse parameters",
    "errorType": "java.lang.IllegalArgumentException",
    "stackTrace": [
        "com.nitor.plantuml.lambda.LambdaBase.handleInputError(LambdaBase.java:125)",
        "com.nitor.plantuml.lambda.LambdaBase.getEncodedUml(LambdaBase.java:119)",
        "com.nitor.plantuml.lambda.TxtHandler.handleRequest(TxtHandler.java:21)"
    ],
    "cause": {
        "errorMessage": "java.lang.String cannot be cast to org.json.simple.JSONObject",
        "errorType": "java.lang.ClassCastException",
        "stackTrace": [
            "com.nitor.plantuml.lambda.LambdaBase.getEncodedUml(LambdaBase.java:106)",
            "com.nitor.plantuml.lambda.TxtHandler.handleRequest(TxtHandler.java:21)"
        ]
    }
}

  Error --------------------------------------------------

  Invoked function failed

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Forums:        forum.serverless.com
     Chat:          gitter.im/serverless/serverless

  Your Environment Information -----------------------------
     OS:                     win32
     Node Version:           8.2.1
     Serverless Version:     1.24.1

And again, with base64 encoded argument which gave the same error.

Finally, I noted in the README that:

Serverless does not support specifying binary response MIME types for API Gateway. So this has to be done manually after serverless deployment.

However, I'm not sure what this is referring to or where to set it up.

Any help you can provide would be appreciated.

Thanks,

-James

mmajis commented 6 years ago

Hi James!

Currently the code expects diagram data to be encoded with PlantUML's text encoding explained here: http://plantuml.com/pte

The above page links to a javascript implementation and here's a node package too: https://www.npmjs.com/package/plantuml-encoder

See the example diagram links in the readme for working examples.

The binary response setup needs to be done with API Gateway directly. After deploying with serverless, find the API Gateway instance in the AWS web console and access "Binary Support" in its menu. Add "/" as binary media type there. Sadly this still can't be done easily with serverless after almost a year.

mmajis commented 6 years ago

Closing this old issue.

I recently added serverless plugins to handle the binary response setup. Also, there's now a way to deploy using AWS Serverless repository (https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:293246570391:applications~plantuml-render). There's also a UI for testing and light use.

The requirement to encode the diagrams in URL path remains.

The easiest way I've found to encode is with a node cli app (https://www.npmjs.com/package/node-plantuml):

npm install node-plantuml -g
puml encode path/to/diagramFile.plantuml

Also you can grab encoded URLs from the diagram images displayed in the UI.