[jboss-svn-commits] JBL Code SVN: r37280 - in labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap: attachment and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jul 21 16:42:34 EDT 2011
Author: dward
Date: 2011-07-21 16:42:34 -0400 (Thu, 21 Jul 2011)
New Revision: 37280
Added:
labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/
labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/AttachmentPartImpl.java
labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/BoundaryDelimitedInputStream.java
labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/ByteArrayContentHandler.java
labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/Constants.java
labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/ContentHandlerRegistry.java
labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/IOUtils.java
labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/ImageDataContentHandler.java
labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/JavaUtils.java
labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/MimeConstants.java
labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/MimeUtils.java
labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/MultipartRelatedDecoder.java
labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/RawByteArrayOutputStream.java
labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/SimpleBoyerMoore.java
labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/SwapableMemoryDataSource.java
labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/XmlDataContentHandler.java
Modified:
labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxy.java
Log:
JBESB-3636: ESB - SOAPProxy throws SAXParseException when soapAction is missing in WSDL and message has attachment
Added: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/AttachmentPartImpl.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/AttachmentPartImpl.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/AttachmentPartImpl.java 2011-07-21 20:42:34 UTC (rev 37280)
@@ -0,0 +1,494 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.actions.soap.attachment;
+//package org.jboss.ws.core.soap.attachment;
+
+import org.jboss.util.Base64;
+//import java.util.ResourceBundle;
+//import org.jboss.ws.api.util.BundleUtils;
+//import org.jboss.ws.common.IOUtils;
+//import org.jboss.ws.WSException;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.mail.internet.MimeMultipart;
+import javax.xml.soap.AttachmentPart;
+import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPException;
+import java.io.*;
+import java.util.Iterator;
+
+/**
+ * Implementation of the <code>AttachmentPart</code> interface.
+ * @see javax.xml.soap.AttachmentPart
+ *
+ * @author <a href="mailto:jason at stacksmash.com">Jason T. Greene</a>
+ * @author Thomas.Diesler at jboss.org
+ */
+public class AttachmentPartImpl extends AttachmentPart
+{
+ //private static final ResourceBundle bundle = BundleUtils.getBundle(AttachmentPartImpl.class);
+ private MimeHeaders mimeHeaders = new MimeHeaders();
+
+ private DataHandler dataHandler;
+
+ private String cachedContentId;
+
+ private String cachedContentType;
+
+ private String cachedContentLocation;
+
+ static
+ {
+ // Load JAF content handlers
+ ContentHandlerRegistry.register();
+ }
+
+ public AttachmentPartImpl()
+ {
+ }
+
+ public AttachmentPartImpl(DataHandler handler)
+ {
+ this.dataHandler = handler;
+ }
+
+ private void clearHeaderCache()
+ {
+ cachedContentId = null;
+ cachedContentType = null;
+ cachedContentLocation = null;
+ }
+
+ public void addMimeHeader(String name, String value)
+ {
+ clearHeaderCache();
+ mimeHeaders.addHeader(name, value);
+ }
+
+ public void clearContent()
+ {
+ dataHandler = null;
+ }
+
+ public Iterator getAllMimeHeaders()
+ {
+ clearHeaderCache();
+ return mimeHeaders.getAllHeaders();
+ }
+
+ public Object getContent() throws SOAPException
+ {
+ if (dataHandler == null)
+ //throw new SOAPException(BundleUtils.getMessage(bundle, "NO_CONTENT_AVAILABLE"));
+ throw new SOAPException("NO_CONTENT_AVAILABLE");
+
+ try
+ {
+ return dataHandler.getContent();
+ }
+ catch (IOException e)
+ {
+ throw new SOAPException(e);
+ }
+ }
+
+ public DataHandler getDataHandler() throws SOAPException
+ {
+ if (dataHandler == null)
+ //throw new SOAPException(BundleUtils.getMessage(bundle, "NO_DATA_HANDLER_ON_ATTACHMENT"));
+ throw new SOAPException("NO_DATA_HANDLER_ON_ATTACHMENT");
+
+ return dataHandler;
+ }
+
+ public Iterator getMatchingMimeHeaders(String[] names)
+ {
+ clearHeaderCache();
+ return mimeHeaders.getMatchingHeaders(names);
+ }
+
+ public String[] getMimeHeader(String name)
+ {
+ return mimeHeaders.getHeader(name);
+ }
+
+ /**
+ * Returns the first occurence of a MIME header.
+ *
+ * @param header the mime header
+ * @return the value of the first occurence of a MIME header
+ */
+ public String getFirstMimeHeader(String header)
+ {
+ String[] values = mimeHeaders.getHeader(header.toLowerCase());
+ if ((values != null) && (values.length > 0))
+ {
+ return values[0];
+ }
+ return null;
+ }
+
+ public Iterator getNonMatchingMimeHeaders(String[] names)
+ {
+ clearHeaderCache();
+ return mimeHeaders.getNonMatchingHeaders(names);
+ }
+
+ public int getSize() throws SOAPException
+ {
+ if (dataHandler == null)
+ return 0;
+
+ try
+ {
+ // We may need to buffer the stream, otherwise an additional read may fail
+ if((this.dataHandler.getDataSource() instanceof ByteArrayDataSource) == false)
+ this.dataHandler = new DataHandler(new ByteArrayDataSource(dataHandler.getInputStream(), dataHandler.getContentType()));
+
+ ByteArrayDataSource ds = (ByteArrayDataSource)this.dataHandler.getDataSource();
+ return ds.getSize();
+ }
+ catch (IOException e)
+ {
+ throw new SOAPException(e);
+ }
+ }
+
+ public void removeAllMimeHeaders()
+ {
+ clearHeaderCache();
+ mimeHeaders.removeAllHeaders();
+ }
+
+ public void removeMimeHeader(String name)
+ {
+ clearHeaderCache();
+ mimeHeaders.removeHeader(name);
+ }
+
+ /**
+ * Sets the content of this attachment part to that of the given Object and sets the value of the Content-Type header
+ * to the given type. The type of the Object should correspond to the value given for the Content-Type.
+ * This depends on the particular set of DataContentHandler objects in use.
+ *
+ * @param object the Java object that makes up the content for this attachment part
+ * @param contentType the MIME string that specifies the type of the content
+ * @throws IllegalArgumentException if the contentType does not match the type of the content object,
+ * or if there was no DataContentHandler object for this content object
+ */
+ public void setContent(Object object, String contentType)
+ {
+
+ // Override the content type if its a mime multipart object because we need to preserve
+ // the all of the content type parameters
+ if (object instanceof MimeMultipart)
+ contentType = ((MimeMultipart)object).getContentType();
+
+ dataHandler = new DataHandler(object, contentType);
+
+ setContentType(contentType);
+ }
+
+ public void setDataHandler(DataHandler dataHandler)
+ {
+ if (dataHandler == null)
+ //throw new IllegalArgumentException(BundleUtils.getMessage(bundle, "NULL_DATA_HANDLER"));
+ throw new IllegalArgumentException("NULL_DATA_HANDLER");
+
+ this.dataHandler = dataHandler;
+ setContentType(dataHandler.getContentType());
+ }
+
+ public void setMimeHeader(String name, String value)
+ {
+ clearHeaderCache();
+ mimeHeaders.setHeader(name, value);
+ }
+
+ public String getContentId()
+ {
+ if (cachedContentId == null)
+ {
+ cachedContentId = getFirstMimeHeader(MimeConstants.CONTENT_ID);
+ }
+
+ return cachedContentId;
+ }
+
+ public String getContentLocation()
+ {
+ if (cachedContentLocation == null)
+ {
+ cachedContentLocation = getFirstMimeHeader(MimeConstants.CONTENT_LOCATION);
+ }
+
+ return cachedContentLocation;
+ }
+
+ public String getContentType()
+ {
+ if (cachedContentType == null)
+ {
+ cachedContentType = getFirstMimeHeader(MimeConstants.CONTENT_TYPE);
+ }
+
+ return cachedContentType;
+ }
+
+ public void setContentId(String contentId)
+ {
+ setMimeHeader(MimeConstants.CONTENT_ID, contentId);
+ cachedContentId = contentId;
+ }
+
+ public void setContentLocation(String contentLocation)
+ {
+ setMimeHeader(MimeConstants.CONTENT_LOCATION, contentLocation);
+ cachedContentLocation = contentLocation;
+ }
+
+ public void setContentType(String contentType)
+ {
+ setMimeHeader(MimeConstants.CONTENT_TYPE, contentType);
+ cachedContentType = contentType;
+ }
+
+ /**
+ * Returns an InputStream which can be used to obtain the content of AttachmentPart as Base64 encoded character data,
+ * this method would base64 encode the raw bytes of the attachment and return.
+ *
+ * @return an InputStream from which the Base64 encoded AttachmentPart can be read.
+ * @throws SOAPException if there is no content set into this AttachmentPart object or if there was a data transformation error.
+ * @since SAAJ 1.3
+ */
+ @Override
+ public InputStream getBase64Content() throws SOAPException
+ {
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ try
+ {
+ // TODO: we might skip the buffer and encode lazily
+ IOUtils.copyStream(bout, getDataHandler().getInputStream());
+ String base64 = Base64.encodeBytes(bout.toByteArray());
+ return new ByteArrayInputStream(base64.getBytes());
+ }
+ catch (IOException e)
+ {
+ throw new SOAPException(e);
+ }
+ }
+
+ /**
+ * Gets the content of this AttachmentPart object as an InputStream
+ * as if a call had been made to getContent and no DataContentHandler
+ * had been registered for the content-type of this AttachmentPart.
+ *
+ * Note that reading from the returned InputStream would result in consuming the data in the stream.
+ * It is the responsibility of the caller to reset the InputStream appropriately before calling a Subsequent API.
+ * If a copy of the raw attachment content is required then the getRawContentBytes() API should be used instead.
+ *
+ * @return an InputStream from which the raw data contained by the AttachmentPart can be accessed.
+ * @throws SOAPException if there is no content set into this AttachmentPart object or if there was a data transformation error.
+ * @since SAAJ 1.3
+ */
+ @Override
+ public InputStream getRawContent() throws SOAPException
+ {
+ try
+ {
+ return getDataHandler().getInputStream();
+ }
+ catch (IOException e)
+ {
+ throw new SOAPException(e);
+ }
+ }
+
+ /**
+ * Gets the content of this AttachmentPart object as a byte[] array as if a call had been
+ * made to getContent and no DataContentHandler had been registered for the content-type of this AttachmentPart.
+ *
+ * @return a byte[] array containing the raw data of the AttachmentPart.
+ * @throws SOAPException if there is no content set into this AttachmentPart object or if there was a data transformation error.
+ * @since SAAJ 1.3
+ */
+ @Override
+ public byte[] getRawContentBytes() throws SOAPException
+ {
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ try
+ {
+ IOUtils.copyStream(bout, getDataHandler().getInputStream());
+ return bout.toByteArray();
+ }
+ catch (IOException e)
+ {
+ throw new SOAPException(e);
+ }
+ }
+
+ /**
+ * Sets the content of this attachment part from the Base64 source InputStream
+ * and sets the value of the Content-Type header to the value contained in contentType,
+ * This method would first decode the base64 input and write the resulting raw bytes to the attachment.
+ *
+ * A subsequent call to getSize() may not be an exact measure of the content size.
+ *
+ * @param content the base64 encoded data to add to the attachment part
+ * @param contentType the value to set into the Content-Type header
+ * @throws SOAPException if an there is an error in setting the content
+ * @throws NullPointerException if content is null
+ * @since SAAJ 1.3
+ */
+ @Override
+ public void setBase64Content(InputStream content, String contentType) throws SOAPException
+ {
+ if(null == content)
+ //throw new SOAPException(BundleUtils.getMessage(bundle, "CONTENT_IS_NULL"));
+ throw new SOAPException("CONTENT_IS_NULL");
+
+ try
+ {
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ IOUtils.copyStream(bout, content);
+ content.close();
+ byte[] bytes = bout.toByteArray();
+ byte[] raw;
+
+ try
+ {
+ // CTS passes contents that are not base64 encoded
+ raw = Base64.decode(bytes, 0, bytes.length);
+ }
+ catch (Throwable e)
+ {
+ throw new SOAPException(e);
+ }
+
+ dataHandler = new DataHandler(new ByteArrayDataSource(raw, contentType));
+ setContentType(contentType);
+
+ }
+ catch (IOException e)
+ {
+ throw new SOAPException(e);
+ }
+ }
+
+ /**
+ * Sets the content of this attachment part to that contained by the InputStream content and sets the value of the Content-Type header to the value contained in contentType.
+ *
+ * A subsequent call to getSize() may not be an exact measure of the content size.
+ *
+ * @param content the raw data to add to the attachment part
+ * @param contentType the value to set into the Content-Type header
+ * @throws SOAPException if an there is an error in setting the content
+ * @throws NullPointerException if content is null
+ * @since SAAJ 1.3
+ */
+ @Override
+ public void setRawContent(InputStream content, String contentType) throws SOAPException
+ {
+ if(null == content)
+ //throw new SOAPException(BundleUtils.getMessage(bundle, "CONTENT_IS_NULL"));
+ throw new SOAPException("CONTENT_IS_NULL");
+
+ dataHandler = new DataHandler(new ByteArrayDataSource(content, contentType));
+ setContentType(contentType);
+ }
+
+ /**
+ * Sets the content of this attachment part to that contained
+ * by the byte[] array content and sets the value of the Content-Type
+ * header to the value contained in contentType.
+ *
+ * @param content the raw data to add to the attachment part
+ * @param contentType the value to set into the Content-Type header
+ * @param offset the offset in the byte array of the content
+ * @param len the number of bytes that form the content
+ * @throws SOAPException if an there is an error in setting the content or content is null
+ * @since SAAJ 1.3
+ */
+ @Override
+ public void setRawContentBytes(byte[] content, int offset, int len, String contentType) throws SOAPException
+ {
+ setRawContent(new ByteArrayInputStream(content, offset, len), contentType);
+ }
+
+ class ByteArrayDataSource implements DataSource
+ {
+ private byte[] data;
+ private String type;
+
+ ByteArrayDataSource(InputStream is, String type) {
+ this.type = type;
+ try {
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ IOUtils.copyStream(os, is);
+ data = os.toByteArray();
+ } catch (IOException ioex) {
+ //throw new WSException(ioex);
+ throw new RuntimeException(ioex);
+ }
+ }
+
+ ByteArrayDataSource(byte[] data, String type) {
+ this.data = data;
+ this.type = type;
+ }
+
+ ByteArrayDataSource(String data, String type) {
+ try {
+ this.data = data.getBytes("iso-8859-1");
+ } catch (UnsupportedEncodingException uex) {
+ //throw new WSException(uex);
+ throw new RuntimeException(uex);
+ }
+ this.type = type;
+ }
+
+ public InputStream getInputStream() throws IOException {
+ if (data == null)
+ //throw new IOException(BundleUtils.getMessage(bundle, "NO_DATA"));
+ throw new IOException("NO_DATA");
+ return new ByteArrayInputStream(data);
+ }
+
+ public OutputStream getOutputStream() throws IOException {
+ //throw new IOException(BundleUtils.getMessage(bundle, "CANNOT_DO_THIS"));
+ throw new IOException("CANNOT_DO_THIS");
+ }
+
+ public String getContentType() {
+ return type;
+ }
+
+ public String getName() {
+ return "ByteArrayDataSource";
+ }
+
+ public int getSize() {
+ return this.data.length;
+ }
+ }
+}
Property changes on: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/AttachmentPartImpl.java
___________________________________________________________________
Added: svn:keywords
+ Revision Date
Added: svn:eol-style
+ native
Added: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/BoundaryDelimitedInputStream.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/BoundaryDelimitedInputStream.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/BoundaryDelimitedInputStream.java 2011-07-21 20:42:34 UTC (rev 37280)
@@ -0,0 +1,331 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.actions.soap.attachment;
+//package org.jboss.ws.core.soap.attachment;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * <code>BoundaryDelimitedInputStream</code> encapsulates a stream that is
+ * sepearated into different sections by a common boundary, such as a MIME
+ * multipart message. The full stream is referred to as the outer stream. Each
+ * boundary separated section in the outer stream is referred to as an inner
+ * stream.
+ *
+ * All read() methods will start from the first inner stream, returning -1 when
+ * a boundary is reached. Subsequent calls will then advance to the next stream,
+ * skipping the boundary.
+ *
+ * @author <a href="mailto:jason at stacksmash.com">Jason T. Greene</a>
+ */
+public class BoundaryDelimitedInputStream extends FilterInputStream
+{
+ private static final int BOUNDARY_NOT_FOUND = SimpleBoyerMoore.PATTERN_NOT_FOUND;
+
+ private byte[] boundary;
+
+ private SimpleBoyerMoore boyerMoore;
+
+ private byte[] leftOvers;
+
+ private int leftOverPosition;
+
+ private InputStream source;
+
+ private boolean simulateEof;
+
+ private boolean realEof;
+
+ private boolean bufferingCompleted;
+
+ private boolean checkLeadingCRLF;
+
+ /**
+ * Constructs a <code>BoundaryDelimitedInputStream</code> using the passed
+ * <code>InputStream</code> as the source for the outer stream.
+ *
+ * @param in the source input stream
+ * @param boundary the byte boundary separating sections of this stream
+ */
+ public BoundaryDelimitedInputStream(InputStream in, byte[] boundary)
+ {
+ super(in);
+ source = in;
+ this.boundary = (byte[]) boundary.clone();
+ boyerMoore = new SimpleBoyerMoore(this.boundary);
+ checkLeadingCRLF = boundary.length > 0 && boundary[0] != '\r';
+ }
+
+ /*
+ * Buffers read-ahead data for future read calls.
+ */
+ private void createLeftOvers(byte[] buffer, int start, int end)
+ {
+ int length = end - start;
+
+ if (length <= 0)
+ return;
+
+ // If we are no longer buffering, we no longer have to expand the buffer, so we
+ // can reuse it (if its still there, which may not be the case if a boundary was found
+ // after the left over buffer was consumed) by just moving the position back.
+ if (bufferingCompleted && leftOvers != null)
+ {
+ leftOverPosition -= length;
+ return;
+ }
+
+ int leftOverLength = (leftOvers == null) ? 0 : leftOvers.length - leftOverPosition;
+
+ byte[] newLeftOvers = new byte[length + leftOverLength];
+
+ System.arraycopy(buffer, start, newLeftOvers, 0, length);
+
+ if (leftOvers != null)
+ System.arraycopy(leftOvers, leftOverPosition, newLeftOvers, length, leftOverLength);
+
+ leftOvers = newLeftOvers;
+ leftOverPosition = 0;
+ }
+
+ /*
+ * Reads from previous buffered read-ahead data
+ */
+ private int consumeLeftOvers(byte[] buffer, int offset, int length)
+ {
+ if (leftOvers == null) return 0;
+
+ int i = 0;
+ while (i < length && leftOverPosition < leftOvers.length)
+ {
+ buffer[offset + i++] = leftOvers[leftOverPosition++];
+ }
+
+ if (leftOverPosition >= leftOvers.length)
+ {
+ leftOvers = null;
+ leftOverPosition = 0;
+ }
+
+ return i;
+ }
+
+ /*
+ * Repeatably reaads from the source stream until the desired number of bytes
+ * are returned.
+ */
+ private int fullRead(byte[] buffer, int offset, int length) throws IOException
+ {
+ int count = 0;
+ int read = 0;
+
+ do
+ {
+ read = source.read(buffer, offset + count, length - count);
+ if (read > 0)
+ count += read;
+ }
+ while (read > 0 && count < length);
+
+ if (read < 0)
+ realEof = true;
+
+ return count;
+ }
+
+ private int findBoundary(byte[] buffer, int length)
+ {
+ return boyerMoore.patternSearch(buffer, 0, length);
+ }
+
+ private int read(byte[] b, int off, int len, boolean skip) throws IOException
+ {
+ if (len == 0) return 0;
+
+ if (simulateEof)
+ {
+ simulateEof = false;
+ return -1;
+ }
+
+ if (realEof)
+ {
+ if (leftOvers == null)
+ return -1;
+ if (bufferingCompleted == false)
+ {
+ bufferingCompleted = true;
+ }
+ }
+
+ // Our buffer must always contain room for 2 boundary string occurences,
+ // and one of those boundary string size chunks must extend past the length
+ // of the requested read size to insure the returned byte chunk contains
+ // no potion of the boundary.
+ int bufferLength = Math.max(boundary.length * 2, len + boundary.length);
+
+ byte[] buffer = new byte[bufferLength];
+
+ int position = consumeLeftOvers(buffer, 0, bufferLength);
+ if (position < bufferLength)
+ position += fullRead(buffer, position, bufferLength - position);
+
+ // This should only occur when the source stream is already closed at start
+ if (realEof && position == 0)
+ return -1;
+
+ int returnLength;
+
+ int boundaryPosition = findBoundary(buffer, position);
+ if (boundaryPosition == BOUNDARY_NOT_FOUND || boundaryPosition >= len)
+ {
+ returnLength = Math.min(len, position);
+ createLeftOvers(buffer, returnLength, position);
+ }
+ else
+ {
+ if (checkLeadingCRLF && boundaryPosition > 1)
+ {
+ if (buffer[boundaryPosition - 1] == '\n' && buffer[boundaryPosition - 2] == '\r')
+ {
+ boundaryPosition -= 2;
+ }
+ }
+ returnLength = boundaryPosition;
+ createLeftOvers(buffer, returnLength + boundary.length, position);
+
+ // If there is no data to return, send the eof immediately
+ if (returnLength == 0)
+ return -1;
+
+ // Notify the client that this inner stream has ended by returning -1 on the
+ // next read request.
+ simulateEof = true;
+ }
+
+ if (! skip)
+ System.arraycopy(buffer, 0, b, off, returnLength);
+
+ return returnLength;
+ }
+
+
+ /**
+ * This method will always return 0 because this input stream must
+ * always read ahead to determine the location of the boundary.
+ */
+ public int available() throws IOException
+ {
+ return 0;
+ }
+
+ /**
+ * Close this input stream, and its source input stream. Once this
+ * is called, no further data can be read.
+ */
+ public void close() throws IOException
+ {
+ source.close();
+ leftOvers = null;
+ leftOverPosition = 0;
+ realEof = true;
+ }
+
+ /**
+ * Returns false. Mark is not support by this input stream.
+ */
+ public boolean markSupported()
+ {
+ return false;
+ }
+
+ /**
+ * Reads a single byte from the inner input stream. See the general contract
+ * of the read method of <code>InputStream</code>.
+ *
+ * @return a signle byte value from the stream in the range of 0-255 or -1
+ * on eof of the inner stream.
+ */
+ public int read() throws IOException
+ {
+ byte[] b = new byte[1];
+ if (read(b) == -1)
+ return -1;
+ return b[0] & 0xff;
+ }
+
+ /**
+ * Reads from the inner input stream, attempting to fill the passed byte array.
+ * See the general contract of the read method of <code>InputStream</code>.
+ *
+ * @param b the byte array to populate
+ * @return number of bytes returned in <code>b</code>, -1 on EOF
+ */
+ public int read(byte[] b) throws IOException
+ {
+ return read(b, 0, b.length);
+ }
+
+ /**
+ * Skips the specified number of bytes from the inner input stream. See the
+ * general contract of the read method of <code>InputStream</code>.
+ *
+ * @param n the number of bytes to skip
+ * @return the number of bytes actually skipped, -1 on EOF
+ */
+ public long skip(long n) throws IOException
+ {
+ return read(null, 0, (int) n, true);
+ }
+
+ /**
+ * Reads the specified number of bytes starting from the specified offset
+ * into the specified buffer from the inner input stream. See the
+ * general contract of the read method of <code>InputStream</code>.
+ *
+ * @param b the byte array to populate
+ * @param off the offset in the array to start at
+ * @param len the number of bytes to read, -1 on EOF
+ */
+ public int read(byte[] b, int off, int len) throws IOException
+ {
+ return read(b, off, len, false);
+ }
+
+ /**
+ * Returns whether the outer stream is closed.
+ *
+ * @return boolean indicating whether the outer stream is closed
+ */
+ public boolean isOuterStreamClosed()
+ {
+ return realEof && leftOvers == null;
+ }
+
+
+ public void printLeftOvers()
+ {
+ if (leftOvers != null) System.out.println("LEFT = " + new String(leftOvers, leftOverPosition, leftOvers.length - leftOverPosition));
+ }
+}
Property changes on: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/BoundaryDelimitedInputStream.java
___________________________________________________________________
Added: svn:keywords
+ Revision Date
Added: svn:eol-style
+ native
Added: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/ByteArrayContentHandler.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/ByteArrayContentHandler.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/ByteArrayContentHandler.java 2011-07-21 20:42:34 UTC (rev 37280)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.actions.soap.attachment;
+//package org.jboss.ws.core.soap.attachment;
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.activation.ActivationDataFlavor;
+import javax.activation.DataContentHandler;
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+
+//import org.jboss.ws.common.IOUtils;
+//import org.jboss.ws.core.utils.MimeUtils;
+
+/**
+ * @author Heiko Braun <heiko.braun at jboss.com>
+ * @since Jul 31, 2006
+ */
+public class ByteArrayContentHandler implements DataContentHandler {
+
+ private DataFlavor[] flavors = new ActivationDataFlavor[]
+ {
+ new ActivationDataFlavor(ByteArrayInputStream.class, "application/octet-stream", "OCTETS"),
+ };
+
+ public Object getContent(DataSource dataSource) throws IOException {
+ return dataSource.getInputStream();
+ }
+
+ public Object getTransferData(DataFlavor dataFlavor, DataSource dataSource) throws UnsupportedFlavorException, IOException {
+ return getContent(dataSource);
+ }
+
+ public DataFlavor[] getTransferDataFlavors() {
+ return flavors;
+ }
+
+ public void writeTo(Object object, String string, OutputStream outputStream) throws IOException {
+
+ if(object instanceof byte[])
+ {
+ outputStream.write((byte[])object);
+ }
+ else if(object instanceof DataHandler)
+ {
+ IOUtils.copyStream(outputStream, ((DataHandler)object).getInputStream());
+ }
+ else
+ {
+ MimeUtils.ByteArrayConverter converter = MimeUtils.getConverterForJavaType(object.getClass());
+ converter.writeTo(object, outputStream);
+ }
+ }
+}
Property changes on: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/ByteArrayContentHandler.java
___________________________________________________________________
Added: svn:keywords
+ Revision Date
Added: svn:eol-style
+ native
Added: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/Constants.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/Constants.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/Constants.java 2011-07-21 20:42:34 UTC (rev 37280)
@@ -0,0 +1,337 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+//package org.jboss.ws.common;
+package org.jboss.soa.esb.actions.soap.attachment;
+
+import javax.xml.namespace.QName;
+//import javax.xml.soap.Name;
+import javax.xml.soap.SOAPConstants;
+import javax.xml.ws.http.HTTPBinding;
+import javax.xml.ws.soap.SOAPBinding;
+
+/**
+ * A collection of constants relevant to JBossWS
+ *
+ * @author Thomas.Diesler at jboss.org
+ * @author Anil.Saldhana at jboss.org
+ * @author richard.opalka at jboss.org
+ * @since 10-Oct-2004
+ */
+public interface Constants
+{
+ /** Header for XML Documents */
+ static final String XML_HEADER = "<?xml version='1.0' encoding='UTF-8'?>";
+ /** Default charset for XML Documents */
+ static final String DEFAULT_XML_CHARSET = "UTF-8";
+ /** JBossWS namespace URI */
+ static final String NS_JBOSSWS_URI = "http://www.jboss.org/jbossws";
+ /** XML Namespace */
+ static final String NS_XML = "http://www.w3.org/XML/1998/namespace";
+ /** XML namespace declaration namespace */
+ static final String NS_XMLNS = "http://www.w3.org/2000/xmlns/";
+ /** XMLSchema namespace http://www.w3.org/2001/XMLSchema */
+ static final String NS_SCHEMA_XSD = "http://www.w3.org/2001/XMLSchema";
+ /** XMLSchema instance namespace http://www.w3.org/2001/XMLSchema-instance */
+ static final String NS_SCHEMA_XSI = "http://www.w3.org/2001/XMLSchema-instance";
+ /** SOAP-1.1 namespace http://schemas.xmlsoap.org/wsdl/soap/ */
+ static final String NS_SOAP11 = "http://schemas.xmlsoap.org/wsdl/soap/";
+ /** SOAP-1.1 envelope namespace http://schemas.xmlsoap.org/soap/envelope/ */
+ static final String NS_SOAP11_ENV = SOAPConstants.URI_NS_SOAP_ENVELOPE;
+ /** SOAP-1.2 namespace http://schemas.xmlsoap.org/wsdl/soap12/ */
+ static final String NS_SOAP12 = "http://schemas.xmlsoap.org/wsdl/soap12/";
+ /** HTTP binding namespace http://schemas.xmlsoap.org/wsdl/http/ */
+ static final String NS_HTTP = "http://schemas.xmlsoap.org/wsdl/http/";
+ /** SOAP-1.2 envelope namespace http://www.w3.org/2003/05/soap-envelope */
+ static final String NS_SOAP12_ENV = SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE;
+ /** The namespace for the SwA mime type */
+ static final String NS_SWA_MIME = "http://schemas.xmlsoap.org/wsdl/mime/";
+ /** Default namespace for WSDL-1.1 http://schemas.xmlsoap.org/wsdl/ */
+ static final String NS_WSDL11 = "http://schemas.xmlsoap.org/wsdl/";
+ /** The namespace for the MTOM content type attribute. */
+ static final String NS_XML_MIME = "http://www.w3.org/2005/05/xmlmime";
+ /** The namespace for XOP. */
+ static final String NS_XOP = "http://www.w3.org/2004/08/xop/include";
+
+ /** A constant representing the identity of the SOAP 1.1 over HTTP binding. */
+ public static final String SOAP11HTTP_BINDING = SOAPBinding.SOAP11HTTP_BINDING;
+ /** A constant representing the identity of the SOAP 1.2 over HTTP binding. */
+ public static final String SOAP12HTTP_BINDING = SOAPBinding.SOAP12HTTP_BINDING;
+ /** A constant representing the identity of the SOAP 1.1 over HTTP binding with MTOM enabled by default. */
+ public static final String SOAP11HTTP_MTOM_BINDING = SOAPBinding.SOAP11HTTP_MTOM_BINDING;
+ /** A constant representing the identity of the SOAP 1.2 over HTTP binding with MTOM enabled by default. */
+ public static final String SOAP12HTTP_MTOM_BINDING = SOAPBinding.SOAP12HTTP_MTOM_BINDING;
+ /** A constant representing the identity of the XML/HTTP binding. */
+ public static final String HTTP_BINDING = HTTPBinding.HTTP_BINDING;
+
+ /** SOAP-1.1 encoding URI */
+ static final String URI_SOAP11_ENC = SOAPConstants.URI_NS_SOAP_ENCODING;
+ /** SOAP-1.2 encoding URI */
+ static final String URI_SOAP12_ENC = SOAPConstants.URI_NS_SOAP_1_2_ENCODING;
+ /** SOAP HTTP transport URI in wsdl soap binding */
+ static final String URI_SOAP_HTTP = "http://schemas.xmlsoap.org/soap/http";
+ /** Literal encoding URI */
+ static final String URI_LITERAL_ENC = "";
+ /** WSDL 2.0 Encoding Rules */
+ static final String URI_STYLE_RPC = "http://www.w3.org/2004/03/wsdl/style/rpc";
+ static final String URI_STYLE_DOCUMENT = "http://www.w3.org/2004/03/wsdl/style/iri";
+
+ /** WS-Eventing namespace uri **/
+ static final String URI_WS_EVENTING = "http://schemas.xmlsoap.org/ws/2004/08/eventing";
+
+ /** WS-Policy namespace uri **/
+ static final String URI_WS_POLICY = "http://schemas.xmlsoap.org/ws/2004/09/policy";
+
+ /** WS-Addressing namespace uri **/
+ static final String URI_WS_ADDRESSING = "http://www.w3.org/2005/08/addressing";
+
+ /** JAX-WS binding customizations namespace uri **/
+ static final String URI_JAXWS_WSDL_CUSTOMIZATIONS = "http://java.sun.com/xml/ns/jaxws";
+
+ /**Style of WSDL */
+ static final String RPC_LITERAL = "RPC/Literal";
+ static final String DOCUMENT_LITERAL = "Document/Literal";
+
+ // Some prefixes
+ static final String PREFIX_ENV = SOAPConstants.SOAP_ENV_PREFIX;
+ static final String PREFIX_XMIME = "xmime";
+ static final String PREFIX_SOAP11 = "soap";
+ static final String PREFIX_SOAP11_ENC = "soap11-enc";
+ static final String PREFIX_TNS = "tns";
+ static final String PREFIX_WSDL = "wsdl";
+ static final String PREFIX_XOP = "xop";
+ static final String PREFIX_XSD = "xsd";
+ static final String PREFIX_XSI = "xsi";
+ static final String PREFIX_XML = "xml";
+
+ /** XOP Include */
+ static final QName NAME_XOP_INCLUDE = new QName(NS_XOP, "Include", PREFIX_XOP);
+
+ /** SOAP-1.1 roles */
+ static final String URI_SOAP11_NEXT_ACTOR = "http://schemas.xmlsoap.org/soap/actor/next";
+
+ /** SOAP-1.1 attributes */
+ static final String SOAP11_ATTR_ACTOR = "actor";
+ static final String SOAP11_ATTR_MUST_UNDERSTAND = "mustUnderstand";
+
+ /** SOAP-1.1 fault codes */
+ static final QName SOAP11_FAULT_CODE_CLIENT = new QName(NS_SOAP11_ENV, "Client", PREFIX_ENV);
+ static final QName SOAP11_FAULT_CODE_SERVER = new QName(NS_SOAP11_ENV, "Server", PREFIX_ENV);
+ static final QName SOAP11_FAULT_CODE_VERSION_MISMATCH = new QName(NS_SOAP11_ENV, "VersionMismatch", PREFIX_ENV);
+ static final QName SOAP11_FAULT_CODE_MUST_UNDERSTAND = new QName(NS_SOAP11_ENV, "MustUnderstand", PREFIX_ENV);
+
+ /** SOAP-1.1 elements */
+ static final QName SOAP11_FAULTCODE = new QName("faultcode");
+ static final QName SOAP11_FAULTSTRING = new QName("faultstring");
+ static final QName SOAP11_FAULTACTOR = new QName("faultactor");
+ static final QName SOAP11_DETAIL = new QName("detail");
+
+ /** SOAP-1.2 attributes */
+ static final String SOAP12_ATTR_ROLE = "role";
+ static final String SOAP12_ATTR_RELAY = "relay";
+
+ /**SOAP-1.2 elements */
+ static final QName SOAP12_CODE = new QName(NS_SOAP12_ENV, "Code", PREFIX_ENV);
+ static final QName SOAP12_VALUE = new QName(NS_SOAP12_ENV, "Value", PREFIX_ENV);
+ static final QName SOAP12_SUBCODE = new QName(NS_SOAP12_ENV, "Subcode", PREFIX_ENV);
+ static final QName SOAP12_REASON = new QName(NS_SOAP12_ENV, "Reason", PREFIX_ENV);
+ static final QName SOAP12_TEXT = new QName(NS_SOAP12_ENV, "Text", PREFIX_ENV);
+ static final QName SOAP12_ROLE = new QName(NS_SOAP12_ENV, "Role", PREFIX_ENV);
+ static final QName SOAP12_NODE = new QName(NS_SOAP12_ENV, "Node", PREFIX_ENV);
+ static final QName SOAP12_DETAIL = new QName(NS_SOAP12_ENV, "Detail", PREFIX_ENV);
+
+ /** The default RPC return parameter name */
+ static final String DEFAULT_RPC_RETURN_NAME = "result"; // FIXME: According to JSR-181 this should be 'return'
+
+ /** Standard Literal XML types */
+ static final QName TYPE_LITERAL_ANYSIMPLETYPE = new QName(NS_SCHEMA_XSD, "anySimpleType", PREFIX_XSD);
+ static final QName TYPE_LITERAL_ANYTYPE = new QName(NS_SCHEMA_XSD, "anyType", PREFIX_XSD);
+ static final QName TYPE_LITERAL_ANYURI = new QName(NS_SCHEMA_XSD, "anyURI", PREFIX_XSD);
+ static final QName TYPE_LITERAL_BASE64BINARY = new QName(NS_SCHEMA_XSD, "base64Binary", PREFIX_XSD);
+ static final QName TYPE_LITERAL_BOOLEAN = new QName(NS_SCHEMA_XSD, "boolean", PREFIX_XSD);
+ static final QName TYPE_LITERAL_BYTE = new QName(NS_SCHEMA_XSD, "byte", PREFIX_XSD);
+ static final QName TYPE_LITERAL_DATE = new QName(NS_SCHEMA_XSD, "date", PREFIX_XSD);
+ static final QName TYPE_LITERAL_DATETIME = new QName(NS_SCHEMA_XSD, "dateTime", PREFIX_XSD);
+ static final QName TYPE_LITERAL_DECIMAL = new QName(NS_SCHEMA_XSD, "decimal", PREFIX_XSD);
+ static final QName TYPE_LITERAL_DOUBLE = new QName(NS_SCHEMA_XSD, "double", PREFIX_XSD);
+ static final QName TYPE_LITERAL_DURATION = new QName(NS_SCHEMA_XSD, "duration", PREFIX_XSD);
+ static final QName TYPE_LITERAL_FLOAT = new QName(NS_SCHEMA_XSD, "float", PREFIX_XSD);
+ static final QName TYPE_LITERAL_GDAY = new QName(NS_SCHEMA_XSD, "gDay", PREFIX_XSD);
+ static final QName TYPE_LITERAL_GMONTH = new QName(NS_SCHEMA_XSD, "gMonth", PREFIX_XSD);
+ static final QName TYPE_LITERAL_GMONTHDAY = new QName(NS_SCHEMA_XSD, "gMonthDay", PREFIX_XSD);
+ static final QName TYPE_LITERAL_GYEAR = new QName(NS_SCHEMA_XSD, "gYear", PREFIX_XSD);
+ static final QName TYPE_LITERAL_GYEARMONTH = new QName(NS_SCHEMA_XSD, "gYearMonth", PREFIX_XSD);
+ static final QName TYPE_LITERAL_HEXBINARY = new QName(NS_SCHEMA_XSD, "hexBinary", PREFIX_XSD);
+ static final QName TYPE_LITERAL_ID = new QName(NS_SCHEMA_XSD, "ID", PREFIX_XSD);
+ static final QName TYPE_LITERAL_INT = new QName(NS_SCHEMA_XSD, "int", PREFIX_XSD);
+ static final QName TYPE_LITERAL_INTEGER = new QName(NS_SCHEMA_XSD, "integer", PREFIX_XSD);
+ static final QName TYPE_LITERAL_LANGUAGE = new QName(NS_SCHEMA_XSD, "language", PREFIX_XSD);
+ static final QName TYPE_LITERAL_LONG = new QName(NS_SCHEMA_XSD, "long", PREFIX_XSD);
+ static final QName TYPE_LITERAL_NAME = new QName(NS_SCHEMA_XSD, "Name", PREFIX_XSD);
+ static final QName TYPE_LITERAL_NCNAME = new QName(NS_SCHEMA_XSD, "NCName", PREFIX_XSD);
+ static final QName TYPE_LITERAL_NEGATIVEINTEGER = new QName(NS_SCHEMA_XSD, "negativeInteger", PREFIX_XSD);
+ static final QName TYPE_LITERAL_NMTOKEN = new QName(NS_SCHEMA_XSD, "NMTOKEN", PREFIX_XSD);
+ static final QName TYPE_LITERAL_NMTOKENS = new QName(NS_SCHEMA_XSD, "NMTOKENS", PREFIX_XSD);
+ static final QName TYPE_LITERAL_NONNEGATIVEINTEGER = new QName(NS_SCHEMA_XSD, "nonNegativeInteger", PREFIX_XSD);
+ static final QName TYPE_LITERAL_NONPOSITIVEINTEGER = new QName(NS_SCHEMA_XSD, "nonPositiveInteger", PREFIX_XSD);
+ static final QName TYPE_LITERAL_NORMALIZEDSTRING = new QName(NS_SCHEMA_XSD, "normalizedString", PREFIX_XSD);
+ static final QName TYPE_LITERAL_POSITIVEINTEGER = new QName(NS_SCHEMA_XSD, "positiveInteger", PREFIX_XSD);
+ static final QName TYPE_LITERAL_QNAME = new QName(NS_SCHEMA_XSD, "QName", PREFIX_XSD);
+ static final QName TYPE_LITERAL_SHORT = new QName(NS_SCHEMA_XSD, "short", PREFIX_XSD);
+ static final QName TYPE_LITERAL_STRING = new QName(NS_SCHEMA_XSD, "string", PREFIX_XSD);
+ static final QName TYPE_LITERAL_TIME = new QName(NS_SCHEMA_XSD, "time", PREFIX_XSD);
+ static final QName TYPE_LITERAL_TOKEN = new QName(NS_SCHEMA_XSD, "token", PREFIX_XSD);
+ static final QName TYPE_LITERAL_UNSIGNEDBYTE = new QName(NS_SCHEMA_XSD, "unsignedByte", PREFIX_XSD);
+ static final QName TYPE_LITERAL_UNSIGNEDINT = new QName(NS_SCHEMA_XSD, "unsignedInt", PREFIX_XSD);
+ static final QName TYPE_LITERAL_UNSIGNEDLONG = new QName(NS_SCHEMA_XSD, "unsignedLong", PREFIX_XSD);
+ static final QName TYPE_LITERAL_UNSIGNEDSHORT = new QName(NS_SCHEMA_XSD, "unsignedShort", PREFIX_XSD);
+
+ /** Standard SOAP-1.1 encoded XML types */
+ static final QName TYPE_SOAP11_ANYSIMPLETYPE = new QName(URI_SOAP11_ENC, "anySimpleType", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_ANYTYPE = new QName(URI_SOAP11_ENC, "anyType", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_ANYURI = new QName(URI_SOAP11_ENC, "anyURI", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_BASE64 = new QName(URI_SOAP11_ENC, "base64", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_BASE64BINARY = new QName(URI_SOAP11_ENC, "base64Binary", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_BOOLEAN = new QName(URI_SOAP11_ENC, "boolean", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_BYTE = new QName(URI_SOAP11_ENC, "byte", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_DATE = new QName(URI_SOAP11_ENC, "date", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_DATETIME = new QName(URI_SOAP11_ENC, "dateTime", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_DECIMAL = new QName(URI_SOAP11_ENC, "decimal", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_DOUBLE = new QName(URI_SOAP11_ENC, "double", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_DURATION = new QName(URI_SOAP11_ENC, "duration", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_FLOAT = new QName(URI_SOAP11_ENC, "float", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_GDAY = new QName(URI_SOAP11_ENC, "gDay", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_GMONTH = new QName(URI_SOAP11_ENC, "gMonth", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_GMONTHDAY = new QName(URI_SOAP11_ENC, "gMonthDay", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_GYEAR = new QName(URI_SOAP11_ENC, "gYear", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_GYEARMONTH = new QName(URI_SOAP11_ENC, "gYearMonth", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_HEXBINARY = new QName(URI_SOAP11_ENC, "hexBinary", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_ID = new QName(URI_SOAP11_ENC, "ID", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_INT = new QName(URI_SOAP11_ENC, "int", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_INTEGER = new QName(URI_SOAP11_ENC, "integer", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_LANGUAGE = new QName(URI_SOAP11_ENC, "language", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_LONG = new QName(URI_SOAP11_ENC, "long", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_NAME = new QName(URI_SOAP11_ENC, "Name", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_NCNAME = new QName(URI_SOAP11_ENC, "NCName", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_NEGATIVEINTEGER = new QName(URI_SOAP11_ENC, "negativeInteger", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_NMTOKEN = new QName(URI_SOAP11_ENC, "NMTOKEN", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_NMTOKENS = new QName(URI_SOAP11_ENC, "NMTOKENS", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_NONNEGATIVEINTEGER = new QName(URI_SOAP11_ENC, "nonNegativeInteger", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_NONPOSITIVEINTEGER = new QName(URI_SOAP11_ENC, "nonPositiveInteger", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_NORMALIZEDSTRING = new QName(URI_SOAP11_ENC, "normalizedString", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_POSITIVEINTEGER = new QName(URI_SOAP11_ENC, "positiveInteger", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_QNAME = new QName(URI_SOAP11_ENC, "QName", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_SHORT = new QName(URI_SOAP11_ENC, "short", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_STRING = new QName(URI_SOAP11_ENC, "string", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_TIME = new QName(URI_SOAP11_ENC, "time", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_TOKEN = new QName(URI_SOAP11_ENC, "token", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_UNSIGNEDBYTE = new QName(URI_SOAP11_ENC, "unsignedByte", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_UNSIGNEDINT = new QName(URI_SOAP11_ENC, "unsignedInt", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_UNSIGNEDLONG = new QName(URI_SOAP11_ENC, "unsignedLong", PREFIX_SOAP11_ENC);
+ static final QName TYPE_SOAP11_UNSIGNEDSHORT = new QName(URI_SOAP11_ENC, "unsignedShort", PREFIX_SOAP11_ENC);
+
+ /** Encoded mime type namespace for internall and DII use */
+ static final String NS_ATTACHMENT_MIME_TYPE = "http://www.jboss.org/jbossws/attachment/mimetype";
+
+ /** Attachment Types */
+ static final QName TYPE_MIME_APPLICATION_XML = new QName(NS_ATTACHMENT_MIME_TYPE, "application_xml");
+ static final QName TYPE_MIME_IMAGE_JPEG = new QName(NS_ATTACHMENT_MIME_TYPE, "image_jpeg");
+ static final QName TYPE_MIME_IMAGE_GIF = new QName(NS_ATTACHMENT_MIME_TYPE, "image_gif");
+ static final QName TYPE_MIME_MULTIPART_MIXED = new QName(NS_ATTACHMENT_MIME_TYPE, "multipart_mixed");
+ static final QName TYPE_MIME_TEXT_PLAIN = new QName(NS_ATTACHMENT_MIME_TYPE, "text_plain");
+ static final QName TYPE_MIME_TEXT_XML = new QName(NS_ATTACHMENT_MIME_TYPE, "text_xml");
+
+ static final QName TYPE_XMIME_DEFAULT = new QName(NS_XML_MIME, "base64Binary");
+
+ /** For out of bound transport (i.e. in headers); http://www.w3.org/2004/08/wsdl/feature/AD/data */
+ static final String WSDL_PROPERTY_APPLICATION_DATA = "http://www.w3.org/2004/08/wsdl/feature/AD/data";
+ /** The key to the original message part name */
+ static final String WSDL_PROPERTY_MESSAGE_NAME = "http://www.jboss.org/jbossws/messagename";
+ /** Key to the inbound message name */
+ static final String WSDL_PROPERTY_MESSAGE_NAME_IN = "http://www.jboss.org/jbossws/messagename/in";
+ /** Key to the outbound message name */
+ static final String WSDL_PROPERTY_MESSAGE_NAME_OUT = "http://www.jboss.org/jbossws/messagename/out";
+ /** Key to the inbound message name */
+ static final String WSDL_PROPERTY_MESSAGE_NAME_FAULT = "http://www.jboss.org/jbossws/messagename/fault";
+ /** Key to the inbound wsa action */
+ static final String WSDL_PROPERTY_ACTION_IN = "http://www.jboss.org/jbossws/wsa/actionIn";
+ /** Key to the outbound wsa action */
+ static final String WSDL_PROPERTY_ACTION_OUT = "http://www.jboss.org/jbossws/wsa/actionOut";
+ /** Key to the fault wsa action */
+ static final String WSDL_PROPERTY_ACTION_FAULT = "http://www.jboss.org/jbossws/wsa/actionFault";
+
+ static final String WSDL_PROPERTY_EVENTSOURCE = "http://www.jboss.org/jbossws/wse/isEventSource";
+
+ static final String WSDL_ELEMENT_EPR = "http://www.jboss.org/jbossws/epr";
+ static final String WSDL_ELEMENT_POLICY = "http://www.jboss.org/jbossws/wsp/policy";
+ static final String WSDL_PROPERTY_POLICYURIS = "http://www.jboss.org/jbossws/wsp/policyURIs";
+ static final String WSDL_ELEMENT_POLICYREFERENCE = "http://www.jboss.org/jbossws/wsp/policyReference";
+
+ /** The key to the original message part name */
+ static final String WSDL_PROPERTY_PART_NAME = "http://www.jboss.org/jbossws/partname";
+ /** The key to the message part type in case a part does not reference an element; http://www.jboss.org/jbossws/part/xmltype */
+ static final String WSDL_PROPERTY_PART_XMLTYPE = "http://www.jboss.org/jbossws/part/xmltype";
+ /** Used as WSDL 2.0 property string to provide support for WSDL 1.1 mime types */
+ static final String WSDL_PROPERTY_WSDL11_MIME_TYPE = NS_ATTACHMENT_MIME_TYPE;
+ /** Indicate that the operation has zero arguments */
+ static final String WSDL_PROPERTY_ZERO_ARGS = "http://www.jboss.org/jbossws/zero-args";
+ /** Indicate that the operation has a void return*/
+ static final String WSDL_PROPERTY_VOID_RETURN = "http://www.jboss.org/jbossws/void-return";
+ /** Indicates that an output is a return parameter */
+ static final String WSDL_PROPERTY_RETURN_PART = "http://www.jboss.org/jbossws/return-part";
+
+ static final QName WSDL_ATTRIBUTE_WSA_ACTION = new QName(URI_WS_ADDRESSING, "Action");
+
+ static final QName WSDL_ATTRIBUTE_WSE_EVENTSOURCE = new QName(URI_WS_EVENTING, "EventSource");
+
+ static final QName WSDL_ATTRIBUTE_WSP_POLICYURIS = new QName(URI_WS_POLICY, "PolicyURIs");
+ static final QName WSDL_ELEMENT_WSP_POLICYREFERENCE = new QName(URI_WS_POLICY, "PolicyReference");
+ static final QName WSDL_ELEMENT_JAXWS_BINDINGS = new QName(URI_JAXWS_WSDL_CUSTOMIZATIONS, "bindings");
+ static final QName WSDL_ELEMENT_JAXWS_CLASS = new QName(URI_JAXWS_WSDL_CUSTOMIZATIONS, "class");
+ static final QName WSDL_ELEMENT_JAXWS_METHOD = new QName(URI_JAXWS_WSDL_CUSTOMIZATIONS, "method");
+ static final QName WSDL_ELEMENT_JAXWS_JAVADOC = new QName(URI_JAXWS_WSDL_CUSTOMIZATIONS, "javadoc");
+
+ /** WSDL-2.0 exchange patterns */
+ static final String WSDL20_PATTERN_IN_ONLY = "http://www.w3.org/2004/08/wsdl/in-only";
+ static final String WSDL20_PATTERN_ROUST_IN_ONLY = "http://www.w3.org/2004/08/wsdl/robust-in-only";
+ static final String WSDL20_PATTERN_IN_OUT = "http://www.w3.org/2004/08/wsdl/in-out";
+ static final String WSDL20_PATTERN_IN_OPTIONAL_OUT = "http://www.w3.org/2004/08/wsdl/in-opt-out";
+ static final String WSDL20_PATTERN_OUT_ONLY = "http://www.w3.org/2004/08/wsdl/out-only";
+ static final String WSDL20_PATTERN_ROBUST_OUT_ONLY = "http://www.w3.org/2004/08/wsdl/robust-out-only";
+ static final String WSDL20_PATTERN_OUT_IN = "http://www.w3.org/2004/08/wsdl/out-in";
+ static final String WSDL20_PATTERN_OUT_OPT_IN = "http://www.w3.org/2004/08/wsdl/out-opt-in";
+
+ static final String ASYNC_METHOD_SUFFIX = "Async";
+
+ static final String EAGER_INITIALIZE_JAXB_CONTEXT_CACHE = "org.jboss.ws.eagerInitializeJAXBContextCache";
+
+ static final String DOM_CONTENT_CANONICAL_NORMALIZATION = "org.jboss.ws.DOMContentCanonicalNormalization";
+
+ static final String ALWAYS_RESOLVE_DOCUMENT_BUILDER_FACTORY = "org.jboss.ws.alwaysResolveDocumentBuilderFactory";
+
+ static final String HTTP_KEEP_ALIVE = "org.jboss.ws.http.keepAlive";
+
+ static final String HTTP_MAX_CONNECTIONS = "org.jboss.ws.http.maxConnections";
+
+ static final String NETTY_MESSAGE = "org.jboss.ws.http.netty.Message";
+
+ static final boolean BC_CONTEXT_MODE = Boolean.parseBoolean(System.getProperty("org.jboss.ws.backward_compatible_context_creator", "false"));
+}
Property changes on: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/Constants.java
___________________________________________________________________
Added: svn:keywords
+ Revision Date
Added: svn:eol-style
+ native
Added: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/ContentHandlerRegistry.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/ContentHandlerRegistry.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/ContentHandlerRegistry.java 2011-07-21 20:42:34 UTC (rev 37280)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.actions.soap.attachment;
+//package org.jboss.ws.core.soap.attachment;
+
+import java.awt.datatransfer.DataFlavor;
+import java.util.HashSet;
+import java.util.Iterator;
+//import java.util.ResourceBundle;
+
+import javax.activation.CommandMap;
+import javax.activation.DataContentHandler;
+import javax.activation.MailcapCommandMap;
+
+//import org.jboss.ws.api.util.BundleUtils;
+
+import com.sun.mail.handlers.multipart_mixed;
+import com.sun.mail.handlers.text_html;
+import com.sun.mail.handlers.text_plain;
+
+/**
+ * <code>ContentHandlerRegistry</code> is responsible for registering
+ * JBossWS data content handlers in JAF.
+ *
+ * @author <a href="mailto:jason at stacksmash.com">Jason T. Greene</a>
+ */
+public class ContentHandlerRegistry
+{
+ //private static final ResourceBundle bundle = BundleUtils.getBundle(ContentHandlerRegistry.class);
+ private static final String JAF_CONTENT_HANDLER = "x-java-content-handler";
+
+ private static HashSet handlerRegistry = new HashSet();
+
+ static
+ {
+ addRegistryEntry(XmlDataContentHandler.class);
+ addRegistryEntry(ImageDataContentHandler.class);
+ addRegistryEntry(ByteArrayContentHandler.class);
+ addRegistryEntry(text_plain.class);
+ addRegistryEntry(text_html.class);
+ addRegistryEntry(multipart_mixed.class);
+ }
+
+ private static void addRegistryEntry(Class contentHandler)
+ {
+ handlerRegistry.add(contentHandler);
+ }
+
+ private static void registerContentHandler(Class contentHandler)
+ {
+ DataContentHandler handler;
+ MailcapCommandMap mailcap;
+
+ try
+ {
+ mailcap = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
+ handler = (DataContentHandler) contentHandler.newInstance();
+ }
+ catch (Exception e)
+ {
+ //throw new RuntimeException(BundleUtils.getMessage(bundle, "CAN_NOT_REGISTER_CONTENT_HANDLER", e.getMessage()));
+ throw new RuntimeException("CAN_NOT_REGISTER_CONTENT_HANDLER: " + e.getMessage());
+ }
+
+ DataFlavor[] flavors = handler.getTransferDataFlavors();
+ if (flavors == null)
+ return;
+
+ for (int i = 0; i < flavors.length; i++)
+ {
+ DataFlavor flavor = flavors[i];
+ String entry = flavor.getMimeType() + ";;" + JAF_CONTENT_HANDLER + "=" + contentHandler.getName();
+ mailcap.addMailcap(entry);
+ }
+ }
+
+ /**
+ * Loads all JBossWS content handlers.
+ */
+ public static void register()
+ {
+ Iterator i = handlerRegistry.iterator();
+ while (i.hasNext())
+ registerContentHandler((Class) i.next());
+ }
+}
Property changes on: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/ContentHandlerRegistry.java
___________________________________________________________________
Added: svn:keywords
+ Revision Date
Added: svn:eol-style
+ native
Added: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/IOUtils.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/IOUtils.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/IOUtils.java 2011-07-21 20:42:34 UTC (rev 37280)
@@ -0,0 +1,206 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.actions.soap.attachment;
+//package org.jboss.ws.common;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.Writer;
+//import java.util.ResourceBundle;
+
+import javax.activation.DataHandler;
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+//import javax.xml.ws.WebServiceException;
+
+import org.jboss.mx.util.MBeanServerLocator;
+
+//import org.jboss.ws.api.util.BundleUtils;
+//import org.jboss.wsf.spi.SPIProvider;
+//import org.jboss.wsf.spi.SPIProviderResolver;
+//import org.jboss.wsf.spi.management.ServerConfig;
+//import org.jboss.wsf.spi.management.ServerConfigFactory;
+
+/**
+ * IO utilites
+ *
+ * @author Thomas.Diesler at jboss.org
+ */
+public final class IOUtils
+{
+ //private static final ResourceBundle bundle = BundleUtils.getBundle(IOUtils.class);
+ // Hide the constructor
+ private IOUtils()
+ {
+ }
+
+ public static Writer getCharsetFileWriter(File file, String charset) throws IOException
+ {
+ return new OutputStreamWriter(new FileOutputStream(file), charset);
+ }
+
+ /** Copy the input stream to the output stream
+ */
+ public static void copyStream(OutputStream outs, InputStream ins) throws IOException
+ {
+ try
+ {
+ byte[] bytes = new byte[1024];
+ int r = ins.read(bytes);
+ while (r > 0)
+ {
+ outs.write(bytes, 0, r);
+ r = ins.read(bytes);
+ }
+ }
+ catch (IOException e)
+ {
+ throw e;
+ }
+ finally{
+ ins.close();
+ }
+ }
+
+ /** Copy the reader to the output stream
+ */
+ public static void copyReader(OutputStream outs, Reader reader) throws IOException
+ {
+ try
+ {
+ OutputStreamWriter writer = new OutputStreamWriter(outs);
+ char[] bytes = new char[1024];
+ int r = reader.read(bytes);
+ while (r > 0)
+ {
+ writer.write(bytes, 0, r);
+ r = reader.read(bytes);
+ }
+ }
+ catch (IOException e)
+ {
+ throw e;
+ }
+ finally{
+ reader.close();
+ }
+ }
+
+ public static byte[] convertToBytes(DataHandler dh)
+ {
+ try
+ {
+ ByteArrayOutputStream buffOS = new ByteArrayOutputStream();
+ dh.writeTo(buffOS);
+ return buffOS.toByteArray();
+ }
+ catch (IOException e)
+ {
+ //throw new WebServiceException(BundleUtils.getMessage(bundle, "UNABLE_TO_CONVERT_DATAHANDLER", e.getMessage()));
+ throw new RuntimeException("UNABLE_TO_CONVERT_DATAHANDLER: " + e.getMessage());
+ }
+ }
+
+ /**
+ * Transform a Reader to an InputStream
+ * Background is that DocumentBuilder.parse() cannot take the Reader directly
+ */
+ public static InputStream transformReader(Reader reader) throws IOException
+ {
+ try
+ {
+ int capacity = 1024;
+ char[] charBuffer = new char[capacity];
+ StringBuilder strBuffer = new StringBuilder(capacity);
+
+ int len = reader.read(charBuffer, 0, capacity);
+ while (len > 0)
+ {
+ strBuffer.append(charBuffer, 0, len);
+ len = reader.read(charBuffer, 0, capacity);
+ }
+ return new ByteArrayInputStream(strBuffer.toString().getBytes());
+ }
+ catch (IOException e)
+ {
+ throw e;
+ }
+ finally{
+ reader.close();
+ }
+ }
+
+ public static File createTempDirectory() throws IOException
+ {
+ //File tmpdir = null;
+
+ //try
+ //{
+ // TODO: recursive dependency, ohoh
+
+ //SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
+ //ServerConfig config = spiProvider.getSPI(ServerConfigFactory.class).getServerConfig();
+ //tmpdir = new File(config.getServerTempDir().getCanonicalPath() + "/jbossws");
+ //tmpdir.mkdirs();
+ //}
+ //catch (Throwable t)
+ //{
+ // Use the Java temp directory if there is no server config (the client)
+ //}
+
+ //return tmpdir;
+ if (tempDir == null)
+ {
+ synchronized (IOUtils.class)
+ {
+ if (tempDir == null)
+ {
+ MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
+ try
+ {
+ tempDir = (File)mbeanServer.getAttribute(new ObjectName("jboss.system:type=ServerConfig"), "ServerTempDir");
+ }
+ catch (JMException ignored) {}
+ String tempName = IOUtils.class.getSimpleName();
+ if ( tempDir == null || !tempDir.exists() )
+ {
+ File tempFile = File.createTempFile(tempName + "-", ".tmp");
+ tempDir = tempFile.getParentFile();
+ tempFile.delete();
+ }
+ tempDir = new File(tempDir, tempName);
+ tempDir.mkdirs();
+ }
+ }
+ }
+ return tempDir;
+ }
+ private static File tempDir = null;
+}
Property changes on: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/IOUtils.java
___________________________________________________________________
Added: svn:keywords
+ Revision Date
Added: svn:eol-style
+ native
Added: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/ImageDataContentHandler.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/ImageDataContentHandler.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/ImageDataContentHandler.java 2011-07-21 20:42:34 UTC (rev 37280)
@@ -0,0 +1,213 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.actions.soap.attachment;
+//package org.jboss.ws.core.soap.attachment;
+
+import java.awt.Component;
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.MediaTracker;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+//import java.util.ResourceBundle;
+
+import javax.activation.ActivationDataFlavor;
+import javax.activation.DataContentHandler;
+import javax.activation.DataSource;
+import javax.imageio.ImageIO;
+import javax.imageio.ImageWriter;
+import javax.imageio.stream.ImageOutputStream;
+
+//import org.jboss.logging.Logger;
+import org.apache.log4j.Logger;
+//import org.jboss.ws.api.util.BundleUtils;
+
+/**
+ * <code>ImageDataContentHandler</code> is a JAF content handler that handles
+ * marshalling/unmarshalling between <code>Image</code> objects and a stream.
+ *
+ * This handler provides support for all mime types handled by the ImageIO
+ * implementation on the virtual machine that this class is ran under. These
+ * are dynamically registered, so any custom ImageIO plugins are discovered and
+ * used.
+ *
+ * It's important to note that some mime types (for example image/gif) may not
+ * have encoding support provided by the ImageIO implementation. If this happens
+ * an exception will be thrown indicating the lack of encoding support.
+ *
+ * @author <a href="mailto:jason at stacksmash.com">Jason T. Greene</a>
+ * @author <a href="mailto:mageshbk at jboss.com">Magesh Kumar B</a>
+ */
+public class ImageDataContentHandler extends Component implements DataContentHandler
+{
+ //private static final ResourceBundle bundle = BundleUtils.getBundle(ImageDataContentHandler.class);
+ // provide logging
+ private static Logger log = Logger.getLogger(ImageDataContentHandler.class);
+
+ private static DataFlavor[] flavors;
+
+ static
+ {
+ buildFlavors();
+
+ // Don't write back to disk since the images are in memory anyways
+ ImageIO.setUseCache(false);
+ }
+
+ private static void buildFlavors()
+ {
+ String[] mimeTypes = ImageIO.getReaderMIMETypes();
+ if (mimeTypes == null)
+ return;
+ ArrayList flavs = new ArrayList ();
+ DataFlavor flavor;
+ //flavors = new DataFlavor[mimeTypes.length];
+ for (int i = 0; i < mimeTypes.length; i++)
+ {
+ try
+ {
+ flavor = new ActivationDataFlavor(Image.class, mimeTypes[i], "Image");
+ flavs.add(flavor);
+ }
+ catch (IllegalArgumentException iae)
+ {
+ //This mime type is not supported
+ //log.warn(BundleUtils.getMessage(bundle, "UNSUPPORTED_MIME_TYPE", mimeTypes[i] ));
+ log.warn("UNSUPPORTED_MIME_TYPE: " + mimeTypes[i]);
+ }
+ }
+ int size = flavs.size();
+ flavors = new DataFlavor[size];
+ for (int i = 0; i < size; i++)
+ {
+ flavors[i] = (ActivationDataFlavor)flavs.get(i);
+ }
+ }
+
+ private static ImageWriter getImageWriter(String mimeType) {
+ Iterator i = ImageIO.getImageWritersByMIMEType(mimeType);
+ if (! i.hasNext())
+ return null;
+
+ return (ImageWriter) i.next();
+ }
+
+ private BufferedImage getBufferedImage(Image image) throws IOException
+ {
+ if (image instanceof BufferedImage)
+ return (BufferedImage) image;
+
+ try
+ {
+ BufferedImage buffered;
+
+ MediaTracker tracker = new MediaTracker(this);
+ tracker.addImage(image, 0);
+ tracker.waitForAll();
+ buffered = new BufferedImage(image.getHeight(null), image.getWidth(null), BufferedImage.TYPE_INT_RGB);
+ Graphics2D gfx = buffered.createGraphics();
+ gfx.drawImage(image, 0, 0, null);
+ return buffered;
+ }
+ catch (InterruptedException e)
+ {
+ //throw new IOException(BundleUtils.getMessage(bundle, "COULD_NOT_CONVERT_IMAGE", e.getMessage()));
+ throw new IOException("COULD_NOT_CONVERT_IMAGE: " + e.getMessage());
+ }
+ }
+
+ /**
+ * Returns a {@link Image} from the specified
+ * data source.
+ *
+ * @param ds the activation datasource
+ * @return an AWT image object
+ */
+ public Object getContent(DataSource ds) throws IOException
+ {
+ return ImageIO.read(ds.getInputStream());
+ }
+
+ /**
+ * Returns a {@link Image}from the specified data source. This method is
+ * useless for this content handler because the image format is dynamically
+ * discovered.
+ *
+ * @param df the flavor specifiying the mime type of ds
+ * @param ds the activation data source
+ * @return an AWT image object
+ */
+ public Object getTransferData(DataFlavor df, DataSource ds) throws UnsupportedFlavorException, IOException
+ {
+ return getContent(ds);
+ }
+
+ /**
+ * Returns the acceptable data flavors that this content handler supports.
+ *
+ * @return array of <code>ActivationDataHandlers</code>
+ */
+ public DataFlavor[] getTransferDataFlavors()
+ {
+ return flavors;
+ }
+
+ /**
+ * Writes the passed in {@link Image} object using the specified
+ * mime type to the specified output stream.
+ *
+ * @param obj an AWT image object
+ * @param mimeType the mime type of the image format to use
+ * @param os the output stream to write this image to
+ */
+ public void writeTo(Object obj, String mimeType, OutputStream os) throws IOException
+ {
+ if (obj == null)
+ //throw new IOException(BundleUtils.getMessage(bundle, "CANNOT_WRITE_NULL_SOURCE_OBJECT"));
+ throw new IOException("CANNOT_WRITE_NULL_SOURCE_OBJECT");
+
+ if (!(obj instanceof Image))
+ //throw new IOException(BundleUtils.getMessage(bundle, "IMAGE_EXPECTED", obj.getClass().getName()));
+ throw new IOException("IMAGE_EXPECTED: " + obj.getClass().getName());
+
+ ImageWriter writer = getImageWriter(mimeType);
+ if (writer == null)
+ //throw new IOException(BundleUtils.getMessage(bundle, "IMAGE_ENCODING_NOT_AVAILABLE", mimeType ));
+ throw new IOException("IMAGE_ENCODING_NOT_AVAILABLE: " + mimeType);
+
+ BufferedImage buffered = getBufferedImage((Image) obj);
+ ImageOutputStream stream = ImageIO.createImageOutputStream(os);
+
+ writer.setOutput(stream);
+ writer.write(buffered);
+
+ // We must close the stream now because if we are wrapping a ServletOutputStream,
+ // a future gc can commit a stream that used in another thread (very very bad)
+ stream.flush();
+ stream.close();
+ }
+}
Property changes on: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/ImageDataContentHandler.java
___________________________________________________________________
Added: svn:keywords
+ Revision Date
Added: svn:eol-style
+ native
Added: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/JavaUtils.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/JavaUtils.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/JavaUtils.java 2011-07-21 20:42:34 UTC (rev 37280)
@@ -0,0 +1,697 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.actions.soap.attachment;
+//package org.jboss.ws.common;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+import java.lang.reflect.WildcardType;
+import java.util.HashMap;
+import java.util.HashSet;
+//import java.util.ResourceBundle;
+
+//import org.jboss.logging.Logger;
+import org.apache.log4j.Logger;
+//import org.jboss.ws.api.util.BundleUtils;
+
+/** Java utilities
+ *
+ * @author Thomas.Diesler at jboss.org
+ * @since 22-Dec-2004
+ */
+public class JavaUtils
+{
+ //private static final ResourceBundle bundle = BundleUtils.getBundle(JavaUtils.class);
+ // provide logging
+ private static final Logger log = Logger.getLogger(JavaUtils.class);
+
+ private static HashMap<String, Class<?>> primitiveNames = new HashMap<String, Class<?>>(8);
+ private static HashMap<String, String> primitiveNameDescriptors = new HashMap<String, String>(8);
+ private static HashSet<String> reservedKeywords = new HashSet<String>(50);
+
+ static
+ {
+ primitiveNames.put("int", int.class);
+ primitiveNames.put("short", short.class);
+ primitiveNames.put("boolean", boolean.class);
+ primitiveNames.put("byte", byte.class);
+ primitiveNames.put("long", long.class);
+ primitiveNames.put("double", double.class);
+ primitiveNames.put("float", float.class);
+ primitiveNames.put("char", char.class);
+
+ primitiveNameDescriptors.put("int", "I");
+ primitiveNameDescriptors.put("short", "S");
+ primitiveNameDescriptors.put("boolean", "Z");
+ primitiveNameDescriptors.put("byte", "B");
+ primitiveNameDescriptors.put("long", "J");
+ primitiveNameDescriptors.put("double", "D");
+ primitiveNameDescriptors.put("float", "F");
+ primitiveNameDescriptors.put("char", "C");
+
+ reservedKeywords.add("abstract");
+ reservedKeywords.add("continue");
+ reservedKeywords.add("for");
+ reservedKeywords.add("new");
+ reservedKeywords.add("switch");
+ reservedKeywords.add("assert");
+ reservedKeywords.add("default");
+ reservedKeywords.add("if");
+ reservedKeywords.add("package");
+ reservedKeywords.add("synchronized");
+ reservedKeywords.add("boolean");
+ reservedKeywords.add("do");
+ reservedKeywords.add("goto");
+ reservedKeywords.add("private");
+ reservedKeywords.add("this");
+ reservedKeywords.add("break");
+ reservedKeywords.add("double");
+ reservedKeywords.add("implements");
+ reservedKeywords.add("protected");
+ reservedKeywords.add("throw");
+ reservedKeywords.add("byte");
+ reservedKeywords.add("else");
+ reservedKeywords.add("import");
+ reservedKeywords.add("public");
+ reservedKeywords.add("throws");
+ reservedKeywords.add("case");
+ reservedKeywords.add("enum");
+ reservedKeywords.add("instanceof");
+ reservedKeywords.add("return");
+ reservedKeywords.add("transient");
+ reservedKeywords.add("catch");
+ reservedKeywords.add("extends");
+ reservedKeywords.add("int");
+ reservedKeywords.add("short");
+ reservedKeywords.add("try");
+ reservedKeywords.add("char");
+ reservedKeywords.add("final");
+ reservedKeywords.add("interface");
+ reservedKeywords.add("static");
+ reservedKeywords.add("void");
+ reservedKeywords.add("class");
+ reservedKeywords.add("finally");
+ reservedKeywords.add("long");
+ reservedKeywords.add("strictfp");
+ reservedKeywords.add("volatile");
+ reservedKeywords.add("const");
+ reservedKeywords.add("float");
+ reservedKeywords.add("native");
+ reservedKeywords.add("super");
+ reservedKeywords.add("while");
+ }
+
+ /**
+ * Load a Java type from a given class loader.
+ *
+ * @param typeName maybe the source notation of a primitve, class name, array of both
+ */
+ public static Class<?> loadJavaType(String typeName) throws ClassNotFoundException
+ {
+ return loadJavaType(typeName, null);
+ }
+
+ /**
+ * Load a Java type from a given class loader.
+ *
+ * @param typeName maybe the source notation of a primitve, class name, array of both
+ */
+ public static Class<?> loadJavaType(String typeName, ClassLoader classLoader) throws ClassNotFoundException
+ {
+ if (classLoader == null)
+ classLoader = Thread.currentThread().getContextClassLoader();
+
+ Class<?> javaType = primitiveNames.get(typeName);
+ if (javaType == null)
+ javaType = getArray(typeName, classLoader);
+
+ if (javaType == null)
+ javaType = classLoader.loadClass(typeName);
+
+ return javaType;
+ }
+
+ /**
+ * True if the given type name is the source notation of a primitive or array of which.
+ */
+ public static boolean isPrimitive(String javaType)
+ {
+ return getPrimitiveType(javaType) != null;
+ }
+
+ /**
+ * True if the given class is a primitive or array of which.
+ */
+ public static boolean isPrimitive(Class<?> javaType)
+ {
+ return javaType.isPrimitive() || (javaType.isArray() && isPrimitive(javaType.getComponentType()));
+ }
+
+ public static Class<?> getPrimitiveType(String javaType)
+ {
+ Class<?> type = primitiveNames.get(javaType);
+ if (type != null)
+ return type;
+
+ try
+ {
+ // null loader = primitive only
+ type = getArray(javaType, null);
+ }
+ catch (ClassNotFoundException e)
+ {
+ // This will actually never be thrown since is null
+ }
+
+ return type;
+ }
+
+ private static Class<?> getArray(String javaType, ClassLoader loader) throws ClassNotFoundException
+ {
+ if (javaType.charAt(0) == '[')
+ return getArrayFromJVMName(javaType, loader);
+
+ if (javaType.endsWith("[]"))
+ return getArrayFromSourceName(javaType, loader);
+
+ return null;
+ }
+
+ private static Class<?> getArrayFromJVMName(String javaType, ClassLoader loader) throws ClassNotFoundException
+ {
+ Class<?> componentType;
+ int componentStart = javaType.lastIndexOf('[') + 1;
+ switch (javaType.charAt(componentStart))
+ {
+ case 'I': componentType = int.class; break;
+ case 'S': componentType = short.class; break;
+ case 'Z': componentType = boolean.class; break;
+ case 'B': componentType = byte.class; break;
+ case 'J': componentType = long.class; break;
+ case 'D': componentType = double.class; break;
+ case 'F': componentType = float.class; break;
+ case 'C': componentType = char.class; break;
+ case 'L':
+ if (loader == null)
+ return null;
+ String name = javaType.substring(componentStart + 1, javaType.length() - 1);
+ componentType = loader.loadClass(name);
+ break;
+ default:
+ //throw new IllegalArgumentException(BundleUtils.getMessage(bundle, "INVALID_BINARY_COMPONENT_FOR_ARRAY", javaType.charAt(componentStart)));
+ throw new IllegalArgumentException("INVALID_BINARY_COMPONENT_FOR_ARRAY: " + javaType.charAt(componentStart));
+ }
+
+ // componentStart doubles as the number of '['s which is the number of dimensions
+ return Array.newInstance(componentType, new int[componentStart]).getClass();
+ }
+
+ private static Class<?> getArrayFromSourceName(String javaType, ClassLoader loader) throws ClassNotFoundException
+ {
+ int arrayStart = javaType.indexOf('[');
+ String componentName = javaType.substring(0, arrayStart);
+
+ Class<?> componentType = primitiveNames.get(componentName);
+ if (componentType == null)
+ {
+ if (loader == null)
+ return null;
+
+ componentType = loader.loadClass(componentName);
+ }
+
+ // [][][][] divided by 2
+ int dimensions = (javaType.length() - arrayStart) >> 1;
+
+ return Array.newInstance(componentType, new int[dimensions]).getClass();
+ }
+
+ /**
+ * Given a class, strip out the package name
+ *
+ * @param cls
+ * @return just the classname
+ */
+
+ public static String getJustClassName(Class<?> cls)
+ {
+ if (cls == null)
+ return null;
+ if (cls.isArray())
+ {
+ Class<?> c = cls.getComponentType();
+ return getJustClassName(c.getName());
+ }
+
+ return getJustClassName(cls.getName());
+ }
+
+ /**
+ * Given a FQN of a class, strip out the package name
+ *
+ * @param classname
+ * @return just the classname
+ */
+ public static String getJustClassName(String classname)
+ {
+ int index = classname.lastIndexOf('.');
+ if (index < 0)
+ index = 0;
+ else index = index + 1;
+ return classname.substring(index);
+ }
+
+ /**
+ * Get the corresponding primitive for a give wrapper type.
+ * Also handles arrays of which.
+ */
+ public static Class<?> getPrimitiveType(Class<?> javaType)
+ {
+ if (javaType == Integer.class)
+ return int.class;
+ if (javaType == Short.class)
+ return short.class;
+ if (javaType == Boolean.class)
+ return boolean.class;
+ if (javaType == Byte.class)
+ return byte.class;
+ if (javaType == Long.class)
+ return long.class;
+ if (javaType == Double.class)
+ return double.class;
+ if (javaType == Float.class)
+ return float.class;
+ if (javaType == Character.class)
+ return char.class;
+
+ if (javaType == Integer[].class)
+ return int[].class;
+ if (javaType == Short[].class)
+ return short[].class;
+ if (javaType == Boolean[].class)
+ return boolean[].class;
+ if (javaType == Byte[].class)
+ return byte[].class;
+ if (javaType == Long[].class)
+ return long[].class;
+ if (javaType == Double[].class)
+ return double[].class;
+ if (javaType == Float[].class)
+ return float[].class;
+ if (javaType == Character[].class)
+ return char[].class;
+
+ if (javaType.isArray() && javaType.getComponentType().isArray())
+ {
+ Class<?> compType = getPrimitiveType(javaType.getComponentType());
+ return Array.newInstance(compType, 0).getClass();
+ }
+
+ return javaType;
+ }
+
+ /**
+ * Converts an n-dimensional array of wrapper types to primitive types
+ */
+ public static Object getPrimitiveValueArray(Object value)
+ {
+ if (value == null)
+ return null;
+
+ Class<?> javaType = value.getClass();
+ if (javaType.isArray())
+ {
+ int length = Array.getLength(value);
+ Object destArr = Array.newInstance(getPrimitiveType(javaType.getComponentType()), length);
+ for (int i = 0; i < length; i++)
+ {
+ Object srcObj = Array.get(value, i);
+ Array.set(destArr, i, getPrimitiveValueArray(srcObj));
+ }
+ return destArr;
+ }
+
+ return value;
+ }
+
+ /**
+ * Get the corresponding wrapper type for a give primitive.
+ * Also handles arrays of which.
+ */
+ public static Class<?> getWrapperType(Class<?> javaType)
+ {
+ if (javaType == int.class)
+ return Integer.class;
+ if (javaType == short.class)
+ return Short.class;
+ if (javaType == boolean.class)
+ return Boolean.class;
+ if (javaType == byte.class)
+ return Byte.class;
+ if (javaType == long.class)
+ return Long.class;
+ if (javaType == double.class)
+ return Double.class;
+ if (javaType == float.class)
+ return Float.class;
+ if (javaType == char.class)
+ return Character.class;
+
+ if (javaType == int[].class)
+ return Integer[].class;
+ if (javaType == short[].class)
+ return Short[].class;
+ if (javaType == boolean[].class)
+ return Boolean[].class;
+ if (javaType == byte[].class)
+ return Byte[].class;
+ if (javaType == long[].class)
+ return Long[].class;
+ if (javaType == double[].class)
+ return Double[].class;
+ if (javaType == float[].class)
+ return Float[].class;
+ if (javaType == char[].class)
+ return Character[].class;
+
+ if (javaType.isArray() && javaType.getComponentType().isArray())
+ {
+ Class<?> compType = getWrapperType(javaType.getComponentType());
+ return Array.newInstance(compType, 0).getClass();
+ }
+
+ return javaType;
+ }
+
+ /**
+ * Converts an n-dimensional array of primitive types to wrapper types
+ */
+ public static Object getWrapperValueArray(Object value)
+ {
+ if (value == null)
+ return null;
+
+ Class<?> javaType = value.getClass();
+ if (javaType.isArray())
+ {
+ int length = Array.getLength(value);
+ Object destArr = Array.newInstance(getWrapperType(javaType.getComponentType()), length);
+ for (int i = 0; i < length; i++)
+ {
+ Object srcObj = Array.get(value, i);
+ Array.set(destArr, i, getWrapperValueArray(srcObj));
+ }
+ return destArr;
+ }
+
+ return value;
+ }
+
+ public static Object syncArray(Object array, Class<?> target)
+ {
+ return (JavaUtils.isPrimitive(target)) ? JavaUtils.getPrimitiveValueArray(array) : JavaUtils.getWrapperValueArray(array);
+ }
+
+ /**
+ * Return true if the dest class is assignable from the src.
+ * Also handles arrays and primitives.
+ */
+ public static boolean isAssignableFrom(Class<?> dest, Class<?> src)
+ {
+ if (dest == null)
+ //throw new IllegalArgumentException(BundleUtils.getMessage(bundle, "DESTINATION_CLASS_CANNOT_BE_NULL"));
+ throw new IllegalArgumentException("DESTINATION_CLASS_CANNOT_BE_NULL");
+ if (src == null)
+ //throw new IllegalArgumentException(BundleUtils.getMessage(bundle, "SOURCE_CLASS_CANNOT_BE_NULL"));
+ throw new IllegalArgumentException("SOURCE_CLASS_CANNOT_BE_NULL");
+
+ boolean isAssignable = dest.isAssignableFrom(src);
+ if (isAssignable == false && dest.getName().equals(src.getName()))
+ {
+ ClassLoader destLoader = dest.getClassLoader();
+ ClassLoader srcLoader = src.getClassLoader();
+ if(log.isTraceEnabled()) log.trace("Not assignable because of conflicting class loaders:\ndstLoader=" + destLoader + "\nsrcLoader=" + srcLoader);
+ }
+
+ if (isAssignable == false && isPrimitive(dest))
+ {
+ dest = getWrapperType(dest);
+ isAssignable = dest.isAssignableFrom(src);
+ }
+ if (isAssignable == false && isPrimitive(src))
+ {
+ src = getWrapperType(src);
+ isAssignable = dest.isAssignableFrom(src);
+ }
+ return isAssignable;
+ }
+
+ public static String convertJVMNameToSourceName(String typeName, ClassLoader loader)
+ {
+ // TODO Don't use a ClassLoader for this, we need to just convert it
+ try
+ {
+ Class<?> javaType = loadJavaType(typeName, loader);
+ typeName = getSourceName(javaType);
+ }
+ catch (Exception e)
+ {
+ }
+
+ return typeName;
+ }
+
+ /**
+ * Converts a JVM external name to a JVM signature name. An external name is
+ * that which is returned from {@link Class#getName()} A signature name is
+ * the name in class file format.
+ * <p>
+ * For example:
+ * <p>
+ * [java.lang.Object
+ * <p>
+ * becomes:
+ * <p>
+ * [Ljava/lang/Object;
+ *
+ * @param externalName
+ * @return
+ */
+ public static String toSignature(String externalName)
+ {
+ if (externalName == null)
+ return null;
+
+ String ret = primitiveNameDescriptors.get(externalName);
+ if (ret != null)
+ return ret;
+
+ ret = externalName.replace('.', '/');
+ return (ret.charAt(0) == '[') ? ret : "L" + ret + ";";
+ }
+
+ public static String printArray(Object[] val)
+ {
+ if (val == null)
+ return "null";
+
+ StringBuilder out = new StringBuilder("[");
+ for (int i = 0; i < val.length; i++)
+ {
+ if (i > 0)
+ {
+ out.append(",");
+ }
+ out.append(val[i].getClass().isArray() ? printArray((Object[])val[i]) : val[i]);
+ }
+ return out.append("]").toString();
+ }
+
+ public static String getSourceName(Class<?> type)
+ {
+ if (! type.isArray())
+ return type.getName();
+
+ String arrayNotation = "";
+ Class<?> component = type;
+ while(component.isArray())
+ {
+ component = component.getComponentType();
+ arrayNotation += "[]";
+ }
+
+ return component.getName() + arrayNotation;
+ }
+
+ public static String capitalize(String source)
+ {
+ if (source == null)
+ return null;
+
+ if (source.length() == 0)
+ return source;
+
+ if (Character.isUpperCase(source.charAt(0)))
+ return source;
+
+ char c = Character.toUpperCase(source.charAt(0));
+
+ return c + source.substring(1);
+ }
+
+ public static boolean isLoaded(String className, ClassLoader loader)
+ {
+ try
+ {
+ loadJavaType(className, loader);
+ }
+ catch (ClassNotFoundException e)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public static String getPackageName(Class<?> clazz)
+ {
+ String fullName = clazz.getName();
+ int dotIndex = fullName.lastIndexOf(".");
+ return dotIndex == -1 ? "" : fullName.substring(0, dotIndex);
+ }
+
+ public static boolean isReservedKeyword(String keyword)
+ {
+ return reservedKeywords.contains(keyword);
+ }
+
+ /**
+ * Erases a type according to the JLS type erasure rules
+ *
+ * @param t type to erase
+ * @return erased type
+ */
+ public static Class<?> erasure(Type type)
+ {
+ if (type instanceof ParameterizedType)
+ {
+ return erasure(((ParameterizedType)type).getRawType());
+ }
+ if (type instanceof TypeVariable<?>)
+ {
+ return erasure(((TypeVariable<?>)type).getBounds()[0]);
+ }
+ if (type instanceof WildcardType)
+ {
+ return erasure(((WildcardType)type).getUpperBounds()[0]);
+ }
+ if (type instanceof GenericArrayType)
+ {
+ return Array.newInstance(erasure(((GenericArrayType)type).getGenericComponentType()), 0).getClass();
+ }
+
+ // Only type left is class
+ return (Class<?>)type;
+ }
+
+ public static String[] getRawParameterTypeArguments(ParameterizedType type)
+ {
+ Type[] arguments = type.getActualTypeArguments();
+ String[] ret = new String[arguments.length];
+ for (int i = 0; i < arguments.length; i++)
+ {
+ Class<?> raw = erasure(arguments[i]);
+ ret[i] = raw.getName();
+ }
+
+ return ret;
+ }
+
+ /**
+ * This method tests for retro translation by searching for a known problem where Class
+ * does not implement Type. If this is true, then code must never cast a Class to a Type.
+ *
+ * @return true if we are in retro
+ */
+ public static boolean isRetro14()
+ {
+ return !(String.class instanceof java.lang.reflect.Type);
+ }
+
+ /**
+ * Tests if this class loader is a JBoss RepositoryClassLoader
+ *
+ * @param loader
+ * @return
+ */
+ public static boolean isJBossRepositoryClassLoader(ClassLoader loader)
+ {
+ Class<?> clazz = loader.getClass();
+ while (!clazz.getName().startsWith("java"))
+ {
+ if ("org.jboss.mx.loading.RepositoryClassLoader".equals(clazz.getName()))
+ return true;
+ clazz = clazz.getSuperclass();
+ }
+
+ return false;
+ }
+
+ /**
+ * Clears black lists on a JBoss RepositoryClassLoader. This is somewhat of a hack, and
+ * could be replaced with an integration module. This is needed when the following order of
+ * events occur.
+ *
+ * <ol>
+ * <li>loadClass() returns not found</li>
+ * <li>Some call to defineClass()</li>
+ * <ol>
+ *
+ * The CNFE triggers a black list addition, which cause the class never again to be found.
+ *
+ * @param loader the loader to clear black lists for
+ */
+ public static void clearBlacklists(ClassLoader loader)
+ {
+ if (isJBossRepositoryClassLoader(loader))
+ {
+ for(Method m : loader.getClass().getMethods())
+ {
+ if("clearBlackLists".equalsIgnoreCase(m.getName()))
+ {
+ try
+ {
+ m.invoke(loader);
+ }
+ catch (Exception e)
+ {
+ if(log.isTraceEnabled()) log.trace("Could not clear blacklists on " + loader);
+ }
+ }
+ }
+ }
+ }
+}
Property changes on: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/JavaUtils.java
___________________________________________________________________
Added: svn:keywords
+ Revision Date
Added: svn:eol-style
+ native
Added: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/MimeConstants.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/MimeConstants.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/MimeConstants.java 2011-07-21 20:42:34 UTC (rev 37280)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.actions.soap.attachment;
+//package org.jboss.ws.core.soap.attachment;
+
+/**
+ * Generic mime related constants.
+ *
+ * @author <a href="mailto:jason at stacksmash.com">Jason T. Greene</a>
+ */
+public class MimeConstants
+{
+ // Header constants
+ public static final String ACCEPT = "Accept";
+ public static final String CONTENT_ID = "Content-Id";
+ public static final String CONTENT_TYPE = "Content-Type";
+ public static final String CONTENT_LOCATION = "Content-Location";
+ public static final String CONTENT_DESCRIPTION = "Content-Description";
+ public static final String CONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding";
+
+ // Types
+ public static final String TYPE_APPLICATION_OCTET_STREAM = "application/octet-stream";
+ public static final String TYPE_APPLICATION_XOP_XML = "application/xop+xml";
+ public static final String TYPE_MULTIPART_RELATED = "multipart/related";
+ public static final String TYPE_TEXT_XML = "text/xml";
+ public static final String TYPE_XML_UTF8 = TYPE_TEXT_XML + "; charset=UTF-8";
+ public static final String TYPE_SOAP11 = TYPE_TEXT_XML;
+ public static final String TYPE_SOAP12 = "application/soap+xml";
+ public static final String TYPE_FASTINFOSET = "application/fastinfoset";
+
+ // Encoding
+ public static final String TEXT_8BIT_ENCODING = "8bit";
+ public static final String TEXT_7BIT_ENCODING = "7bit";
+ public static final String BINARY_ENCODING = "binary";
+ public static final String QUOTED_PRINTABLE_ENCODING = "quoted-printable";
+ public static final String BASE64_ENCODING = "base64";
+
+ // Misc
+ public static final String CID_DOMAIN = "ws.jboss.org";
+ public static final String ROOTPART_CID = "<rootpart@" + CID_DOMAIN + ">";
+ public static final String START_INFO_XOP = "text/xml";
+}
Property changes on: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/MimeConstants.java
___________________________________________________________________
Added: svn:keywords
+ Revision Date
Added: svn:eol-style
+ native
Added: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/MimeUtils.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/MimeUtils.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/MimeUtils.java 2011-07-21 20:42:34 UTC (rev 37280)
@@ -0,0 +1,418 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.actions.soap.attachment;
+//package org.jboss.ws.core.utils;
+
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Map;
+//import java.util.ResourceBundle;
+import java.util.Set;
+
+import javax.imageio.ImageIO;
+import javax.imageio.ImageReader;
+import javax.imageio.ImageWriter;
+import javax.imageio.stream.ImageInputStream;
+import javax.imageio.stream.ImageOutputStream;
+import javax.mail.internet.ContentType;
+import javax.mail.internet.MimeMultipart;
+import javax.mail.internet.ParseException;
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+
+//import org.jboss.ws.WSException;
+//import org.jboss.ws.api.util.BundleUtils;
+//import org.jboss.ws.common.Constants;
+//import org.jboss.ws.common.IOUtils;
+//import org.jboss.ws.common.JavaUtils;
+
+/**
+ * Generic mime utility class.
+ *
+ * @author <a href="mailto:jason at stacksmash.com">Jason T. Greene</a>
+ */
+public class MimeUtils
+{
+ //private static final ResourceBundle bundle = BundleUtils.getBundle(MimeUtils.class);
+
+ private static Map<String, Class> mime2class = new HashMap<String, Class>();
+ private static Map<Class, String> class2mime = new HashMap<Class, String>();
+
+ static {
+ mime2class.put("text/plain", java.lang.String.class);
+ mime2class.put("image/jpeg", java.awt.Image.class);
+ mime2class.put("text/xml", javax.xml.transform.Source.class);
+ mime2class.put("application/xml", javax.xml.transform.Source.class);
+ mime2class.put("application/octet-stream", javax.activation.DataHandler.class);
+
+ class2mime.put(java.awt.Image.class, "image/jpeg");
+ class2mime.put(javax.xml.transform.Source.class, "text/xml");
+ class2mime.put(java.lang.String.class, "text/plain");
+ }
+
+ /**
+ * Converts a MIME type into a proprietary JBossWS attachment xml type.
+ *
+ * @param mimeType the MIME type string to convert
+ * @return the xml type that this mime type corresponds to
+ */
+ public static QName convertMimeTypeToXmlType(String mimeType)
+ {
+ StringBuilder mimeName = new StringBuilder(mimeType);
+
+ int pos = mimeName.indexOf("/");
+
+ if (pos == -1)
+ return null;
+
+ mimeName.setCharAt(pos, '_');
+
+ return new QName(Constants.NS_ATTACHMENT_MIME_TYPE, mimeName.toString());
+ }
+
+ /**
+ * Gets the base portion of a MIME type string. This basically just strips
+ * off any type parameter elements.
+ *
+ * @param mimeType any MIME type string
+ * @return a reduced MIME string containing no type parameters
+ */
+ public static String getBaseMimeType(String mimeType)
+ {
+ ContentType contentType;
+
+ if (mimeType == null)
+ return null;
+ try
+ {
+ contentType = new ContentType(mimeType);
+ }
+ catch (ParseException e)
+ {
+ return null;
+ }
+
+ return contentType.getBaseType();
+ }
+
+ /**
+ * Checks if there is a matching mime pattern for mimeType in mimeTypes. This
+ * will return true if there is an exact match (for example text/plain =
+ * text/plain), or if there is a wildcard subtype match (text/plain =
+ * text/*).
+ *
+ * @param mimeType the mime type to search for
+ * @param mimeTypes the set of mime types to search
+ * @return true if there is a match, false if not
+ */
+ public static boolean isMemberOf(String mimeType, Set mimeTypes)
+ {
+ if (mimeTypes.contains(mimeType))
+ return true;
+
+ try
+ {
+ if (mimeTypes.contains(new ContentType(mimeType).getPrimaryType() + "/*"))
+ return true;
+ }
+ catch (ParseException e)
+ {
+ // eat
+ }
+
+ return false;
+ }
+
+ /**
+ * Resolve the class for a mype type.
+ * Defaults to <code>DataHandler</code> if no mapping could be found.
+ */
+ public static Class resolveClass(String mimeType) {
+ Class cl = mime2class.get(mimeType);
+ if(null==cl)
+ cl = javax.activation.DataHandler.class;
+ return cl;
+ }
+
+ /**
+ * Resolve the mime type for an object.
+ * Default to <code>application/octet-stream</code>
+ * if no mapping could be found.
+ */
+ public static String resolveMimeType(Object obj) {
+ String mimeType = (obj instanceof MimeMultipart) ?
+ ((MimeMultipart)obj).getContentType() :
+ resolveMimeType(obj.getClass());
+ return mimeType;
+ }
+
+ public static String resolveMimeType(Class clazz) {
+ String mimeType = "application/octet-stream";
+ for(Class cl : class2mime.keySet())
+ {
+ if(JavaUtils.isAssignableFrom(cl, clazz))
+ mimeType = class2mime.get(cl);
+ }
+ return mimeType;
+ }
+
+ public static ByteArrayConverter getConverterForJavaType(Class targetClazz)
+ {
+ ByteArrayConverter converter = null;
+ if(JavaUtils.isAssignableFrom(java.awt.Image.class, targetClazz))
+ converter = new ImageConverter();
+ else if (JavaUtils.isAssignableFrom(javax.xml.transform.Source.class, targetClazz))
+ converter = new SourceConverter();
+ else if (JavaUtils.isAssignableFrom(java.lang.String.class, targetClazz))
+ converter = new StringConverter();
+ else if (JavaUtils.isAssignableFrom(java.io.InputStream.class, targetClazz))
+ converter = new StreamConverter();
+ else if (JavaUtils.isAssignableFrom(byte[].class, targetClazz))
+ converter = new RealByteArrayConverter();
+
+ if(null == converter)
+ //throw new WSException(BundleUtils.getMessage(bundle, "NO_BYTEARRAYCONVERTER_CLASS", targetClazz.getName()));
+ throw new RuntimeException("NO_BYTEARRAYCONVERTER_CLASS: " + targetClazz.getName());
+
+ return converter;
+ }
+
+ public static ByteArrayConverter getConverterForContentType(String contentType)
+ {
+ ByteArrayConverter converter = null;
+
+ if(contentType != null)
+ {
+ if("image/jpeg".equals(contentType) || "image/jpg".equals(contentType))
+ converter = new ImageConverter();
+ else if("text/xml".equals(contentType) || "application/xml".equals(contentType))
+ converter = new SourceConverter();
+ else if("text/plain".equals(contentType))
+ converter = new StringConverter();
+ else if("application/octet-stream".equals(contentType))
+ converter = new StreamConverter();
+ }
+
+ if(null == converter)
+ //throw new WSException(BundleUtils.getMessage(bundle, "NO_BYTEARRAYCONVERTER_CONTENT_TYPE", contentType));
+ throw new RuntimeException("NO_BYTEARRAYCONVERTER_CONTENT_TYPE: " + contentType);
+
+ return converter;
+ }
+ public static class ImageConverter implements ByteArrayConverter
+ {
+ public Object readFrom(InputStream in) {
+ Object converted = null;
+
+ try
+ {
+ ImageReader decoder = ImageIO.getImageReadersByFormatName("JPEG").next();
+ ImageInputStream iis = ImageIO.createImageInputStream(in);
+ decoder.setInput(iis);
+ BufferedImage bim = decoder.read(0);
+ converted = bim;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ return converted;
+ }
+
+ public void writeTo(Object obj, OutputStream out) {
+ if(obj instanceof BufferedImage)
+ {
+ ImageWriter encoder = ImageIO.getImageWritersByFormatName("JPEG").next();
+ try
+ {
+ ImageOutputStream ios = ImageIO.createImageOutputStream(out);
+ encoder.setOutput(ios);
+ encoder.write((BufferedImage)obj);
+ }
+ catch (IOException e)
+ {
+ //throw new WSException(BundleUtils.getMessage(bundle, "FAILED_TO_CONVERT", obj.getClass()));
+ throw new RuntimeException("FAILED_TO_CONVERT" + obj.getClass());
+ }
+ }
+ else
+ {
+ //throw new WSException(BundleUtils.getMessage(bundle, "UNABLE_TO_CONVERT", obj.getClass()));
+ throw new RuntimeException("UNABLE_TO_CONVERT: " + obj.getClass());
+ }
+
+ }
+
+ }
+
+ public static class SourceConverter implements ByteArrayConverter
+ {
+ public Object readFrom(InputStream in) {
+ return new StreamSource(in);
+ }
+
+ public void writeTo(Object obj, OutputStream out) {
+ if(obj instanceof StreamSource)
+ {
+ StreamSource s = (StreamSource)obj;
+ try
+ {
+ IOUtils.copyStream(out, s.getInputStream());
+ }
+ catch (IOException e)
+ {
+ //throw new WSException(BundleUtils.getMessage(bundle, "FAILED_TO_CONVERT", obj.getClass()));
+ throw new RuntimeException("FAILED_TO_CONVERT: "+ obj.getClass() + " - " + e.getMessage());
+ }
+ }
+ else
+ {
+ //throw new WSException(BundleUtils.getMessage(bundle, "UNABLE_TO_CONVERT", obj.getClass()));
+ throw new RuntimeException("UNABLE_TO_CONVERT: " + obj.getClass());
+ }
+ }
+ }
+
+ public static class StringConverter implements ByteArrayConverter
+ {
+ public Object readFrom(InputStream in) {
+ Object converted = null;
+ try
+ {
+ StringBuilder out = new StringBuilder();
+ byte[] b = new byte[4096];
+ for (int n; (n = in.read(b)) != -1;) {
+ out.append(new String(b, 0, n));
+ }
+ converted = out.toString();
+ }
+ catch (IOException e)
+ {
+ //throw new WSException(BundleUtils.getMessage(bundle, "FAILED_TO_CONVERT_STRING"));
+ throw new RuntimeException("FAILED_TO_CONVERT_STRING: " + e.getMessage());
+ }
+
+ return converted;
+ }
+
+ public void writeTo(Object obj, OutputStream out) {
+ if(obj instanceof String)
+ {
+ String s = (String)obj;
+ try
+ {
+ out.write(s.getBytes("UTF-8"));
+ }
+ catch (IOException e)
+ {
+ //throw new WSException(BundleUtils.getMessage(bundle, "FAILED_TO_CONVERT", obj.getClass()));
+ throw new RuntimeException("FAILED_TO_CONVERT: " + obj.getClass() + " - " + e.getMessage());
+ }
+ }
+ else
+ {
+ //throw new WSException(BundleUtils.getMessage(bundle, "UNABLE_TO_CONVERT", obj.getClass()));
+ throw new RuntimeException("UNABLE_TO_CONVERT: " + obj.getClass());
+ }
+ }
+ }
+
+ public static class RealByteArrayConverter implements ByteArrayConverter
+ {
+ public Object readFrom(InputStream in)
+ {
+ Object converted = null;
+ try
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ IOUtils.copyStream(baos, in);
+
+ in.close();
+
+ converted = baos.toByteArray();
+ }
+ catch (IOException e)
+ {
+ //throw new WSException(BundleUtils.getMessage(bundle, "FAILED_TO_CONVERT_BYTE"));
+ throw new RuntimeException("FAILED_TO_CONVERT_BYTE: " + e.getMessage());
+ }
+
+ return converted;
+ }
+
+ public void writeTo(Object obj, OutputStream out)
+ {
+ if (obj instanceof byte[])
+ {
+ byte[] bytes = (byte[])obj;
+ try
+ {
+ out.write(bytes);
+ }
+ catch (IOException e)
+ {
+ //throw new WSException(BundleUtils.getMessage(bundle, "FAILED_TO_CONVERT", obj.getClass()));
+ throw new RuntimeException("FAILED_TO_CONVERT: " + obj.getClass() + " - " + e.getMessage());
+ }
+ }
+ else
+ {
+ //throw new WSException(BundleUtils.getMessage(bundle, "UNABLE_TO_CONVERT", obj.getClass()));
+ throw new RuntimeException("UNABLE_TO_CONVERT: " + obj.getClass());
+ }
+ }
+ }
+
+ public static class StreamConverter implements ByteArrayConverter
+ {
+ public Object readFrom(InputStream in) {
+ return in;
+ }
+
+ public void writeTo(Object obj, OutputStream out) {
+ if(obj instanceof InputStream)
+ {
+ try
+ {
+ IOUtils.copyStream(out, (InputStream)obj);
+ }
+ catch (IOException e)
+ {
+ //throw new WSException(BundleUtils.getMessage(bundle, "FAILED_TO_CONVERT", obj.getClass()));
+ throw new RuntimeException("FAILED_TO_CONVERT: " + obj.getClass());
+ }
+ }
+ }
+ }
+ public interface ByteArrayConverter
+ {
+ Object readFrom(InputStream in);
+ void writeTo(Object obj, OutputStream out);
+ }
+
+
+}
Property changes on: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/MimeUtils.java
___________________________________________________________________
Added: svn:keywords
+ Revision Date
Added: svn:eol-style
+ native
Added: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/MultipartRelatedDecoder.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/MultipartRelatedDecoder.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/MultipartRelatedDecoder.java 2011-07-21 20:42:34 UTC (rev 37280)
@@ -0,0 +1,240 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.actions.soap.attachment;
+//package org.jboss.ws.core.soap.attachment;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PushbackInputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.LinkedList;
+//import java.util.ResourceBundle;
+
+import javax.activation.DataHandler;
+import javax.mail.Header;
+import javax.mail.MessagingException;
+import javax.mail.internet.ContentType;
+import javax.mail.internet.InternetHeaders;
+import javax.mail.internet.ParseException;
+import javax.xml.soap.AttachmentPart;
+
+//import org.jboss.ws.WSException;
+//import org.jboss.ws.api.util.BundleUtils;
+
+/**
+ * Abstract MutilPartRelatedDecoder decodes a mime multipart/related stream.
+ *
+ * @author <a href="mailto:jason at stacksmash.com">Jason T. Greene</a>
+ * @author Thomas.Diesler at jboss.org
+ * @since 18-Jan-2006
+ */
+public class MultipartRelatedDecoder
+{
+ //private static final ResourceBundle bundle = BundleUtils.getBundle(MultipartRelatedDecoder.class);
+ private ContentType contentType;
+
+ private String rootType;
+
+ private AttachmentPartImpl rootPart;
+
+ private LinkedList<AttachmentPart> relatedParts = new LinkedList<AttachmentPart>();
+
+ /**
+ * Constructs a <code>MultipartRelatedDecoder</code>. This will block until the message
+ * has been decoded.
+ *
+ * @param contentType the mime Content-Type header provided by the transport
+ * @param stream The stream to pull the multipart message from
+ */
+ public MultipartRelatedDecoder(ContentType contentType) throws IOException, MessagingException
+ {
+ this.contentType = contentType;
+ if (MimeConstants.TYPE_MULTIPART_RELATED.equalsIgnoreCase(contentType.getBaseType()) == false)
+ //throw new IllegalArgumentException(BundleUtils.getMessage(bundle, "NON_MULTIPART_RELATED_TYPE"));
+ throw new IllegalArgumentException("NON_MULTIPART_RELATED_TYPE");
+
+ rootType = contentType.getParameter("type");
+ if (rootType == null)
+ //throw new IllegalArgumentException(BundleUtils.getMessage(bundle, "MISSING_THE_ROOT_TYPE_PARAMETER"));
+ throw new IllegalArgumentException("MISSING_THE_ROOT_TYPE_PARAMETER");
+ }
+
+ private boolean isValidRootType(String type) throws ParseException
+ {
+ // The type multipart/related parameter can not have parameters itself
+ ContentType contentType = new ContentType(type);
+ type = contentType.getBaseType();
+
+ return rootType.equals(type);
+ }
+
+ public void decodeMultipartRelatedMessage(InputStream stream) throws IOException, MessagingException
+ {
+ String boundaryParameter = contentType.getParameter("boundary");
+ String start = contentType.getParameter("start");
+ byte[] boundary;
+ byte[] crlf;
+
+ if (boundaryParameter == null)
+ //throw new IllegalArgumentException(BundleUtils.getMessage(bundle, "NOT_CONTAIN_A_BOUNDARY"));
+ throw new IllegalArgumentException("NOT_CONTAIN_A_BOUNDARY");
+
+ try
+ {
+ // [JBWS-1393] - Problem interpreting messages with attachment when confronted with no <start> header
+ if (start == null)
+ boundary = ("--" + boundaryParameter).getBytes("US-ASCII");
+ else
+ boundary = ("\r\n--" + boundaryParameter).getBytes("US-ASCII");
+
+ crlf = ("\r\n").getBytes("US-ASCII");
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ //throw new WSException(BundleUtils.getMessage(bundle, "US_ASCII_NOT_SUPPORTED"));
+ throw new IOException("US_ASCII_NOT_SUPPORTED: " + e.getMessage());
+ }
+
+ // [JBWS-1620] - Incorrect handling of MIME boundaries in MultipartRelatedDecoder
+ PushbackInputStream pushBackStream = new PushbackInputStream(stream,2);
+ pushBackStream.unread(crlf);
+
+ BoundaryDelimitedInputStream delimitedStream = new BoundaryDelimitedInputStream(pushBackStream, boundary);
+
+ // Eat first inner stream since its empty
+ byte[] buffer = new byte[256];
+ while (delimitedStream.read(buffer) != -1)
+ {
+ }
+
+ while (!delimitedStream.isOuterStreamClosed())
+ {
+ // If the stream is empty or an end marker is reached, skip to the next
+ // one
+ if (!advanceToHeaders(delimitedStream))
+ continue;
+
+ InternetHeaders headers = new InternetHeaders(delimitedStream);
+ String typeHeader[] = headers.getHeader(MimeConstants.CONTENT_TYPE);
+
+ if (typeHeader == null)
+ //throw new IllegalArgumentException(BundleUtils.getMessage(bundle, "CONTENT_TYPE_MISSING"));
+ throw new IllegalArgumentException("CONTENT_TYPE_MISSING");
+
+ SwapableMemoryDataSource source = new SwapableMemoryDataSource(delimitedStream, typeHeader[0]);
+ AttachmentPartImpl part = new AttachmentPartImpl(new DataHandler(source));
+
+ Enumeration enumeration = headers.getAllHeaders();
+
+ while (enumeration.hasMoreElements())
+ {
+ Header header = (Header)enumeration.nextElement();
+ part.addMimeHeader(header.getName(), header.getValue());
+ }
+
+ // The root part is either the one pointed to by the start parameter, or
+ // the first occuring part if start is not defined.
+
+ /*
+ if ( start != null && part.getContentId().startsWith("<")) {
+ if ( !(start.charAt(0)=='<')) {
+ start = "<"+start+">";
+ }
+ }
+ */
+
+ if (rootPart == null && (start == null || start.equals(part.getContentId())))
+ {
+ if (isValidRootType(part.getContentType()) == false)
+ //throw new IllegalArgumentException(BundleUtils.getMessage(bundle, "OTHER_THAN_THE_ONE_FOUND"));
+ throw new IllegalArgumentException("OTHER_THAN_THE_ONE_FOUND");
+
+ rootPart = part;
+ }
+ else
+ {
+ relatedParts.add(part);
+ }
+ }
+ if (rootPart == null)
+ //throw new IllegalArgumentException(BundleUtils.getMessage(bundle, "NO_ROOT_PART_WAS_FOUND"));
+ throw new IllegalArgumentException("NO_ROOT_PART_WAS_FOUND");
+ }
+
+ private boolean advanceToHeaders(InputStream stream) throws IOException
+ {
+ boolean dash = false, cr = false;
+ while (true)
+ {
+ int b = stream.read();
+
+ switch (b)
+ {
+ case -1:
+ return false;
+ case '\r':
+ cr = true;
+ dash = false;
+ break;
+ case '-':
+ if (dash == true)
+ {
+ // Two dashes indicate no further content
+ stream.close();
+ return false;
+ }
+ dash = true;
+ cr = false;
+ break;
+ case '\n':
+ if (cr == true)
+ return true;
+ dash = false;
+ break;
+ default:
+ dash = false;
+ cr = false;
+ }
+ }
+ }
+
+ /**
+ * Returns an <code>AttachmentPart</code> representing the root part of this multipart/related message.
+ *
+ * @return the root part of this multipart/related message
+ */
+ public AttachmentPart getRootPart()
+ {
+ return rootPart;
+ }
+
+ /**
+ * Returns a collection of <code>AttachmentPart</code> objects that represent the attachments on this message.
+ * If there are no attachments, an empty collection is returned.
+ */
+ public Collection<AttachmentPart> getRelatedParts()
+ {
+ return relatedParts;
+ }
+}
Property changes on: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/MultipartRelatedDecoder.java
___________________________________________________________________
Added: svn:keywords
+ Revision Date
Added: svn:eol-style
+ native
Added: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/RawByteArrayOutputStream.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/RawByteArrayOutputStream.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/RawByteArrayOutputStream.java 2011-07-21 20:42:34 UTC (rev 37280)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.actions.soap.attachment;
+//package org.jboss.ws.core.soap.attachment;
+
+import java.io.ByteArrayOutputStream;
+
+/**
+ * Extension of ByteArrayOutputStream that provides access to buf, saving a copy.
+ *
+ * @author <a href="mailto:jason at stacksmash.com">Jason T. Greene</a>
+ */
+public class RawByteArrayOutputStream extends ByteArrayOutputStream
+{
+ public byte[] getBytes()
+ {
+ return buf;
+ }
+}
Property changes on: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/RawByteArrayOutputStream.java
___________________________________________________________________
Added: svn:keywords
+ Revision Date
Added: svn:eol-style
+ native
Added: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/SimpleBoyerMoore.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/SimpleBoyerMoore.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/SimpleBoyerMoore.java 2011-07-21 20:42:34 UTC (rev 37280)
@@ -0,0 +1,103 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.actions.soap.attachment;
+//package org.jboss.ws.core.soap.attachment;
+
+/**
+ * <code>SimpleBoyerMoore</code> is an implementation of the simplified
+ * version of the Boyer-Moore pattern search algorithm. This just means that the
+ * "good match" portion of the algorithm is removed, which improves the
+ * performance of non repeating patterns with the obvious side-effect of
+ * reducing repeating pattern performance (e.g. gaggaggaaaggaggaagagaggaga).
+ *
+ * This version of the algorithm performs incredibly well if the pattern is
+ * rare, for example a MIME boundary.
+ *
+ * This algorithm is binary safe.
+ *
+ * @author <a href="mailto:jason at stacksmash.com">Jason T. Greene</a>
+ */
+public class SimpleBoyerMoore
+{
+ private int[] badMatch = new int[256];
+
+ private byte[] pattern;
+
+ public static final int PATTERN_NOT_FOUND = -1;
+
+ /**
+ * Constructs a <code>SimpleBoyerMoore</code> instance. This internally
+ * stores the pattern so that the same instance can be used across several
+ * searches.
+ *
+ * @param pattern the pattern to search for
+ */
+ public SimpleBoyerMoore(byte[] pattern)
+ {
+ this.pattern = pattern;
+ precomputeBadMatchTable();
+ }
+
+ private void precomputeBadMatchTable()
+ {
+ java.util.Arrays.fill(badMatch, pattern.length);
+ for (int i = 0; i < pattern.length - 1; i++)
+ {
+ badMatch[pattern[i] & 0xff] = pattern.length - i - 1;
+ }
+ }
+
+ /**
+ * Find an occurence of the search pattern within text.
+ *
+ * @param text a byte array of data to seach
+ * @param offset the index in text to start searching from
+ * @param length the maximum number of bytes to search
+ *
+ * @return if a match is found, the index of text where the patter occurs,
+ * otherwise {@link #PATTERN_NOT_FOUND}
+ */
+ public int patternSearch(byte[] text, int offset, int length)
+ {
+ if (pattern.length > length)
+ {
+ return PATTERN_NOT_FOUND;
+ }
+
+ int i = 0, j = 0, k = 0;
+ int end = offset + length;
+
+ for (i = offset + pattern.length - 1; i < end; i += badMatch[text[i] & 0xff])
+ {
+ for (j = pattern.length - 1, k = i; (j >= 0) && (text[k] == pattern[j]); j--)
+ {
+ k--;
+ }
+ if (j == -1)
+ {
+ return k + 1;
+ }
+ }
+
+ return PATTERN_NOT_FOUND;
+ }
+}
Property changes on: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/SimpleBoyerMoore.java
___________________________________________________________________
Added: svn:keywords
+ Revision Date
Added: svn:eol-style
+ native
Added: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/SwapableMemoryDataSource.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/SwapableMemoryDataSource.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/SwapableMemoryDataSource.java 2011-07-21 20:42:34 UTC (rev 37280)
@@ -0,0 +1,204 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.actions.soap.attachment;
+//package org.jboss.ws.core.soap.attachment;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+//import java.util.ResourceBundle;
+
+import javax.activation.DataSource;
+
+//import org.jboss.logging.Logger;
+import org.apache.log4j.Logger;
+//import org.jboss.ws.WSException;
+//import org.jboss.ws.api.util.BundleUtils;
+//import org.jboss.ws.common.IOUtils;
+
+/**
+ * A datasource which offloads large attachments to disk.
+ *
+ * @author Thomas.Diesler at jboss.org
+ * @author <a href="mailto:jason at stacksmash.com">Jason T. Greene</a>
+ */
+public class SwapableMemoryDataSource implements DataSource
+{
+ //private static final ResourceBundle bundle = BundleUtils.getBundle(SwapableMemoryDataSource.class);
+ private static Logger log = Logger.getLogger(SwapableMemoryDataSource.class);
+
+ private static final int BLOCK_SIZE = 32 * 1024;
+
+ private static final int DEFAULT_MAX_MEMORY_SIZE = 64 * 1024;
+
+ private static final String SWAP_PREFIX = "JBossWSattachment";
+
+ private static final String SWAP_SUFFIX = ".dat";
+
+ private File swapFile;
+
+ private String contentType = MimeConstants.TYPE_APPLICATION_OCTET_STREAM;
+
+ private byte[] content;
+
+ private int contentLength;
+
+ private int maxMemorySize = 64 * 1024;
+
+
+ /**
+ * Constructs a <code>SwapableMemoryDataSource</code> from inputStream, and contentType.
+ * The instance then reads from the input stream, and stores it in memory unless the size
+ * of the content is larger that 64KB, at whichpoint the stream is stored in a temporary
+ * file on disk.
+ *
+ * @param inputStream the stream to read from
+ * @param contentType the content type of this stream
+ */
+ public SwapableMemoryDataSource(InputStream inputStream, String contentType) throws IOException
+ {
+ this(inputStream, contentType, DEFAULT_MAX_MEMORY_SIZE);
+ }
+
+ /**
+ * Constructs a <code>SwapableMemoryDataSource</code> from inputStream, and
+ * contentType. The instance then reads from the input stream, and stores it
+ * in memory unless the size of the content is larger than maxMemorySize, at
+ * whichpoint the stream is stored in a temporary file on disk.
+ *
+ * @param inputStream the stream to read from
+ * @param contentType the content type of this stream
+ * @param maxMemorySize the maximum size in bytes that this data source is
+ * allowed to allocate for stream storage
+ */
+ public SwapableMemoryDataSource(InputStream inputStream, String contentType, int maxMemorySize) throws IOException
+ {
+ if (contentType != null)
+ this.contentType = contentType;
+
+ this.maxMemorySize = maxMemorySize;
+
+ load(inputStream);
+ }
+
+ private void load(InputStream inputStream) throws IOException
+ {
+ RawByteArrayOutputStream rbaos = new RawByteArrayOutputStream();
+ OutputStream os = rbaos;
+
+ byte[] buffer = new byte[BLOCK_SIZE];
+ int count = inputStream.read(buffer);
+ while (count > 0) {
+ os.write(buffer, 0, count);
+
+ if (rbaos != null && rbaos.size() > maxMemorySize)
+ {
+ File tmpdir = IOUtils.createTempDirectory();
+ swapFile = File.createTempFile(SWAP_PREFIX, SWAP_SUFFIX, tmpdir);
+ swapFile.deleteOnExit();
+ os = new FileOutputStream(swapFile);
+ rbaos.writeTo(os);
+ rbaos = null;
+ }
+
+ count = inputStream.read(buffer);
+ }
+
+ os.flush();
+ os.close();
+
+ if (rbaos == null)
+ {
+ if(log.isDebugEnabled()) log.debug("Using swap file, location = " + swapFile.toURL() + " size = " + swapFile.length());
+ }
+ else
+ {
+ contentLength = rbaos.size();
+ if(log.isDebugEnabled()) log.debug("Using memory buffer, size = " + contentLength);
+ content = rbaos.getBytes();
+ }
+ }
+
+ protected void finalize() throws Throwable
+ {
+ super.finalize();
+ cleanup();
+ }
+
+ public void cleanup()
+ {
+ if (swapFile != null)
+ swapFile.delete();
+ }
+
+ /**
+ * Returns the content type of this data source.
+ *
+ * @return the content type
+ */
+ public String getContentType()
+ {
+ return contentType;
+ }
+
+ /**
+ * Returns a new input stream on this data source. Multiple calls
+ * are allowed because the data is stored.
+ *
+ * @return a new input stream at the start of the data
+ */
+ public InputStream getInputStream() throws IOException
+ {
+ if (content != null)
+ return new ByteArrayInputStream(content, 0, contentLength);
+
+ if (swapFile != null)
+ return new FileInputStream(swapFile);
+
+ //throw new WSException(BundleUtils.getMessage(bundle, "NO_CONTENT_AVAILABLE"));
+ throw new IOException("NO_CONTENT_AVAILABLE");
+ }
+
+ /**
+ * This method always returns null.
+ *
+ * @return null
+ */
+ public String getName()
+ {
+ return null;
+ }
+
+ /**
+ * This method always returns null.
+ *
+ * @return null
+ */
+ public OutputStream getOutputStream() throws IOException
+ {
+ return null;
+ }
+}
Property changes on: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/SwapableMemoryDataSource.java
___________________________________________________________________
Added: svn:keywords
+ Revision Date
Added: svn:eol-style
+ native
Added: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/XmlDataContentHandler.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/XmlDataContentHandler.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/XmlDataContentHandler.java 2011-07-21 20:42:34 UTC (rev 37280)
@@ -0,0 +1,121 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.actions.soap.attachment;
+//package org.jboss.ws.core.soap.attachment;
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+//import java.util.ResourceBundle;
+
+import javax.activation.ActivationDataFlavor;
+import javax.activation.DataContentHandler;
+import javax.activation.DataSource;
+import javax.xml.transform.stream.StreamSource;
+
+//import org.jboss.ws.api.util.BundleUtils;
+//import org.jboss.ws.common.IOUtils;
+
+/**
+ * <code>XmlDataContentHandler</code> is a JAF content handler that provides
+ * marchalling/unmarshalling between a <code>StreamSource</code> and a generic
+ * stream.
+ *
+ * @author <a href="mailto:jason at stacksmash.com">Jason T. Greene</a>
+ */
+public class XmlDataContentHandler implements DataContentHandler
+{
+ //private static final ResourceBundle bundle = BundleUtils.getBundle(XmlDataContentHandler.class);
+ private DataFlavor[] flavors = new ActivationDataFlavor[]
+ {
+ new ActivationDataFlavor(StreamSource.class, "text/xml", "XML"),
+ new ActivationDataFlavor(StreamSource.class, "application/xml", "XML")
+ };
+
+ /**
+ * Returns a {@link StreamSource} from the specified
+ * data source.
+ *
+ * @param ds the activation datasource
+ * @return an XML stream source
+ */
+ public Object getContent(DataSource ds) throws IOException
+ {
+ return new StreamSource(ds.getInputStream());
+ }
+
+ /**
+ * Returns a {@link StreamSource} from the specified
+ * data source. The flavor must be one of the ones returned by {@link #getTransferDataFlavors()}.
+ *
+ * @param df the flavor specifiying the mime type of ds
+ * @param ds the activation data source
+ * @return an XML stream source
+ */
+ public Object getTransferData(DataFlavor df, DataSource ds) throws UnsupportedFlavorException, IOException
+ {
+ return getContent(ds);
+ }
+
+ /**
+ * Returns the acceptable data flavors that this content handler supports.
+ *
+ * @return array of <code>ActivationDataHandlers</code>
+ */
+ public DataFlavor[] getTransferDataFlavors()
+ {
+ return flavors;
+ }
+
+ /**
+ * Writes the passed in {@link StreamSource} object using the specified
+ * mime type to the specified output stream. The mime type must be text/xml.
+ *
+ * @param obj an XML stream source
+ * @param mimeType the string "text/xml"
+ * @param os the output stream to write this xml stream to
+ */
+ public void writeTo(Object obj, String mimeType, OutputStream os) throws IOException
+ {
+ if (! mimeType.startsWith(MimeConstants.TYPE_TEXT_XML) && ! mimeType.startsWith("application/xml"))
+ //throw new IOException(BundleUtils.getMessage(bundle, "EXPECTED_TEXT_XML", mimeType));
+ throw new IOException("EXPECTED_TEXT_XML: " + mimeType);
+
+ if (! (obj instanceof StreamSource))
+ //throw new IOException(BundleUtils.getMessage(bundle, "ONLY_SUPPORTS_STREAMSOURCE"));
+ throw new IOException("ONLY_SUPPORTS_STREAMSOURCE");
+
+ // TODO - add support for reader source
+ InputStream stream = ((StreamSource) obj).getInputStream();
+ if (stream != null)
+ {
+ IOUtils.copyStream(os, stream);
+ }
+ else
+ {
+ IOUtils.copyReader(os, ((StreamSource) obj).getReader());
+
+ }
+ }
+}
Property changes on: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/attachment/XmlDataContentHandler.java
___________________________________________________________________
Added: svn:keywords
+ Revision Date
Added: svn:eol-style
+ native
Modified: labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxy.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxy.java 2011-07-21 20:10:49 UTC (rev 37279)
+++ labs/jbossesb/branches/JBESB_4_10_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxy.java 2011-07-21 20:42:34 UTC (rev 37280)
@@ -28,6 +28,7 @@
import java.util.List;
import java.util.Map;
+import javax.mail.internet.ContentType;
import javax.wsdl.Binding;
import javax.wsdl.BindingOperation;
import javax.wsdl.Definition;
@@ -55,6 +56,8 @@
import org.jboss.soa.esb.actions.ActionLifecycleException;
import org.jboss.soa.esb.actions.ActionProcessingException;
import org.jboss.soa.esb.actions.soap.WebServiceUtils;
+import org.jboss.soa.esb.actions.soap.attachment.MimeConstants;
+import org.jboss.soa.esb.actions.soap.attachment.MultipartRelatedDecoder;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.http.HttpRequest;
import org.jboss.soa.esb.lifecycle.LifecycleResourceException;
@@ -487,6 +490,20 @@
{
throw new ActionProcessingException( "unsupported payload type: " + payload.getClass().getName() );
}
+ try
+ {
+ ContentType content_type = new ContentType( HttpRequest.getRequest(message).getContentType() );
+ if ( MimeConstants.TYPE_MULTIPART_RELATED.equalsIgnoreCase(content_type.getBaseType()) )
+ {
+ MultipartRelatedDecoder decoder = new MultipartRelatedDecoder(content_type);
+ decoder.decodeMultipartRelatedMessage( is.getByteStream() );
+ is = new InputSource( decoder.getRootPart().getRawContent() );
+ }
+ }
+ catch (Exception e)
+ {
+ throw new ActionProcessingException(e);
+ }
QName element = null;
ContentHandler ch = new ElementFinder();
try
More information about the jboss-svn-commits
mailing list