Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/epam/Wilma
Browse files Browse the repository at this point in the history
  • Loading branch information
tkohegyi committed Feb 11, 2024
2 parents c8ad87e + 7f7fab5 commit 15112c3
Show file tree
Hide file tree
Showing 37 changed files with 334 additions and 321 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ status.txt
wilma-service-api-net/wilma-service-api/nuget.exe
*.snk
.vs/
MigrationBackup
System.*


10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ It is written in Java, and the solution consists of two standalone applications:
* JRE 8 for V1.6.x releases of Wilma
* JRE 7 in case version earlier than V1.6.x in use
* The latest [release](https://github.com/epam/Wilma/releases) of Wilma application downloaded and extracted into a folder.
### Note on V1.6 and V2.0 versions
#### Note on V1.6 and V2.0 versions
Please be noted that there were non-backward compatible changes when Wilma is upgraded from V1.6 to V2.0. Configurations used in V1.6 (that was xml based) cannot be used for configuring V2.0 (which is json based). You should also know that V1.6 release works reliable with HTTP only, because the supported HTTPS protocols (SSLv3, TLS1) become obsolete in the meantime. On the other hand, V2.0 can be used for TLS1.1, TLS 1.2 and even for TLS1.3 - however extra configurations may be necessary and unexpected events may occur (like the used jdk does not support some of these protocols fully). HTTP part shall work without issue.

#### Configuring Components/Services to use Wilma
### Configuring Components/Services to use Wilma
The most simple way to do this is by configuring the Component/Service to use Wilma **as HTTP(S) proxy**.
In case of Java components/services, this can be done by adding a few VM arguments to the run configuration:

Expand All @@ -29,7 +29,7 @@ JAVA_PROXY_FLAGS=-Dhttp.proxyHost=[wilma-url] -Dhttp.proxyPort=[wilma-proxy-port
java ${JAVA_PROXY_FLAGS} ...
```

#### Configure and run Wilma
### Configure and run Wilma

To run Wilma with simplest configuration, just download the release, extract it and run:
`java -jar wilma-x.y.z.jar wilma.conf.properties`
Expand Down Expand Up @@ -58,7 +58,7 @@ Feel free to seek for assistance/advise, or discuss usage scenarios by submittin
* **Docker image** of combined Wilma and Wilma Message Search application is available on DockerHub, see details [here](https://github.com/epam/Wilma/wiki/Docker-image-of-Wilma)

#### Requirements
* JDK 11 (pls use earlier Wilma [releases](https://github.com/epam/Wilma/releases) than V2.0.x when you need to use Java 8 version)
* JDK 15 (pls use earlier Wilma [releases](https://github.com/epam/Wilma/releases) than V2.0.x when you need to use Java 8 version)
* The latest [release](https://github.com/epam/Wilma/releases) of Wilma Message Search application downloaded and extracted into a folder.

#### Running
Expand All @@ -72,7 +72,7 @@ There are several ways you can help us:
* **Write some code.** We would love to see pull requests to this tool. Feel free to contribute (send pull request) on GitHub.

#### Advised working environment
* OpenJDK 15 for V2.0.x
* OpenJDK 15 for V2.5.x
* IntelliJ IDEA Community Edition
* Gradle (included in source) and Git

Expand Down
20 changes: 10 additions & 10 deletions common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'checkstyle'
apply plugin: 'java'
//apply plugin: 'jacoco'
apply plugin: 'jacoco'

if ( !hasProperty('buildNumber') ) {
rootProject.ext.buildNumber = 'SNAPSHOT'
Expand Down Expand Up @@ -58,12 +58,12 @@ tasks.withType(Checkstyle) {
}
}

//jacoco {
// toolVersion = "0.8.7"
//}
//jacocoTestReport {
// reports {
// xml.required
// }
//}
//test.finalizedBy jacocoTestReport
jacoco {
toolVersion = "0.8.11"
}
jacocoTestReport {
reports {
xml.required
}
}
test.finalizedBy jacocoTestReport
10 changes: 5 additions & 5 deletions config/docker/Dockerfile-Wilma
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM debian

MAINTAINER Tamas Kohegyi <tkohegyi2@gmail.com>
MAINTAINER Tamas Kohegyi <tamas_kohegyi@epam.com>

RUN \
mkdir /data && \
Expand All @@ -14,10 +14,10 @@ RUN \
apt-get install -y openjdk-17-jre && \
apt-get upgrade -y && \
rm -rf /var/lib/apt/lists/* && \
wget https://github.com/epam/Wilma/releases/download/V2.3.480/wilma-application-2.3.480.zip && \
unzip wilma-application-2.3.480.zip && \
mv wilma-2.3.480.jar wilma.jar && \
rm -f wilma-application-2.3.480.zip
wget https://github.com/epam/Wilma/releases/download/V2.5.493/wilma-application-2.5.493.zip && \
unzip wilma-application-2.5.493.zip && \
mv wilma-2.5.493.jar wilma.jar && \
rm -f wilma-application-2.5.493.zip

COPY start_wilma.sh /data/
RUN \
Expand Down
12 changes: 6 additions & 6 deletions config/docker/Dockerfile-Wilma_and_Wilma_Message_Search
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# this starts from Wilma base, so just adds the message search related things
FROM epam/wilma
FROM epamenterprise/wilma

MAINTAINER Tamas Kohegyi <tkohegyi2@gmail.com>
MAINTAINER Tamas Kohegyi <tamas_kohegyi@epam.com>

RUN \
mkdir /data/wilma-ms && \
Expand All @@ -11,10 +11,10 @@ RUN \
apt-get upgrade -y && \
apt-get install -y openjdk-17-jdk && \
rm -rf /var/libs/apt/lists/* && \
wget https://github.com/epam/Wilma/releases/download/V2.3.480/wilma-message-search-2.3.480.zip && \
unzip -o wilma-message-search-2.3.480.zip && \
mv wilma-message-search-2.3.480.jar wilma-message-search.jar && \
rm -f wilma-message-search-2.3.480.zip
wget https://github.com/epam/Wilma/releases/download/V2.5.493/wilma-message-search-2.5.493.zip && \
unzip -o wilma-message-search-2.5.493.zip && \
mv wilma-message-search-2.5.493.jar wilma-message-search.jar && \
rm -f wilma-message-search-2.5.493.zip

COPY start_wilma_and_message_search.sh /data/
RUN \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class WilmaHttpResponse extends WilmaHttpEntity {

private String contentType;
private int statusCode;
private String reasonPhrase;
//holder of request headers
private final Map<String, String> requestHeaders = new HashMap<>();
//information about the original URI request received to the Wilma (to the proxy)
Expand Down Expand Up @@ -104,7 +105,7 @@ public boolean isVolatile() {
* without any compression method).
*
* @param newBodyArray is the prepared (gzipped, etc, as necessary) content of the new response
* @param newBody is the new message content - the human readable part
* @param newBody is the new message content - the human-readable part
*/
@Override
public void setNewBody(byte[] newBodyArray, String newBody) {
Expand All @@ -120,4 +121,12 @@ public String getProxyRequestLine() {
public void setProxyRequestLine(final String proxyRequestLine) {
this.proxyRequestLine = proxyRequestLine;
}

public String getReasonPhrase() {
return reasonPhrase;
}

public void setReasonPhrase(String reasonPhrase) {
this.reasonPhrase = reasonPhrase;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,3 @@ dependencies {
testImplementation group: 'com.nixxcode.jvmbrotli', name: 'jvmbrotli-win32-x86-amd64', version: '0.2.0'
testImplementation group: 'com.nixxcode.jvmbrotli', name: 'jvmbrotli-linux-x86-amd64', version: '0.2.0'
}

test.useJUnit()
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public WilmaHttpResponse transformResponse(final MitmJavaProxyHttpResponse respo
boolean isResponseVolatile = response.isResponseVolatile();
WilmaHttpResponse result = responseFactory.createNewWilmaHttpResponse(isResponseVolatile);
if (response.getRawResponse() != null) {
result.setReasonPhrase(response.getRawResponse().getStatusLine().getReasonPhrase());
for (Header header : response.getRawResponse().getAllHeaders()) {
result.addHeader(header.getName(), header.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.epam.wilma.domain.http.header.HttpHeaderChange;
import com.epam.wilma.domain.http.header.HttpHeaderToBeUpdated;
import org.apache.http.Header;
import org.apache.http.StatusLine;
import website.magyar.mitm.proxy.http.MitmJavaProxyHttpResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -95,8 +94,13 @@ private void updateBodyPart(final MitmJavaProxyHttpResponse browserMobHttpRespon
try {
byte[] newBody = wilmaResponse.getNewBody();
browserMobHttpResponse.setBody(newBody);
browserMobHttpResponse.getRawResponse().setStatusCode(wilmaResponse.getStatusCode());
//content-type
browserMobHttpResponse.setContentType(wilmaResponse.getContentType());
//status code
browserMobHttpResponse.setStatus(wilmaResponse.getStatusCode());
browserMobHttpResponse.getRawResponse().setStatusCode(wilmaResponse.getStatusCode());
//reason-phrase
browserMobHttpResponse.setReasonPhrase(wilmaResponse.getReasonPhrase());
} catch (IOException e) {
//ups, were unable to set new response correctly ...
logger.warn("Message ont-the-fly update was failed for message: {}", wilmaResponse.getWilmaMessageId(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.apache.http.Header;

/**
* This class is originated from project: https://github.com/tkohegyi/mitmJavaProxy
* This class is originated from project: <a href="https://github.com/tkohegyi/mitmJavaProxy">tkohegyi/mitmJavaProxy</a>
*
* @author Tamas_Kohegyi
*/
Expand Down Expand Up @@ -38,25 +38,31 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
ResponseInfo other = (ResponseInfo) obj;
if (body == null) {
if (other.body != null)
if (other.body != null) {
return false;
} else if (!body.equals(other.body))
return false;
}
} else {
if (!body.equals(other.body)) {
return false;
}
}
return statusCode == other.statusCode;
}

@Override
public String toString() {
return "ResponseInfo [statusCode=" + statusCode + ", body=" + body
+ "]";
return "ResponseInfo [statusCode=" + statusCode + ", body=" + body + "]";
}

public String getContentEncoding() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ public void testTransformShouldSetRequestLineAndProxyRequestLine() {
verify(response).setProxyRequestLine(REQUEST_PROXY_LINE);
}

@Test
public void testTransformShouldSetStatusCodeAndReasonPhrase() {
//GIVEN
int statusCode = 303;
String reasonPhrase = "WILMA";
setMocksForMessageContent();
setMocksForMessageConfiguration();
given(browserMobHttpResponse.getStatus()).willReturn(statusCode);
given(browserMobHttpResponse.getRawResponse().getStatusLine().getReasonPhrase()).willReturn(reasonPhrase);
//WHEN
underTest.transformResponse(browserMobHttpResponse);
//THEN
verify(response).setStatusCode(statusCode);
verify(response).setReasonPhrase(reasonPhrase);
}

private void setMocksForMessageConfiguration() {
MessagePropertyDTO propertiesDTO = new MessagePropertyDTO(PREFIX);
Expand All @@ -171,6 +186,7 @@ private void setMocksForMessageContent() {
given(browserMobHttpResponse.getRequestHeaders()).willReturn(requestHeaders);
given(browserMobHttpResponse.getBodyString()).willReturn(RESPONSE_BODY);
given(browserMobHttpResponse.getStatus()).willReturn(200);
given(browserMobHttpResponse.getContentType()).willReturn(CONTENT_TYPE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public void testUpdateResponseShouldUpdateStatusCodePart() {
//WHEN
underTest.updateResponse(browserMobHttpResponse, wilmaHttpResponse);
//THEN
verify(browserMobHttpResponse).setStatus(0);
verify(browserMobHttpResponse.getRawResponse()).setStatusCode(0);
}

Expand All @@ -137,4 +138,17 @@ public void testUpdateResponseShouldUpdateContentTypePart() {
verify(browserMobHttpResponse).setContentType("html");
}

@Test
public void testUpdateResponseShouldUpdateReasonPhrasePart() {
//GIVEN
given(browserMobHttpResponse.getRawResponse()).willReturn(httpResponse);
given(wilmaHttpResponse.getStatusCode()).willReturn(0);
given(wilmaHttpResponse.getReasonPhrase()).willReturn("phrase");
given(wilmaHttpResponse.isVolatile()).willReturn(true);
//WHEN
underTest.updateResponse(browserMobHttpResponse, wilmaHttpResponse);
//THEN
verify(browserMobHttpResponse).setReasonPhrase("phrase");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
/**
* Generates a JSON response from the given template resource by using
* parameters from the request. Properties in the templates with JsonPath value
* will be replaces with the evaluated expression value (e.g.
* {@code"$.persons[0].name"}).
* will be replaced with the evaluated expression value (e.g. {@code "$.persons[0].name"}).
*
* @author Balazs_Berkes
*/
Expand All @@ -51,7 +50,7 @@ public class JsonResponseFormatter implements ResponseFormatter {
@Override
public byte[] formatResponse(final WilmaHttpRequest wilmaRequest, final HttpServletResponse resp,
final byte[] templateResource, final ParameterList params) {
JsonElement response = new JsonParser().parse(new String(templateResource, StandardCharsets.UTF_8));
JsonElement response = JsonParser.parseString(new String(templateResource, StandardCharsets.UTF_8));

new NonRecursiveJsonTreeEvaluator(wilmaRequest.getBody()).replaceAllNonRecursive(response);

Expand Down Expand Up @@ -96,15 +95,15 @@ public void replaceAllNonRecursive(final JsonElement node) {
}

/**
* Replaces the current node value if needed.
* Replaces the current node value if needed. Node type cannot be changed.
* @param parent parent node
* @param key name of the current node
* @param value the current node
*/
protected void replaceJsonPath(final JsonObject parent, final String key, final JsonPrimitive value) {
if (isExpression(value.getAsString())) {
Object requestValue = JsonPath.read(source, value.getAsString());
//can be Object, Boolean, Number, Character, String - we don't handle the Object case
//can be Boolean, Number, String - we don't handle the Object and Character cases
if (requestValue instanceof Boolean) {
parent.add(key, new JsonPrimitive((Boolean)requestValue));
}
Expand All @@ -114,9 +113,6 @@ protected void replaceJsonPath(final JsonObject parent, final String key, final
if (requestValue instanceof String) {
parent.add(key, new JsonPrimitive((String)requestValue));
}
if (requestValue instanceof Character) {
parent.add(key, new JsonPrimitive((Character) requestValue));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void testFormatTemplate() {

byte[] formattedResponse = underTest.formatResponse(wilmaRequest, response, template.getBytes(), null);

assertEquals(whitespaceFree(new String(formattedResponse)), whitespaceFree(expected));
assertEquals(whitespaceFree(expected), whitespaceFree(new String(formattedResponse)));
}

private String whitespaceFree(String string) {
Expand All @@ -75,6 +75,8 @@ private String refundRequest() {
+ " \"number\":\"1\",\n"
+ " \"name\":\"John Smith\",\n"
+ " \"pet\":\"cat\",\n"
+ " \"bool\":true,\n"
+ " \"num\":7,\n"
+ " \"email\":\"[email protected]\"\n"
+ " }"
+ " ]\n"
Expand All @@ -88,7 +90,9 @@ private String refundTemplate() {
+ " {\n"
+ " \"id\":\"$.request[0].id\",\n"
+ " \"number\":\"$.request[0].number\",\n"
+ " \"pet\":\"$.request[0].pet\"\n"
+ " \"pet\":\"$.request[0].pet\",\n"
+ " \"bool2\": \"$.request[0].bool\",\n"
+ " \"num2\": \"$.request[0].num\"\n"
+ " }\n"
+ " ]\n"
+ "}";
Expand All @@ -101,14 +105,18 @@ private String refundExpectedResponse() {
+ " {\n"
+ " \"id\":\"103\",\n"
+ " \"number\":\"1\",\n"
+ " \"pet\":\"cat\"\n"
+ " \"pet\":\"cat\",\n"
+ " \"bool2\":true,\n"
+ " \"num2\":7\n"
+ " }\n"
+ " ]"
+ "}";
}

private String gotRequest() {
return "{\n" + " \"characters\":[\n" + " {\n"
+ " \"bool\":true,\n"
+ " \"num\": 7,\n"
+ " \"name\":\"Jaime Lannister\",\n"
+ " \"title\":\"The Kingslayer\",\n"
+ " \"location\":\"King's Landing\"\n" + " },\n"
Expand Down
Loading

0 comments on commit 15112c3

Please sign in to comment.