'Disable Transfer-Encoding chunked in wiremock standalone server
I am running wiremock standalone using wiremockserver.
The application does not work in PCF because of the header Transfer-Encoding: chunked.
(If this header is present then in PCF I get the error 502 Bad Gateway: Registered endpoint failed to handle the request. and in headers x-cf-routererror endpoint_failure endpoint_failure (net/http: http/1.x transport connection broken: too many transfer encodings: ["chunked" "chunked"]).)
I don't want this header so I tried to disable the chunked encoding in wiremock:
@SpringBootApplication
public class MockApplication implements CommandLineRunner {
private final int serverPort;
private final ResourceLoader resourceLoader;
public MockApplication(@Value("${server.port}") final int serverPort, final ResourceLoader resourceLoader) {
this.serverPort = serverPort;
this.resourceLoader = resourceLoader;
}
public static void main(final String[] args) {
SpringApplication.run(MockApplication.class, args); //start springboot application
}
@Override
public void run(final String... args) {
final WireMockServer wireMockServer = new WireMockServer(options().port(serverPort+2)
.useChunkedTransferEncoding(Options.ChunkedEncodingPolicy.NEVER)
.extensions(new ResponseTemplateTransformer(false)));
wireMockServer.start(); //start wiremock server
}
Spring boot app posts data to wiremock app using restTemplate. sample request:
{
"request": {
"url": "/some-wiremock-endpoint",
"method": "POST",
"bodyPatterns": [
{
"contains": "12345"
}
]
},
"response": {
"status": 200,
"headers": null,
"body": "{\"books\":[{\"book_number\":\"12345\",\"book_code\":\"FICTION\"}]}"
}
}
When the customer uses http://localhost:8080/some-wiremock-endpoint then the springboot app connects to wiremock url http://localhost:8082/some-wiremock-endpoint to retrieve the stub data from wiremock server:
ResponseEntity<String> exchange = null;
try {
exchange = restTemplate.exchange(wiremockUrlAndUri, HttpMethod.POST, request, String.class);
//http://localhost:8082/some-wiremock-endpoint is the wiremockUrlAndUri value in this case.
When I see exchange.getHeaders() then I still see Transfer-Encoding: chunked header.
How do I disable this header in Springboot application?
Solution 1:[1]
I changed the code a bit. Now it works :) What do you think of it?
using System;
using System.Drawing;
using System.Windows.Forms;
namespace App51
{
public partial class Form1 : Form
{
Form2 frm2;
Form3 frm3;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
IsMdiContainer = true;
if (control is MdiClient)
{
control.BackColor = Color.DeepSkyBlue;
break;
}
}
private void abrirForm2ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (frm2 != null)
{
if (frm2.Visible == true)
{
frm2.WindowState = FormWindowState.Normal;
frm2.BringToFront();
frm2.Activate();
}
else
{
frm2 = new Form2();
frm2.FormClosed += delegate { frm2 = null; };
frm2.MdiParent = this;
frm2.Show();
}
}
else
{
frm2 = new Form2();
frm2.FormClosed += delegate { frm2 = null; };
frm2.MdiParent = this;
frm2.Show();
}
}
private void abrirForm3ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (frm3 != null)
{
if (frm3.Visible == true)
{
frm3.WindowState = FormWindowState.Normal;
frm3.BringToFront();
frm3.Activate();
}
else
{
frm3 = new Form3();
frm3.FormClosed += delegate { frm3 = null; };
frm3.MdiParent = this;
frm3.Show();
}
}
else
{
frm3 = new Form3();
frm3.FormClosed += delegate { frm3 = null; };
frm3.MdiParent = this;
frm3.Show();
}
}
} }
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
