opentable / wiremock-body-transformer

Wiremock Body Transformer Extension
Apache License 2.0
65 stars 42 forks source link

java.lang.NoClassDefFoundError: com/opentable/extension/BodyTransformer #25

Closed mmaraka closed 7 years ago

mmaraka commented 7 years ago

Hi, Am trying to use wiremock-body-transformer when deployed wiremock as WAR.

These are the changes have made to WireMockWebContextListener to use BodyTransformer(). On running the server, am seeing "java.lang.NoClassDefFoundError: com/opentable/extension/BodyTransformer". I want to deploy as war so that I can easily have LoadBalancer and all the internal features of the tools.

Appreciate any help on this!

@Override
public void contextInitialized(ServletContextEvent sce) {
    ServletContext context = sce.getServletContext();

    boolean verboseLoggingEnabled = Boolean.parseBoolean(
        firstNonNull(context.getInitParameter("verboseLoggingEnabled"), "true"));

// WireMockApp wireMockApp = new WireMockApp(new WarConfiguration(context), new NotImplementedContainer());

    Map<String, ResponseDefinitionTransformer> transformers = new HashMap<String, ResponseDefinitionTransformer>();
    transformers.put("body-transformer", new BodyTransformer());

    Optional<Integer> maxRequestJournalEntries = readMaxRequestJournalEntries(context);
    String fileSourceRoot = context.getInitParameter(FILE_SOURCE_ROOT_KEY);        
    ServletContextFileSource fileSource = new ServletContextFileSource(context, fileSourceRoot);
    JsonFileMappingsSource defaultMappingsLoader = new JsonFileMappingsSource(fileSource.child("mappings"));
    MappingsSaver mappingsSaver = new NotImplementedMappingsSaver();
    WireMockApp wireMockApp = new WireMockApp(false, defaultMappingsLoader,
            mappingsSaver, false, maxRequestJournalEntries,
            transformers,
            Collections.<String, RequestMatcherExtension> emptyMap(),
            fileSource, new NotImplementedContainer());

    context.setAttribute(APP_CONTEXT_KEY, wireMockApp);
    context.setAttribute(StubRequestHandler.class.getName(), wireMockApp.buildStubRequestHandler());
    context.setAttribute(AdminRequestHandler.class.getName(), wireMockApp.buildAdminRequestHandler());
    context.setAttribute(Notifier.KEY, new Slf4jNotifier(verboseLoggingEnabled));
}

Thanks, mmaraka

mmaraka commented 7 years ago

Am able to resolve this after adding BodyTransformer to my workspace. Its working as expected. Thanks!

tranhungt commented 7 years ago

👍