Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Cannot use bodyBase64 in response since #593 #863

Closed
sylvainlaurent opened this issue Jan 29, 2018 · 4 comments
Closed

Cannot use bodyBase64 in response since #593 #863

sylvainlaurent opened this issue Jan 29, 2018 · 4 comments
Labels

Comments

@sylvainlaurent
Copy link

Since #593 (v2.5.1) base64Body cannot be used in the response: the exception is (with 2.14.0):

java.lang.NullPointerException: The input is required.
	at org.apache.commons.lang3.Validate.notNull(Validate.java:222)
	at com.github.jknack.handlebars.Handlebars.compileInline(Handlebars.java:382)
	at com.github.jknack.handlebars.Handlebars.compileInline(Handlebars.java:368)
	at com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer.uncheckedCompileTemplate(ResponseTemplateTransformer.java:146)
	at com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer.transform(ResponseTemplateTransformer.java:96)
	at com.github.tomakehurst.wiremock.stubbing.InMemoryStubMappings.applyTransformations(InMemoryStubMappings.java:89)
	at com.github.tomakehurst.wiremock.stubbing.InMemoryStubMappings.serveFor(InMemoryStubMappings.java:70)
	at com.github.tomakehurst.wiremock.core.WireMockApp.serveStubFor(WireMockApp.java:163)
	at com.github.tomakehurst.wiremock.http.StubRequestHandler.handleRequest(StubRequestHandler.java:50)
	at com.github.tomakehurst.wiremock.http.AbstractRequestHandler.handle(AbstractRequestHandler.java:44)
	at com.github.tomakehurst.wiremock.servlet.WireMockHandlerDispatchingServlet.service(WireMockHandlerDispatchingServlet.java:116)

it's OK with 2.5.0.

@tomakehurst
Copy link
Member

Can you share the code (or example code) and/or mapping that causes this exception?

@tomakehurst tomakehurst added the bug label Feb 1, 2018
@sylvainlaurent
Copy link
Author

Actually the problem occurs if I specify the ResponseTemplateTransformer globally:

public class TestWireMock593 {

    @Rule
    public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort().extensions(new ResponseTemplateTransformer(true)));


    @Before
    public void setup() {

        RestAssured.port = wireMockRule.port();
    }

    @Test
    public void exampleTest() {

        byte[] bodyBytes = given()
                .when()
                .get("/documents/document/123")
                .then()
                .statusCode(200)
                .extract().response().body().asByteArray();
        assertEquals(739L, bodyBytes.length);

    }
}

If the transformer is not global, then it's OK.

@sylvainlaurent
Copy link
Author

The mapping was:

{
  "request": {
    "method": "GET",
    "urlPattern": "/documents/document/.+"
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/pdf"
    },
    //the base64 encoding of the content of /src/main/resources/wiremock/__files/minimal.pdf
    //unfortunately we cannot use bodyFileName="" because of https://github.com/tomakehurst/wiremock/issues/247
    "base64Body": "JVBERi0xLjEKJcKlwrHDqwoKMSAwIG9iagogIDw8IC9UeXBlIC9DYXRhbG9nCiAgICAgL1BhZ2VzIDIgMCBSCiAgPj4KZW5kb2JqCgoyIDAgb2JqCiAgPDwgL1R5cGUgL1BhZ2VzCiAgICAgL0tpZHMgWzMgMCBSXQogICAgIC9Db3VudCAxCiAgICAgL01lZGlhQm94IFswIDAgMzAwIDE0NF0KICA+PgplbmRvYmoKCjMgMCBvYmoKICA8PCAgL1R5cGUgL1BhZ2UKICAgICAgL1BhcmVudCAyIDAgUgogICAgICAvUmVzb3VyY2VzCiAgICAgICA8PCAvRm9udAogICAgICAgICAgIDw8IC9GMQogICAgICAgICAgICAgICA8PCAvVHlwZSAvRm9udAogICAgICAgICAgICAgICAgICAvU3VidHlwZSAvVHlwZTEKICAgICAgICAgICAgICAgICAgL0Jhc2VGb250IC9UaW1lcy1Sb21hbgogICAgICAgICAgICAgICA+PgogICAgICAgICAgID4+CiAgICAgICA+PgogICAgICAvQ29udGVudHMgNCAwIFIKICA+PgplbmRvYmoKCjQgMCBvYmoKICA8PCAvTGVuZ3RoIDU1ID4+CnN0cmVhbQogIEJUCiAgICAvRjEgMTggVGYKICAgIDAgMCBUZAogICAgKEhlbGxvIFdvcmxkKSBUagogIEVUCmVuZHN0cmVhbQplbmRvYmoKCnhyZWYKMCA1CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAxOCAwMDAwMCBuIAowMDAwMDAwMDc3IDAwMDAwIG4gCjAwMDAwMDAxNzggMDAwMDAgbiAKMDAwMDAwMDQ1NyAwMDAwMCBuIAp0cmFpbGVyCiAgPDwgIC9Sb290IDEgMCBSCiAgICAgIC9TaXplIDUKICA+PgpzdGFydHhyZWYKNTY1CiUlRU9GCg=="
  }
}

@sylvainlaurent
Copy link
Author

thanks!�

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

No branches or pull requests

2 participants