Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BD8E5D55F for ; Fri, 19 Oct 2012 10:05:48 +0000 (UTC) Received: (qmail 99460 invoked by uid 500); 19 Oct 2012 10:05:48 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 99378 invoked by uid 500); 19 Oct 2012 10:05:47 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 99353 invoked by uid 99); 19 Oct 2012 10:05:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Oct 2012 10:05:47 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Oct 2012 10:05:44 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id CEC1E23888FE; Fri, 19 Oct 2012 10:05:00 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1400019 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/component/binding/ camel-core/src/main/java/org/apache/camel/processor/binding/ camel-core/src/main/java/org/apache/camel/spi/ camel-core/src/main/resources/META-INF/serv... Date: Fri, 19 Oct 2012 10:05:00 -0000 To: commits@camel.apache.org From: jstrachan@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121019100500.CEC1E23888FE@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jstrachan Date: Fri Oct 19 10:04:59 2012 New Revision: 1400019 URL: http://svn.apache.org/viewvc?rev=1400019&view=rev Log: initial spike of support for Bindings on camel endpoints. see https://cwiki.apache.org/confluence/display/CAMEL/Binding for more details Added: camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/ camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingComponent.java (with props) camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingConsumerProcessor.java (with props) camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingEndpoint.java (with props) camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingNameComponent.java (with props) camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingProducer.java (with props) camel/trunk/camel-core/src/main/java/org/apache/camel/processor/binding/ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/binding/DataFormatBinding.java (with props) camel/trunk/camel-core/src/main/java/org/apache/camel/processor/binding/package.html - copied, changed from r1399705, camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/package.html camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Binding.java (with props) camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/binding - copied, changed from r1399705, camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/bean camel/trunk/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonBindingTest.java - copied, changed from r1399705, camel/trunk/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalTest.java camel/trunk/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonNameBindingTest.java (with props) Added: camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingComponent.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingComponent.java?rev=1400019&view=auto ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingComponent.java (added) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingComponent.java Fri Oct 19 10:04:59 2012 @@ -0,0 +1,100 @@ +/** + * + * 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.binding; + +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.Endpoint; +import org.apache.camel.impl.DefaultComponent; +import org.apache.camel.spi.Binding; +import org.apache.camel.util.CamelContextHelper; +import org.apache.camel.util.ObjectHelper; + +import static org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint; + +/** + * A composite {@link Component} which creates a {@link BindingEndpoint} from a + * configured {@link Binding} instance and using the optional {@link #setUriPostfix(String)} + * and {@link #setUriPostfix(String)} to create the underlying endpoint from the remaining URI + */ +public class BindingComponent extends DefaultComponent { + private Binding binding; + private String uriPrefix; + private String uriPostfix; + + public BindingComponent() { + } + + public BindingComponent(Binding binding) { + this.binding = binding; + } + + public BindingComponent(Binding binding, String uriPrefix) { + this(binding); + this.uriPrefix = uriPrefix; + } + + public BindingComponent(Binding binding, String uriPrefix, String uriPostfix) { + this(binding, uriPrefix); + this.uriPostfix = uriPostfix; + } + + public Binding getBinding() { + return binding; + } + + public void setBinding(Binding binding) { + this.binding = binding; + } + + public String getUriPostfix() { + return uriPostfix; + } + + public void setUriPostfix(String uriPostfix) { + this.uriPostfix = uriPostfix; + } + + public String getUriPrefix() { + return uriPrefix; + } + + public void setUriPrefix(String uriPrefix) { + this.uriPrefix = uriPrefix; + } + + @Override + protected Endpoint createEndpoint(String uri, String remaining, Map parameters) + throws Exception { + Binding bindingValue = getBinding(); + ObjectHelper.notNull(bindingValue, "binding"); + CamelContext camelContext = getCamelContext(); + String delegateURI = createDelegateURI(remaining, parameters); + Endpoint delegate = getMandatoryEndpoint(camelContext, delegateURI); + return new BindingEndpoint(uri, this, bindingValue, delegate); + } + + protected String createDelegateURI(String remaining, Map parameters) { + return getOrEmpty(uriPrefix) + remaining + getOrEmpty(uriPostfix); + } + + protected static String getOrEmpty(String text) { + return text != null ? text : ""; + } +} Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingComponent.java ------------------------------------------------------------------------------ svn:eol-style = native Added: camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingConsumerProcessor.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingConsumerProcessor.java?rev=1400019&view=auto ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingConsumerProcessor.java (added) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingConsumerProcessor.java Fri Oct 19 10:04:59 2012 @@ -0,0 +1,53 @@ +/** + * + * 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.binding; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.support.ServiceSupport; +import org.apache.camel.util.ServiceHelper; + +/** + * Applies a {@link org.apache.camel.spi.Binding} to a consumer + */ +public class BindingConsumerProcessor extends ServiceSupport implements Processor { + private final BindingEndpoint endpoint; + private final Processor delegateProcessor; + private final Processor bindingProcessor; + + public BindingConsumerProcessor(BindingEndpoint endpoint, Processor delegateProcessor) { + this.endpoint = endpoint; + this.delegateProcessor = delegateProcessor; + this.bindingProcessor = endpoint.getBinding().createConsumeProcessor(); + } + + @Override + public void process(Exchange exchange) throws Exception { + endpoint.pipelineBindingProcessor(bindingProcessor, exchange, delegateProcessor); + } + + @Override + protected void doStart() throws Exception { + ServiceHelper.startService(bindingProcessor); + } + + @Override + protected void doStop() throws Exception { + ServiceHelper.stopService(bindingProcessor); + } +} Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingConsumerProcessor.java ------------------------------------------------------------------------------ svn:eol-style = native Added: camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingEndpoint.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingEndpoint.java?rev=1400019&view=auto ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingEndpoint.java (added) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingEndpoint.java Fri Oct 19 10:04:59 2012 @@ -0,0 +1,95 @@ +/** + * + * 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.binding; + +import org.apache.camel.Component; +import org.apache.camel.Consumer; +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.impl.DefaultEndpoint; +import org.apache.camel.spi.Binding; +import org.apache.camel.util.ExchangeHelper; + +/** + * Applies a {@link org.apache.camel.spi.Binding} to an underlying {@link Endpoint} so that the binding processes messages + * before its sent to the endpoint and processes messages received by the endpoint consumer before its passed + * to the real consumer. + */ +public class BindingEndpoint extends DefaultEndpoint { + private final Binding binding; + private final Endpoint delegate; + + public BindingEndpoint(String uri, Component component, Binding binding, Endpoint delegate) { + super(uri, component); + this.binding = binding; + this.delegate = delegate; + } + + @Override + public Producer createProducer() throws Exception { + return new BindingProducer(this); + } + + @Override + public Consumer createConsumer(Processor processor) throws Exception { + Processor bindingProcessor = new BindingConsumerProcessor(this, processor); + return delegate.createConsumer(bindingProcessor); + } + + @Override + public boolean isSingleton() { + return true; + } + + public Binding getBinding() { + return binding; + } + + public Endpoint getDelegate() { + return delegate; + } + + + /** + * Applies the {@link Binding} processor to the given exchange before passing it on to the delegateProcessor (either a producer or consumer) + */ + public void pipelineBindingProcessor(Processor bindingProcessor, Exchange exchange, Processor delegateProcessor) throws Exception { + // use same exchange - seems Pipeline does these days + Exchange bindingExchange = exchange; + bindingProcessor.process(bindingExchange); + Exchange delegateExchange = createNextExchange(bindingExchange); + ExchangeHelper.copyResults(bindingExchange, delegateExchange); + delegateProcessor.process(delegateExchange); + } + + // TODO this code was copied from Pipeline - should make it static and reuse the code? + protected Exchange createNextExchange(Exchange previousExchange) { + Exchange answer = previousExchange; + + // now lets set the input of the next exchange to the output of the + // previous message if it is not null + if (answer.hasOut()) { + answer.setIn(answer.getOut()); + answer.setOut(null); + } + return answer; + } + +} Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingEndpoint.java ------------------------------------------------------------------------------ svn:eol-style = native Added: camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingNameComponent.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingNameComponent.java?rev=1400019&view=auto ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingNameComponent.java (added) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingNameComponent.java Fri Oct 19 10:04:59 2012 @@ -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.binding; + +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.Endpoint; +import org.apache.camel.impl.DefaultComponent; +import org.apache.camel.spi.Binding; +import org.apache.camel.util.CamelContextHelper; + +import static org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint; + +/** + * A Binding component using the URI form binding:nameOfBinding:endpointURI + * to extract the binding name which is then resolved from the registry and used to create a + * {@link BindingEndpoint} from the underlying {@link Endpoint} + */ +public class BindingNameComponent extends DefaultComponent { + protected static final String BAD_FORMAT_MESSAGE + = "URI should be of the format binding:nameOfBinding:endpointURI"; + + @Override + protected Endpoint createEndpoint(String uri, String remaining, Map parameters) + throws Exception { + + CamelContext camelContext = getCamelContext(); + int idx = remaining.indexOf(":"); + if (idx <= 0) { + throw new IllegalArgumentException(BAD_FORMAT_MESSAGE); + } + String bindingName = remaining.substring(0, idx); + String delegateURI = remaining.substring(idx + 1); + if (delegateURI.isEmpty()) { + throw new IllegalArgumentException(BAD_FORMAT_MESSAGE); + } + Binding binding = CamelContextHelper.mandatoryLookup(camelContext, bindingName, Binding.class); + Endpoint delegate = getMandatoryEndpoint(camelContext, delegateURI); + return new BindingEndpoint(uri, this, binding, delegate); + } +} Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingNameComponent.java ------------------------------------------------------------------------------ svn:eol-style = native Added: camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingProducer.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingProducer.java?rev=1400019&view=auto ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingProducer.java (added) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingProducer.java Fri Oct 19 10:04:59 2012 @@ -0,0 +1,58 @@ +/** + * + * 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.binding; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.impl.DefaultProducer; +import org.apache.camel.util.ServiceHelper; + +/** + * A {@link Producer} which applies a {@link org.apache.camel.spi.Binding} before invoking the underlying {@link Producer} on the {@link Endpoint} + */ +public class BindingProducer extends DefaultProducer { + private final BindingEndpoint endpoint; + private final Processor bindingProcessor; + private final Producer delegateProducer; + + public BindingProducer(BindingEndpoint endpoint) throws Exception { + super(endpoint); + this.endpoint = endpoint; + bindingProcessor = endpoint.getBinding().createProduceProcessor(); + delegateProducer = endpoint.getDelegate().createProducer(); + } + + @Override + public void process(Exchange exchange) throws Exception { + endpoint.pipelineBindingProcessor(bindingProcessor, exchange, delegateProducer); + } + + @Override + protected void doStart() throws Exception { + ServiceHelper.startServices(bindingProcessor, delegateProducer); + super.doStart(); + } + + @Override + protected void doStop() throws Exception { + ServiceHelper.stopServices(delegateProducer, bindingProcessor); + super.doStop(); + } +} Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/component/binding/BindingProducer.java ------------------------------------------------------------------------------ svn:eol-style = native Added: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/binding/DataFormatBinding.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/binding/DataFormatBinding.java?rev=1400019&view=auto ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/binding/DataFormatBinding.java (added) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/binding/DataFormatBinding.java Fri Oct 19 10:04:59 2012 @@ -0,0 +1,98 @@ +/** + * + * 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.processor.binding; + +import org.apache.camel.Exchange; +import org.apache.camel.ExchangePattern; +import org.apache.camel.Processor; +import org.apache.camel.processor.MarshalProcessor; +import org.apache.camel.processor.UnmarshalProcessor; +import org.apache.camel.spi.Binding; +import org.apache.camel.spi.DataFormat; +import org.apache.camel.util.ObjectHelper; + +/** + * Represents a {@link org.apache.camel.spi.Binding} which Marshals the message in the ProduceProcessor and + * Unmarshals the message in the ConsumeProcessor + */ +public class DataFormatBinding implements Binding { + private DataFormat producerDataFormat; + private DataFormat consumerDataFormat; + + public DataFormatBinding() { + } + + public DataFormatBinding(DataFormat dataFormat) { + this(dataFormat, dataFormat); + } + + public DataFormatBinding(DataFormat consumerDataFormat, DataFormat producerDataFormat) { + this.consumerDataFormat = consumerDataFormat; + this.producerDataFormat = producerDataFormat; + } + + @Override + public Processor createProduceProcessor() { + ObjectHelper.notNull(producerDataFormat, "producerDataFormat"); + return new MarshalProcessor(producerDataFormat); + } + + @Override + public Processor createConsumeProcessor() { + ObjectHelper.notNull(consumerDataFormat, "consumerDataFormat"); + return new UnmarshalProcessor(consumerDataFormat); + } + + /** + * Sets the data format for both producer and consumer sides + */ + public void setDataFormat(DataFormat dataFormat) { + setConsumerDataFormat(dataFormat); + setProducerDataFormat(dataFormat); + } + + + public DataFormat getConsumerDataFormat() { + return consumerDataFormat; + } + + public void setConsumerDataFormat(DataFormat consumerDataFormat) { + this.consumerDataFormat = consumerDataFormat; + } + + public DataFormat getProducerDataFormat() { + return producerDataFormat; + } + + public void setProducerDataFormat(DataFormat producerDataFormat) { + this.producerDataFormat = producerDataFormat; + } + + + /** + * We need to set the exchange as being out capable for the output to be copied in a pipeline + *

+ * TODO should we be more clever about other patterns here? + */ + protected void makeOutCapable(Exchange exchange) { + if (!exchange.getPattern().isOutCapable()) { + exchange.setPattern(ExchangePattern.InOut); + } + } + +} Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/binding/DataFormatBinding.java ------------------------------------------------------------------------------ svn:eol-style = native Copied: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/binding/package.html (from r1399705, camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/package.html) URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/binding/package.html?p2=camel/trunk/camel-core/src/main/java/org/apache/camel/processor/binding/package.html&p1=camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/package.html&r1=1399705&r2=1400019&rev=1400019&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/package.html (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/binding/package.html Fri Oct 19 10:04:59 2012 @@ -19,7 +19,7 @@ -Helper classes for the Aggregator pattern. +Helper classes for the Binding concept on Endpoints. Added: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Binding.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Binding.java?rev=1400019&view=auto ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Binding.java (added) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Binding.java Fri Oct 19 10:04:59 2012 @@ -0,0 +1,40 @@ +/** + * + * 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.spi; + +import org.apache.camel.Processor; + +/** + * Represents a Binding or contract + * which can be applied to an Endpoint; such as ensuring that a particular + * Data Format is used on messages in and out of an endpoint. + */ +public interface Binding { + + /** + * Returns a new {@link Processor} which is used by a producer on an endpoint to implement + * the producer side binding before the message is sent to the underlying endpoint. + */ + Processor createProduceProcessor(); + + /** + * Returns a new {@link Processor} which is used by a consumer on an endpoint to process the + * message with the binding before its passed to the endpoint consumer producer. + */ + Processor createConsumeProcessor(); +} Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Binding.java ------------------------------------------------------------------------------ svn:eol-style = native Copied: camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/binding (from r1399705, camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/bean) URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/binding?p2=camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/binding&p1=camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/bean&r1=1399705&r2=1400019&rev=1400019&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/bean (original) +++ camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/binding Fri Oct 19 10:04:59 2012 @@ -15,4 +15,4 @@ # limitations under the License. # -class=org.apache.camel.component.bean.BeanComponent \ No newline at end of file +class=org.apache.camel.component.binding.BindingNameComponent \ No newline at end of file Copied: camel/trunk/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonBindingTest.java (from r1399705, camel/trunk/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalTest.java) URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonBindingTest.java?p2=camel/trunk/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonBindingTest.java&p1=camel/trunk/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalTest.java&r1=1399705&r2=1400019&rev=1400019&view=diff ============================================================================== --- camel/trunk/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalTest.java (original) +++ camel/trunk/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonBindingTest.java Fri Oct 19 10:04:59 2012 @@ -16,75 +16,50 @@ */ package org.apache.camel.component.jackson; -import java.util.HashMap; -import java.util.Map; +import javax.naming.Context; +import org.apache.camel.Endpoint; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.binding.BindingComponent; +import org.apache.camel.processor.binding.DataFormatBinding; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.Test; -public class JacksonMarshalTest extends CamelTestSupport { - - @Test - public void testMarshalAndUnmarshalMap() throws Exception { - - Map in = new HashMap(); - in.put("name", "Camel"); - - MockEndpoint mock = getMockEndpoint("mock:reverse"); - mock.expectedMessageCount(1); - mock.message(0).body().isInstanceOf(Map.class); - mock.message(0).body().equals(in); - - Object marshalled = template.requestBody("direct:in", in); - String marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled); - assertEquals("{\"name\":\"Camel\"}", marshalledAsString); - - template.sendBody("direct:back", marshalled); - - mock.assertIsSatisfied(); - } +public class JacksonBindingTest extends CamelTestSupport { + protected MockEndpoint results; @Test public void testMarshalAndUnmarshalPojo() throws Exception { - TestPojo in = new TestPojo(); in.setName("Camel"); - MockEndpoint mock = getMockEndpoint("mock:reversePojo"); - mock.expectedMessageCount(1); - mock.message(0).body().isInstanceOf(TestPojo.class); - mock.message(0).body().equals(in); - - Object marshalled = template.requestBody("direct:inPojo", in); - String marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled); - assertEquals("{\"name\":\"Camel\"}", marshalledAsString); + results.expectedMessageCount(1); + results.message(0).body().isInstanceOf(TestPojo.class); + results.message(0).body().equals(in); - template.sendBody("direct:backPojo", marshalled); - - mock.assertIsSatisfied(); + template.sendBody("direct:start", in); + results.assertIsSatisfied(); } @Override protected RouteBuilder createRouteBuilder() throws Exception { + results = getMockEndpoint("mock:results"); return new RouteBuilder() { @Override public void configure() throws Exception { - - JacksonDataFormat format = new JacksonDataFormat(); - - from("direct:in").marshal(format); - from("direct:back").unmarshal(format).to("mock:reverse"); - - JacksonDataFormat formatPojo = new JacksonDataFormat(TestPojo.class); - - from("direct:inPojo").marshal(formatPojo); - from("direct:backPojo").unmarshal(formatPojo).to("mock:reversePojo"); - + from("direct:start").to("jsonmq:orders").to("file:target/copyOfMessages"); + from("jsonmq:orders").to(results); } }; } + @Override + protected Context createJndiContext() throws Exception { + Context context = super.createJndiContext(); + JacksonDataFormat format = new JacksonDataFormat(TestPojo.class); + context.bind("jsonmq", new BindingComponent(new DataFormatBinding(format), "file:target/")); + return context; + } } Added: camel/trunk/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonNameBindingTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonNameBindingTest.java?rev=1400019&view=auto ============================================================================== --- camel/trunk/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonNameBindingTest.java (added) +++ camel/trunk/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonNameBindingTest.java Fri Oct 19 10:04:59 2012 @@ -0,0 +1,69 @@ +/** + * 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.jackson; + +import javax.naming.Context; + +import org.apache.camel.Endpoint; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.processor.binding.DataFormatBinding; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class JacksonNameBindingTest extends CamelTestSupport { + protected Endpoint boundEndpoint; + protected MockEndpoint results; + + @Test + public void testMarshalAndUnmarshalPojo() throws Exception { + TestPojo in = new TestPojo(); + in.setName("Camel"); + + results.expectedMessageCount(1); + results.message(0).body().isInstanceOf(TestPojo.class); + results.message(0).body().equals(in); + + template.sendBody("direct:start", in); + results.assertIsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + results = getMockEndpoint("mock:results"); + return new RouteBuilder() { + + @Override + public void configure() throws Exception { + // lets use the URI to associate the binding + // though it would be cleaner to use a DSL... + boundEndpoint = endpoint("binding:jackson:file:target/queue"); + + from("direct:start").to(boundEndpoint).to("file:target/copyOfMessages"); + from(boundEndpoint).to(results); + } + }; + } + + @Override + protected Context createJndiContext() throws Exception { + Context context = super.createJndiContext(); + JacksonDataFormat format = new JacksonDataFormat(TestPojo.class); + context.bind("jackson", new DataFormatBinding(format)); + return context; + } +} Propchange: camel/trunk/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonNameBindingTest.java ------------------------------------------------------------------------------ svn:eol-style = native