Diff
Modified: trunk/components/base/src/main/java/org/servicemix/components/http/HttpBinding.java (921 => 922)
--- trunk/components/base/src/main/java/org/servicemix/components/http/HttpBinding.java 2005-11-24 08:32:08 UTC (rev 921)
+++ trunk/components/base/src/main/java/org/servicemix/components/http/HttpBinding.java 2005-11-24 09:21:29 UTC (rev 922)
@@ -27,10 +27,7 @@
* @version $Revision$
*/
public interface HttpBinding {
- HttpMarshaler getMarshaler();
- void setMarshaler(HttpMarshaler marshaler);
-
/**
* Invokes the HTTP request from a servlet
*
Added: trunk/components/base/src/main/java/org/servicemix/components/http/HttpSoapConnector.java (921 => 922)
--- trunk/components/base/src/main/java/org/servicemix/components/http/HttpSoapConnector.java 2005-11-24 08:32:08 UTC (rev 921)
+++ trunk/components/base/src/main/java/org/servicemix/components/http/HttpSoapConnector.java 2005-11-24 09:21:29 UTC (rev 922)
@@ -0,0 +1,146 @@
+/**
+ *
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ **/
+package org.servicemix.components.http;
+
+import java.net.UnknownHostException;
+
+import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
+
+import org.mortbay.http.HttpContext;
+import org.mortbay.http.SocketListener;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.servlet.ServletHandler;
+
+public class HttpSoapConnector extends HttpSoapInOutBinding {
+ private SocketListener listener;
+
+ private Server server;
+
+ private String host;
+
+ private int port;
+
+ /**
+ * Constructor
+ *
+ * @param host
+ * @param port
+ */
+ public HttpSoapConnector(String host, int port) {
+ this.host = host;
+ this.port = port;
+ }
+
+ public HttpSoapConnector() {
+ }
+
+ /**
+ * Constructor
+ *
+ * @param listener
+ */
+ public HttpSoapConnector(SocketListener listener) {
+ this.listener = listener;
+ }
+
+ /**
+ * Called when the Component is initialized
+ *
+ * @param cc
+ * @throws JBIException
+ */
+ public void init(ComponentContext cc) throws JBIException {
+ super.init(cc);
+ //should set all ports etc here - from the naming context I guess ?
+ if (listener == null) {
+ listener = new SocketListener();
+ }
+ try {
+ listener.setHost(host);
+ } catch (UnknownHostException e) {
+ throw new JBIException("init failed", e);
+ }
+ listener.setPort(port);
+ server = new Server();
+ }
+
+ /**
+ * start the Component
+ *
+ * @throws JBIException
+ */
+ public void start() throws JBIException {
+ server.addListener(listener);
+ HttpContext context = server.addContext("/");
+ ServletHandler handler = new ServletHandler();
+ handler.addServlet("jbiServlet", "/*", BindingServlet.class
+ .getName());
+ context.addHandler(handler);
+ try {
+ context.setAttribute("binding", this);
+ server.start();
+ } catch (Exception e) {
+ throw new JBIException("Start failed: " + e, e);
+ }
+ }
+
+ /**
+ * stop
+ */
+ public void stop() throws JBIException {
+ try {
+ server.stop();
+ } catch (InterruptedException e) {
+ throw new JBIException("Stop failed: " + e, e);
+ }
+ }
+
+ /**
+ * shutdown
+ */
+ public void shutDown() throws JBIException {
+ server = null;
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public int getPort() {
+ return port;
+ }
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ public Server getServer() {
+ return server;
+ }
+
+ public void setServer(Server server) {
+ this.server = server;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+}
Added: trunk/components/base/src/main/java/org/servicemix/components/http/HttpSoapInOutBinding.java (921 => 922)
--- trunk/components/base/src/main/java/org/servicemix/components/http/HttpSoapInOutBinding.java 2005-11-24 08:32:08 UTC (rev 921)
+++ trunk/components/base/src/main/java/org/servicemix/components/http/HttpSoapInOutBinding.java 2005-11-24 09:21:29 UTC (rev 922)
@@ -0,0 +1,148 @@
+/**
+ *
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ **/
+package org.servicemix.components.http;
+
+import java.io.IOException;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.DeliveryChannel;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchangeFactory;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.transform.Source;
+
+import org.codehaus.xfire.MessageContext;
+import org.codehaus.xfire.XFire;
+import org.codehaus.xfire.XFireFactory;
+import org.codehaus.xfire.aegis.AegisBindingProvider;
+import org.codehaus.xfire.fault.XFireFault;
+import org.codehaus.xfire.service.Service;
+import org.codehaus.xfire.service.binding.BeanInvoker;
+import org.codehaus.xfire.service.binding.ObjectServiceFactory;
+import org.codehaus.xfire.soap.SoapConstants;
+import org.codehaus.xfire.transport.http.XFireServletController;
+import org.servicemix.components.util.ComponentSupport;
+
+public class HttpSoapInOutBinding extends ComponentSupport implements
+ HttpBinding {
+
+ protected XFire xfire;
+ protected XFireServletController controller;
+ protected Service inOnlyService;
+ protected Service inOutService;
+ protected boolean inOut = true;
+
+ public HttpSoapInOutBinding() {
+ xfire = XFireFactory.newInstance().getXFire();
+ ObjectServiceFactory factory = new ObjectServiceFactory(xfire.getTransportManager(),
+ new AegisBindingProvider());
+ factory.setStyle(SoapConstants.STYLE_DOCUMENT);
+ inOnlyService = factory.create(InOnlyService.class);
+ inOnlyService.setInvoker(new BeanInvoker(new InOnlyService(this)));
+ xfire.getServiceRegistry().register(inOnlyService);
+ inOutService = factory.create(InOutService.class);
+ inOutService.setInvoker(new BeanInvoker(new InOutService(this)));
+ xfire.getServiceRegistry().register(inOutService);
+ controller = new Controller(xfire);
+ }
+
+ public void process(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ controller.doService(request, response);
+ }
+
+ public void invokeInOnly(Source source, MessageContext context) throws XFireFault {
+ throw new XFireFault("Not implemented", XFireFault.SENDER);
+ }
+
+ public Source invokeInOut(Source source, MessageContext context) throws XFireFault {
+ if (source == null) {
+ throw new XFireFault("Invalid source.", XFireFault.SENDER);
+ }
+ try {
+ DeliveryChannel channel = getDeliveryChannel();
+ MessageExchangeFactory factory = channel.createExchangeFactory();
+ InOut exchange = factory.createInOutExchange();
+ NormalizedMessage inMessage = exchange.createMessage();
+ inMessage.setContent(source);
+ exchange.setInMessage(inMessage);
+ boolean result = channel.sendSync(exchange);
+ if (!result) {
+ throw new XFireFault("Error sending exchange", XFireFault.SENDER);
+ }
+ if (exchange.getStatus() == ExchangeStatus.ERROR) {
+ Exception e = exchange.getError();
+ exchange.setStatus(ExchangeStatus.DONE);
+ channel.send(exchange);
+ if (e == null) {
+ throw new XFireFault("Received error", XFireFault.SENDER);
+ } else {
+ throw new XFireFault(e, XFireFault.SENDER);
+ }
+ }
+ NormalizedMessage outMessage = exchange.getOutMessage();
+ if (outMessage == null) {
+ exchange.setError(new Exception("Expected an out message"));
+ channel.sendSync(exchange);
+ throw new XFireFault("No response", XFireFault.SENDER);
+ }
+ Source src = ""
+ exchange.setStatus(ExchangeStatus.DONE);
+ channel.send(exchange);
+ return src;
+ } catch (JBIException e) {
+ throw new XFireFault(e);
+ }
+ }
+
+ public static class InOnlyService {
+ private HttpSoapInOutBinding component;
+ public InOnlyService() {}
+ public InOnlyService(HttpSoapInOutBinding component) {
+ this.component = component;
+ }
+ public void invokeInOnly(Source source, MessageContext context) throws XFireFault {
+ this.component.invokeInOnly(source, context);
+ }
+ }
+
+ public static class InOutService {
+ private HttpSoapInOutBinding component;
+ public InOutService() {}
+ public InOutService(HttpSoapInOutBinding component) {
+ this.component = component;
+ }
+ public Source invokeInOut(Source source, MessageContext context) throws XFireFault {
+ return this.component.invokeInOut(source, context);
+ }
+ }
+
+ public class Controller extends XFireServletController {
+ public Controller(XFire xfire) {
+ super(xfire);
+ }
+ protected String getService(HttpServletRequest request) {
+ return inOut ? inOutService.getName() : inOnlyService.getName();
+ }
+ }
+
+}
Added: trunk/components/base/src/test/java/org/servicemix/components/http/HttpSoapTest.java (921 => 922)
--- trunk/components/base/src/test/java/org/servicemix/components/http/HttpSoapTest.java 2005-11-24 08:32:08 UTC (rev 921)
+++ trunk/components/base/src/test/java/org/servicemix/components/http/HttpSoapTest.java 2005-11-24 09:21:29 UTC (rev 922)
@@ -0,0 +1,73 @@
+/**
+ *
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ **/
+package org.servicemix.components.http;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.URL;
+import java.net.URLConnection;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.servicemix.components.util.EchoComponent;
+import org.servicemix.jbi.container.ActivationSpec;
+import org.servicemix.jbi.container.JBIContainer;
+import org.servicemix.jbi.util.FileUtil;
+
+public class HttpSoapTest extends TestCase {
+
+ public void test() throws Exception {
+ JBIContainer container = new JBIContainer();
+ container.setMonitorInstallationDirectory(false);
+ container.setUseMBeanServer(false);
+ container.setCreateMBeanServer(false);
+ container.init();
+ container.start();
+ ActivationSpec as = new ActivationSpec();
+ as.setId("echo");
+ as.setComponent(new EchoComponent());
+ as.setService(new QName("echo"));
+ container.activateComponent(as);
+ as = new ActivationSpec();
+ as.setId("xfireBinding");
+ as.setComponent(new HttpSoapConnector(null, 8081));
+ as.setDestinationService(new QName("echo"));
+ container.activateComponent(as);
+
+ URLConnection connection = new URL("http://localhost:8081") .openConnection();
+ connection.setDoOutput(true);
+ connection.setDoInput(true);
+ OutputStream os = connection.getOutputStream();
+ // Post the request file.
+ InputStream fis = getClass().getResourceAsStream("soap-request.xml");
+ FileUtil.copyInputStream(fis, os);
+ // Read the response.
+ BufferedReader in = new BufferedReader(new InputStreamReader(connection
+ .getInputStream()));
+ String inputLine;
+ while ((inputLine = in.readLine()) != null) {
+ System.out.println(inputLine);
+ }
+ in.close();
+ }
+
+}
Added: trunk/components/base/src/test/resources/org/servicemix/components/http/soap-request.xml (921 => 922)
--- trunk/components/base/src/test/resources/org/servicemix/components/http/soap-request.xml 2005-11-24 08:32:08 UTC (rev 921)
+++ trunk/components/base/src/test/resources/org/servicemix/components/http/soap-request.xml 2005-11-24 09:21:29 UTC (rev 922)
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
+ <env:Body>
+ <ns1:getQuote xmlns:ns1="urn:xmethods-delayed-quotes"
+ xmlns:se="http://schemas.xmlsoap.org/soap/envelope/"
+ se:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
+
+ <ns1:symbol>IBM</ns1:symbol>
+
+ </ns1:getQuote>
+ </env:Body>
+</env:Envelope>