hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r615594 - in /httpcomponents/httpclient/trunk/module-httpmime: ./ src/ src/examples/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/http/ src/main/java/org/apache/http/client/ src/main/java/or...
Date Sun, 27 Jan 2008 13:21:43 GMT
Author: olegk
Date: Sun Jan 27 05:21:42 2008
New Revision: 615594

URL: http://svn.apache.org/viewvc?rev=615594&view=rev
Log:
Added HttpClient MIME module

Added:
    httpcomponents/httpclient/trunk/module-httpmime/
    httpcomponents/httpclient/trunk/module-httpmime/pom.xml   (with props)
    httpcomponents/httpclient/trunk/module-httpmime/src/
    httpcomponents/httpclient/trunk/module-httpmime/src/examples/
    httpcomponents/httpclient/trunk/module-httpmime/src/main/
    httpcomponents/httpclient/trunk/module-httpmime/src/main/java/
    httpcomponents/httpclient/trunk/module-httpmime/src/main/java/org/
    httpcomponents/httpclient/trunk/module-httpmime/src/main/java/org/apache/
    httpcomponents/httpclient/trunk/module-httpmime/src/main/java/org/apache/http/
    httpcomponents/httpclient/trunk/module-httpmime/src/main/java/org/apache/http/client/
    httpcomponents/httpclient/trunk/module-httpmime/src/main/java/org/apache/http/client/mime/
    httpcomponents/httpclient/trunk/module-httpmime/src/main/java/org/apache/http/client/mime/HttpMultipart.java
  (with props)
    httpcomponents/httpclient/trunk/module-httpmime/src/main/java/org/apache/http/client/mime/StringPart.java
  (with props)
    httpcomponents/httpclient/trunk/module-httpmime/src/test/
    httpcomponents/httpclient/trunk/module-httpmime/src/test/java/
    httpcomponents/httpclient/trunk/module-httpmime/src/test/java/org/
    httpcomponents/httpclient/trunk/module-httpmime/src/test/java/org/apache/
    httpcomponents/httpclient/trunk/module-httpmime/src/test/java/org/apache/http/
    httpcomponents/httpclient/trunk/module-httpmime/src/test/java/org/apache/http/client/
    httpcomponents/httpclient/trunk/module-httpmime/src/test/java/org/apache/http/client/mime/
    httpcomponents/httpclient/trunk/module-httpmime/src/test/java/org/apache/http/client/mime/TestAll.java
  (with props)
    httpcomponents/httpclient/trunk/module-httpmime/src/test/java/org/apache/http/client/mime/TestMultipartForm.java
  (with props)

Added: httpcomponents/httpclient/trunk/module-httpmime/pom.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-httpmime/pom.xml?rev=615594&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/module-httpmime/pom.xml (added)
+++ httpcomponents/httpclient/trunk/module-httpmime/pom.xml Sun Jan 27 05:21:42 2008
@@ -0,0 +1,147 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+   $HeadURL:$
+   $Revision:$
+   $Date:$
+
+   ====================================================================
+   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.
+   ====================================================================
+
+   This software consists of voluntary contributions made by many
+   individuals on behalf of the Apache Software Foundation.  For more
+   information on the Apache Software Foundation, please see
+   <http://www.apache.org />.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.httpcomponents</groupId>
+    <artifactId>httpcomponents-client</artifactId>
+    <version>4.0-alpha3-SNAPSHOT</version>
+  </parent>
+  <artifactId>httpclient-mime</artifactId>
+  <name>HttpClient (MIME entities)</name>
+  <inceptionYear>2000</inceptionYear>
+  <description>
+   HttpComponents HttpClient - MIME coded entities
+  </description>
+  <url>http://hc.apache.org/httpcomponents-client</url>
+  <packaging>jar</packaging>  
+
+  <licenses>
+    <license>
+      <name>Apache License</name>
+      <url>../LICENSE.txt</url>
+      <distribution>repo</distribution>
+    </license>
+  </licenses>
+
+  <scm>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-httpmime</connection>
+    <developerConnection>scm:svn:http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-httpmime</developerConnection>
+    <url>http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-httpmime</url>
+  </scm>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpclient</artifactId>
+      <version>${pom.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.james</groupId>
+      <artifactId>apache-mime4j</artifactId>
+      <version>0.3</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <properties>
+    <maven.compile.source>1.5</maven.compile.source>
+    <maven.compile.target>1.5</maven.compile.target>
+    <maven.compile.optimize>true</maven.compile.optimize>
+    <maven.compile.deprecation>true</maven.compile.deprecation>
+  </properties>
+
+  <build>
+    <resources>
+      <resource>
+        <directory>src/main/resources</directory>
+        <filtering>false</filtering>
+        <includes>
+            <include>META-INF/*</include>
+        </includes>
+      </resource>
+      <resource>
+        <directory>src/main/resources</directory>
+        <filtering>true</filtering>
+        <includes>
+            <include>**/*.properties</include>
+        </includes>
+      </resource>
+    </resources>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>${maven.compile.source}</source>
+          <target>${maven.compile.target}</target>
+          <optimize>${maven.compile.optimize}</optimize>
+          <showDeprecations>${maven.compile.deprecation}</showDeprecations>
+        </configuration>
+      </plugin>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <includes>
+            <include>**/TestAll.java</include>
+          </includes>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+  <reporting>
+    <plugins>
+
+       <plugin>
+         <groupId>org.apache.maven.plugins</groupId>
+         <artifactId>maven-project-info-reports-plugin</artifactId>
+         <reportSets>
+           <reportSet>
+             <reports>
+               <report>dependencies</report>
+               <report>issue-tracking</report>
+               <report>scm</report>
+             </reports>
+           </reportSet>
+         </reportSets>
+      </plugin>
+
+    </plugins>
+  </reporting>
+
+</project>

Propchange: httpcomponents/httpclient/trunk/module-httpmime/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/module-httpmime/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/httpclient/trunk/module-httpmime/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: httpcomponents/httpclient/trunk/module-httpmime/src/main/java/org/apache/http/client/mime/HttpMultipart.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-httpmime/src/main/java/org/apache/http/client/mime/HttpMultipart.java?rev=615594&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/module-httpmime/src/main/java/org/apache/http/client/mime/HttpMultipart.java
(added)
+++ httpcomponents/httpclient/trunk/module-httpmime/src/main/java/org/apache/http/client/mime/HttpMultipart.java
Sun Jan 27 05:21:42 2008
@@ -0,0 +1,88 @@
+/*
+ * $HeadURL:$
+ * $Revision:$
+ * $Date:$
+ *
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.mime;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.util.List;
+
+import org.apache.james.mime4j.field.ContentTypeField;
+import org.apache.james.mime4j.field.Field;
+import org.apache.james.mime4j.message.BodyPart;
+import org.apache.james.mime4j.message.Entity;
+import org.apache.james.mime4j.message.Multipart;
+import org.apache.james.mime4j.util.CharsetUtil;
+
+/**
+ * Extension of the mime4j standard class needed to work around 
+ * some formatting issues in the {@link Multipart#writeTo(OutputStream)}
+ * method until they have been addressed downstream.
+ */
+public class HttpMultipart extends Multipart {
+
+    @Override
+    public void writeTo(OutputStream out) throws IOException {
+        Entity e = getParent();
+        ContentTypeField cField = (ContentTypeField) e.getHeader().getField(
+                Field.CONTENT_TYPE);
+        String boundary = cField.getBoundary();
+        String charset = cField.getCharset();
+        
+        List<?> bodyParts = getBodyParts();
+
+        BufferedWriter writer = new BufferedWriter(
+                new OutputStreamWriter(out, CharsetUtil.getCharset(charset)),
+                8192);
+        
+        writer.write(getPreamble());
+        writer.write("\r\n");
+
+        for (int i = 0; i < bodyParts.size(); i++) {
+            writer.write("--");
+            writer.write(boundary);
+            writer.write("\r\n");
+            writer.flush();
+            ((BodyPart) bodyParts.get(i)).writeTo(out);
+            writer.write("\r\n");
+        }
+
+        writer.write("--");
+        writer.write(boundary);
+        writer.write("--\r\n");
+        writer.write(getEpilogue());
+        writer.write("\r\n");
+        writer.flush();
+    }
+    
+}

Propchange: httpcomponents/httpclient/trunk/module-httpmime/src/main/java/org/apache/http/client/mime/HttpMultipart.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/module-httpmime/src/main/java/org/apache/http/client/mime/HttpMultipart.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/httpclient/trunk/module-httpmime/src/main/java/org/apache/http/client/mime/HttpMultipart.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/httpclient/trunk/module-httpmime/src/main/java/org/apache/http/client/mime/StringPart.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-httpmime/src/main/java/org/apache/http/client/mime/StringPart.java?rev=615594&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/module-httpmime/src/main/java/org/apache/http/client/mime/StringPart.java
(added)
+++ httpcomponents/httpclient/trunk/module-httpmime/src/main/java/org/apache/http/client/mime/StringPart.java
Sun Jan 27 05:21:42 2008
@@ -0,0 +1,45 @@
+package org.apache.http.client.mime;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.StringReader;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.http.protocol.HTTP;
+import org.apache.james.mime4j.message.AbstractBody;
+import org.apache.james.mime4j.message.TextBody;
+
+public class StringPart extends AbstractBody implements TextBody {
+
+    private final String text;
+    private final String charset;
+    
+    public StringPart(final String text, String charset) {
+        super();
+        if (text == null) {
+            throw new IllegalArgumentException("Text may not be null");
+        }
+        if (charset == null) {
+            charset = HTTP.UTF_8;
+        }
+        this.text = text;
+        this.charset = charset;
+    }
+    
+    public StringPart(final String text) {
+        this(text, null);
+    }
+    
+    public Reader getReader() throws IOException {
+        return new StringReader(this.text);
+    }
+
+    public void writeTo(final OutputStream out) throws IOException {
+        if (out == null) {
+            throw new IllegalArgumentException("Output stream may not be null");
+        }
+        IOUtils.copy(getReader(), out, this.charset);
+    }
+    
+}

Propchange: httpcomponents/httpclient/trunk/module-httpmime/src/main/java/org/apache/http/client/mime/StringPart.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/module-httpmime/src/main/java/org/apache/http/client/mime/StringPart.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/httpclient/trunk/module-httpmime/src/main/java/org/apache/http/client/mime/StringPart.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/httpclient/trunk/module-httpmime/src/test/java/org/apache/http/client/mime/TestAll.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-httpmime/src/test/java/org/apache/http/client/mime/TestAll.java?rev=615594&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/module-httpmime/src/test/java/org/apache/http/client/mime/TestAll.java
(added)
+++ httpcomponents/httpclient/trunk/module-httpmime/src/test/java/org/apache/http/client/mime/TestAll.java
Sun Jan 27 05:21:42 2008
@@ -0,0 +1,54 @@
+/*
+ * $HeadURL:$
+ * $Revision:$
+ * $Date:$
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.mime;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class TestAll extends TestCase {
+
+    public TestAll(String testName) {
+        super(testName);
+    }
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite();
+        suite.addTest(TestMultipartForm.suite());
+        return suite;
+    }
+
+    public static void main(String args[]) {
+        String[] testCaseName = { TestAll.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/module-httpmime/src/test/java/org/apache/http/client/mime/TestAll.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/module-httpmime/src/test/java/org/apache/http/client/mime/TestAll.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/httpclient/trunk/module-httpmime/src/test/java/org/apache/http/client/mime/TestAll.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/httpclient/trunk/module-httpmime/src/test/java/org/apache/http/client/mime/TestMultipartForm.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-httpmime/src/test/java/org/apache/http/client/mime/TestMultipartForm.java?rev=615594&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/module-httpmime/src/test/java/org/apache/http/client/mime/TestMultipartForm.java
(added)
+++ httpcomponents/httpclient/trunk/module-httpmime/src/test/java/org/apache/http/client/mime/TestMultipartForm.java
Sun Jan 27 05:21:42 2008
@@ -0,0 +1,118 @@
+/*
+ * $HeadURL:$
+ * $Revision:$
+ * $Date:$
+ *
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.mime;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.james.mime4j.field.Field;
+import org.apache.james.mime4j.message.BodyPart;
+import org.apache.james.mime4j.message.Header;
+import org.apache.james.mime4j.message.Message;
+import org.apache.james.mime4j.message.Multipart;
+
+public class TestMultipartForm extends TestCase {
+
+    // ------------------------------------------------------------ Constructor
+    public TestMultipartForm(final String testName) throws IOException {
+        super(testName);
+    }
+
+    // ------------------------------------------------------------------- Main
+    public static void main(String args[]) {
+        String[] testCaseName = { TestMultipartForm.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+    // ------------------------------------------------------- TestCase Methods
+
+    public static Test suite() {
+        return new TestSuite(TestMultipartForm.class);
+    }
+
+    public void testMultipartFormContent() throws Exception {
+        Message message = new Message();
+        Header header = new Header();
+        header.addField(
+                Field.parse("Content-Type: multipart/form-data; boundary=foo"));
+        message.setHeader(header);
+        
+        Multipart multipart = new HttpMultipart();
+        multipart.setParent(message);
+        BodyPart p1 = new BodyPart();
+        Header h1 = new Header();
+        h1.addField(Field.parse("Content-Type: text/plain"));
+        p1.setHeader(h1);
+        p1.setBody(new StringPart("this stuff"));
+        BodyPart p2 = new BodyPart();
+        Header h2 = new Header();
+        h2.addField(Field.parse("Content-Type: text/plain"));
+        p2.setHeader(h2);
+        p2.setBody(new StringPart("that stuff"));
+        BodyPart p3 = new BodyPart();
+        Header h3 = new Header();
+        h3.addField(Field.parse("Content-Type: text/plain"));
+        p3.setHeader(h3);
+        p3.setBody(new StringPart("all kind of stuff"));
+
+        multipart.addBodyPart(p1);
+        multipart.addBodyPart(p2);
+        multipart.addBodyPart(p3);
+        
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        multipart.writeTo(out);
+        out.close();
+        
+        String expected = "\r\n" + 
+            "--foo\r\n" +
+            "Content-Type: text/plain\r\n" +
+            "\r\n" +
+            "this stuff\r\n" +
+            "--foo\r\n" +
+            "Content-Type: text/plain\r\n" +
+            "\r\n" +
+            "that stuff\r\n" +
+            "--foo\r\n" +
+            "Content-Type: text/plain\r\n" +
+            "\r\n" +
+            "all kind of stuff\r\n" +
+            "--foo--\r\n" +
+            "\r\n";
+        String s = out.toString("US-ASCII");
+        assertEquals(expected, s);
+    }
+    
+}

Propchange: httpcomponents/httpclient/trunk/module-httpmime/src/test/java/org/apache/http/client/mime/TestMultipartForm.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/module-httpmime/src/test/java/org/apache/http/client/mime/TestMultipartForm.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/httpclient/trunk/module-httpmime/src/test/java/org/apache/http/client/mime/TestMultipartForm.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message