Skip to content

Commit

Permalink
Better handling of property scopes and nulls
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.codehaus.org/mule/branches/mule-3.x@19421 bf997673-6b11-0410-b953-e057580c5b09
  • Loading branch information
rossmason committed Sep 8, 2010
1 parent fe23c83 commit 15882da
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.mule.registry.RegistryMap;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -121,7 +122,7 @@ public MuleRequestMessage createRequest(IBeanInvocationData data) throws IBeansE
{
try
{
message.addAttachment(dataSource.getName(), new DataHandler(dataSource));
message.addOutboundAttachment(dataSource.getName(), new DataHandler(dataSource));
}
catch (Exception e)
{
Expand All @@ -141,38 +142,7 @@ public MuleRequestMessage createRequest(IBeanInvocationData data) throws IBeansE

public MuleResponseMessage createResponse(Object payload, Map<String, Object> headers, Map<String, DataHandler> attachments) throws IBeansException
{
//TODO MimeType
DefaultMuleMessage message = new DefaultMuleMessage(payload, muleContext);

if (headers != null)
{
for (Map.Entry<String, Object> entry : headers.entrySet())
{
try
{
message.setInboundProperty(entry.getKey(), entry.getValue());
}
catch (Exception e)
{
throw new IBeansException(e);
}
}
}

if (attachments != null)
{
for (Map.Entry<String, DataHandler> entry : attachments.entrySet())
{
try
{
message.addAttachment(entry.getKey(), entry.getValue());
}
catch (Exception e)
{
throw new IBeansException(e);
}
}
}
MuleMessage message = new DefaultMuleMessage(payload, headers, new HashMap<String, Object>(), attachments, muleContext);
try
{
return new MuleResponseMessage(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void setPayload(Object payload)

public void addHeader(String name, Object value)
{
message.setProperty(name, value, PropertyScope.INBOUND);
message.setOutboundProperty(name, value);
}

public Object removeHeader(String name)
Expand All @@ -69,7 +69,7 @@ public void addAttachment(String name, DataHandler handler)
{
try
{
message.addAttachment(name, handler);
message.addOutboundAttachment(name, handler);
}
catch (Exception e)
{
Expand All @@ -79,11 +79,11 @@ public void addAttachment(String name, DataHandler handler)

public DataHandler removeAttachment(String name)
{
DataHandler dh = message.getAttachment(name);
DataHandler dh = message.getOutboundAttachment(name);
try
{
if(dh!=null)
message.removeAttachment(name);
message.removeOutboundAttachment(name);
}
catch (Exception e)
{
Expand All @@ -94,12 +94,12 @@ public DataHandler removeAttachment(String name)

public DataHandler getAttachment(String name)
{
return message.getAttachment(name);
return message.getOutboundAttachment(name);
}

public Set<String> getAttachmentNames()
{
return message.getAttachmentNames();
return message.getOutboundAttachmentNames();
}

public int getTimeout()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public MuleResponseMessage(MuleMessage message) throws MimeTypeParseException
if(message.getDataType()==null)
{
//s this is response
String mime = message.getInboundProperty(MuleProperties.CONTENT_TYPE_PROPERTY);
String mime = message.findPropertyInAnyScope(MuleProperties.CONTENT_TYPE_PROPERTY,null);
if (mime == null)
{
//case insensitive
mime = message.getInboundProperty("ContentType");
mime = message.findPropertyInAnyScope("ContentType", null);
}
if(mime==null) mime = MimeTypes.ANY.getBaseType();

Expand Down Expand Up @@ -118,12 +118,12 @@ public Set<String> getHeaderNames()

public DataHandler getAttachment(String name)
{
return message.getAttachment(name);
return message.getInboundAttachment(name);
}

public Set<String> getAttachmentNames()
{
return message.getAttachmentNames();
return message.getInboundAttachmentNames();
}

public MuleMessage getMessage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.mule.module.ibeans.spi.support.DataTypeConverter;
import org.mule.routing.filters.ExpressionFilter;
import org.mule.transformer.types.DataTypeFactory;
import org.mule.transport.NullPayload;

import java.lang.reflect.Method;

Expand Down Expand Up @@ -98,6 +99,10 @@ else if (requiredType.getType().equals(Response.class))
}


}
if(finalResult instanceof NullPayload)
{
finalResult = null;
}
invocationContext.setResult(finalResult);
}
Expand Down

0 comments on commit 15882da

Please sign in to comment.