Author: heiko.braun(a)jboss.com
Date: 2007-10-15 09:37:59 -0400 (Mon, 15 Oct 2007)
New Revision: 4767
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/core/CommonMessageContext.java
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxrpc/handler/MessageContextJAXRPC.java
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/handler/MessageContextJAXWS.java
stack/native/trunk/src/main/java/org/jboss/ws/core/soap/attachment/AttachmentPartImpl.java
stack/native/trunk/src/main/java/org/jboss/ws/core/soap/attachment/SwapableMemoryDataSource.java
stack/native/trunk/src/main/java/org/jboss/wsf/stack/jbws/RequestHandlerImpl.java
stack/native/trunk/version.properties
Log:
Fix JBWS-1856: Attachment part not cleanup correctly
Modified: stack/native/trunk/src/main/java/org/jboss/ws/core/CommonMessageContext.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/core/CommonMessageContext.java 2007-10-15
13:33:39 UTC (rev 4766)
+++
stack/native/trunk/src/main/java/org/jboss/ws/core/CommonMessageContext.java 2007-10-15
13:37:59 UTC (rev 4767)
@@ -23,22 +23,25 @@
// $Id$
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import javax.xml.soap.SOAPMessage;
-import javax.xml.ws.handler.MessageContext.Scope;
-
import org.jboss.logging.Logger;
import org.jboss.ws.core.binding.SerializationContext;
+import org.jboss.ws.core.soap.attachment.SwapableMemoryDataSource;
import org.jboss.ws.extensions.xop.XOPContext;
import org.jboss.ws.metadata.umdm.EndpointMetaData;
import org.jboss.ws.metadata.umdm.OperationMetaData;
import org.jboss.xb.binding.NamespaceRegistry;
+import javax.xml.soap.AttachmentPart;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.ws.handler.MessageContext.Scope;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
/**
* The common JAXRPC/JAXWS MessageContext
*
@@ -120,6 +123,8 @@
public SOAPMessage getSOAPMessage()
{
+ if(message!=null && ((message instanceof SOAPMessage) == false))
+ throw new UnsupportedOperationException("No SOAPMessage avilable. Current
message context carries " + message.getClass());
return (SOAPMessage)message;
}
@@ -323,6 +328,33 @@
return valid;
}
+ public static void cleanupAttachments(CommonMessageContext messageContext)
+ {
+ // cleanup attachments
+ MessageAbstraction msg = messageContext.getMessageAbstraction();
+
+ if(msg!=null && (msg instanceof SOAPMessage)) // in case of http binding
+ {
+ Iterator it = ((SOAPMessage)msg).getAttachments();
+ while(it.hasNext())
+ {
+ AttachmentPart attachment = (AttachmentPart)it.next();
+ try
+ {
+ if(attachment.getDataHandler().getDataSource() instanceof
SwapableMemoryDataSource)
+ {
+ SwapableMemoryDataSource swapFile =
(SwapableMemoryDataSource)attachment.getDataHandler().getDataSource();
+ swapFile.cleanup();
+ }
+ }
+ catch (SOAPException e)
+ {
+ log.warn("Failed to cleanup attachment part", e);
+ }
+ }
+ }
+ }
+
private static class ImmutableEntry<K, V> implements Map.Entry<K, V>
{
final K k;
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxrpc/handler/MessageContextJAXRPC.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxrpc/handler/MessageContextJAXRPC.java 2007-10-15
13:33:39 UTC (rev 4766)
+++
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxrpc/handler/MessageContextJAXRPC.java 2007-10-15
13:37:59 UTC (rev 4767)
@@ -88,6 +88,7 @@
public static CommonMessageContext processPivot(CommonMessageContext requestContext)
{
log.debug("Begin response processing");
+ cleanupAttachments(requestContext);
return requestContext;
}
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/handler/MessageContextJAXWS.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/handler/MessageContextJAXWS.java 2007-10-15
13:33:39 UTC (rev 4766)
+++
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/handler/MessageContextJAXWS.java 2007-10-15
13:37:59 UTC (rev 4767)
@@ -24,16 +24,21 @@
// $Id: MessageContextImpl.java 275 2006-05-04 21:36:29Z jason.greene(a)jboss.com $
import javax.xml.ws.handler.MessageContext;
+import javax.xml.soap.AttachmentPart;
+import javax.xml.soap.SOAPException;
import org.jboss.logging.Logger;
import org.jboss.ws.core.CommonMessageContext;
import org.jboss.ws.core.binding.SerializationContext;
import org.jboss.ws.core.jaxws.SerializationContextJAXWS;
import org.jboss.ws.core.soap.MessageContextAssociation;
+import org.jboss.ws.core.soap.attachment.SwapableMemoryDataSource;
import org.jboss.ws.metadata.umdm.EndpointMetaData;
import org.jboss.ws.metadata.umdm.ServiceMetaData;
import org.jboss.xb.binding.NamespaceRegistry;
+import java.util.Iterator;
+
/**
* The interface MessageContext abstracts the message context that is processed by a
handler in the handle method.
*
@@ -110,7 +115,9 @@
resContext.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, new Boolean(!outbound));
MessageContextAssociation.pushMessageContext(resContext);
+ cleanupAttachments(reqContext);
return resContext;
}
+
}
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/core/soap/attachment/AttachmentPartImpl.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/core/soap/attachment/AttachmentPartImpl.java 2007-10-15
13:33:39 UTC (rev 4766)
+++
stack/native/trunk/src/main/java/org/jboss/ws/core/soap/attachment/AttachmentPartImpl.java 2007-10-15
13:37:59 UTC (rev 4767)
@@ -153,28 +153,19 @@
if (dataHandler == null)
return 0;
- // In order to be accurate this method must be somewhat inefficient
- // TODO optimize this for specific data sources
- int count = 0, ret = 0;
- byte[] buffer = new byte[256];
-
try
{
- InputStream stream = dataHandler.getInputStream();
+ // 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()));
- do
- {
- count += ret;
- ret = stream.read(buffer);
- }
- while (ret != -1);
+ ByteArrayDataSource ds = (ByteArrayDataSource)this.dataHandler.getDataSource();
+ return ds.getSize();
}
catch (IOException e)
{
throw new SOAPException(e);
}
-
- return count;
}
public void removeAllMimeHeaders()
@@ -444,11 +435,7 @@
this.type = type;
try {
ByteArrayOutputStream os = new ByteArrayOutputStream();
- int ch;
-
- while ((ch = is.read()) != -1)
- os.write(ch);
-
+ IOUtils.copyStream(os, is);
data = os.toByteArray();
} catch (IOException ioex) {
throw new WSException(ioex);
@@ -486,5 +473,9 @@
public String getName() {
return "ByteArrayDataSource";
}
+
+ public int getSize() {
+ return this.data.length;
+ }
}
}
\ No newline at end of file
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/core/soap/attachment/SwapableMemoryDataSource.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/core/soap/attachment/SwapableMemoryDataSource.java 2007-10-15
13:33:39 UTC (rev 4766)
+++
stack/native/trunk/src/main/java/org/jboss/ws/core/soap/attachment/SwapableMemoryDataSource.java 2007-10-15
13:37:59 UTC (rev 4767)
@@ -49,7 +49,7 @@
private static final int DEFAULT_MAX_MEMORY_SIZE = 64 * 1024;
- private static final String SWAP_PREFIX = "JBossWSsattachment";
+ private static final String SWAP_PREFIX = "JBossWSattachment";
private static final String SWAP_SUFFIX = ".dat";
@@ -119,7 +119,7 @@
rbaos = null;
}
- count = inputStream.read(buffer);
+ count = inputStream.read(buffer);
}
os.flush();
@@ -140,7 +140,11 @@
protected void finalize() throws Throwable
{
super.finalize();
+ cleanup();
+ }
+ public void cleanup()
+ {
if (swapFile != null)
swapFile.delete();
}
Modified:
stack/native/trunk/src/main/java/org/jboss/wsf/stack/jbws/RequestHandlerImpl.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/wsf/stack/jbws/RequestHandlerImpl.java 2007-10-15
13:33:39 UTC (rev 4766)
+++
stack/native/trunk/src/main/java/org/jboss/wsf/stack/jbws/RequestHandlerImpl.java 2007-10-15
13:37:59 UTC (rev 4767)
@@ -311,6 +311,10 @@
}
finally
{
+
+ // Cleanup outbound attachments
+ CommonMessageContext.cleanupAttachments(
MessageContextAssociation.peekMessageContext() );
+
// Reset the message context association
MessageContextAssociation.popMessageContext();
Modified: stack/native/trunk/version.properties
===================================================================
--- stack/native/trunk/version.properties 2007-10-15 13:33:39 UTC (rev 4766)
+++ stack/native/trunk/version.properties 2007-10-15 13:37:59 UTC (rev 4767)
@@ -25,7 +25,7 @@
# Dependend integration projects
jbossws-spi=1.0.0.GA
-jbossws-common=1.0.0.GA
+jbossws-common=snapshot
jbossws-framework=snapshot
jbossws-jboss40=2.0.1.GA
jbossws-jboss42=2.0.1.GA
Show replies by date