This content has been marked as final.
Show 3 replies
-
1. Re: jbr-provider and http response codes
beve Feb 25, 2008 10:19 AM (in response to mikaeljl)Hi Mikael,
could you try this and see if it works for you:message.getProperties().setProperty("ResponseCode", new Integer(500));
Regards,
Daniel -
2. Re: jbr-provider and http response codes
mikaeljl Feb 25, 2008 10:36 AM (in response to mikaeljl)Hi!
Thank you for the tip, I've tried with both:message.getProperties().setProperty("ResponseCode", new Integer(500)); message.getProperties().setProperty("ResponseCodeMessage", new String("Indicating error... JustDoinSomeTestin"));
Still gives a 200 OK response.
I've also tried with:message.getProperties().setProperty("ResponseCode", new ResponseHeader("ResponseCode","500")); message.getProperties().setProperty("ResponseCodeMessage", new ResponseHeader("ResponseCodeMessage", "JustDoinSomeTestin"));
But that just resulted in two http headers named "ResponseCode"/"ResponseCodeMessage" not exactly what I was hoping for...
If you look at
org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListener.java
You will see that the decompose method seems to do:if(value instanceof ResponseHeader) { ResponseHeader header = (ResponseHeader) value; responseMap.put(header.getName(), header.getValue()); }
So, how to get the status code down to the remoting layer?
/Mikael -
3. Re: jbr-provider and http response codes
beve Feb 25, 2008 2:17 PM (in response to mikaeljl)You might be able to do the following as a workaround...
If you set the ResponseCode like this:message.getProperties().setProperty("ResponseCode", new Integer(500));
And specify a message composer in jboss-esb.xml like this:<jbr-listener name="Http-Gateway" busidref="Http-2" is-gateway="true" maxThreads="1"> <property name="composer-class" value="some.package.name.t.JBRComposer"/> </jbr-listener>
And then implement a MessageComposer like this:import java.io.Serializable; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; import org.apache.log4j.Logger; import org.jboss.remoting.InvocationRequest; import org.jboss.soa.esb.actions.AbstractActionLifecycle; import org.jboss.soa.esb.actions.ActionUtils; import org.jboss.soa.esb.helpers.ConfigTree; import org.jboss.soa.esb.listeners.message.AbstractMessageComposer; import org.jboss.soa.esb.listeners.message.MessageDeliverException; import org.jboss.soa.esb.message.Body; import org.jboss.soa.esb.message.Message; import org.jboss.soa.esb.message.MessagePayloadProxy; import org.jboss.soa.esb.message.Properties; import org.jboss.soa.esb.message.ResponseHeader; import org.jboss.soa.esb.message.MessagePayloadProxy.NullPayloadHandling; import org.jboss.soa.esb.message.body.content.BytesBody; public class JBRComposer<T extends InvocationRequest> extends AbstractMessageComposer<T> { private Logger logger = Logger.getLogger( JBRComposer.class ); private MessagePayloadProxy payloadProxy; public void setConfiguration(ConfigTree config) { super.setConfiguration(config); payloadProxy = new MessagePayloadProxy(config, new String[] {ActionUtils.POST_ACTION_DATA, Body.DEFAULT_LOCATION, BytesBody.BYTES_LOCATION}, new String[] {ActionUtils.POST_ACTION_DATA}); // Allow null to be set on as the message payload... payloadProxy.setNullSetPayloadHandling(NullPayloadHandling.LOG); } protected MessagePayloadProxy getPayloadProxy() { return payloadProxy; } @SuppressWarnings("unchecked") protected void populateMessage(Message message, T invocationRequest) throws MessageDeliverException { // Set the payload from the JBR invocation... payloadProxy.setPayload(message, invocationRequest.getParameter()); // Copy the request properties onto the message... Map properties = invocationRequest.getRequestPayload(); if (properties != null) { // Purposely not iterating over the Map.Entry Set because there's // a bug in the Map impl used by JBossRemoting. Not all the // "values" are actually in the Map.Entry set. Some of them are handled // from within an overridden impl of the Map.get(Object) method. Set names = properties.keySet(); for (Object name : names) { Object value = properties.get(name); if(value != null) { message.getProperties().setProperty(name.toString(), value); } } } } public Object decompose(Message message, T invocationRequest) throws MessageDeliverException { Properties properties = message.getProperties(); String propertyNames[] = properties.getNames(); Map responseMap = invocationRequest.getReturnPayload(); if(responseMap == null) { responseMap = new LinkedHashMap(); invocationRequest.setReturnPayload(responseMap); } for(String name : propertyNames) { Object value = properties.getProperty(name); if(value instanceof ResponseHeader) { ResponseHeader header = (ResponseHeader) value; responseMap.put(header.getName(), header.getValue()); } else if ( name.equals("ResponseCode") ) { responseMap.put(name, value ); } } return super.decompose(message, invocationRequest); } }
I've tried this by modifying the webservice_producer quickstart.
Regards,
Daniel