Index: modules/luni/src/test/java.injected/java/net/HttpURLConnectionTest.java =================================================================== --- modules/luni/src/test/java.injected/java/net/HttpURLConnectionTest.java (revision 0) +++ modules/luni/src/test/java.injected/java/net/HttpURLConnectionTest.java (revision 0) @@ -0,0 +1,85 @@ +/* + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package java.net; + +import java.io.IOException; +import java.io.InterruptedIOException; + +import junit.framework.TestCase; + + +/** + * Tests for HTTPURLConnection class constructors and methods. + * + */ +public class HttpURLConnectionTest extends TestCase { + + //http methods will be assembled on the fly to deceive VM + private String pos = "POS"; + private String ge = "GE"; + private String pu = "PU"; + private String t = "T"; + + + //TODO: replace with connection to a mock server + Thread httpServer = new Thread(new Runnable() { + public void run() { + try { + ServerSocket ss = new ServerSocket(port); + try { + ss.accept().close(); + } catch (InterruptedIOException e) { + } finally { + ss.close(); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + }); + private int port = 34567; + + + public void setUp() throws Exception { + super.setUp(); + httpServer.start(); + } + + public void tearDown() throws Exception { + super.tearDown(); + httpServer.interrupt(); + } + + /** + * @tests org.apache.harmony.luni.internal.net.www.http.getOutputStream() + */ + public void testGetOutputStream() throws Exception { + // Regression for HARMONY-482 + HttpURLConnection c = (HttpURLConnection) new URL("http://127.0.0.1:" + + port).openConnection(); + + c.setDoOutput(true); + c.method = pos + t; + c.getOutputStream(); + + c.method = pu + t; + c.getOutputStream(); + + c.method = ge + t; + c.getOutputStream(); + } +} Index: modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java =================================================================== --- modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java (revision 407764) +++ modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java (working copy) @@ -526,7 +526,7 @@ * server. */ public InputStream getErrorStream() { - if (connected && method != "HEAD" && responseCode >= HTTP_BAD_REQUEST) + if (connected && !method.equals("HEAD") && responseCode >= HTTP_BAD_REQUEST) return uis; return null; } @@ -699,12 +699,12 @@ } // they are requesting a stream to write to. This implies a POST method - if (method == "GET") { + if (method.equals("GET")) { method = "POST"; } // If the request method is neither PUT or POST, then you're not writing - if (method != "PUT" && method != "POST") { + if (!method.equals("PUT") && !method.equals("POST")) { throw new ProtocolException(Msg.getString("K008f", method)); } @@ -848,7 +848,7 @@ } } while (getResponseCode() == 100); - if (method == "HEAD" || (responseCode >= 100 && responseCode < 200) + if (method.equals("HEAD") || (responseCode >= 100 && responseCode < 200) || responseCode == HTTP_NO_CONTENT || responseCode == HTTP_NOT_MODIFIED) { closeSocket(); Index: modules/luni/make/common/build.xml =================================================================== --- modules/luni/make/common/build.xml (revision 407730) +++ modules/luni/make/common/build.xml (working copy) @@ -66,6 +66,23 @@ + + + + + + + + + + + + @@ -98,6 +115,7 @@ +