Source Code Cross Referenced for ExcludedProxyTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » luni » tests » java » net » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.luni.tests.java.net 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        package org.apache.harmony.luni.tests.java.net;
019:
020:        import java.io.IOException;
021:        import java.io.InputStream;
022:        import java.io.OutputStream;
023:        import java.net.Socket;
024:        import java.net.InetSocketAddress;
025:        import java.net.Proxy;
026:        import java.net.SocketAddress;
027:        import java.net.URL;
028:        import java.net.URLConnection;
029:
030:        import tests.support.Support_Configuration;
031:        import tests.support.resource.Support_Resources;
032:        import junit.framework.TestCase;
033:
034:        /*
035:         * This test is designed for collecting all the testcases which needs a proxy
036:         * server. They will be moved to corresponding test class when ProxyHandler of
037:         * Jetty is ready in the future.
038:         * 
039:         */
040:
041:        public class ExcludedProxyTest extends TestCase {
042:            /**
043:             * @tests java.net.HttpURLConnection#usingProxy()
044:             */
045:            public void test_usingProxy() throws Exception {
046:                try {
047:                    System.setProperty("http.proxyHost",
048:                            Support_Configuration.ProxyServerTestHost);
049:
050:                    URL u1 = new URL("http://"
051:                            + Support_Configuration.HomeAddress);
052:                    URLConnection conn1 = u1.openConnection();
053:                    conn1.getInputStream();
054:
055:                    boolean exception = false;
056:                    try {
057:                        System.setProperty("http.proxyPort", "81");
058:                        URL u3 = new URL("http://"
059:                                + Support_Configuration.InetTestAddress);
060:                        URLConnection conn3 = u3.openConnection();
061:                        conn3.getInputStream();
062:                        fail("Should throw IOException");
063:                    } catch (IOException e) {
064:                        // expected
065:                    }
066:
067:                    System.setProperty("http.proxyPort", "80");
068:
069:                    URL u2 = new URL("http://"
070:                            + Support_Configuration.ProxyServerTestHost
071:                            + "/cgi-bin/test.pl");
072:                    java.net.HttpURLConnection conn2 = (java.net.HttpURLConnection) u2
073:                            .openConnection();
074:                    conn2.setDoOutput(true);
075:                    conn2.setRequestMethod("POST");
076:                    OutputStream out2 = conn2.getOutputStream();
077:                    String posted2 = "this is a test";
078:                    out2.write(posted2.getBytes());
079:                    out2.close();
080:                    conn2.getResponseCode();
081:                    InputStream is2 = conn2.getInputStream();
082:                    String response2 = "";
083:                    byte[] b2 = new byte[1024];
084:                    int count2 = 0;
085:                    while ((count2 = is2.read(b2)) > 0)
086:                        response2 += new String(b2, 0, count2);
087:                    assertTrue("Response to POST method invalid", response2
088:                            .equals(posted2));
089:
090:                    String posted4 = "just a test";
091:                    URL u4 = new URL("http://"
092:                            + Support_Configuration.ProxyServerTestHost
093:                            + "/cgi-bin/test.pl");
094:                    java.net.HttpURLConnection conn4 = (java.net.HttpURLConnection) u4
095:                            .openConnection();
096:                    conn4.setDoOutput(true);
097:                    conn4.setRequestMethod("POST");
098:                    conn4.setRequestProperty("Content-length", String
099:                            .valueOf(posted4.length()));
100:                    OutputStream out = conn4.getOutputStream();
101:                    out.write(posted4.getBytes());
102:                    out.close();
103:                    conn4.getResponseCode();
104:                    InputStream is = conn4.getInputStream();
105:                    String response = "";
106:                    byte[] b4 = new byte[1024];
107:                    int count = 0;
108:                    while ((count = is.read(b4)) > 0)
109:                        response += new String(b4, 0, count);
110:                    assertTrue("Response to POST method invalid", response
111:                            .equals(posted4));
112:                } finally {
113:                    System.setProperties(null);
114:                }
115:            }
116:
117:            /**
118:             * @tests java.net.SocketImpl#SocketImpl()
119:             */
120:            public void test_Constructor() {
121:                try {
122:                    try {
123:                        System.setProperty("socksProxyHost",
124:                                Support_Configuration.SocksServerTestHost);
125:                        System
126:                                .setProperty(
127:                                        "socksProxyPort",
128:                                        String
129:                                                .valueOf(Support_Configuration.SocksServerTestPort));
130:                        Socket s = new Socket(
131:                                Support_Configuration.HomeAddress, 80);
132:                        OutputStream os = s.getOutputStream();
133:                        os.write("GET / HTTP/1.0\r\n\r\n".getBytes());
134:                        s.getInputStream();
135:                    } catch (IOException e) {
136:                        fail("Could not open socket: "
137:                                + Support_Configuration.HomeAddress + " " + e);
138:                    }
139:                    boolean exception = false;
140:                    try {
141:                        System.setProperty("socksProxyHost",
142:                                Support_Configuration.SocksServerTestHost);
143:                        System
144:                                .setProperty(
145:                                        "socksProxyPort",
146:                                        String
147:                                                .valueOf(Support_Configuration.SocksServerTestPort + 1));
148:                        Socket s = new Socket(
149:                                Support_Configuration.HomeAddress, 80);
150:                        OutputStream os = s.getOutputStream();
151:                        os.write("GET / HTTP/1.0\r\n\r\n".getBytes());
152:                        s.getInputStream();
153:                    } catch (IOException e) {
154:                        exception = true;
155:                    }
156:                    assertTrue("Exception should have been thrown", exception);
157:                } finally {
158:                    System.setProperties(null);
159:                }
160:            }
161:
162:            /**
163:             * @tests java.net.URL#openConnection(Proxy)
164:             */
165:            public void test_openConnectionLjava_net_Proxy() throws IOException {
166:                SocketAddress addr1 = new InetSocketAddress(
167:                        Support_Configuration.ProxyServerTestHost, 808);
168:                SocketAddress addr2 = new InetSocketAddress(
169:                        Support_Configuration.ProxyServerTestHost, 1080);
170:                Proxy proxy1 = new Proxy(Proxy.Type.HTTP, addr1);
171:                Proxy proxy2 = new Proxy(Proxy.Type.SOCKS, addr2);
172:                Proxy proxyList[] = { proxy1, proxy2 };
173:                for (int i = 0; i < proxyList.length; ++i) {
174:                    String posted = "just a test";
175:                    URL u = new URL("http://"
176:                            + Support_Configuration.ProxyServerTestHost
177:                            + "/cgi-bin/test.pl");
178:                    java.net.HttpURLConnection conn = (java.net.HttpURLConnection) u
179:                            .openConnection(proxyList[i]);
180:                    conn.setDoOutput(true);
181:                    conn.setRequestMethod("POST");
182:                    conn.setRequestProperty("Content-length", String
183:                            .valueOf(posted.length()));
184:                    OutputStream out = conn.getOutputStream();
185:                    out.write(posted.getBytes());
186:                    out.close();
187:                    conn.getResponseCode();
188:                    InputStream is = conn.getInputStream();
189:                    String response = "";
190:                    byte[] b = new byte[1024];
191:                    int count = 0;
192:                    while ((count = is.read(b)) > 0) {
193:                        response += new String(b, 0, count);
194:                    }
195:                    assertTrue("Response to POST method invalid", response
196:                            .equals(posted));
197:                }
198:
199:                URL httpUrl = new URL("http://abc.com");
200:                URL jarUrl = new URL("jar:"
201:                        + Support_Resources
202:                                .getResourceURL("/JUC/lf.jar!/plus.bmp"));
203:                URL ftpUrl = new URL("ftp://"
204:                        + Support_Configuration.FTPTestAddress + "/nettest.txt");
205:                URL fileUrl = new URL("file://abc");
206:                URL[] urlList = { httpUrl, jarUrl, ftpUrl, fileUrl };
207:                for (int i = 0; i < urlList.length; ++i) {
208:                    try {
209:                        urlList[i].openConnection(null);
210:                    } catch (IllegalArgumentException iae) {
211:                        // expected
212:                    }
213:                }
214:                // should not throw exception
215:                fileUrl.openConnection(Proxy.NO_PROXY);
216:            }
217:        }
w__ww_.___j___av__a_2__s_._com__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.