Skip to content

Instantly share code, notes, and snippets.

@eeichinger
Last active January 15, 2016 16:34
Show Gist options
  • Save eeichinger/69bca505865f7c1a0f7d to your computer and use it in GitHub Desktop.
Save eeichinger/69bca505865f7c1a0f7d to your computer and use it in GitHub Desktop.
Use WireMockRule in Recording mode against a https backend
#!/usr/bin/env sh
SCRIPTPATH=$(cd "$(dirname "$0")"; realpath .)
# 2.0.8-beta auto-ungzips response bodies. But not sure how stable that is, so use 1.57 for now
JARFILE=${SCRIPTPATH}/wiremock-1.57-standalone.jar
#JARFILE=${SCRIPTPATH}/wiremock-standalone-2.0.8-beta.jar
WIREMOCK_OPTS=
if [ -z "$KEYSTORE" ]; then
KEYSTORE=${SCRIPTPATH}/my/keystore.jks
fi
if [ -z "$KEYSTORE_PASSWORD" ]; then
KEYSTORE_PASSWORD=changeit
fi
if [ -z "$TRUSTSTORE" ]; then
TRUSTSTORE=${KEYSTORE}
fi
if [ -z "$TRUSTSTORE_PASSWORD" ]; then
TRUSTSTORE_PASSWORD=changeit
fi
if [ "$1" = "jpda" ] ; then
if [ -z "$JPDA_TRANSPORT" ]; then
JPDA_TRANSPORT="dt_socket"
fi
if [ -z "$JPDA_ADDRESS" ]; then
JPDA_ADDRESS="8000"
fi
if [ -z "$JPDA_SUSPEND" ]; then
JPDA_SUSPEND="y"
fi
if [ -z "$JPDA_OPTS" ]; then
JPDA_OPTS="-agentlib:jdwp=transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND"
fi
WIREMOCK_OPTS="$WIREMOCK_OPTS $JPDA_OPTS"
shift
fi
echo scriptpath: ${SCRIPTPATH}
echo jarfile: ${JARFILE}
echo keystore: ${KEYSTORE}
echo jvmargs: ${WIREMOCK_OPTS}
java ${WIREMOCK_OPTS} -jar ${JARFILE} \
--verbose \
--root-dir=${SCRIPTPATH} \
--port 1234 \
--record-mappings \
--https-port 0 \
--https-truststore=${TRUSTSTORE} \
--truststore-password=${TRUSTSTORE_PASSWORD} \
--https-keystore=${KEYSTORE} \
--keystore-password=${KEYSTORE_PASSWORD} \
--proxy-via="my.proxy.com:3128" \
@Rule
public WireMockRule wireMockRule = new WireMockRule(wireMockConfig()
.port(0)
.trustStorePath("/path/to/my/keystore.jks")
.trustStorePassword("changeit")
) {
{
enableRecordMappings();
}
private void enableRecordMappings() {
Options options = (Options) ReflectionTestUtils.getField(this, "options");
FileSource fileSource = options.filesRoot();
fileSource.createIfNecessary();
FileSource filesFileSource = fileSource.child(FILES_ROOT);
filesFileSource.createIfNecessary();
FileSource mappingsFileSource = fileSource.child(MAPPINGS_ROOT);
mappingsFileSource.createIfNecessary();
enableRecordMappings(mappingsFileSource, filesFileSource);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment