entity.setContentType(request.getContentType());
((HttpEntityEnclosingRequest) method).setEntity(entity);
}
// for this create ui server and port, properties.
JProxyServletWsdlMonitorMessageExchange capturedData = new JProxyServletWsdlMonitorMessageExchange(project);
capturedData.setRequestHost(httpRequest.getServerName());
capturedData.setRequestMethod(httpRequest.getMethod());
capturedData.setRequestHeader(httpRequest);
capturedData.setHttpRequestParameters(httpRequest);
capturedData.setQueryParameters(httpRequest.getQueryString());
capturedData.setTargetURL(httpRequest.getRequestURL().toString());
// CaptureInputStream capture = new CaptureInputStream( httpRequest.getInputStream() );
// check connection header
String connectionHeader = httpRequest.getHeader("Connection");
if (connectionHeader != null) {
connectionHeader = connectionHeader.toLowerCase();
if (!connectionHeader.contains("keep-alive") && !connectionHeader.contains("close")) {
connectionHeader = null;
}
}
// copy headers
boolean xForwardedFor = false;
@SuppressWarnings("unused")
Enumeration<?> headerNames = httpRequest.getHeaderNames();
while (headerNames.hasMoreElements()) {
String hdr = (String) headerNames.nextElement();
String lhdr = hdr.toLowerCase();
if (dontProxyHeaders.contains(lhdr)) {
continue;
}
if (connectionHeader != null && connectionHeader.contains(lhdr)) {
continue;
}
Enumeration<?> vals = httpRequest.getHeaders(hdr);
while (vals.hasMoreElements()) {
String val = (String) vals.nextElement();
if (val != null) {
method.setHeader(lhdr, val);
xForwardedFor |= "X-Forwarded-For".equalsIgnoreCase(hdr);
}
}
}
// Proxy headers
method.setHeader("Via", "SoapUI Monitor");
if (!xForwardedFor) {
method.addHeader("X-Forwarded-For", request.getRemoteAddr());
}
StringBuffer url = new StringBuffer("http://");
url.append(httpRequest.getServerName());
if (httpRequest.getServerPort() != 80) {
url.append(":" + httpRequest.getServerPort());
}
if (httpRequest.getServletPath() != null) {
url.append(httpRequest.getServletPath());
try {
method.setURI(new java.net.URI(url.toString().replaceAll(" ", "%20")));
} catch (URISyntaxException e) {
SoapUI.logError(e);
}
if (httpRequest.getQueryString() != null) {
url.append("?" + httpRequest.getQueryString());
try {
method.setURI(new java.net.URI(url.toString()));
} catch (URISyntaxException e) {
SoapUI.logError(e);
}
}
}
method.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS, false);
setProtocolversion(method, request.getProtocol());
ProxyUtils.setForceDirectConnection(method.getParams());
listenerCallBack.fireBeforeProxy(project, request, response, method);
if (settings.getBoolean(LaunchForm.SSLTUNNEL_REUSESTATE)) {
if (httpState == null) {
httpState = new BasicHttpContext();
}
HttpClientSupport.execute(method, httpState);
} else {
HttpClientSupport.execute(method);
}
// wait for transaction to end and store it.
capturedData.stopCapture();
capturedData.setRequest(requestBody == null ? null : requestBody.toByteArray());
capturedData.setRawResponseBody(method.getResponseBody());
capturedData.setResponseHeader(method.getHttpResponse());
capturedData.setRawRequestData(getRequestToBytes(request.toString(), requestBody));
capturedData.setRawResponseData(getResponseToBytes(method, capturedData.getRawResponseBody()));
byte[] decompressedResponseBody = method.getDecompressedResponseBody();
capturedData.setResponseContent(decompressedResponseBody != null ? new String(decompressedResponseBody) : "");
capturedData.setResponseStatusCode(method.hasHttpResponse() ? method.getHttpResponse().getStatusLine()
.getStatusCode() : null);
capturedData.setResponseStatusLine(method.hasHttpResponse() ? method.getHttpResponse().getStatusLine()
.toString() : null);
listenerCallBack.fireAfterProxy(project, request, response, method, capturedData);
((HttpServletResponse) response).setStatus(method.hasHttpResponse() ? method.getHttpResponse()
.getStatusLine().getStatusCode() : null);
if (!response.isCommitted()) {
StringToStringsMap responseHeaders = capturedData.getResponseHeaders();
// capturedData = null;
// copy headers to response
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
for (Map.Entry<String, List<String>> headerEntry : responseHeaders.entrySet()) {
for (String header : headerEntry.getValue()) {
httpServletResponse.addHeader(headerEntry.getKey(), header);
}
}
if (capturedData.getRawResponseBody() != null) {
IO.copy(new ByteArrayInputStream(capturedData.getRawResponseBody()), httpServletResponse.getOutputStream());
}
}
synchronized (this) {
if (contentTypeMatches(method)) {