activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r521746 - in /activemq/camel/trunk/camel-cxf/src/main: java/org/apache/camel/component/cxf/ resources/META-INF/services/org/apache/camel/EndpointResolver/
Date Fri, 23 Mar 2007 14:50:20 GMT
Author: jstrachan
Date: Fri Mar 23 07:50:19 2007
New Revision: 521746

URL: http://svn.apache.org/viewvc?view=rev&rev=521746
Log:
added initial shell of a CXF componet

Added:
    activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java
  (with props)
    activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java
  (with props)
    activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
  (with props)
    activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpointResolver.java
  (with props)
    activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfExchange.java
  (with props)
    activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfMessage.java
  (with props)
    activemq/camel/trunk/camel-cxf/src/main/resources/META-INF/services/org/apache/camel/EndpointResolver/cxf

Added: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java?view=auto&rev=521746
==============================================================================
--- activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java
(added)
+++ activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java
Fri Mar 23 07:50:19 2007
@@ -0,0 +1,42 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.component.cxf;
+
+import org.apache.cxf.message.Message;
+
+import java.util.Set;
+
+/**
+ * The binding of how Camel messages get mapped to Apache CXF and back again
+ *
+ * @version $Revision$
+ */
+public class CxfBinding {
+
+    public Object extractBodyFromCxf(CxfExchange exchange, Message message) {
+        //  TODO how do we choose a format?
+        Set<Class<?>> contentFormats = message.getContentFormats();
+        for (Class<?> contentFormat : contentFormats) {
+            Object answer = message.get(contentFormat);
+            if (answer != null) {
+                return answer;
+            }
+        }
+        return null;
+    }
+}

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java?view=auto&rev=521746
==============================================================================
--- activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java
(added)
+++ activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java
Fri Mar 23 07:50:19 2007
@@ -0,0 +1,57 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.component.cxf;
+
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.CamelContext;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URI;
+import java.net.SocketAddress;
+import java.net.InetSocketAddress;
+
+/**
+ * @version $Revision$
+ */
+public class CxfComponent extends DefaultComponent<CxfExchange> {
+    private Map<String, CxfEndpoint> map = new HashMap<String, CxfEndpoint>();
+
+    public CxfComponent() {
+    }
+
+    public CxfComponent(CamelContext context) {
+        super(context);
+    }
+
+    public synchronized CxfEndpoint createEndpoint(String uri, String[] urlParts) throws
IOException, URISyntaxException {
+        CxfEndpoint endpoint = map.get(uri);
+        if (endpoint == null) {
+            String remainingUrl = uri.substring("mina:".length());
+            URI u = new URI(remainingUrl);
+
+            String protocol = u.getScheme();
+
+            map.put(uri, endpoint);
+        }
+        return endpoint;
+    }
+
+}

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java?view=auto&rev=521746
==============================================================================
--- activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
(added)
+++ activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
Fri Mar 23 07:50:19 2007
@@ -0,0 +1,66 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.component.cxf;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.DefaultEndpoint;
+
+/**
+ * The endpoint in the service engine
+ *
+ * @version $Revision$
+ */
+public class CxfEndpoint extends DefaultEndpoint<CxfExchange> {
+    private CxfBinding binding;
+
+    protected CxfEndpoint(String uri, CamelContext camelContext) {
+        super(uri, camelContext);
+    }
+
+    public void onExchange(CxfExchange cxfExchange) {
+        // TODO send into CXF
+    }
+
+    public CxfExchange createExchange() {
+        return new CxfExchange(getContext(), getBinding());
+    }
+
+    public CxfBinding getBinding() {
+        if (binding == null) {
+            binding = new CxfBinding();
+        }
+        return binding;
+    }
+
+    public void setBinding(CxfBinding binding) {
+        this.binding = binding;
+    }
+
+    @Override
+    protected void doActivate() throws Exception {
+        super.doActivate();
+
+        // TODO process any inbound messages from CXF
+
+        Processor<CxfExchange> processor = getInboundProcessor();
+        if (processor != null) {
+
+        }
+    }
+}

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpointResolver.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpointResolver.java?view=auto&rev=521746
==============================================================================
--- activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpointResolver.java
(added)
+++ activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpointResolver.java
Fri Mar 23 07:50:19 2007
@@ -0,0 +1,87 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.component.cxf;
+
+import org.apache.camel.EndpointResolver;
+import org.apache.camel.Component;
+import org.apache.camel.CamelContext;
+import org.apache.camel.util.ObjectHelper;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.concurrent.Callable;
+
+/**
+ * An implementation of {@link EndpointResolver} that creates
+ * {@link CxfEndpoint} objects.
+ *
+ * The syntax for a MINA URI looks like:
+ *
+ * <pre><code>mina:</code></pre>
+ *
+ * @version $Revision:520964 $
+ */
+public class CxfEndpointResolver implements EndpointResolver<CxfExchange> {
+
+	public static final String DEFAULT_COMPONENT_NAME = CxfEndpointResolver.class.getName();
+
+	/**
+	 * Finds the {@link CxfComponent} specified by the uri.  If the {@link CxfComponent}
+	 * object do not exist, it will be created.
+	 */
+	public Component resolveComponent(CamelContext container, String uri) {
+		String[] id = getEndpointId(uri);
+		return resolveCxfComponent(container, id[0]);
+	}
+
+	/**
+	 * Finds the {@link CxfEndpoint} specified by the uri.  If the {@link CxfEndpoint} or it's
associated
+	 * {@see QueueComponent} object do not exist, they will be created.
+	 */
+	public CxfEndpoint resolveEndpoint(CamelContext container, String uri) throws IOException,
URISyntaxException {
+		String[] urlParts = getEndpointId(uri);
+    	CxfComponent component = resolveCxfComponent(container, urlParts[0]);
+        return component.createEndpoint(uri, urlParts);
+    }
+
+	/**
+	 * @return an array that looks like: [componentName,endpointName]
+	 */
+	private String[] getEndpointId(String uri) {
+		String rc [] = {CxfEndpointResolver.DEFAULT_COMPONENT_NAME, null};
+		String splitURI[] = ObjectHelper.splitOnCharacter(uri, ":", 3);
+    	if( splitURI[2] != null ) {
+    		rc[0] =  splitURI[1];
+    		rc[1] =  splitURI[2];
+    	} else {
+    		rc[1] =  splitURI[1];
+    	}
+		return rc;
+	}
+
+	@SuppressWarnings("unchecked")
+	private CxfComponent resolveCxfComponent(final CamelContext context, final String componentName)
{
+    	Component rc = context.getOrCreateComponent(componentName, new Callable(){
+			public CxfComponent call() throws Exception {
+                return new CxfComponent(context);
+			}});
+    	return (CxfComponent) rc;
+	}
+
+
+}

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpointResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpointResolver.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpointResolver.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfExchange.java?view=auto&rev=521746
==============================================================================
--- activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfExchange.java
(added)
+++ activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfExchange.java
Fri Mar 23 07:50:19 2007
@@ -0,0 +1,119 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.component.cxf;
+
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.CamelContext;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.transport.Destination;
+import org.apache.cxf.transport.Conduit;
+
+/**
+ * An {@link Exchange} for working with Apache CXF
+ *
+ * @version $Revision$
+ */
+public class CxfExchange extends DefaultExchange {
+    private final CxfBinding binding;
+    private Exchange exchange;
+
+    public CxfExchange(CamelContext context, CxfBinding binding) {
+        super(context);
+        this.binding = binding;
+    }
+
+    public CxfExchange(CamelContext context, CxfBinding binding, Exchange exchange) {
+        super(context);
+        this.binding = binding;
+        this.exchange = exchange;
+
+        setIn(new CxfMessage(exchange.getInMessage()));
+        setOut(new CxfMessage(exchange.getOutMessage()));
+        setFault(new CxfMessage(exchange.getInFaultMessage()));
+    }
+    @Override
+    public CxfMessage getIn() {
+        return (CxfMessage) super.getIn();
+    }
+
+    @Override
+    public CxfMessage getOut() {
+        return (CxfMessage) super.getOut();
+    }
+
+    @Override
+    public CxfMessage getFault() {
+        return (CxfMessage) super.getFault();
+    }
+
+    /**
+     * @return the Camel <-> JBI binding
+     */
+    public CxfBinding getBinding() {
+        return binding;
+    }
+
+    // Expose CXF APIs directly on the exchange
+    //-------------------------------------------------------------------------
+
+    /**
+     * Returns the underlying CXF message exchange for an inbound exchange
+     * or null for outbound messages
+     *
+     * @return the inbound message exchange
+     */
+    public Exchange getExchange() {
+        return exchange;
+    }
+
+    public Message getOutFaultMessage() {
+        return getExchange().getOutFaultMessage();
+    }
+
+    public Message getInMessage() {
+        return getExchange().getInMessage();
+    }
+
+    public Message getInFaultMessage() {
+        return getExchange().getInFaultMessage();
+    }
+
+    public Message getOutMessage() {
+        return getExchange().getOutMessage();
+    }
+
+    public Destination getDestination() {
+        return getExchange().getDestination();
+    }
+
+    public Conduit getConduit() {
+        return getExchange().getConduit();
+    }
+
+
+    @Override
+    protected CxfMessage createInMessage() {
+        return new CxfMessage();
+    }
+
+    @Override
+    protected CxfMessage createOutMessage() {
+        return new CxfMessage();
+    }
+}

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfExchange.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfExchange.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfExchange.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfMessage.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfMessage.java?view=auto&rev=521746
==============================================================================
--- activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfMessage.java
(added)
+++ activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfMessage.java
Fri Mar 23 07:50:19 2007
@@ -0,0 +1,104 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.component.cxf;
+
+import org.apache.camel.impl.DefaultMessage;
+import org.apache.cxf.message.Message;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * An Apache CXF {@link Message} which provides access to the underlying CXF features
+ *
+ * @version $Revision$
+ */
+public class CxfMessage extends DefaultMessage {
+    private Message cxfMessage;
+
+    public CxfMessage() {
+    }
+
+    public CxfMessage(Message cxfMessage) {
+        this.cxfMessage = cxfMessage;
+    }
+
+    @Override
+    public String toString() {
+        if (cxfMessage != null) {
+            return "CxfMessage: " + cxfMessage;
+        }
+        else {
+            return "CxfMessage: " + getBody();
+        }
+    }
+
+    @Override
+    public CxfExchange getExchange() {
+        return (CxfExchange) super.getExchange();
+    }
+
+    /**
+     * Returns the underlying CXF message
+     *
+     * @return the CXF message
+     */
+    public Message getMessage() {
+        return cxfMessage;
+    }
+
+    public void setMessage(Message cxfMessage) {
+        this.cxfMessage = cxfMessage;
+    }
+
+    public Object getHeader(String name) {
+        Object answer = null;
+        if (cxfMessage != null) {
+            answer = cxfMessage.get(name);
+        }
+        if (answer == null) {
+            answer = super.getHeader(name);
+        }
+        return answer;
+    }
+
+    @Override
+    public CxfMessage newInstance() {
+        return new CxfMessage();
+    }
+
+    @Override
+    protected Object createBody() {
+        if (cxfMessage != null) {
+            return getExchange().getBinding().extractBodyFromCxf(getExchange(), cxfMessage);
+        }
+        return null;
+    }
+
+    @Override
+    protected void populateInitialHeaders(Map<String, Object> map) {
+        if (cxfMessage != null) {
+            Set<Map.Entry<String,Object>> entries = cxfMessage.entrySet();
+            for (Map.Entry<String, Object> entry : entries) {
+                String name = entry.getKey();
+                Object value = entry.getValue();
+                map.put(name, value);
+            }
+        }
+    }
+}

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfMessage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfMessage.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfMessage.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-cxf/src/main/resources/META-INF/services/org/apache/camel/EndpointResolver/cxf
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-cxf/src/main/resources/META-INF/services/org/apache/camel/EndpointResolver/cxf?view=auto&rev=521746
==============================================================================
--- activemq/camel/trunk/camel-cxf/src/main/resources/META-INF/services/org/apache/camel/EndpointResolver/cxf
(added)
+++ activemq/camel/trunk/camel-cxf/src/main/resources/META-INF/services/org/apache/camel/EndpointResolver/cxf
Fri Mar 23 07:50:19 2007
@@ -0,0 +1 @@
+class=org.apache.camel.component.cxf.CxfEndpointResolver



Mime
View raw message