You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by el...@apache.org on 2014/11/14 09:46:47 UTC
[3/3] mina git commit: Added mising Apache headers
Added mising Apache headers
Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/59b7dbab
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/59b7dbab
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/59b7dbab
Branch: refs/heads/2.0
Commit: 59b7dbabce68e400fab6905ca11abcc37672ce3f
Parents: 1d22556
Author: Emmanuel Lécharny <el...@symas.com>
Authored: Fri Nov 14 09:46:22 2014 +0100
Committer: Emmanuel Lécharny <el...@symas.com>
Committed: Fri Nov 14 09:46:22 2014 +0100
----------------------------------------------------------------------
.../org/apache/mina/http/HttpClientEncoder.java | 69 ++++++----
.../mina/http/HttpRequestImplTestCase.java | 127 +++++++++++--------
2 files changed, 117 insertions(+), 79 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina/blob/59b7dbab/mina-http/src/main/java/org/apache/mina/http/HttpClientEncoder.java
----------------------------------------------------------------------
diff --git a/mina-http/src/main/java/org/apache/mina/http/HttpClientEncoder.java b/mina-http/src/main/java/org/apache/mina/http/HttpClientEncoder.java
index 81203fb..26f7994 100644
--- a/mina-http/src/main/java/org/apache/mina/http/HttpClientEncoder.java
+++ b/mina-http/src/main/java/org/apache/mina/http/HttpClientEncoder.java
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.mina.http;
import java.nio.ByteBuffer;
@@ -18,24 +37,24 @@ public class HttpClientEncoder implements ProtocolEncoder {
private static final Logger LOG = LoggerFactory.getLogger(HttpClientCodec.class);
private static final CharsetEncoder ENCODER = Charset.forName("UTF-8").newEncoder();
- public void encode(IoSession session, Object message, ProtocolEncoderOutput out)
- throws Exception {
- LOG.debug("encode {}", message.getClass().getCanonicalName());
- if (message instanceof HttpRequest) {
- LOG.debug("HttpRequest");
- HttpRequest msg = (HttpRequest)message;
- StringBuilder sb = new StringBuilder(msg.getMethod().toString());
- sb.append(" ");
- sb.append(msg.getRequestPath());
- if (!"".equals(msg.getQueryString())) {
- sb.append("?");
- sb.append(msg.getQueryString());
- }
- sb.append(" ");
- sb.append(msg.getProtocolVersion());
- sb.append("\r\n");
+ public void encode(IoSession session, Object message, ProtocolEncoderOutput out)
+ throws Exception {
+ LOG.debug("encode {}", message.getClass().getCanonicalName());
+ if (message instanceof HttpRequest) {
+ LOG.debug("HttpRequest");
+ HttpRequest msg = (HttpRequest)message;
+ StringBuilder sb = new StringBuilder(msg.getMethod().toString());
+ sb.append(" ");
+ sb.append(msg.getRequestPath());
+ if (!"".equals(msg.getQueryString())) {
+ sb.append("?");
+ sb.append(msg.getQueryString());
+ }
+ sb.append(" ");
+ sb.append(msg.getProtocolVersion());
+ sb.append("\r\n");
- for (Map.Entry<String, String> header : msg.getHeaders().entrySet()) {
+ for (Map.Entry<String, String> header : msg.getHeaders().entrySet()) {
sb.append(header.getKey());
sb.append(": ");
sb.append(header.getValue());
@@ -50,19 +69,19 @@ public class HttpClientEncoder implements ProtocolEncoder {
buf.flip();
out.write(buf);
} else if (message instanceof ByteBuffer) {
- LOG.debug("Body");
- out.write(message);
+ LOG.debug("Body");
+ out.write(message);
} else if (message instanceof HttpEndOfContent) {
- LOG.debug("End of Content");
+ LOG.debug("End of Content");
// end of HTTP content
// keep alive ?
- }
+ }
- }
+ }
- public void dispose(IoSession arg0) throws Exception {
- // TODO Auto-generated method stub
+ public void dispose(IoSession arg0) throws Exception {
+ // TODO Auto-generated method stub
- }
+ }
}
http://git-wip-us.apache.org/repos/asf/mina/blob/59b7dbab/mina-http/src/test/java/org/apache/mina/http/HttpRequestImplTestCase.java
----------------------------------------------------------------------
diff --git a/mina-http/src/test/java/org/apache/mina/http/HttpRequestImplTestCase.java b/mina-http/src/test/java/org/apache/mina/http/HttpRequestImplTestCase.java
index ef6a42f..ba3b724 100644
--- a/mina-http/src/test/java/org/apache/mina/http/HttpRequestImplTestCase.java
+++ b/mina-http/src/test/java/org/apache/mina/http/HttpRequestImplTestCase.java
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.mina.http;
import static org.junit.Assert.*;
@@ -12,65 +31,65 @@ import org.junit.Test;
public class HttpRequestImplTestCase {
- @Test
- public void testGetParameterNoParameter() {
- HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/","", null);
- assertNull("p0 doesn't exist", req.getParameter("p0"));
- }
+ @Test
+ public void testGetParameterNoParameter() {
+ HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/","", null);
+ assertNull("p0 doesn't exist", req.getParameter("p0"));
+ }
- @Test
- public void testGetParameterOneEmptyParameter() {
- HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/", "p0=", null);
- assertEquals("p0 is emtpy", "", req.getParameter("p0"));
- assertNull("p1 doesn't exist", req.getParameter("p1"));
- }
+ @Test
+ public void testGetParameterOneEmptyParameter() {
+ HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/", "p0=", null);
+ assertEquals("p0 is emtpy", "", req.getParameter("p0"));
+ assertNull("p1 doesn't exist", req.getParameter("p1"));
+ }
- @Test
- public void testGetParameterOneParameter() {
- HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/", "p0=0", null);
- assertEquals("p0 is '0'", "0", req.getParameter("p0"));
- assertNull("p1 doesn't exist", req.getParameter("p1"));
- }
+ @Test
+ public void testGetParameterOneParameter() {
+ HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/", "p0=0", null);
+ assertEquals("p0 is '0'", "0", req.getParameter("p0"));
+ assertNull("p1 doesn't exist", req.getParameter("p1"));
+ }
- @Test
- public void testGetParameter3Parameters() {
- HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/", "p0=&p1=1&p2=2", null);
- assertEquals("p0 is emtpy", "", req.getParameter("p0"));
- assertEquals("p1 is '1'", "1", req.getParameter("p1"));
- assertEquals("p2 is '2'", "2", req.getParameter("p2"));
- assertNull("p3 doesn't exist", req.getParameter("p3"));
- }
+ @Test
+ public void testGetParameter3Parameters() {
+ HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/", "p0=&p1=1&p2=2", null);
+ assertEquals("p0 is emtpy", "", req.getParameter("p0"));
+ assertEquals("p1 is '1'", "1", req.getParameter("p1"));
+ assertEquals("p2 is '2'", "2", req.getParameter("p2"));
+ assertNull("p3 doesn't exist", req.getParameter("p3"));
+ }
- @Test
- public void testGetParametersNoParameter() {
- HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/", "", null);
- assertTrue("Empty Map", req.getParameters().isEmpty());
- }
+ @Test
+ public void testGetParametersNoParameter() {
+ HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/", "", null);
+ assertTrue("Empty Map", req.getParameters().isEmpty());
+ }
- @Test
- public void testGetParameters3Parameters() {
- HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/","p0=&p1=1&p2=2", null);
- Map<String, List<String>> parameters = req.getParameters();
- assertEquals("3 parameters", 3, parameters.size());
- assertEquals("one p0", 1, parameters.get("p0").size());
- assertEquals("p0 is emtpy", "", parameters.get("p0").get(0));
- assertEquals("one p1", 1, parameters.get("p1").size());
- assertEquals("p1 is '1'", "1", parameters.get("p1").get(0));
- assertEquals("one p2", 1, parameters.get("p2").size());
- assertEquals("p2 is '2'", "2", parameters.get("p2").get(0));
- }
+ @Test
+ public void testGetParameters3Parameters() {
+ HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/","p0=&p1=1&p2=2", null);
+ Map<String, List<String>> parameters = req.getParameters();
+ assertEquals("3 parameters", 3, parameters.size());
+ assertEquals("one p0", 1, parameters.get("p0").size());
+ assertEquals("p0 is emtpy", "", parameters.get("p0").get(0));
+ assertEquals("one p1", 1, parameters.get("p1").size());
+ assertEquals("p1 is '1'", "1", parameters.get("p1").get(0));
+ assertEquals("one p2", 1, parameters.get("p2").size());
+ assertEquals("p2 is '2'", "2", parameters.get("p2").get(0));
+ }
- @Test
- public void testGetParameters3ParametersWithDuplicate() {
- HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/","p0=&p1=1&p0=2", null);
- Map<String, List<String>> parameters = req.getParameters();
- assertEquals("2 parameters", 2, parameters.size());
- assertEquals("two p0", 2, parameters.get("p0").size());
- assertEquals("1st p0 is emtpy", "", parameters.get("p0").get(0));
- assertEquals("2nd p0 is '2'", "2", parameters.get("p0").get(1));
- assertEquals("one p1", 1, parameters.get("p1").size());
- assertEquals("p1 is '1'", "1", parameters.get("p1").get(0));
- assertNull("No p2", parameters.get("p2"));
- }
+ @Test
+ public void testGetParameters3ParametersWithDuplicate() {
+ HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/","p0=&p1=1&p0=2", null);
+ Map<String, List<String>> parameters = req.getParameters();
+ assertEquals("2 parameters", 2, parameters.size());
+ assertEquals("two p0", 2, parameters.get("p0").size());
+ assertEquals("1st p0 is emtpy", "", parameters.get("p0").get(0));
+ assertEquals("2nd p0 is '2'", "2", parameters.get("p0").get(1));
+ assertEquals("one p1", 1, parameters.get("p1").size());
+ assertEquals("p1 is '1'", "1", parameters.get("p1").get(0));
+ assertNull("No p2", parameters.get("p2"));
+ }
}