| Commit in servicemix/base/src/main/java/org/servicemix/components/http on MAIN | |||
| HttpConnector.java | +3 | -9 | 1.4 -> 1.5 |
| HttpInOnlyBinding.java | +7 | -27 | 1.2 -> 1.3 |
| HttpInOutBinding.java | +61 | -3 | 1.5 -> 1.6 |
| +71 | -39 | ||
made it easy to use the HttpConnector in both InOut or InOnly modes
servicemix/base/src/main/java/org/servicemix/components/http
diff -u -r1.4 -r1.5 --- HttpConnector.java 18 Aug 2005 18:28:25 -0000 1.4 +++ HttpConnector.java 30 Aug 2005 13:41:17 -0000 1.5 @@ -30,7 +30,7 @@
/** * An embedded Servlet engine to implement a HTTP connector *
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
public class HttpConnector extends HttpInOutBinding {
private SocketListener listener = new SocketListener();
@@ -43,19 +43,13 @@
*
* @param host
* @param port
- * @throws UnknownHostException
*/
- public HttpConnector(String host, int port) throws UnknownHostException {
+ public HttpConnector(String host, int port) {
this.host = host;
this.port = port;
}
- /**
- * Default Constructor
- *
- * @throws UnknownHostException
- */
- public HttpConnector() throws UnknownHostException {
+ public HttpConnector() {
}
/**
servicemix/base/src/main/java/org/servicemix/components/http
diff -u -r1.2 -r1.3 --- HttpInOnlyBinding.java 19 Aug 2005 10:36:30 -0000 1.2 +++ HttpInOnlyBinding.java 30 Aug 2005 13:41:23 -0000 1.3 @@ -1,4 +1,4 @@
-/**
+/**
* * Copyright 2005 Protique Ltd *
@@ -18,38 +18,18 @@
package org.servicemix.components.http;
-import javax.jbi.JBIException; -import javax.jbi.messaging.MessageExchangeFactory; -import javax.jbi.messaging.NormalizedMessage;
import javax.jbi.messaging.InOnly;
-import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException;
/** * A HTTP Binding Component which performs an [EMAIL PROTECTED] InOnly} exchange with JBI and returns the response. *
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
-public class HttpInOnlyBinding extends HttpBindingSupport {
+public class HttpInOnlyBinding extends HttpInOutBinding {
- public void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException,
- JBIException {
- //response.setContentType("application/soap+xml");
- MessageExchangeFactory factory = getExchangeFactory();
- InOnly exchange = factory.createInOnlyExchange();
- NormalizedMessage inMessage = exchange.createMessage();
- try {
- HttpMarshaler marshaler = getMarshaler();
- marshaler.toNMS(exchange, inMessage, request);
- exchange.setInMessage(inMessage);
- done(exchange);
- response.setStatus(HttpServletResponse.SC_OK);
- }
- catch (IOException e) {
- fail(exchange, e);
- outputException(response, e);
- }
+ // Properties
+ //-------------------------------------------------------------------------
+ public boolean isDefaultInOut() {
+ return false;
} }
servicemix/base/src/main/java/org/servicemix/components/http
diff -u -r1.5 -r1.6 --- HttpInOutBinding.java 19 Aug 2005 10:36:30 -0000 1.5 +++ HttpInOutBinding.java 30 Aug 2005 13:41:24 -0000 1.6 @@ -1,4 +1,4 @@
-/**
+/**
* * Copyright 2005 Protique Ltd *
@@ -19,6 +19,7 @@
package org.servicemix.components.http; import javax.jbi.JBIException;
+import javax.jbi.messaging.InOnly;
import javax.jbi.messaging.InOut; import javax.jbi.messaging.MessageExchangeFactory; import javax.jbi.messaging.NormalizedMessage;
@@ -29,15 +30,28 @@
import java.io.IOException; /**
- * A HTTP Binding Component which performs an [EMAIL PROTECTED] InOut} exchange with JBI and returns the response.
+ * A HTTP Binding Component which performs an [EMAIL PROTECTED] InOut} exchange with JBI and returns the response + * by default but is configurable to be an [EMAIL PROTECTED] InOnly} exchange.
*
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public class HttpInOutBinding extends HttpBindingSupport {
+ private boolean defaultInOut = true; +
public void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException,
JBIException {
//response.setContentType("application/soap+xml");
+ if (isInOutRequest(request, response)) {
+ processInOut(request, response);
+ }
+ else {
+ processInOnly(request, response);
+ }
+ }
+
+ public void processInOut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException,
+ JBIException {
MessageExchangeFactory factory = getExchangeFactory();
InOut exchange = factory.createInOutExchange();
NormalizedMessage inMessage = exchange.createMessage();
@@ -48,6 +62,8 @@
if (result) {
getMarshaler().toResponse(exchange, exchange.getOutMessage(), response);
}
+ done(exchange); + response.setStatus(HttpServletResponse.SC_OK);
}
catch (IOException e) {
fail(exchange, e);
@@ -58,5 +74,47 @@
outputException(response, e);
}
}
+
+ public void processInOnly(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException,
+ JBIException {
+ MessageExchangeFactory factory = getExchangeFactory();
+ InOnly exchange = factory.createInOnlyExchange();
+ NormalizedMessage inMessage = exchange.createMessage();
+ try {
+ HttpMarshaler marshaler = getMarshaler();
+ marshaler.toNMS(exchange, inMessage, request);
+ exchange.setInMessage(inMessage);
+ done(exchange);
+ response.setStatus(HttpServletResponse.SC_OK);
+ }
+ catch (IOException e) {
+ fail(exchange, e);
+ outputException(response, e);
+ }
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public boolean isDefaultInOut() {
+ return defaultInOut;
+ }
+
+ /**
+ * Sets whether an InOut (the default) or an InOnly message exchange will be used by default.
+ */
+ public void setDefaultInOut(boolean defaultInOut) {
+ this.defaultInOut = defaultInOut;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+
+ /**
+ * Return true if this request is an [EMAIL PROTECTED] InOut} request otherwise it will be assumed to be an [EMAIL PROTECTED] InOnly}
+ */
+ protected boolean isInOutRequest(HttpServletRequest request, HttpServletResponse response) {
+ return isDefaultInOut();
+ }
+
}
