mock-server / mockserver

MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby. MockServer also includes a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding).
http://mock-server.com
Apache License 2.0
4.6k stars 1.07k forks source link

Mockserver crash on start because missing Janino dependency #562

Closed vvargas90 closed 5 years ago

vvargas90 commented 5 years ago

Mockserver version: 5.5.0

Steps to reproduce:

  1. Create a new MockserverClient object. My implementation looks like this: MockServerClient mockServerClient = new MockServerClient(mockServerHost, mockServerPort);

Expected result: MockserverClient is initialized at that host and port

Actual result: The following error happen:

java.lang.NoClassDefFoundError: org/codehaus/janino/ScriptEvaluator
    at ch.qos.logback.core.boolex.JaninoEventEvaluatorBase.start(JaninoEventEvaluatorBase.java:57)
    at ch.qos.logback.core.joran.action.NestedComplexPropertyIA.end(NestedComplexPropertyIA.java:161)
    at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:309)
    at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:193)
    at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:179)
    at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:62)
    at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:165)
    at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:152)
    at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:110)
    at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:53)
    at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75)
    at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)
    at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)
    at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
    at org.mockserver.logging.MockServerLogger.<init>(MockServerLogger.java:53)
    at org.mockserver.logging.MockServerLogger.<init>(MockServerLogger.java:49)
    at org.mockserver.logging.MockServerLogger.<clinit>(MockServerLogger.java:26)
    at org.mockserver.client.MockServerClient.<init>(MockServerClient.java:40)
    at org.mockserver.client.MockServerClient.<init>(MockServerClient.java:78)
    at com.stuart.frontend.mock.Mock.<init>(Mock.java:16)
    at com.stuart.frontend.tests.BaseMockServerTest.initMockServerClient(BaseMockServerTest.java:17)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:455)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:401)
    at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
    at org.testng.TestNG.runSuites(TestNG.java:1049)
    at org.testng.TestNG.run(TestNG.java:1017)
    at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
    at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)

Comments: As workaround adding janino dependency in your pom.xml fixes the issue

jamesdbloom commented 5 years ago

MockServer hasn't used such a logback filter for many many versions. So I doubt this is caused by MockServer, what does your logback.xml or logback configuration look like. The error is caused by a script filter in logback using a janino script evaluator.

vvargas90 commented 5 years ago

I have one pretty similar as the on you have as example in https://github.com/jamesdbloom/mockserver/blob/master/mockserver-netty/src/main/resources/example_logback.xml

<configuration debug="false">
    <!-- to use add system property logback.configurationFile, for example: -Dlogback.configurationFile=/Users/james.bloom/git/mockserver/mockserver-netty/src/main/resources/example_logback.xml -->

    <!-- To completely disable all logging completely -Droot.logLevel=OFF -->

    <!-- application log -->
    <appender name="FILE" class="org.mockserver.logging.DelayedFileCreationRollingFileAppender">
        <file>${log.dir:-./}mockserver.log</file>
        <encoder>
            <pattern>%date %level [%thread] %logger{35} [%file:%line] %msg%n</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>TRACE</level>
        </filter>

        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.dir:-./}mockserver.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>100MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <maxHistory>1</maxHistory>
        </rollingPolicy>
    </appender>

    <!-- make application log asynchronous -->
    <appender name="ASYNC_FILE" class="ch.qos.logback.classic.AsyncAppender">
        <queueSize>128</queueSize>
        <discardingThreshold>0</discardingThreshold>
        <appender-ref ref="FILE" />
    </appender>

    <!-- application console log (for errors and warnings) -->
    <appender name="STDERR" class="ch.qos.logback.core.ConsoleAppender">
        <target>System.err</target>
        <encoder>
            <pattern>%date %level %logger{20} %msg%n</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>WARN</level>
        </filter>
    </appender>

    <!-- make console log (for errors and warnings) asynchronous -->
    <appender name="ASYNC_STDERR" class="ch.qos.logback.classic.AsyncAppender">
        <queueSize>128</queueSize>
        <discardingThreshold>0</discardingThreshold>
        <appender-ref ref="STDERR" />
    </appender>

    <!-- application console log -->
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <target>System.out</target>
        <encoder>
            <pattern>%date %level %logger{20} %msg%n</pattern>
        </encoder>
        <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
            <evaluator>
                <!--<expression>level &gt;= INFO &amp;&amp; level &lt; WARN</expression>-->
                <expression>level &lt; WARN</expression>
            </evaluator>
            <OnMismatch>DENY</OnMismatch>
            <OnMatch>NEUTRAL</OnMatch>
        </filter>
    </appender>

    <!-- make console log asynchronous -->
    <appender name="ASYNC_STDOUT" class="ch.qos.logback.classic.AsyncAppender">
        <queueSize>128</queueSize>
        <discardingThreshold>0</discardingThreshold>
        <appender-ref ref="STDOUT" />
    </appender>

    <!-- request log configuration -->
    <appender name="REQUEST_LOG" class="org.mockserver.logging.DelayedFileCreationRollingFileAppender">
        <file>${log.dir:-./}mockserver_request.log</file>

        <encoder>
            <pattern>%msg%n</pattern>
        </encoder>

        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.dir:-./}mockserver_request.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>100MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <maxHistory>3</maxHistory>
        </rollingPolicy>
    </appender>

    <logger name="REQUEST" level="WARN" additivity="false">
        <appender-ref ref="REQUEST_LOG"/>
    </logger>

    <logger name="org.mockserver" level="${mockserver.logLevel:-WARN}"/>
    <logger name="org.mockserver.proxy" level="${mockserver.logLevel:-WARN}"/>
    <logger name="org.mockserver.mockserver" level="${mockserver.logLevel:-WARN}"/>

    <root level="${root.logLevel:-WARN}">
        <appender-ref ref="ASYNC_FILE"/>
        <appender-ref ref="ASYNC_STDERR"/>
        <appender-ref ref="ASYNC_STDOUT"/>
    </root>
</configuration>
jamesdbloom commented 5 years ago

If you change to the latest version of the example logback file your problem will be resolved:

<configuration debug="false">

    <!-- to use add system property logback.configurationFile, for example: -Dlogback.configurationFile=/Users/james.bloom/git/mockserver/mockserver-netty/src/main/resources/example_logback.xml -->
    <!-- To completely disable all logging completely -Droot.logLevel=OFF -->

    <!-- application log -->
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${log.dir:-./}mockserver.log</file>
        <encoder>
            <pattern>%date %level [%thread] %logger{35} [%file:%line] %msg%n</pattern>
        </encoder>

        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.dir:-./}mockserver.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>100MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <maxHistory>1</maxHistory>
        </rollingPolicy>
    </appender>

    <!-- make application log asynchronous -->
    <appender name="ASYNC_FILE" class="ch.qos.logback.classic.AsyncAppender">
        <queueSize>128</queueSize>
        <discardingThreshold>0</discardingThreshold>
        <appender-ref ref="FILE" />
    </appender>

    <!-- application console log -->
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <target>System.out</target>
        <encoder>
            <pattern>%date %level %logger{20} %msg%n</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>WARN</level>
        </filter>
    </appender>

    <!-- make console log asynchronous -->
    <appender name="ASYNC_STDOUT" class="ch.qos.logback.classic.AsyncAppender">
        <queueSize>128</queueSize>
        <discardingThreshold>0</discardingThreshold>
        <appender-ref ref="STDOUT" />
    </appender>

    <logger name="org.mockserver" level="${mockserver.logLevel:-INFO}"/>
    <logger name="io.netty.handler.ssl.SslHandler" level="WARN"/>

    <root level="${root.logLevel:-WARN}">
        <appender-ref ref="ASYNC_FILE"/>
        <appender-ref ref="ASYNC_STDOUT"/>
    </root>
</configuration>

In github at: https://github.com/jamesdbloom/mockserver/blob/master/mockserver-netty/src/main/resources/example_logback.xml

vvargas90 commented 5 years ago

Alright, that fixed the issue. Thanks 😄