You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by sc...@apache.org on 2007/09/13 22:16:51 UTC
svn commit: r575432 - in
/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments:
IncomingAttachmentInputStream.java MultipartAttachmentStreams.java
Author: scheu
Date: Thu Sep 13 13:16:47 2007
New Revision: 575432
URL: http://svn.apache.org/viewvc?rev=575432&view=rev
Log:
WSCOMMONS-246
Contributor:Michal Stochmialek
Preserve casing of HTTP header
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/IncomingAttachmentInputStream.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MultipartAttachmentStreams.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/IncomingAttachmentInputStream.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/IncomingAttachmentInputStream.java?rev=575432&r1=575431&r2=575432&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/IncomingAttachmentInputStream.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/IncomingAttachmentInputStream.java Thu Sep 13 13:16:47 2007
@@ -1,128 +1,132 @@
-/*
- * 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.axiom.attachments;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-
-public class IncomingAttachmentInputStream extends InputStream {
- private HashMap _headers = null;
-
- private InputStream _stream = null;
- private IncomingAttachmentStreams parentContainer;
-
- public static final String HEADER_CONTENT_DESCRIPTION = "content-description";
- public static final String HEADER_CONTENT_TYPE = "content-type";
- public static final String HEADER_CONTENT_TRANSFER_ENCODING = "content-transfer-encoding";
- public static final String HEADER_CONTENT_TYPE_JMS = "contentType";
- public static final String HEADER_CONTENT_LENGTH = "content-length";
- public static final String HEADER_CONTENT_LOCATION = "content-location";
- public static final String HEADER_CONTENT_ID = "content-id";
-
- /** @param in */
- public IncomingAttachmentInputStream(InputStream in,
- IncomingAttachmentStreams parentContainer) {
- _stream = in;
- this.parentContainer = parentContainer;
- }
-
- /** @return MIME headers for this attachment. May be null if no headers were set. */
- public Map getHeaders() {
- return _headers;
- }
-
- /**
- * Add a header.
- *
- * @param name
- * @param value
- */
- public void addHeader(String name, String value) {
- if (_headers == null) {
- _headers = new HashMap();
- }
- _headers.put(name, value);
- }
-
- /**
- * Get a header value.
- *
- * @param name
- * @return The header found or null if not found.
- */
- public String getHeader(String name) {
- Object header = null;
- if (_headers == null || (header = _headers.get(name)) == null) {
- return null;
- }
- return header.toString();
- }
-
- /** @return The header with HTTPConstants.HEADER_CONTENT_ID as the key. */
- public String getContentId() {
- return getHeader(HEADER_CONTENT_ID);
- }
-
- /** @return The header with HTTPConstants.HEADER_CONTENT_LOCATION as the key. */
- public String getContentLocation() {
- return getHeader(HEADER_CONTENT_LOCATION);
- }
-
- /** @return The header with HTTPConstants.HEADER_CONTENT_TYPE as the key. */
- public String getContentType() {
- return getHeader(HEADER_CONTENT_TYPE);
- }
-
- /**
- * Don't want to support mark and reset since this may get us into concurrency problem when
- * different pieces of software may have a handle to the underlying InputStream.
- */
- public boolean markSupported() {
- return false;
- }
-
- public void reset() throws IOException {
- throw new IOException("markNotSupported");
- }
-
- public void mark(int readLimit) {
- // do nothing
- }
-
- public int read() throws IOException {
- int retval = _stream.read();
- parentContainer.setReadyToGetNextStream(retval == -1);
- return retval;
- }
-
- public int read(byte[] b) throws IOException {
- int retval = _stream.read(b);
- parentContainer.setReadyToGetNextStream(retval == -1);
- return retval;
- }
-
- public int read(byte[] b, int off, int len) throws IOException {
- int retval = _stream.read(b, off, len);
- parentContainer.setReadyToGetNextStream(retval == -1);
- return retval;
- }
-}
+/*
+ * 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.axiom.attachments;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+public class IncomingAttachmentInputStream extends InputStream {
+ private HashMap _headers = null;
+
+ private HashMap _headersLowerCase = null;
+
+ private InputStream _stream = null;
+ private IncomingAttachmentStreams parentContainer;
+
+ public static final String HEADER_CONTENT_DESCRIPTION = "content-description";
+ public static final String HEADER_CONTENT_TYPE = "content-type";
+ public static final String HEADER_CONTENT_TRANSFER_ENCODING = "content-transfer-encoding";
+ public static final String HEADER_CONTENT_TYPE_JMS = "contentType";
+ public static final String HEADER_CONTENT_LENGTH = "content-length";
+ public static final String HEADER_CONTENT_LOCATION = "content-location";
+ public static final String HEADER_CONTENT_ID = "content-id";
+
+ /** @param in */
+ public IncomingAttachmentInputStream(InputStream in,
+ IncomingAttachmentStreams parentContainer) {
+ _stream = in;
+ this.parentContainer = parentContainer;
+ }
+
+ /** @return MIME headers for this attachment. May be null if no headers were set. */
+ public Map getHeaders() {
+ return _headers;
+ }
+
+ /**
+ * Add a header.
+ *
+ * @param name
+ * @param value
+ */
+ public void addHeader(String name, String value) {
+ if (_headers == null) {
+ _headers = new HashMap();
+ _headersLowerCase = new HashMap();
+ }
+ _headers.put(name, value);
+ _headersLowerCase.put(name.toLowerCase(), value);
+ }
+
+ /**
+ * Get a header value.
+ *
+ * @param name
+ * @return The header found or null if not found.
+ */
+ public String getHeader(String name) {
+ Object header = null;
+ if (_headersLowerCase == null || (header = _headersLowerCase.get(name.toLowerCase())) == null) {
+ return null;
+ }
+ return header.toString();
+ }
+
+ /** @return The header with HTTPConstants.HEADER_CONTENT_ID as the key. */
+ public String getContentId() {
+ return getHeader(HEADER_CONTENT_ID);
+ }
+
+ /** @return The header with HTTPConstants.HEADER_CONTENT_LOCATION as the key. */
+ public String getContentLocation() {
+ return getHeader(HEADER_CONTENT_LOCATION);
+ }
+
+ /** @return The header with HTTPConstants.HEADER_CONTENT_TYPE as the key. */
+ public String getContentType() {
+ return getHeader(HEADER_CONTENT_TYPE);
+ }
+
+ /**
+ * Don't want to support mark and reset since this may get us into concurrency problem when
+ * different pieces of software may have a handle to the underlying InputStream.
+ */
+ public boolean markSupported() {
+ return false;
+ }
+
+ public void reset() throws IOException {
+ throw new IOException("markNotSupported");
+ }
+
+ public void mark(int readLimit) {
+ // do nothing
+ }
+
+ public int read() throws IOException {
+ int retval = _stream.read();
+ parentContainer.setReadyToGetNextStream(retval == -1);
+ return retval;
+ }
+
+ public int read(byte[] b) throws IOException {
+ int retval = _stream.read(b);
+ parentContainer.setReadyToGetNextStream(retval == -1);
+ return retval;
+ }
+
+ public int read(byte[] b, int off, int len) throws IOException {
+ int retval = _stream.read(b, off, len);
+ parentContainer.setReadyToGetNextStream(retval == -1);
+ return retval;
+ }
+}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MultipartAttachmentStreams.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MultipartAttachmentStreams.java?rev=575432&r1=575431&r2=575432&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MultipartAttachmentStreams.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MultipartAttachmentStreams.java Thu Sep 13 13:16:47 2007
@@ -1,96 +1,96 @@
-/*
- * 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.axiom.attachments;
-
-import org.apache.axiom.om.OMException;
-
-import javax.mail.Header;
-import javax.mail.MessagingException;
-import javax.mail.internet.InternetHeaders;
-import java.io.IOException;
-import java.util.Enumeration;
-
-/**
- * The MultipartAttachmentStreams class is used to create IncomingAttachmentInputStream objects when
- * the HTTP stream shows a marked separation between the SOAP and each attachment parts. Unlike the
- * DIME version, this class will use the BoundaryDelimitedStream to parse data in the SwA format.
- * Another difference between the two is that the MultipartAttachmentStreams class must also provide
- * a way to hold attachment parts parsed prior to where the SOAP part appears in the HTTP stream
- * (i.e. the root part of the multipart-related message). Our DIME counterpart didn't have to worry
- * about this since the SOAP part is guaranteed to be the first in the stream. But since SwA has no
- * such guarantee, we must fall back to caching these first parts. Afterwards, we can stream the
- * rest of the attachments that are after the SOAP part of the request message.
- */
-public final class MultipartAttachmentStreams extends IncomingAttachmentStreams {
- private BoundaryDelimitedStream _delimitedStream = null;
-
- public MultipartAttachmentStreams(BoundaryDelimitedStream delimitedStream)
- throws OMException {
- this._delimitedStream = delimitedStream;
- }
-
- /** @see org.apache.axis.attachments.IncomingAttachmentStreams#getNextStream() */
- public IncomingAttachmentInputStream getNextStream() throws OMException {
- IncomingAttachmentInputStream stream;
-
- if (!isReadyToGetNextStream()) {
- throw new IllegalStateException("nextStreamNotReady");
- }
-
- InternetHeaders headers;
-
- try {
- _delimitedStream = _delimitedStream.getNextStream();
- if (_delimitedStream == null) {
- return null;
- }
-
- headers = new InternetHeaders(_delimitedStream);
-
- } catch (IOException ioe) {
- ioe.printStackTrace();
- throw new OMException(ioe);
- } catch (MessagingException me) {
- me.printStackTrace();
- throw new OMException(me);
- }
-
- stream = new IncomingAttachmentInputStream(_delimitedStream, this);
-
- Header header;
- String name;
- String value;
- Enumeration e = headers.getAllHeaders();
- while (e != null && e.hasMoreElements()) {
- header = (Header) e.nextElement();
- name = header.getName().toLowerCase();
- value = header.getValue();
- if (IncomingAttachmentInputStream.HEADER_CONTENT_ID.equals(name)
- || IncomingAttachmentInputStream.HEADER_CONTENT_TYPE.equals(name)
- || IncomingAttachmentInputStream.HEADER_CONTENT_LOCATION.equals(name)) {
- value = value.trim();
- }
- stream.addHeader(name, value);
- }
-
- setReadyToGetNextStream(false);
- return stream;
- }
-}
+/*
+ * 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.axiom.attachments;
+
+import org.apache.axiom.om.OMException;
+
+import javax.mail.Header;
+import javax.mail.MessagingException;
+import javax.mail.internet.InternetHeaders;
+import java.io.IOException;
+import java.util.Enumeration;
+
+/**
+ * The MultipartAttachmentStreams class is used to create IncomingAttachmentInputStream objects when
+ * the HTTP stream shows a marked separation between the SOAP and each attachment parts. Unlike the
+ * DIME version, this class will use the BoundaryDelimitedStream to parse data in the SwA format.
+ * Another difference between the two is that the MultipartAttachmentStreams class must also provide
+ * a way to hold attachment parts parsed prior to where the SOAP part appears in the HTTP stream
+ * (i.e. the root part of the multipart-related message). Our DIME counterpart didn't have to worry
+ * about this since the SOAP part is guaranteed to be the first in the stream. But since SwA has no
+ * such guarantee, we must fall back to caching these first parts. Afterwards, we can stream the
+ * rest of the attachments that are after the SOAP part of the request message.
+ */
+public final class MultipartAttachmentStreams extends IncomingAttachmentStreams {
+ private BoundaryDelimitedStream _delimitedStream = null;
+
+ public MultipartAttachmentStreams(BoundaryDelimitedStream delimitedStream)
+ throws OMException {
+ this._delimitedStream = delimitedStream;
+ }
+
+ /** @see org.apache.axis.attachments.IncomingAttachmentStreams#getNextStream() */
+ public IncomingAttachmentInputStream getNextStream() throws OMException {
+ IncomingAttachmentInputStream stream;
+
+ if (!isReadyToGetNextStream()) {
+ throw new IllegalStateException("nextStreamNotReady");
+ }
+
+ InternetHeaders headers;
+
+ try {
+ _delimitedStream = _delimitedStream.getNextStream();
+ if (_delimitedStream == null) {
+ return null;
+ }
+
+ headers = new InternetHeaders(_delimitedStream);
+
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ throw new OMException(ioe);
+ } catch (MessagingException me) {
+ me.printStackTrace();
+ throw new OMException(me);
+ }
+
+ stream = new IncomingAttachmentInputStream(_delimitedStream, this);
+
+ Header header;
+ String name;
+ String value;
+ Enumeration e = headers.getAllHeaders();
+ while (e != null && e.hasMoreElements()) {
+ header = (Header) e.nextElement();
+ name = header.getName();
+ value = header.getValue();
+ if (IncomingAttachmentInputStream.HEADER_CONTENT_ID.equals(name)
+ || IncomingAttachmentInputStream.HEADER_CONTENT_TYPE.equals(name)
+ || IncomingAttachmentInputStream.HEADER_CONTENT_LOCATION.equals(name)) {
+ value = value.trim();
+ }
+ stream.addHeader(name, value);
+ }
+
+ setReadyToGetNextStream(false);
+ return stream;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org