Skip to content

Commit cedc33a

Browse files
committed
Stream data using a buffer, not byte by byte.
Updated some lib versions & docs.
1 parent 2ff6d51 commit cedc33a

File tree

5 files changed

+35
-30
lines changed

5 files changed

+35
-30
lines changed

httpproxy.iml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@
66
<content url="file://$MODULE_DIR$">
77
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
88
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
9+
<excludeFolder url="file://$MODULE_DIR$/.clover" />
910
<excludeFolder url="file://$MODULE_DIR$/target" />
1011
</content>
12+
<orderEntry type="library" name="Clover IDEA Plugin" level="application" />
1113
<orderEntry type="inheritedJdk" />
1214
<orderEntry type="sourceFolder" forTests="false" />
13-
<orderEntry type="library" name="Maven: javax.servlet:servlet-api:2.3" level="project" />
14-
<orderEntry type="library" name="Maven: commons-fileupload:commons-fileupload:1.2.1" level="project" />
15+
<orderEntry type="library" name="Maven: javax.servlet:servlet-api:2.4" level="project" />
16+
<orderEntry type="library" name="Maven: commons-fileupload:commons-fileupload:1.2.2" level="project" />
1517
<orderEntry type="library" name="Maven: commons-httpclient:commons-httpclient:3.1" level="project" />
1618
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.0.4" level="project" />
1719
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.2" level="project" />
1820
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.8.2" level="project" />
19-
<orderEntry type="library" scope="TEST" name="Maven: org.apache.httpcomponents:httpclient:tests:4.1.1" level="project" />
20-
<orderEntry type="library" scope="TEST" name="Maven: org.apache.httpcomponents:httpcore:4.1" level="project" />
21+
<orderEntry type="library" scope="TEST" name="Maven: org.apache.httpcomponents:httpclient:tests:4.1.2" level="project" />
22+
<orderEntry type="library" scope="TEST" name="Maven: org.apache.httpcomponents:httpcore:4.1.2" level="project" />
2123
<orderEntry type="library" scope="TEST" name="Maven: httpunit:httpunit:1.7" level="project" />
2224
<orderEntry type="library" scope="TEST" name="Maven: jtidy:jtidy:4aug2000r7-dev" level="project" />
2325
</component>

httpproxy.ipr

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -886,15 +886,15 @@
886886
<root url="jar://$M2_REPO$/commons-codec/commons-codec/1.2/commons-codec-1.2-sources.jar!/" />
887887
</SOURCES>
888888
</library>
889-
<library name="Maven: commons-fileupload:commons-fileupload:1.2.1">
889+
<library name="Maven: commons-fileupload:commons-fileupload:1.2.2">
890890
<CLASSES>
891-
<root url="jar://$M2_REPO$/commons-fileupload/commons-fileupload/1.2.1/commons-fileupload-1.2.1.jar!/" />
891+
<root url="jar://$M2_REPO$/commons-fileupload/commons-fileupload/1.2.2/commons-fileupload-1.2.2.jar!/" />
892892
</CLASSES>
893893
<JAVADOC>
894-
<root url="jar://$M2_REPO$/commons-fileupload/commons-fileupload/1.2.1/commons-fileupload-1.2.1-javadoc.jar!/" />
894+
<root url="jar://$M2_REPO$/commons-fileupload/commons-fileupload/1.2.2/commons-fileupload-1.2.2-javadoc.jar!/" />
895895
</JAVADOC>
896896
<SOURCES>
897-
<root url="jar://$M2_REPO$/commons-fileupload/commons-fileupload/1.2.1/commons-fileupload-1.2.1-sources.jar!/" />
897+
<root url="jar://$M2_REPO$/commons-fileupload/commons-fileupload/1.2.2/commons-fileupload-1.2.2-sources.jar!/" />
898898
</SOURCES>
899899
</library>
900900
<library name="Maven: commons-httpclient:commons-httpclient:3.1">
@@ -930,15 +930,15 @@
930930
<root url="jar://$M2_REPO$/httpunit/httpunit/1.7/httpunit-1.7-sources.jar!/" />
931931
</SOURCES>
932932
</library>
933-
<library name="Maven: javax.servlet:servlet-api:2.3">
933+
<library name="Maven: javax.servlet:servlet-api:2.4">
934934
<CLASSES>
935-
<root url="jar://$M2_REPO$/javax/servlet/servlet-api/2.3/servlet-api-2.3.jar!/" />
935+
<root url="jar://$M2_REPO$/javax/servlet/servlet-api/2.4/servlet-api-2.4.jar!/" />
936936
</CLASSES>
937937
<JAVADOC>
938-
<root url="jar://$M2_REPO$/javax/servlet/servlet-api/2.3/servlet-api-2.3-javadoc.jar!/" />
938+
<root url="jar://$M2_REPO$/javax/servlet/servlet-api/2.4/servlet-api-2.4-javadoc.jar!/" />
939939
</JAVADOC>
940940
<SOURCES>
941-
<root url="jar://$M2_REPO$/javax/servlet/servlet-api/2.3/servlet-api-2.3-sources.jar!/" />
941+
<root url="jar://$M2_REPO$/javax/servlet/servlet-api/2.4/servlet-api-2.4-sources.jar!/" />
942942
</SOURCES>
943943
</library>
944944
<library name="Maven: jtidy:jtidy:4aug2000r7-dev">
@@ -963,26 +963,26 @@
963963
<root url="jar://$M2_REPO$/junit/junit/4.8.2/junit-4.8.2-sources.jar!/" />
964964
</SOURCES>
965965
</library>
966-
<library name="Maven: org.apache.httpcomponents:httpclient:tests:4.1.1">
966+
<library name="Maven: org.apache.httpcomponents:httpclient:tests:4.1.2">
967967
<CLASSES>
968-
<root url="jar://$M2_REPO$/org/apache/httpcomponents/httpclient/4.1.1/httpclient-4.1.1-tests.jar!/" />
968+
<root url="jar://$M2_REPO$/org/apache/httpcomponents/httpclient/4.1.2/httpclient-4.1.2-tests.jar!/" />
969969
</CLASSES>
970970
<JAVADOC>
971-
<root url="jar://$M2_REPO$/org/apache/httpcomponents/httpclient/4.1.1/httpclient-4.1.1-test-javadoc.jar!/" />
971+
<root url="jar://$M2_REPO$/org/apache/httpcomponents/httpclient/4.1.2/httpclient-4.1.2-test-javadoc.jar!/" />
972972
</JAVADOC>
973973
<SOURCES>
974-
<root url="jar://$M2_REPO$/org/apache/httpcomponents/httpclient/4.1.1/httpclient-4.1.1-test-sources.jar!/" />
974+
<root url="jar://$M2_REPO$/org/apache/httpcomponents/httpclient/4.1.2/httpclient-4.1.2-test-sources.jar!/" />
975975
</SOURCES>
976976
</library>
977-
<library name="Maven: org.apache.httpcomponents:httpcore:4.1">
977+
<library name="Maven: org.apache.httpcomponents:httpcore:4.1.2">
978978
<CLASSES>
979-
<root url="jar://$M2_REPO$/org/apache/httpcomponents/httpcore/4.1/httpcore-4.1.jar!/" />
979+
<root url="jar://$M2_REPO$/org/apache/httpcomponents/httpcore/4.1.2/httpcore-4.1.2.jar!/" />
980980
</CLASSES>
981981
<JAVADOC>
982-
<root url="jar://$M2_REPO$/org/apache/httpcomponents/httpcore/4.1/httpcore-4.1-javadoc.jar!/" />
982+
<root url="jar://$M2_REPO$/org/apache/httpcomponents/httpcore/4.1.2/httpcore-4.1.2-javadoc.jar!/" />
983983
</JAVADOC>
984984
<SOURCES>
985-
<root url="jar://$M2_REPO$/org/apache/httpcomponents/httpcore/4.1/httpcore-4.1-sources.jar!/" />
985+
<root url="jar://$M2_REPO$/org/apache/httpcomponents/httpcore/4.1.2/httpcore-4.1.2-sources.jar!/" />
986986
</SOURCES>
987987
</library>
988988
</component>

pom.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515

1616
<dependencies>
1717

18+
<!-- FYI tomcat 5.5 & beyond -->
1819
<dependency>
1920
<groupId>javax.servlet</groupId>
2021
<artifactId>servlet-api</artifactId>
21-
<version>2.3</version>
22+
<version>2.4</version>
2223
</dependency>
2324
<dependency>
2425
<groupId>commons-fileupload</groupId>
2526
<artifactId>commons-fileupload</artifactId>
26-
<version>1.2.1</version>
27+
<version>1.2.2</version>
2728
</dependency>
2829
<dependency>
2930
<groupId>commons-httpclient</groupId>
@@ -41,7 +42,7 @@
4142
<dependency>
4243
<groupId>org.apache.httpcomponents</groupId>
4344
<artifactId>httpclient</artifactId>
44-
<version>4.1.1</version>
45+
<version>4.1.2</version>
4546
<classifier>tests</classifier>
4647
<scope>test</scope>
4748
</dependency>

src/main/java/org/mitre/dsmiley/httpproxy/ProxyServlet.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.commons.fileupload.FileUploadException;
2121
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
2222
import org.apache.commons.fileupload.servlet.ServletFileUpload;
23+
import org.apache.commons.fileupload.util.Streams;
2324
import org.apache.commons.httpclient.Header;
2425
import org.apache.commons.httpclient.HttpClient;
2526
import org.apache.commons.httpclient.HttpMethod;
@@ -47,6 +48,7 @@
4748
* <br />
4849
* History (newest on top):<br/>
4950
* <ul>
51+
* <li>Performance: String data using a buffer, not byte by byte</li>
5052
* <li>Feature: "log" parameter to log requests</li>
5153
* <li>Bug fix: init() should call super.init()</li>
5254
* <li>Bug fix: PATH_INFO could be null</li>
@@ -336,12 +338,8 @@ private void executeProxyRequest(
336338

337339
// Send the content to the client
338340
InputStream inputStreamProxyResponse = httpMethodProxyRequest.getResponseBodyAsStream();
339-
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStreamProxyResponse);
340341
OutputStream outputStreamClientResponse = httpServletResponse.getOutputStream();
341-
int intNextByte;
342-
while ((intNextByte = bufferedInputStream.read()) != -1) {
343-
outputStreamClientResponse.write(intNextByte);
344-
}
342+
Streams.copy(inputStreamProxyResponse,outputStreamClientResponse,false);//copy; don't close streams
345343
}
346344

347345
public String getServletInfo() {

src/test/java/org/mitre/dsmiley/httpproxy/ProxyServletTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@
2525
public class ProxyServletTest
2626
{
2727

28+
/**
29+
* From Apache httpcomponents/httpclient. Note httpunit has a similar thing called PseudoServlet but it is
30+
* not as good since you can't even make it echo the request back.
31+
*/
2832
private LocalTestServer localTestServer;
33+
34+
/** From Meterware httpunit. */
2935
private ServletRunner servletRunner;
3036

3137
@Before
@@ -34,14 +40,12 @@ public void setUp() throws Exception {
3440
localTestServer.start();
3541

3642
servletRunner = new ServletRunner();
37-
//servletRunner.
3843
Properties params = new Properties();
3944
params.setProperty(ProxyServlet.P_PROXY_HOST, "localhost");
4045
params.setProperty(ProxyServlet.P_PROXY_PORT, localTestServer.getServiceAddress().getPort()+"");
4146
params.setProperty(ProxyServlet.P_PROXY_PATH, "/targetPath");//dummy
4247
params.setProperty(ProxyServlet.P_LOG, "true");
4348
servletRunner.registerServlet("/proxyMe/*", ProxyServlet.class.getName(), params);//also matches /proxyMe (no path info)
44-
4549
}
4650

4751
@After

0 commit comments

Comments
 (0)