[jboss-svn-commits] JBL Code SVN: r28580 - in labs/jbossesb/trunk/product: rosetta/src/org/jboss/soa/esb/listeners/gateway and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jul 29 15:39:37 EDT 2009
Author: dward
Date: 2009-07-29 15:39:37 -0400 (Wed, 29 Jul 2009)
New Revision: 28580
Added:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/ResponseStatus.java
Modified:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpRouter.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpMessageComposer.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListener.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/ResponseHeader.java
labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPClient.java
labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPProcessor.java
labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/SOAPProcessorHttpServletResponse.java
Log:
Fix for JBESB-2761
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpRouter.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpRouter.java 2009-07-29 19:34:20 UTC (rev 28579)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpRouter.java 2009-07-29 19:39:37 UTC (rev 28580)
@@ -43,6 +43,7 @@
import org.jboss.soa.esb.listeners.message.MessageDeliverException;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.ResponseHeader;
+import org.jboss.soa.esb.message.ResponseStatus;
/**
* Http router.
@@ -64,6 +65,7 @@
private ResponseType responseType;
private String contentType;
private ConfigTree[] requestHeaders;
+ private boolean httpResponseStatusEnabled;
private final String[] mappedHeaderList ;
@@ -89,6 +91,8 @@
mappedHeaderList = extractMappedHeaderListConfig();
requestHeaders = config.getChildren("header");
+
+ httpResponseStatusEnabled = ResponseStatus.isHttpEnabled(config);
}
public Message process(Message message) throws ActionProcessingException {
@@ -166,9 +170,13 @@
String name = responseHeader.getName();
String value = responseHeader.getValue();
response.addHeader(new HttpHeader(name, value));
- // https://jira.jboss.org/jira/browse/JBESB-2511
- new ResponseHeader(name, value).addToProperties(properties);
+ // JBESB-2511
+ new ResponseHeader(name, value).setPropertyNameThis(properties);
}
+ // JBESB-2761
+ if (httpResponseStatusEnabled) {
+ ResponseStatus.setHttpProperties(properties, responseCode, method.getStatusLine().getReasonPhrase());
+ }
message.getBody().add(HttpResponse.RESPONSE_KEY, response);
}
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpMessageComposer.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpMessageComposer.java 2009-07-29 19:34:20 UTC (rev 28579)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpMessageComposer.java 2009-07-29 19:39:37 UTC (rev 28580)
@@ -49,7 +49,7 @@
* <p>If the request is the submitted from html form(with the <code>Content-Type: application/x-www-form-urlencoded</code>), HttpServletRequest.getParameterMap() result)
* will be put in ESB message properties. The key for it is "RequestParamterMap". It put the the byte array read from request inputstream in message payload.
* <p>In decompose process, the header map in message properties will be added
- * in HttpServletResponse. The value for "ReponseStatus" store in ESB message properties will
+ * in HttpServletResponse. The value for "ResponseStatus" store in ESB message properties will
* put in the http response. The message payload byte[] or String object will be wrote to HttpServletResponse.
* If the object in message payload is not byte[],it will throw exception when the ESB message
* is decomposed
@@ -69,7 +69,7 @@
public static final String HTTP_RESPONSE_HEADER_MAP = "ResponseHeaderMap";
/** Response status key in esb message properties */
- public static final String HTTP_RESPONSE_STATUS = "ReponseStatus";
+ public static final String HTTP_RESPONSE_STATUS = "ResponseStatus";
/** Message payload proxy */
private MessagePayloadProxy payloadProxy;
@@ -150,16 +150,17 @@
}
else if (propertyValue instanceof ResponseHeader)
{
- // https://jira.jboss.org/jira/browse/JBESB-2511
+ // JBESB-2511
ResponseHeader header = (ResponseHeader)propertyValue;
- httpResponse.setHeader( header.getName(), header.getValue() );
+ header.setHeaderNameValue(httpResponse);
}
}
Object status = properties.getProperty(HTTP_RESPONSE_STATUS);
if (status != null) {
- int reponseStatus = (Integer)status;
- httpResponse.setStatus(reponseStatus);
+ // JBESB-2761
+ int responseStatus = Integer.valueOf(status.toString()).intValue();
+ httpResponse.setStatus(responseStatus);
}
Object obj = payloadProxy.getPayload(message);
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListener.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListener.java 2009-07-29 19:34:20 UTC (rev 28579)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListener.java 2009-07-29 19:39:37 UTC (rev 28580)
@@ -377,13 +377,26 @@
}
if(isHttp) {
- responseMap.put(HTTPMetadataConstants.RESPONSE_CODE, HttpURLConnection.HTTP_OK);
+ Integer responseCode;
+ Object code = responseMap.get(HTTPMetadataConstants.RESPONSE_CODE);
+ if (code != null) {
+ responseCode = Integer.valueOf(code.toString());
+ } else {
+ responseCode = Integer.valueOf(HttpURLConnection.HTTP_OK);
+ }
+ responseMap.put(HTTPMetadataConstants.RESPONSE_CODE, responseCode);
+ String responseCodeMessage = (String)responseMap.get(HTTPMetadataConstants.RESPONSE_CODE_MESSAGE);
+ if (responseCodeMessage == null) {
+ responseCodeMessage = "OK";
+ }
+ responseMap.put(HTTPMetadataConstants.RESPONSE_CODE_MESSAGE, responseCodeMessage);
}
return response;
} else {
messageDeliveryAdapter.deliverAsync(invocationRequest);
if(isHttp) {
responseMap.put(HTTPMetadataConstants.RESPONSE_CODE, HttpURLConnection.HTTP_ACCEPTED);
+ responseMap.put(HTTPMetadataConstants.RESPONSE_CODE_MESSAGE, "OK");
}
if(asyncResponse == null) {
@@ -622,10 +635,15 @@
Object value = properties.getProperty(name);
if(value instanceof ResponseHeader) {
- // https://jira.jboss.org/jira/browse/JBESB-2511
- ResponseHeader header = (ResponseHeader) value;
- responseMap.put(header.getName(), header.getValue());
+ // JBESB-2511
+ ResponseHeader header = (ResponseHeader)value;
+ header.putNameValue(responseMap);
}
+ // JBESB-2761
+ if(HTTPMetadataConstants.RESPONSE_CODE.equals(name) ||
+ HTTPMetadataConstants.RESPONSE_CODE_MESSAGE.equals(name)) {
+ responseMap.put(name, value);
+ }
}
return super.decompose(message, invocationRequest);
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/ResponseHeader.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/ResponseHeader.java 2009-07-29 19:34:20 UTC (rev 28579)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/ResponseHeader.java 2009-07-29 19:39:37 UTC (rev 28580)
@@ -15,14 +15,17 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
- * (C) 2005-2006, JBoss Inc.
+ * (C) 2005-2009, JBoss Inc.
*/
package org.jboss.soa.esb.message;
import java.io.Serializable;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
+import javax.servlet.http.HttpServletResponse;
+
/**
* Response header.
* <p/>
@@ -35,16 +38,15 @@
private static final Set<String> BLACKLISTED_PROPERTY_NAMES = new HashSet<String>();
static {
- BLACKLISTED_PROPERTY_NAMES.add("content-length"); // can hang the response
- BLACKLISTED_PROPERTY_NAMES.add("transfer-encoding"); // can hang the response
- BLACKLISTED_PROPERTY_NAMES.add("server"); // creates duplicate values
+ BLACKLISTED_PROPERTY_NAMES.add("content-length"); // hangs the response
+ BLACKLISTED_PROPERTY_NAMES.add("transfer-encoding"); // hangs the response
+ BLACKLISTED_PROPERTY_NAMES.add("server"); // creates duplicate header
}
private String name;
private String value;
- public ResponseHeader() {
- }
+ public ResponseHeader() {}
public ResponseHeader(String name, String value) {
this.name = name;
@@ -67,8 +69,24 @@
this.value = value;
}
- public void addToProperties(Properties properties) {
+ // JBESB-2511
+ @SuppressWarnings("unchecked")
+ public void putNameValue(Map map) {
if ( !BLACKLISTED_PROPERTY_NAMES.contains(name.toLowerCase()) ) {
+ map.put(name, value);
+ }
+ }
+
+ // JBESB-2511
+ public void setHeaderNameValue(HttpServletResponse response) {
+ if ( !BLACKLISTED_PROPERTY_NAMES.contains(name.toLowerCase()) ) {
+ response.setHeader(name, value);
+ }
+ }
+
+ // JBESB-2511
+ public void setPropertyNameThis(Properties properties) {
+ if ( !BLACKLISTED_PROPERTY_NAMES.contains(name.toLowerCase()) ) {
properties.setProperty(name, this);
}
}
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/ResponseStatus.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/ResponseStatus.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/ResponseStatus.java 2009-07-29 19:39:37 UTC (rev 28580)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2009
+ */
+package org.jboss.soa.esb.message;
+
+import org.jboss.remoting.transport.http.HTTPMetadataConstants;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.gateway.HttpMessageComposer;
+
+/**
+ * Utility class for use by SOAPClient, SOAPProducer, SOAPProxy and HttpRouter. The default is
+ * now that these actions will set the http response status back into the Message Properties,
+ * which will then get returned in the http response of a synchronous invocation of the
+ * <jbr-provider/> ({@link org.jboss.soa.esb.listeners.gateway.JBossRemotingGatewayListener JBossRemotingGatewayListener}) or <http-provider/> ({@link org.jboss.soa.esb.listeners.gateway.HttpGatewayListener HttpGatewayListener}).<p/>
+ *
+ * If you want the legacy behavior, you can override this at an action level (META-INF/jboss-esb.xml):<br/>
+ * <action name="..." class="..."><br/>
+ * <property name="http.responseStatusEnabled" value="false"/><br/>
+ * </action><p/>
+ *
+ * or at a global level (jbossesb-properties.xml):<br/>
+ * <esb><br/>
+ * <properties name="transports"><br/>
+ * <property name="org.jboss.soa.esb.http.responseStatusEnabled" value="false"/><br/>
+ * </properties><br/>
+ * </esb>
+ *
+ * @author dward at jboss.org
+ */
+public class ResponseStatus
+{
+
+ public static final String ACTION_HTTP_RESPONSE_STATUS_ENABLED_CONFIG = "http.responseStatusEnabled";
+ public static final String GLOBAL_HTTP_RESPONSE_STATUS_ENABLED_CONFIG = "org.jboss.soa.esb." + ACTION_HTTP_RESPONSE_STATUS_ENABLED_CONFIG;
+
+ private static boolean GLOBAL_HTTP_RESPONSE_STATUS_ENABLED;
+ static {
+ GLOBAL_HTTP_RESPONSE_STATUS_ENABLED =
+ ModulePropertyManager.getPropertyManager(ModulePropertyManager.TRANSPORTS_MODULE)
+ .getProperty(GLOBAL_HTTP_RESPONSE_STATUS_ENABLED_CONFIG, "true").equals("true");
+ }
+
+ private ResponseStatus() {}
+
+ // JBESB-2761
+ public static boolean isHttpEnabled(ConfigTree actionConfig) {
+ return actionConfig.getBooleanAttribute(ACTION_HTTP_RESPONSE_STATUS_ENABLED_CONFIG, GLOBAL_HTTP_RESPONSE_STATUS_ENABLED);
+ }
+
+ // JBESB-2761
+ public static void setHttpProperties(Properties properties, int statusCode, String statusMessage) {
+ if (statusCode > 0) {
+ properties.setProperty(HTTPMetadataConstants.RESPONSE_CODE, statusCode); // <jbr-provider/>
+ properties.setProperty(HttpMessageComposer.HTTP_RESPONSE_STATUS, statusCode); // <http-provider/>
+ }
+ if (statusMessage != null) {
+ properties.setProperty(HTTPMetadataConstants.RESPONSE_CODE_MESSAGE, statusMessage); // <jbr-provider/>
+ // unnecessary to set status message for <http-provider/>
+ }
+ }
+
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/ResponseStatus.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPClient.java
===================================================================
--- labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPClient.java 2009-07-29 19:34:20 UTC (rev 28579)
+++ labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPClient.java 2009-07-29 19:39:37 UTC (rev 28580)
@@ -58,6 +58,7 @@
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.MessagePayloadProxy;
import org.jboss.soa.esb.message.ResponseHeader;
+import org.jboss.soa.esb.message.ResponseStatus;
import org.jboss.soa.esb.message.body.content.BytesBody;
import org.jboss.soa.esb.util.ClassUtil;
import org.w3c.dom.Document;
@@ -291,6 +292,7 @@
private HttpClient httpclient;
private String endpointUrl;
private MessagePayloadProxy payloadProxy;
+ private boolean httpResponseStatusEnabled;
public SOAPClient(ConfigTree config) throws ConfigurationException {
wsdl = config.getRequiredAttribute("wsdl");
@@ -321,6 +323,8 @@
httpclient = HttpClientFactory.createHttpClient(httpClientProps);
endpointUrl = config.getAttribute("endpointUrl");
+
+ httpResponseStatusEnabled = ResponseStatus.isHttpEnabled(config);
}
private void createPayloadProxy(ConfigTree config) {
@@ -447,12 +451,16 @@
protected static class Response {
private Header[] headers;
private String body;
+ private int statusCode;
+ private String statusMessage;
protected Response(String body) {
- this(body, new Header[0]);
+ this(body, new Header[0], 0, null);
}
- protected Response(String body, Header[] headers) {
+ protected Response(String body, Header[] headers, int statusCode, String statusMessage) {
this.headers = headers;
this.body = body;
+ this.statusCode = statusCode;
+ this.statusMessage = statusMessage;
}
protected Header[] getHeaders() {
return headers;
@@ -460,6 +468,12 @@
protected String getBody() {
return body;
}
+ protected int getStatusCode() {
+ return statusCode;
+ }
+ protected String getStatusMessage() {
+ return statusMessage;
+ }
}
private Response invokeEndpoint(String request) throws ActionProcessingException {
@@ -488,7 +502,7 @@
logger.warn("Received status code '" + result + "' on HTTP SOAP (POST) request to '" + endpoint + "'.");
}
- return new Response(post.getResponseBodyAsString(), post.getResponseHeaders());
+ return new Response(post.getResponseBodyAsString(), post.getResponseHeaders(), result, post.getStatusLine().getReasonPhrase());
} catch (IOException e) {
throw new ActionProcessingException("Failed to invoke SOAP Endpoint: '" + endpoint + " ' - '" + soapAction + "'.", e);
} finally {
@@ -520,11 +534,15 @@
throw new ActionProcessingException(e);
}
- // https://jira.jboss.org/jira/browse/JBESB-2511
+ // JBESB-2511
org.jboss.soa.esb.message.Properties properties = message.getProperties();
for (Header header : response.getHeaders()) {
- new ResponseHeader(header.getName(), header.getValue()).addToProperties(properties);
+ new ResponseHeader(header.getName(), header.getValue()).setPropertyNameThis(properties);
}
+ // JBESB-2761
+ if (httpResponseStatusEnabled) {
+ ResponseStatus.setHttpProperties(properties, response.getStatusCode(), response.getStatusMessage());
+ }
}
private Object applyXStreamResponseDeserializer(String response) {
Modified: labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPProcessor.java
===================================================================
--- labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPProcessor.java 2009-07-29 19:34:20 UTC (rev 28579)
+++ labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPProcessor.java 2009-07-29 19:39:37 UTC (rev 28580)
@@ -42,6 +42,7 @@
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.ResponseStatus;
import org.jboss.soa.esb.message.body.content.BytesBody;
import org.jboss.wsf.spi.SPIProvider;
import org.jboss.wsf.spi.SPIProviderResolver;
@@ -114,6 +115,7 @@
private static ThreadLocal<Message> messageTL = new ThreadLocal<Message>();
private String jbossws_endpoint;
private MessagePayloadProxy payloadProxy;
+ private boolean httpResponseStatusEnabled;
/**
* Public constructor.
@@ -125,6 +127,7 @@
payloadProxy = new MessagePayloadProxy(config,
new String[] {BytesBody.BYTES_LOCATION, ActionUtils.POST_ACTION_DATA},
new String[] {ActionUtils.POST_ACTION_DATA});
+ httpResponseStatusEnabled = ResponseStatus.isHttpEnabled(config);
}
/**
@@ -195,9 +198,13 @@
for(Map.Entry<String, List<String>> header: responseHeaders.entrySet())
{
// We can only deal with the first value in the list.
- // https://jira.jboss.org/jira/browse/JBESB-2511
- new ResponseHeader(header.getKey(), header.getValue().get(0)).addToProperties(properties);
+ // JBESB-2511
+ new ResponseHeader(header.getKey(), header.getValue().get(0)).setPropertyNameThis(properties);
}
+ // JBESB-2761
+ if (httpResponseStatusEnabled) {
+ ResponseStatus.setHttpProperties(properties, servletResponse.getStatus(), servletResponse.getStatusMessage());
+ }
final byte[] responseData = servletResponse.getContent() ;
if(contentType != null) {
Modified: labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/SOAPProcessorHttpServletResponse.java
===================================================================
--- labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/SOAPProcessorHttpServletResponse.java 2009-07-29 19:34:20 UTC (rev 28579)
+++ labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/SOAPProcessorHttpServletResponse.java 2009-07-29 19:39:37 UTC (rev 28580)
@@ -50,6 +50,8 @@
private int status ;
+ private String statusMessage ;
+
private ByteArrayOutputStream baos ;
private boolean streamReturned ;
@@ -84,7 +86,13 @@
public void setStatus(final int status)
{
+ setStatus(status, null) ;
+ }
+
+ public void setStatus(final int status, final String statusMessage)
+ {
this.status = status ;
+ this.statusMessage = statusMessage ;
}
public ServletOutputStream getOutputStream() throws IOException
@@ -119,6 +127,11 @@
return status ;
}
+ public String getStatusMessage()
+ {
+ return statusMessage ;
+ }
+
public Map<String, List<String>> getHeaders()
{
return headers ;
@@ -260,11 +273,6 @@
throw new UnsupportedOperationException("Not yet supported") ;
}
- public void setStatus(int arg0, String arg1)
- {
- throw new UnsupportedOperationException("Not yet supported") ;
- }
-
public void flushBuffer() throws IOException
{
throw new UnsupportedOperationException("Not yet supported") ;
More information about the jboss-svn-commits
mailing list