the target {@link MessageHandler} implementation type.
26 | *
27 | * @author Artem Bilan
28 | */
29 | public abstract class MessageHandlerSpec, H extends MessageHandler>
30 | extends IntegrationComponentSpec {
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/support/Consumer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2015 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.support;
18 |
19 | /**
20 | * Implementations accept a given value and perform work on the argument.
21 | *
22 | * This is a copy of Java 8 {@code Consumer} interface.
23 | *
24 | * @param the type of values to accept
25 | *
26 | * @author Jon Brisbin
27 | * @author Stephane Maldini
28 | */
29 | public interface Consumer {
30 |
31 | /**
32 | * Execute the logic of the action, accepting the given parameter.
33 | * @param t The parameter to pass to the consumer.
34 | */
35 | void accept(T t);
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/support/GenericHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.support;
18 |
19 | import java.util.Map;
20 |
21 | /**
22 | * A functional interface to specify {@link org.springframework.messaging.MessageHandler}
23 | * logic with Java 8 Lambda expression:
24 | *
25 | * {@code
26 | * .handle((p, h) -> p / 2)
27 | * }
28 | *
29 | *
30 | * @param the expected {@code payload} type.
31 | *
32 | * @author Artem Bilan
33 | */
34 | public interface GenericHandler
{
35 |
36 | Object handle(P payload, Map headers);
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/support/PropertiesBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.support;
18 |
19 | import java.util.Properties;
20 |
21 |
22 | /**
23 | * A {@code Builder} pattern implementation for the {@link Properties}.
24 | *
25 | * @author Gary Russell
26 | * @author Artem Bilan
27 | */
28 | public class PropertiesBuilder {
29 |
30 | private final Properties properties = new Properties();
31 |
32 | public PropertiesBuilder put(Object key, Object value) {
33 | this.properties.put(key, value);
34 | return this;
35 | }
36 |
37 | public Properties get() {
38 | return this.properties;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/core/ComponentsRegistration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.core;
18 |
19 | import java.util.Collection;
20 |
21 | /**
22 | * The marker interface for the {@link IntegrationComponentSpec} implementation,
23 | * when there is need to register as beans not only the target spec's components,
24 | * but some additional components, e.g. {@code subflows} from
25 | * {@link org.springframework.integration.dsl.RouterSpec}.
26 | *
27 | * Just for internal use only.
28 | *
29 | * @author Artem Bilan
30 | */
31 | public interface ComponentsRegistration {
32 |
33 | Collection getComponentsToRegister();
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/amqp/AmqpAsyncOutboundGatewaySpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.amqp;
18 |
19 | import org.springframework.amqp.rabbit.AsyncRabbitTemplate;
20 | import org.springframework.integration.amqp.outbound.AsyncAmqpOutboundGateway;
21 |
22 | /**
23 | * @author Artem Bilan
24 | * @since 1.2
25 | */
26 | public class AmqpAsyncOutboundGatewaySpec
27 | extends AmqpBaseOutboundEndpointSpec {
28 |
29 | AmqpAsyncOutboundGatewaySpec(AsyncRabbitTemplate template) {
30 | this.target = new AsyncAmqpOutboundGateway(template);
31 | this.target.setRequiresReply(true);
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/GenericEndpointSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl;
18 |
19 | import org.springframework.integration.dsl.core.ConsumerEndpointSpec;
20 | import org.springframework.messaging.MessageHandler;
21 |
22 | /**
23 | * A {@link ConsumerEndpointSpec} for a {@link MessageHandler} implementations.
24 | *
25 | * @param the {@link MessageHandler} implementation type.
26 | *
27 | * @author Artem Bilan
28 | */
29 | public final class GenericEndpointSpec
30 | extends ConsumerEndpointSpec, H> {
31 |
32 | GenericEndpointSpec(H messageHandler) {
33 | super(messageHandler);
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/channel/DirectChannelSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.channel;
18 |
19 | import org.springframework.integration.channel.DirectChannel;
20 |
21 | /**
22 | * @author Artem Bilan
23 | */
24 | public class DirectChannelSpec extends LoadBalancingChannelSpec {
25 |
26 | @Override
27 | protected DirectChannel doGet() {
28 | this.channel = new DirectChannel(this.loadBalancingStrategy);
29 | if (this.failover != null) {
30 | this.channel.setFailover(this.failover);
31 | }
32 | if (this.maxSubscribers != null) {
33 | this.channel.setMaxSubscribers(this.maxSubscribers);
34 | }
35 | return super.doGet();
36 | }
37 |
38 | DirectChannelSpec() {
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/support/Function.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.support;
18 |
19 | /**
20 | * Implementations of this class perform work on the given parameter
21 | * and return a result of an optionally different type.
22 | *
23 | * This is a copy of Java 8 {@code Function} interface.
24 | *
25 | * @param The type of the input to the apply operation
26 | * @param The type of the result of the apply operation
27 | *
28 | * @author Jon Brisbin
29 | * @author Stephane Maldini
30 | */
31 | public interface Function {
32 |
33 | /**
34 | * Execute the logic of the action, accepting the given parameter.
35 | * @param t The parameter to pass to the action.
36 | * @return result
37 | */
38 | R apply(T t);
39 |
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/src/test/java/org/springframework/integration/dsl/samples/filesplitter2aggregator/Name.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.samples.filesplitter2aggregator;
18 |
19 | import javax.xml.bind.annotation.XmlAccessType;
20 | import javax.xml.bind.annotation.XmlAccessorType;
21 | import javax.xml.bind.annotation.XmlType;
22 | import javax.xml.bind.annotation.XmlValue;
23 |
24 | /**
25 | * @author Artem Bilan
26 | * @since 1.2
27 | */
28 | @XmlAccessorType(XmlAccessType.FIELD)
29 | @XmlType(name = "name")
30 | public class Name {
31 |
32 | @XmlValue
33 | private String value;
34 |
35 | public Name() {
36 | }
37 |
38 | public Name(String value) {
39 | this.value = value;
40 | }
41 |
42 | public void setValue(String value) {
43 | this.value = value;
44 | }
45 |
46 | public String getValue() {
47 | return this.value;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/channel/ExecutorChannelSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.channel;
18 |
19 | import java.util.concurrent.Executor;
20 |
21 | import org.springframework.integration.channel.ExecutorChannel;
22 |
23 | /**
24 | * @author Artem Bilan
25 | */
26 | public class ExecutorChannelSpec extends LoadBalancingChannelSpec {
27 |
28 | private final Executor executor;
29 |
30 | ExecutorChannelSpec(Executor executor) {
31 | this.executor = executor;
32 | }
33 |
34 | @Override
35 | protected ExecutorChannel doGet() {
36 | this.channel = new ExecutorChannel(this.executor, this.loadBalancingStrategy);
37 | if (this.failover != null) {
38 | this.channel.setFailover(this.failover);
39 | }
40 | if (this.maxSubscribers != null) {
41 | this.channel.setMaxSubscribers(this.maxSubscribers);
42 | }
43 | return super.doGet();
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/test/resources/org/springframework/integration/dsl/test/feed/sample.rss:
--------------------------------------------------------------------------------
1 |
2 |
3 | Spring Integration
4 | https://www.springsource.org/spring-integration
5 |
6 | Spring Integration is a really cool framework
7 |
8 | en-us
9 | Copyright 2004-2010 SpringSource/VMWare
10 | All Rights Reserved.
11 | Tue, 12 Apr 2010 18:21:32 EST
12 | 240
13 |
14 | https://www.springsource.org/sites/all/themes/dotorg09/images/dotorg09_logo.png
15 | Spring Integration
16 | https://www.springsource.org/spring-integration
17 |
18 |
19 | -
20 |
21 | Spring Integration adapters
22 |
23 | https://www.springsource.org/extensions/se-sia
24 |
25 | Spring Integration adapters are realy cool
26 |
27 | Tue, 23 Apr 2010 12:34:58 EST
28 |
29 |
30 | -
31 |
32 | Spring Integration download
33 |
34 | https://www.springsource.com/products/spring-community-download
35 |
36 | Download Spring Integration
37 |
38 | Sun, 13 Feb 2010 14:12:17 EST
39 |
40 |
41 | -
42 |
43 | Check out Spring Integration forums
44 |
45 | https://forum.spring.io/forumdisplay.php?f=42
46 |
47 | Spring Integration forums are awesome
48 |
49 | Wed, 13 Mar 2010 03:38:21 EST
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/ResequencerSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2015 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl;
18 |
19 | import org.springframework.integration.aggregator.ResequencingMessageGroupProcessor;
20 | import org.springframework.integration.aggregator.ResequencingMessageHandler;
21 |
22 | /**
23 | * @author Artem Bilan
24 | */
25 | public class ResequencerSpec extends CorrelationHandlerSpec {
26 |
27 | ResequencerSpec() {
28 | super(new ResequencingMessageHandler(new ResequencingMessageGroupProcessor()));
29 | }
30 |
31 | /**
32 | * @param releasePartialSequences the releasePartialSequences
33 | * @return the handler spec.
34 | * @see ResequencingMessageHandler#setReleasePartialSequences(boolean)
35 | */
36 | public ResequencerSpec releasePartialSequences(boolean releasePartialSequences) {
37 | this.handler.setReleasePartialSequences(releasePartialSequences);
38 | return _this();
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/http/HttpRequestHandlerEndpointSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.http;
18 |
19 | import org.springframework.integration.http.inbound.HttpRequestHandlingMessagingGateway;
20 |
21 | /**
22 | * The {@link BaseHttpInboundEndpointSpec} implementation for the {@link HttpRequestHandlingMessagingGateway}.
23 | *
24 | * @author Artem Bilan
25 | *
26 | * @since 1.1
27 | * @see HttpRequestHandlingMessagingGateway
28 | */
29 | public class HttpRequestHandlerEndpointSpec
30 | extends BaseHttpInboundEndpointSpec {
31 |
32 | HttpRequestHandlerEndpointSpec(HttpRequestHandlingMessagingGateway endpoint, String... path) {
33 | super(endpoint, path);
34 | }
35 |
36 | public HttpRequestHandlerEndpointSpec convertExceptions(boolean convertExceptions) {
37 | this.target.setConvertExceptions(convertExceptions);
38 | return this;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/test/java/org/springframework/integration/dsl/samples/filesplitter2aggregator/Names.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.samples.filesplitter2aggregator;
18 |
19 | import java.util.List;
20 |
21 | import javax.xml.bind.annotation.XmlAccessType;
22 | import javax.xml.bind.annotation.XmlAccessorType;
23 | import javax.xml.bind.annotation.XmlElement;
24 | import javax.xml.bind.annotation.XmlRootElement;
25 | import javax.xml.bind.annotation.XmlType;
26 |
27 | /**
28 | * @author Artem Bilan
29 | * @since 1.2
30 | */
31 | @XmlAccessorType(XmlAccessType.FIELD)
32 | @XmlRootElement
33 | @XmlType(name = "names")
34 | public class Names {
35 |
36 | @XmlElement(name = "name")
37 | private List names;
38 |
39 | public Names() {
40 | }
41 |
42 | public Names(List names) {
43 | this.names = names;
44 | }
45 |
46 | public void setNames(List names) {
47 | this.names = names;
48 | }
49 |
50 | public List getNames() {
51 | return this.names;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/test/java/org/springframework/integration/dsl/test/jpa/entity/Gender.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.test.jpa.entity;
18 |
19 | import java.util.EnumSet;
20 | import java.util.HashMap;
21 | import java.util.Map;
22 |
23 | /**
24 | * Represents the gender of the person
25 | *
26 | * @author Amol Nayak
27 | *
28 | */
29 | public enum Gender {
30 |
31 | MALE("M"), FEMALE("F");
32 |
33 | private String identifier;
34 |
35 | private static Map identifierMap;
36 |
37 | Gender(String identifier) {
38 | this.identifier = identifier;
39 | }
40 |
41 | public String getIdentifier() {
42 | return identifier;
43 | }
44 |
45 | static {
46 | EnumSet all = EnumSet.allOf(Gender.class);
47 | identifierMap = new HashMap();
48 | for (Gender gender : all) {
49 | identifierMap.put(gender.getIdentifier(), gender);
50 | }
51 | }
52 |
53 | public static Gender getGenderFromIdentifier(String identifier) {
54 | return identifierMap.get(identifier);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/channel/PriorityChannelSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.channel;
18 |
19 | import java.util.Comparator;
20 |
21 | import org.springframework.integration.channel.PriorityChannel;
22 | import org.springframework.messaging.Message;
23 |
24 | /**
25 | * @author Artem Bilan
26 | */
27 | public class PriorityChannelSpec extends MessageChannelSpec {
28 |
29 | private int capacity;
30 |
31 | private Comparator> comparator;
32 |
33 | public PriorityChannelSpec setCapacity(int capacity) {
34 | this.capacity = capacity;
35 | return this;
36 | }
37 |
38 | public PriorityChannelSpec setComparator(Comparator> comparator) {
39 | this.comparator = comparator;
40 | return this;
41 | }
42 |
43 | @Override
44 | protected PriorityChannel doGet() {
45 | this.channel = new PriorityChannel(this.capacity, this.comparator);
46 | return super.doGet();
47 | }
48 |
49 |
50 | PriorityChannelSpec() {
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/support/MapBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.support;
18 |
19 | import java.util.HashMap;
20 | import java.util.Map;
21 |
22 | import org.springframework.expression.spel.standard.SpelExpressionParser;
23 |
24 | /**
25 | * A {@code Builder} pattern implementation for the {@link Map}.
26 | *
27 | * @param The type of target {@link MapBuilder} implementation.
28 | * @param The Map key type.
29 | * @param The Map value type.
30 | *
31 | * @author Artem Bilan
32 | */
33 | public class MapBuilder, K, V> {
34 |
35 | protected final static SpelExpressionParser PARSER = new SpelExpressionParser();
36 |
37 | private final Map map = new HashMap();
38 |
39 | public B put(K key, V value) {
40 | this.map.put(key, value);
41 | return _this();
42 | }
43 |
44 | public Map get() {
45 | return this.map;
46 | }
47 |
48 | @SuppressWarnings("unchecked")
49 | protected final B _this() {
50 | return (B) this;
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/ftp/FtpMessageHandlerSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.ftp;
18 |
19 | import org.apache.commons.net.ftp.FTPFile;
20 |
21 | import org.springframework.integration.dsl.file.FileTransferringMessageHandlerSpec;
22 | import org.springframework.integration.file.remote.RemoteFileTemplate;
23 | import org.springframework.integration.file.remote.session.SessionFactory;
24 | import org.springframework.integration.file.support.FileExistsMode;
25 |
26 | /**
27 | * @author Artem Bilan
28 | */
29 | public class FtpMessageHandlerSpec extends FileTransferringMessageHandlerSpec {
30 |
31 | FtpMessageHandlerSpec(SessionFactory sessionFactory) {
32 | super(sessionFactory);
33 | }
34 |
35 | FtpMessageHandlerSpec(RemoteFileTemplate remoteFileTemplate) {
36 | super(remoteFileTemplate);
37 | }
38 |
39 | FtpMessageHandlerSpec(RemoteFileTemplate remoteFileTemplate, FileExistsMode fileExistsMode) {
40 | super(remoteFileTemplate, fileExistsMode);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/sftp/SftpMessageHandlerSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.sftp;
18 |
19 | import org.springframework.integration.dsl.file.FileTransferringMessageHandlerSpec;
20 | import org.springframework.integration.file.remote.RemoteFileTemplate;
21 | import org.springframework.integration.file.remote.session.SessionFactory;
22 | import org.springframework.integration.file.support.FileExistsMode;
23 |
24 | import com.jcraft.jsch.ChannelSftp;
25 |
26 | /**
27 | * @author Artem Bilan
28 | */
29 | public class SftpMessageHandlerSpec
30 | extends FileTransferringMessageHandlerSpec {
31 |
32 | SftpMessageHandlerSpec(SessionFactory sessionFactory) {
33 | super(sessionFactory);
34 | }
35 |
36 | SftpMessageHandlerSpec(RemoteFileTemplate remoteFileTemplate) {
37 | super(remoteFileTemplate);
38 | }
39 |
40 | SftpMessageHandlerSpec(RemoteFileTemplate remoteFileTemplate, FileExistsMode fileExistsMode) {
41 | super(remoteFileTemplate, fileExistsMode);
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/support/MessageProcessorMessageSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.support;
18 |
19 | import org.springframework.integration.endpoint.AbstractMessageSource;
20 | import org.springframework.integration.handler.MessageProcessor;
21 |
22 | /**
23 | * The {@link org.springframework.integration.core.MessageSource} strategy implementation
24 | * to produce a {@link org.springframework.messaging.Message} from underlying
25 | * {@linkplain #messageProcessor} for polling endpoints.
26 | *
27 | * @author Artem Bilan
28 | * @author Gary Russell
29 | * @since 1.1
30 | */
31 | public class MessageProcessorMessageSource extends AbstractMessageSource {
32 |
33 | private final MessageProcessor> messageProcessor;
34 |
35 | public MessageProcessorMessageSource(MessageProcessor> messageProcessor) {
36 | this.messageProcessor = messageProcessor;
37 | }
38 |
39 | @Override
40 | public String getComponentType() {
41 | return "inbound-channel-adapter";
42 | }
43 |
44 | @Override
45 | protected Object doReceive() {
46 | return this.messageProcessor.processMessage(null);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/mail/Pop3MailInboundChannelAdapterSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.mail;
18 |
19 | import org.springframework.integration.mail.Pop3MailReceiver;
20 |
21 | /**
22 | * A {@link MailInboundChannelAdapterSpec} for POP3.
23 | *
24 | * @author Gary Russell
25 | * @author Artem Bilan
26 | */
27 | public class Pop3MailInboundChannelAdapterSpec
28 | extends MailInboundChannelAdapterSpec {
29 |
30 | Pop3MailInboundChannelAdapterSpec() {
31 | super(new Pop3MailReceiver());
32 | }
33 |
34 | Pop3MailInboundChannelAdapterSpec(Pop3MailReceiver receiver) {
35 | super(receiver, true);
36 | }
37 |
38 | Pop3MailInboundChannelAdapterSpec(String url) {
39 | super(new Pop3MailReceiver(url));
40 | }
41 |
42 | Pop3MailInboundChannelAdapterSpec(String host, String username, String password) {
43 | super(new Pop3MailReceiver(host, username, password));
44 | }
45 |
46 | Pop3MailInboundChannelAdapterSpec(String host, int port, String username, String password) {
47 | super(new Pop3MailReceiver(host, port, username, password));
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/ftp/FtpOutboundGatewaySpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.ftp;
18 |
19 | import org.apache.commons.net.ftp.FTPFile;
20 |
21 | import org.springframework.integration.dsl.file.RemoteFileOutboundGatewaySpec;
22 | import org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway;
23 | import org.springframework.integration.ftp.filters.FtpRegexPatternFileListFilter;
24 | import org.springframework.integration.ftp.filters.FtpSimplePatternFileListFilter;
25 |
26 | /**
27 | * @author Artem Bilan
28 | */
29 | public class FtpOutboundGatewaySpec extends RemoteFileOutboundGatewaySpec {
30 |
31 | FtpOutboundGatewaySpec(AbstractRemoteFileOutboundGateway outboundGateway) {
32 | super(outboundGateway);
33 | }
34 |
35 | @Override
36 | public FtpOutboundGatewaySpec patternFileNameFilter(String pattern) {
37 | return filter(new FtpSimplePatternFileListFilter(pattern));
38 | }
39 |
40 | @Override
41 | public FtpOutboundGatewaySpec regexFileNameFilter(String regex) {
42 | return filter(new FtpRegexPatternFileListFilter(regex));
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/amqp/AmqpOutboundEndpointSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.amqp;
18 |
19 | import org.springframework.amqp.core.AmqpTemplate;
20 | import org.springframework.integration.amqp.outbound.AmqpOutboundEndpoint;
21 | import org.springframework.util.Assert;
22 |
23 | /**
24 | * @author Artem Bilan
25 | */
26 | public class AmqpOutboundEndpointSpec
27 | extends AmqpBaseOutboundEndpointSpec {
28 |
29 | private final boolean expectReply;
30 |
31 | AmqpOutboundEndpointSpec(AmqpTemplate amqpTemplate, boolean expectReply) {
32 | this.expectReply = expectReply;
33 | this.target = new AmqpOutboundEndpoint(amqpTemplate);
34 | this.target.setExpectReply(expectReply);
35 | this.target.setHeaderMapper(this.headerMapper);
36 | if (expectReply) {
37 | this.target.setRequiresReply(true);
38 | }
39 | }
40 |
41 | @Override
42 | public AmqpOutboundEndpointSpec mappedReplyHeaders(String... headers) {
43 | Assert.isTrue(this.expectReply, "'mappedReplyHeaders' can be applied only for gateway");
44 | return super.mappedReplyHeaders(headers);
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/http/HttpControllerEndpointSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.http;
18 |
19 | import org.springframework.integration.http.inbound.HttpRequestHandlingController;
20 |
21 | /**
22 | * The {@link BaseHttpInboundEndpointSpec} implementation for the {@link HttpRequestHandlingController}.
23 | *
24 | * @author Artem Bilan
25 | *
26 | * @since 1.1
27 | * @see HttpRequestHandlingController
28 | */
29 | public class HttpControllerEndpointSpec
30 | extends BaseHttpInboundEndpointSpec {
31 |
32 | HttpControllerEndpointSpec(HttpRequestHandlingController controller, String... path) {
33 | super(controller, path);
34 | }
35 |
36 | public HttpControllerEndpointSpec replyKey(String replyKey) {
37 | this.target.setReplyKey(replyKey);
38 | return this;
39 | }
40 |
41 | public HttpControllerEndpointSpec errorsKey(String errorsKey) {
42 | this.target.setErrorsKey(errorsKey);
43 | return this;
44 | }
45 |
46 | public HttpControllerEndpointSpec errorCode(String errorCode) {
47 | this.target.setErrorCode(errorCode);
48 | return this;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/support/tuple/Tuples.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.support.tuple;
18 |
19 | /**
20 | * The {@link Tuple} factory.
21 | *
22 | * @author Artem Bilan
23 | */
24 | public abstract class Tuples {
25 | /**
26 | * Create a {@link Tuple1} with the given object.
27 | * @param t1 The first value in the tuple.
28 | * @param The type of the first value.
29 | * @return The new {@link Tuple1}.
30 | */
31 | public static Tuple1 of(T1 t1) {
32 | return new Tuple1(1, t1);
33 | }
34 |
35 | /**
36 | * Create a {@link Tuple2} with the given objects.
37 | * @param t1 The first value in the tuple.
38 | * @param t2 The second value in the tuple.
39 | * @param The type of the first value.
40 | * @param The type of the second value.
41 | * @return The new {@link Tuple2}.
42 | */
43 | public static Tuple2 of(T1 t1, T2 t2) {
44 | return new Tuple2(2, t1, t2);
45 | }
46 |
47 | /**
48 | * Build an empty {@link Tuple} instance.
49 | * @return An empty tuple
50 | */
51 | public static Tuple empty() {
52 | return Tuple.empty;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/sftp/SftpOutboundGatewaySpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.sftp;
18 |
19 | import org.springframework.integration.dsl.file.RemoteFileOutboundGatewaySpec;
20 | import org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway;
21 | import org.springframework.integration.sftp.filters.SftpRegexPatternFileListFilter;
22 | import org.springframework.integration.sftp.filters.SftpSimplePatternFileListFilter;
23 |
24 | import com.jcraft.jsch.ChannelSftp;
25 |
26 | /**
27 | * @author Artem Bilan
28 | */
29 | public class SftpOutboundGatewaySpec
30 | extends RemoteFileOutboundGatewaySpec {
31 |
32 |
33 | SftpOutboundGatewaySpec(AbstractRemoteFileOutboundGateway outboundGateway) {
34 | super(outboundGateway);
35 | }
36 |
37 | @Override
38 | public SftpOutboundGatewaySpec patternFileNameFilter(String pattern) {
39 | return filter(new SftpSimplePatternFileListFilter(pattern));
40 | }
41 |
42 | @Override
43 | public SftpOutboundGatewaySpec regexFileNameFilter(String regex) {
44 | return filter(new SftpRegexPatternFileListFilter(regex));
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/support/MessageChannelReference.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.support;
18 |
19 | import org.springframework.messaging.Message;
20 | import org.springframework.messaging.MessageChannel;
21 | import org.springframework.util.Assert;
22 |
23 | /**
24 | * An "artificial" {@link MessageChannel} implementation which will be unwrapped to the
25 | * {@link MessageChannel} bean on the bean registration phase.
26 | * For internal use only.
27 | *
28 | * @author Artem Bilan
29 | * @see org.springframework.integration.dsl.config.IntegrationFlowBeanPostProcessor
30 | */
31 | public class MessageChannelReference implements MessageChannel {
32 |
33 | private final String name;
34 |
35 | public MessageChannelReference(String name) {
36 | Assert.hasText(name, "'name' must not be empty");
37 | this.name = name;
38 | }
39 |
40 | public String getName() {
41 | return this.name;
42 | }
43 |
44 | @Override
45 | public boolean send(Message> message) {
46 | throw new UnsupportedOperationException();
47 | }
48 |
49 | @Override
50 | public boolean send(Message> message, long timeout) {
51 | throw new UnsupportedOperationException();
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/amqp/AmqpPublishSubscribeMessageChannelSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.amqp;
18 |
19 | import org.springframework.amqp.core.FanoutExchange;
20 | import org.springframework.amqp.rabbit.connection.ConnectionFactory;
21 | import org.springframework.integration.amqp.channel.PublishSubscribeAmqpChannel;
22 | import org.springframework.integration.amqp.config.AmqpChannelFactoryBean;
23 |
24 | /**
25 | * A {@link AmqpMessageChannelSpec} for {@link PublishSubscribeAmqpChannel}s.
26 | *
27 | * @author Artem Bilan
28 | */
29 | public class AmqpPublishSubscribeMessageChannelSpec
30 | extends AmqpMessageChannelSpec {
31 |
32 | AmqpPublishSubscribeMessageChannelSpec(ConnectionFactory connectionFactory) {
33 | super(connectionFactory);
34 | this.amqpChannelFactoryBean.setPubSub(true);
35 | }
36 |
37 | /**
38 | * @param exchange the exchange.
39 | * @return the spec.
40 | * @see AmqpChannelFactoryBean#setExchange(FanoutExchange)
41 | */
42 | public AmqpPublishSubscribeMessageChannelSpec exchange(FanoutExchange exchange) {
43 | this.amqpChannelFactoryBean.setExchange(exchange);
44 | return _this();
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src/test/java/org/springframework/integration/dsl/LambdaMessageProcessorTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl;
18 |
19 | import static org.hamcrest.Matchers.instanceOf;
20 | import static org.junit.Assert.assertThat;
21 | import static org.junit.Assert.fail;
22 | import static org.mockito.Mockito.mock;
23 |
24 | import org.junit.Test;
25 |
26 | import org.springframework.beans.factory.BeanFactory;
27 | import org.springframework.integration.dsl.support.GenericHandler;
28 | import org.springframework.messaging.support.GenericMessage;
29 |
30 |
31 | /**
32 | * @author Gary Russell
33 | * @since 1.1.0
34 | *
35 | */
36 | public class LambdaMessageProcessorTests {
37 |
38 | @Test
39 | @SuppressWarnings("divzero")
40 | public void testException() {
41 | try {
42 | handle((m, h) -> 1 / 0);
43 | fail("Expected exception");
44 | }
45 | catch (Exception e) {
46 | assertThat(e.getCause(), instanceOf(ArithmeticException.class));
47 | }
48 | }
49 |
50 | private void handle(GenericHandler> h) {
51 | LambdaMessageProcessor lmp = new LambdaMessageProcessor(h, String.class);
52 | lmp.setBeanFactory(mock(BeanFactory.class));
53 | lmp.processMessage(new GenericMessage<>("foo"));
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/PublishSubscribeSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl;
18 |
19 | import java.util.ArrayList;
20 | import java.util.Collection;
21 | import java.util.List;
22 | import java.util.concurrent.Executor;
23 |
24 | import org.springframework.integration.dsl.channel.PublishSubscribeChannelSpec;
25 |
26 | /**
27 | * @author Artem Bilan
28 | */
29 | public class PublishSubscribeSpec extends PublishSubscribeChannelSpec {
30 |
31 | private final List subscriberFlows = new ArrayList();
32 |
33 | PublishSubscribeSpec() {
34 | super();
35 | }
36 |
37 | PublishSubscribeSpec(Executor executor) {
38 | super(executor);
39 | }
40 |
41 | @Override
42 | public PublishSubscribeSpec id(String id) {
43 | return super.id(id);
44 | }
45 |
46 | public PublishSubscribeSpec subscribe(IntegrationFlow flow) {
47 | IntegrationFlowBuilder flowBuilder = IntegrationFlows.from(this.channel);
48 | flow.configure(flowBuilder);
49 | this.subscriberFlows.add(flowBuilder.get());
50 | return _this();
51 | }
52 |
53 | @Override
54 | public Collection getComponentsToRegister() {
55 | List objects = new ArrayList();
56 | objects.addAll(super.getComponentsToRegister());
57 | objects.addAll(this.subscriberFlows);
58 | return objects;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/channel/LoadBalancingChannelSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.channel;
18 |
19 | import org.springframework.integration.channel.AbstractMessageChannel;
20 | import org.springframework.integration.dispatcher.LoadBalancingStrategy;
21 | import org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy;
22 |
23 | /**
24 | *
25 | * @param the target {@link LoadBalancingChannelSpec} implementation type.
26 | * @param the target {@link AbstractMessageChannel} implementation type.
27 | *
28 | * @author Artem Bilan
29 | */
30 | public abstract class LoadBalancingChannelSpec, C extends AbstractMessageChannel>
31 | extends MessageChannelSpec {
32 |
33 | protected LoadBalancingStrategy loadBalancingStrategy = new RoundRobinLoadBalancingStrategy();
34 |
35 | protected Boolean failover;
36 |
37 | protected Integer maxSubscribers;
38 |
39 | public S loadBalancer(LoadBalancingStrategy loadBalancingStrategy) {
40 | this.loadBalancingStrategy = loadBalancingStrategy;
41 | return _this();
42 | }
43 |
44 | public S failover(Boolean failover) {
45 | this.failover = failover;
46 | return _this();
47 | }
48 |
49 | public S maxSubscribers(Integer maxSubscribers) {
50 | this.maxSubscribers = maxSubscribers;
51 | return _this();
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/support/FixedSubscriberChannelPrototype.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.support;
18 |
19 | import org.springframework.messaging.Message;
20 | import org.springframework.messaging.MessageChannel;
21 |
22 | /**
23 | * An "artificial" {@link MessageChannel} implementation which will be unwrapped to the
24 | * {@link org.springframework.integration.channel.FixedSubscriberChannel} on the bean
25 | * registration phase.
26 | * For internal use only.
27 | *
28 | * @author Artem Bilan
29 | * @see org.springframework.integration.dsl.config.IntegrationFlowBeanPostProcessor
30 | */
31 | public class FixedSubscriberChannelPrototype implements MessageChannel {
32 |
33 | private final String name;
34 |
35 | public FixedSubscriberChannelPrototype() {
36 | this(null);
37 | }
38 |
39 | public FixedSubscriberChannelPrototype(String name) {
40 | this.name = name;
41 | }
42 |
43 | public String getName() {
44 | return this.name;
45 | }
46 |
47 |
48 | @Override
49 | public boolean send(Message> message) {
50 | throw new UnsupportedOperationException();
51 | }
52 |
53 | @Override
54 | public boolean send(Message> message, long timeout) {
55 | throw new UnsupportedOperationException();
56 | }
57 |
58 | @Override
59 | public String toString() {
60 | return "FixedSubscriberChannelPrototype{" +
61 | "name='" + this.name + '\'' +
62 | '}';
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/scripting/Scripts.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.scripting;
18 |
19 | import org.springframework.core.io.Resource;
20 |
21 | /**
22 | * The factory for Dynamic Language Scripts (Groovy, Ruby, Python, JavaScript etc.).
23 | *
24 | * @author Artem Bilan
25 | * @since 1.1
26 | */
27 | public abstract class Scripts {
28 |
29 | /**
30 | * The factory method to produce {@link ScriptSpec} based on the {@link Resource}.
31 | * The {@link Resource} must represent the real file and can be injected like:
32 | *
33 | * @Value("com/my/project/scripts/FilterScript.groovy")
34 | * private Resource filterScript;
35 | *
36 | * @param scriptResource the script file {@link Resource}
37 | * @return the ScriptSpec instance
38 | */
39 | public static ScriptSpec script(Resource scriptResource) {
40 | return new ScriptSpec(scriptResource);
41 | }
42 |
43 | /**
44 | * The factory method to produce {@link ScriptSpec} based on the script file location.
45 | * @param scriptLocation the path to the script file.
46 | * {@code file:}, {@code ftp:}, {@code s3:} etc.
47 | * The {@code classpath:} can be omitted.
48 | * @return the ScriptSpec instance
49 | */
50 | public static ScriptSpec script(String scriptLocation) {
51 | return new ScriptSpec(scriptLocation);
52 | }
53 |
54 | private Scripts() {
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/publish-maven.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'maven'
2 |
3 | ext.optionalDeps = []
4 | ext.providedDeps = []
5 |
6 | ext.optional = { optionalDeps << it }
7 | ext.provided = { providedDeps << it }
8 |
9 | install {
10 | repositories.mavenInstaller {
11 | customizePom(pom, project)
12 | }
13 | }
14 |
15 | def customizePom(pom, gradleProject) {
16 | pom.whenConfigured { generatedPom ->
17 | // respect 'optional' and 'provided' dependencies
18 | gradleProject.optionalDeps.each { dep ->
19 | generatedPom.dependencies.find { it.artifactId == dep.name }?.optional = true
20 | }
21 | gradleProject.providedDeps.each { dep ->
22 | generatedPom.dependencies.find { it.artifactId == dep.name }?.scope = 'provided'
23 | }
24 |
25 | // eliminate test-scoped dependencies (no need in maven central poms)
26 | generatedPom.dependencies.removeAll { dep ->
27 | dep.scope == 'test'
28 | }
29 |
30 | // add all items necessary for maven central publication
31 | generatedPom.project {
32 | name = gradleProject.description
33 | description = gradleProject.description
34 | url = linkHomepage
35 | organization {
36 | name = 'SpringIO'
37 | url = 'https://spring.io'
38 | }
39 | licenses {
40 | license {
41 | name 'The Apache Software License, Version 2.0'
42 | url 'https://www.apache.org/licenses/LICENSE-2.0.txt'
43 | distribution 'repo'
44 | }
45 | }
46 |
47 | scm {
48 | url = linkScmUrl
49 | connection = 'scm:git:' + linkScmConnection
50 | developerConnection = 'scm:git:' + linkScmDevConnection
51 | }
52 |
53 | issueManagement {
54 | system = "Jira"
55 | url = linkIssue
56 | }
57 |
58 | developers {
59 | developer {
60 | id = 'markfisher'
61 | name = 'Mark Fisher'
62 | email = 'mfisher@pivotal.io'
63 | roles = ["project founder and lead emeritus"]
64 | }
65 | developer {
66 | id = 'garyrussell'
67 | name = 'Gary Russell'
68 | email = 'grussell@pivotal.io'
69 | roles = ["project lead"]
70 | }
71 | developer {
72 | id = 'abilan'
73 | name = 'Artem Bilan'
74 | email = 'abilan@pivotal.io'
75 | roles = ["project lead"]
76 | }
77 | }
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/SourcePollingChannelAdapterSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2015 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl;
18 |
19 | import org.springframework.integration.config.SourcePollingChannelAdapterFactoryBean;
20 | import org.springframework.integration.core.MessageSource;
21 | import org.springframework.integration.dsl.core.EndpointSpec;
22 | import org.springframework.integration.scheduling.PollerMetadata;
23 |
24 | /**
25 | * @author Artem Bilan
26 |
27 | */
28 | public final class SourcePollingChannelAdapterSpec extends
29 | EndpointSpec> {
30 |
31 | SourcePollingChannelAdapterSpec(MessageSource> messageSource) {
32 | super(messageSource);
33 | this.endpointFactoryBean.setSource(messageSource);
34 | }
35 |
36 | public SourcePollingChannelAdapterSpec phase(int phase) {
37 | this.endpointFactoryBean.setPhase(phase);
38 | return _this();
39 | }
40 |
41 | public SourcePollingChannelAdapterSpec autoStartup(boolean autoStartup) {
42 | this.endpointFactoryBean.setAutoStartup(autoStartup);
43 | return _this();
44 | }
45 |
46 | public SourcePollingChannelAdapterSpec poller(PollerMetadata pollerMetadata) {
47 | if (pollerMetadata != null) {
48 | if (PollerMetadata.MAX_MESSAGES_UNBOUNDED == pollerMetadata.getMaxMessagesPerPoll()) {
49 | pollerMetadata.setMaxMessagesPerPoll(1);
50 | }
51 | this.endpointFactoryBean.setPollerMetadata(pollerMetadata);
52 | }
53 | return _this();
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/channel/PublishSubscribeChannelSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.channel;
18 |
19 | import java.util.concurrent.Executor;
20 |
21 | import org.springframework.integration.channel.PublishSubscribeChannel;
22 | import org.springframework.util.ErrorHandler;
23 |
24 | /**
25 | *
26 | * @param the target {@link PublishSubscribeChannelSpec} implementation type.
27 | *
28 | * @author Artem Bilan
29 | */
30 | public class PublishSubscribeChannelSpec>
31 | extends MessageChannelSpec {
32 |
33 | protected PublishSubscribeChannelSpec() {
34 | this.channel = new PublishSubscribeChannel();
35 | }
36 |
37 | protected PublishSubscribeChannelSpec(Executor executor) {
38 | this.channel = new PublishSubscribeChannel(executor);
39 | }
40 |
41 | public S errorHandler(ErrorHandler errorHandler) {
42 | this.channel.setErrorHandler(errorHandler);
43 | return _this();
44 | }
45 |
46 | public S ignoreFailures(boolean ignoreFailures) {
47 | this.channel.setIgnoreFailures(ignoreFailures);
48 | return _this();
49 | }
50 |
51 | public S applySequence(boolean applySequence) {
52 | this.channel.setApplySequence(applySequence);
53 | return _this();
54 | }
55 |
56 | public S maxSubscribers(Integer maxSubscribers) {
57 | this.channel.setMaxSubscribers(maxSubscribers);
58 | return _this();
59 | }
60 |
61 | public S minSubscribers(int minSubscribers) {
62 | this.channel.setMinSubscribers(minSubscribers);
63 | return _this();
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/IntegrationFlow.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2015 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl;
18 |
19 | /**
20 | * The main Integration DSL abstraction.
21 | *
22 | * The {@link StandardIntegrationFlow} implementation (produced by {@link IntegrationFlowBuilder})
23 | * represents a container for the integration components, which will be registered
24 | * in the application context. Typically is used as {@code @Bean} definition:
25 | *
26 | * @Bean
27 | * public IntegrationFlow fileReadingFlow() {
28 | * return IntegrationFlows
29 | * .from(s -> s.file(tmpDir.getRoot()), e -> e.poller(Pollers.fixedDelay(100)))
30 | * .transform(Transformers.fileToString())
31 | * .channel(MessageChannels.queue("fileReadingResultChannel"))
32 | * .get();
33 | * }
34 | *
35 | *
36 | * Also this interface can be implemented directly to encapsulate the integration logic
37 | * in the target service:
38 | *
39 | * @Component
40 | * public class MyFlow implements IntegrationFlow {
41 | *
42 | * @Override
43 | * public void configure(IntegrationFlowDefinition<?> f) {
44 | * f.<String, String>transform(String::toUpperCase);
45 | * }
46 | *
47 | * }
48 | *
49 | *
50 | * @author Artem Bilan
51 | *
52 | * @see IntegrationFlowBuilder
53 | * @see StandardIntegrationFlow
54 | * @see IntegrationFlowAdapter
55 | */
56 | public interface IntegrationFlow {
57 |
58 | void configure(IntegrationFlowDefinition> flow);
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/jpa/JpaUpdatingOutboundEndpointSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.jpa;
18 |
19 | import org.springframework.integration.jpa.core.JpaExecutor;
20 | import org.springframework.integration.jpa.support.PersistMode;
21 |
22 | /**
23 | * A {@link JpaBaseOutboundEndpointSpec} extension for the {@code updating}
24 | * {@link org.springframework.integration.jpa.outbound.JpaOutboundGateway} mode.
25 | * The {@code outbound-channel-adapter} is achievable through an internal {@code producesReply} option.
26 | *
27 | * @author Artem Bilan
28 | * @since 1.2
29 | */
30 | public class JpaUpdatingOutboundEndpointSpec extends JpaBaseOutboundEndpointSpec {
31 |
32 | JpaUpdatingOutboundEndpointSpec(JpaExecutor jpaExecutor) {
33 | super(jpaExecutor);
34 | }
35 |
36 | JpaUpdatingOutboundEndpointSpec producesReply(boolean producesReply) {
37 | this.target.setProducesReply(producesReply);
38 | if (producesReply) {
39 | this.target.setRequiresReply(true);
40 | }
41 | return this;
42 | }
43 |
44 | public JpaUpdatingOutboundEndpointSpec persistMode(PersistMode persistMode) {
45 | this.jpaExecutor.setPersistMode(persistMode);
46 | return this;
47 | }
48 |
49 | public JpaUpdatingOutboundEndpointSpec flush(boolean flush) {
50 | this.jpaExecutor.setFlush(flush);
51 | return this;
52 | }
53 |
54 | public JpaUpdatingOutboundEndpointSpec flushSize(int flushSize) {
55 | this.jpaExecutor.setFlushSize(flushSize);
56 | return this;
57 | }
58 |
59 | public JpaUpdatingOutboundEndpointSpec clearOnFlush(boolean clearOnFlush) {
60 | this.jpaExecutor.setClearOnFlush(clearOnFlush);
61 | return this;
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/transaction/TransactionHandleMessageAdvice.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.transaction;
18 |
19 | import java.util.Properties;
20 |
21 | import org.aopalliance.aop.Advice;
22 |
23 | import org.springframework.integration.handler.advice.HandleMessageAdvice;
24 | import org.springframework.messaging.MessageHandler;
25 | import org.springframework.transaction.PlatformTransactionManager;
26 | import org.springframework.transaction.interceptor.TransactionAttributeSource;
27 | import org.springframework.transaction.interceptor.TransactionInterceptor;
28 |
29 | /**
30 | * A {@link TransactionInterceptor} extension with {@link HandleMessageAdvice} marker.
31 | *
32 | * When this {@link Advice} is used from the {@code request-handler-advice-chain}, it is applied
33 | * to the {@link MessageHandler#handleMessage}
34 | * (not to the
35 | * {@link org.springframework.integration.handler.AbstractReplyProducingMessageHandler.RequestHandler#handleRequestMessage}),
36 | * therefore the entire downstream process is wrapped to the transaction.
37 | *
38 | * In any other cases it is operated as a regular {@link TransactionInterceptor}.
39 | *
40 | * @author Artem Bilan
41 | * @since 1.2
42 | */
43 | @SuppressWarnings("serial")
44 | public class TransactionHandleMessageAdvice extends TransactionInterceptor implements HandleMessageAdvice {
45 |
46 | public TransactionHandleMessageAdvice() {
47 | }
48 |
49 | public TransactionHandleMessageAdvice(PlatformTransactionManager ptm, Properties attributes) {
50 | super(ptm, attributes);
51 | }
52 |
53 | public TransactionHandleMessageAdvice(PlatformTransactionManager ptm, TransactionAttributeSource tas) {
54 | super(ptm, tas);
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/support/tuple/Tuple1.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.support.tuple;
18 |
19 | /**
20 | * A tuple that holds a single value.
21 | *
22 | * @param The type held by this tuple
23 | *
24 | * @author Jon Brisbin
25 | * @author Artem Bilan
26 | */
27 | public class Tuple1 extends Tuple {
28 |
29 | private static final long serialVersionUID = -1467756857377152573L;
30 |
31 | protected final T1 t1;
32 |
33 | Tuple1(int size, T1 t1) {
34 | super(1);
35 | this.t1 = t1;
36 | }
37 |
38 | /**
39 | * Type-safe way to get the first object of this {@link Tuple}.
40 | * @return The first object, cast to the correct type.
41 | */
42 | public T1 getT1() {
43 | return this.t1;
44 | }
45 |
46 | @Override
47 | public Object get(int index) {
48 | switch (index) {
49 | case 0:
50 | return this.t1;
51 | default:
52 | return null;
53 | }
54 | }
55 |
56 | @Override
57 | public Object[] toArray() {
58 | return new Object[] {this.t1};
59 | }
60 |
61 | @Override
62 | public boolean equals(Object o) {
63 | if (this == o) {
64 | return true;
65 | }
66 | if (o == null || getClass() != o.getClass()) {
67 | return false;
68 | }
69 | if (!super.equals(o)) {
70 | return false;
71 | }
72 |
73 | Tuple1> tuple1 = (Tuple1>) o;
74 |
75 | return this.t1 != null ? this.t1.equals(tuple1.t1) : tuple1.t1 == null;
76 |
77 | }
78 |
79 | @Override
80 | public int hashCode() {
81 | int result = super.hashCode();
82 | result = 31 * result + (this.t1 != null ? this.t1.hashCode() : 0);
83 | return result;
84 | }
85 |
86 | @Override
87 | public String toString() {
88 | return super.toString() +
89 | (this.t1 != null ? "," + this.t1.toString() : "");
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/GatewayEndpointSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl;
18 |
19 | import org.springframework.integration.dsl.core.ConsumerEndpointSpec;
20 | import org.springframework.messaging.MessageChannel;
21 |
22 | /**
23 | * A {@link ConsumerEndpointSpec} implementation for a mid-flow {@link GatewayMessageHandler}.
24 | *
25 | * @author Artem Bilan
26 | */
27 | public final class GatewayEndpointSpec extends ConsumerEndpointSpec {
28 |
29 | GatewayEndpointSpec(MessageChannel requestChannel) {
30 | super(new GatewayMessageHandler());
31 | this.handler.setRequestChannel(requestChannel);
32 | }
33 |
34 | GatewayEndpointSpec(String requestChannel) {
35 | super(new GatewayMessageHandler());
36 | this.handler.setRequestChannelName(requestChannel);
37 | }
38 |
39 | public GatewayEndpointSpec replyChannel(MessageChannel replyChannel) {
40 | this.handler.setReplyChannel(replyChannel);
41 | return this;
42 | }
43 |
44 | public GatewayEndpointSpec replyChannel(String replyChannel) {
45 | this.handler.setReplyChannelName(replyChannel);
46 | return this;
47 | }
48 |
49 | public GatewayEndpointSpec errorChannel(MessageChannel errorChannel) {
50 | this.handler.setErrorChannel(errorChannel);
51 | return this;
52 | }
53 |
54 | public GatewayEndpointSpec errorChannel(String errorChannel) {
55 | this.handler.setErrorChannelName(errorChannel);
56 | return this;
57 | }
58 |
59 | public GatewayEndpointSpec requestTimeout(Long requestTimeout) {
60 | this.handler.setRequestTimeout(requestTimeout);
61 | return this;
62 | }
63 |
64 | public GatewayEndpointSpec replyTimeout(Long replyTimeout) {
65 | this.handler.setReplyTimeout(replyTimeout);
66 | return this;
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/support/BeanNameMessageProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.support;
18 |
19 | import org.springframework.beans.BeansException;
20 | import org.springframework.beans.factory.BeanFactory;
21 | import org.springframework.beans.factory.BeanFactoryAware;
22 | import org.springframework.integration.handler.MessageProcessor;
23 | import org.springframework.integration.handler.MethodInvokingMessageProcessor;
24 | import org.springframework.messaging.Message;
25 | import org.springframework.util.Assert;
26 |
27 | /**
28 | * An "artificial" {@link MessageProcessor} for lazy-load of target bean by its name.
29 | * For internal use only.
30 | *
31 | * @param the expected {@link #processMessage} result type.
32 | *
33 | * @author Artem Bilan
34 | */
35 | public class BeanNameMessageProcessor implements MessageProcessor, BeanFactoryAware {
36 |
37 | private final String beanName;
38 |
39 | private final String methodName;
40 |
41 | private MessageProcessor delegate;
42 |
43 | private BeanFactory beanFactory;
44 |
45 | public BeanNameMessageProcessor(String object, String methodName) {
46 | this.beanName = object;
47 | this.methodName = methodName;
48 | }
49 |
50 | @Override
51 | public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
52 | Assert.notNull(beanFactory, "'beanFactory' must not be null");
53 | this.beanFactory = beanFactory;
54 | }
55 |
56 | @Override
57 | public T processMessage(Message> message) {
58 | if (this.delegate == null) {
59 | Object target = this.beanFactory.getBean(this.beanName);
60 | this.delegate = new MethodInvokingMessageProcessor(target, this.methodName);
61 | }
62 | return this.delegate.processMessage(message);
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/ScatterGatherSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl;
18 |
19 | import org.springframework.integration.dsl.core.ConsumerEndpointSpec;
20 | import org.springframework.integration.scattergather.ScatterGatherHandler;
21 | import org.springframework.messaging.MessageChannel;
22 |
23 | /**
24 | * A {@link GenericEndpointSpec} extension for the {@link ScatterGatherHandler}.
25 | *
26 | * @author Artem Bilan
27 | * @since 1.2
28 | * @see ScatterGatherHandler
29 | */
30 | public class ScatterGatherSpec extends ConsumerEndpointSpec {
31 |
32 | ScatterGatherSpec(ScatterGatherHandler messageHandler) {
33 | super(messageHandler);
34 | }
35 |
36 | /**
37 | * Specify a {@link MessageChannel} (optional) which is used internally
38 | * in the {@link ScatterGatherHandler} for gathering (aggregate) results for scattered requests.
39 | * @param gatherChannel the {@link MessageChannel} for gathering results.
40 | * @return the current {@link ScatterGatherSpec} instance.
41 | */
42 | public ScatterGatherSpec gatherChannel(MessageChannel gatherChannel) {
43 | this.handler.setGatherChannel(gatherChannel);
44 | return this;
45 | }
46 |
47 | /**
48 | * Specify a timeout (in milliseconds) for the
49 | * {@link org.springframework.messaging.PollableChannel#receive(long)} operation
50 | * to wait for gathering results to output.
51 | * Defaults to {@code -1} - to wait indefinitely.
52 | * @param gatherTimeout the {@link org.springframework.messaging.PollableChannel} receive timeout.
53 | * @return the current {@link ScatterGatherSpec} instance.
54 | */
55 | public ScatterGatherSpec gatherTimeout(long gatherTimeout) {
56 | this.handler.setGatherTimeout(gatherTimeout);
57 | return this;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/mail/ImapMailInboundChannelAdapterSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.mail;
18 |
19 | import org.springframework.integration.mail.ImapMailReceiver;
20 | import org.springframework.integration.mail.SearchTermStrategy;
21 |
22 | /**
23 | * A {@link MailInboundChannelAdapterSpec} for IMAP.
24 | *
25 | * @author Gary Russell
26 | * @author Artem Bilan
27 | */
28 | public class ImapMailInboundChannelAdapterSpec
29 | extends MailInboundChannelAdapterSpec {
30 |
31 | ImapMailInboundChannelAdapterSpec() {
32 | super(new ImapMailReceiver());
33 | }
34 |
35 | ImapMailInboundChannelAdapterSpec(ImapMailReceiver imapMailReceiver) {
36 | super(imapMailReceiver, true);
37 | }
38 |
39 | ImapMailInboundChannelAdapterSpec(String url) {
40 | super(new ImapMailReceiver(url), false);
41 | }
42 |
43 | /**
44 | * A {@link SearchTermStrategy} to use.
45 | * @param searchTermStrategy the searchTermStrategy.
46 | * @return the spec.
47 | * @see ImapMailReceiver#setSearchTermStrategy(SearchTermStrategy)
48 | */
49 | public ImapMailInboundChannelAdapterSpec searchTermStrategy(SearchTermStrategy searchTermStrategy) {
50 | assertReceiver();
51 | this.receiver.setSearchTermStrategy(searchTermStrategy);
52 | return this;
53 | }
54 |
55 | /**
56 | * A flag to determine if message should be marked as read.
57 | * @param shouldMarkMessagesAsRead the shouldMarkMessagesAsRead.
58 | * @return the spec.
59 | * @see ImapMailReceiver#setShouldMarkMessagesAsRead(Boolean)
60 | */
61 | public ImapMailInboundChannelAdapterSpec shouldMarkMessagesAsRead(boolean shouldMarkMessagesAsRead) {
62 | assertReceiver();
63 | this.receiver.setShouldMarkMessagesAsRead(shouldMarkMessagesAsRead);
64 | return this;
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/feed/FeedEntryMessageSourceSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.feed;
18 |
19 | import java.net.URL;
20 |
21 | import org.springframework.integration.dsl.core.MessageSourceSpec;
22 | import org.springframework.integration.feed.inbound.FeedEntryMessageSource;
23 | import org.springframework.integration.metadata.MetadataStore;
24 |
25 | /**
26 | * A {@link MessageSourceSpec} for a {@link FeedEntryMessageSource}.
27 | * @author Artem Bilan
28 | * @since 1.1
29 | */
30 | @SuppressWarnings("deprecation")
31 | public class FeedEntryMessageSourceSpec extends MessageSourceSpec {
32 |
33 | private final URL feedUrl;
34 |
35 | private final String metadataKey;
36 |
37 | private com.rometools.fetcher.FeedFetcher feedFetcher;
38 |
39 | private MetadataStore metadataStore;
40 |
41 | FeedEntryMessageSourceSpec(URL feedUrl, String metadataKey) {
42 | this.feedUrl = feedUrl;
43 | this.metadataKey = metadataKey;
44 | }
45 |
46 | public FeedEntryMessageSourceSpec feedFetcher(com.rometools.fetcher.FeedFetcher feedFetcher) {
47 | this.feedFetcher = feedFetcher;
48 | return this;
49 | }
50 |
51 | public FeedEntryMessageSourceSpec metadataStore(MetadataStore metadataStore) {
52 | this.metadataStore = metadataStore;
53 | return this;
54 | }
55 |
56 | @Override
57 | protected FeedEntryMessageSource doGet() {
58 | FeedEntryMessageSource feedEntryMessageSource;
59 | if (this.feedFetcher == null) {
60 | feedEntryMessageSource = new FeedEntryMessageSource(this.feedUrl, this.metadataKey);
61 | }
62 | else {
63 | feedEntryMessageSource = new FeedEntryMessageSource(this.feedUrl, this.metadataKey, this.feedFetcher);
64 | }
65 | if (this.metadataStore != null) {
66 | feedEntryMessageSource.setMetadataStore(this.metadataStore);
67 | }
68 | return feedEntryMessageSource;
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/support/tuple/Tuple2.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.support.tuple;
18 |
19 | /**
20 | * A tuple that holds two values.
21 | *
22 | * @param The type of the first value held by this tuple
23 | * @param The type of the second value held by this tuple
24 | *
25 | * @author Jon Brisbin
26 | * @author Artem Bilan
27 | */
28 | public class Tuple2 extends Tuple1 {
29 |
30 | private static final long serialVersionUID = -565933838909569191L;
31 |
32 | protected final T2 t2;
33 |
34 | Tuple2(int size, T1 t1, T2 t2) {
35 | super(2, t1);
36 | this.t2 = t2;
37 | }
38 |
39 | /**
40 | * Type-safe way to get the second object of this {@link Tuple}.
41 | * @return The second object, cast to the correct type.
42 | */
43 | public T2 getT2() {
44 | return this.t2;
45 | }
46 |
47 | @Override
48 | public Object get(int index) {
49 | switch (index) {
50 | case 0:
51 | return this.t1;
52 | case 1:
53 | return this.t2;
54 | default:
55 | return null;
56 | }
57 | }
58 |
59 | @Override
60 | public Object[] toArray() {
61 | return new Object[]{this.t1, this.t2};
62 | }
63 |
64 | @Override
65 | public boolean equals(Object o) {
66 | if (this == o) {
67 | return true;
68 | }
69 | if (o == null || getClass() != o.getClass()) {
70 | return false;
71 | }
72 | if (!super.equals(o)) {
73 | return false;
74 | }
75 |
76 | Tuple2, ?> tuple2 = (Tuple2, ?>) o;
77 |
78 | return this.t2 != null ? this.t2.equals(tuple2.t2) : tuple2.t2 == null;
79 |
80 | }
81 |
82 | @Override
83 | public int hashCode() {
84 | int result = super.hashCode();
85 | result = 31 * result + (this.t2 != null ? this.t2.hashCode() : 0);
86 | return result;
87 | }
88 |
89 | @Override
90 | public String toString() {
91 | return super.toString() +
92 | (this.t2 != null ? "," + this.t2.toString() : "");
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/src/test/java/org/springframework/integration/dsl/samples/file2file1/FileChangeLineSeparator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.samples.file2file1;
18 |
19 | import java.io.File;
20 |
21 | import org.springframework.boot.autoconfigure.SpringBootApplication;
22 | import org.springframework.boot.builder.SpringApplicationBuilder;
23 | import org.springframework.context.ConfigurableApplicationContext;
24 | import org.springframework.context.annotation.Bean;
25 | import org.springframework.integration.dsl.IntegrationFlow;
26 | import org.springframework.integration.dsl.IntegrationFlows;
27 | import org.springframework.integration.dsl.core.Pollers;
28 | import org.springframework.integration.dsl.file.Files;
29 | import org.springframework.integration.dsl.support.Transformers;
30 |
31 | /**
32 | * Simple file to file, converting CRLF to LF.
33 | *
34 | * @author Gary Russell
35 | * @since 1.1
36 | *
37 | */
38 | @SpringBootApplication
39 | public class FileChangeLineSeparator {
40 |
41 | public static void main(String[] args) throws Exception {
42 | ConfigurableApplicationContext context = new SpringApplicationBuilder(FileChangeLineSeparator.class)
43 | .web(false)
44 | .run(args);
45 | System.out.println("Put a windows file with a .txt extension in /tmp/in,"
46 | + "\nthe file will be converted to Un*x and placed in"
47 | + "\n/tmp/out"
48 | + "\n\nHit enter to terminate");
49 | System.in.read();
50 | context.close();
51 | }
52 |
53 | @Bean
54 | public IntegrationFlow fileToFile() {
55 | return IntegrationFlows.from(Files.inboundAdapter(new File("/tmp/in"))
56 | .autoCreateDirectory(true)
57 | .patternFilter("*.txt"),
58 | e -> e.poller(Pollers.fixedDelay(5000)))
59 | .transform(Transformers.fileToString())
60 | .transform("payload.replaceAll('\r\n', '\n')")
61 | .handle(Files.outboundAdapter("'/tmp/out'")
62 | .autoCreateDirectory(true))
63 | .get();
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/ftp/FtpInboundChannelAdapterSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.ftp;
18 |
19 | import java.io.File;
20 | import java.util.Comparator;
21 |
22 | import org.apache.commons.net.ftp.FTPFile;
23 |
24 | import org.springframework.integration.dsl.file.RemoteFileInboundChannelAdapterSpec;
25 | import org.springframework.integration.file.remote.session.SessionFactory;
26 | import org.springframework.integration.ftp.filters.FtpRegexPatternFileListFilter;
27 | import org.springframework.integration.ftp.filters.FtpSimplePatternFileListFilter;
28 | import org.springframework.integration.ftp.inbound.FtpInboundFileSynchronizer;
29 | import org.springframework.integration.ftp.inbound.FtpInboundFileSynchronizingMessageSource;
30 |
31 | /**
32 | * A {@link RemoteFileInboundChannelAdapterSpec} for a {@link FtpInboundFileSynchronizingMessageSource}.
33 | *
34 | * @author Artem Bilan
35 | */
36 | public class FtpInboundChannelAdapterSpec
37 | extends RemoteFileInboundChannelAdapterSpec {
39 |
40 | FtpInboundChannelAdapterSpec(SessionFactory sessionFactory, Comparator comparator) {
41 | super(new FtpInboundFileSynchronizer(sessionFactory));
42 | this.target = new FtpInboundFileSynchronizingMessageSource(this.synchronizer, comparator);
43 | }
44 |
45 | /**
46 | * @see FtpSimplePatternFileListFilter
47 | * @see #filter(org.springframework.integration.file.filters.FileListFilter)
48 | */
49 | @Override
50 | public FtpInboundChannelAdapterSpec patternFilter(String pattern) {
51 | return filter(new FtpSimplePatternFileListFilter(pattern));
52 | }
53 |
54 | /**
55 | * @see FtpRegexPatternFileListFilter
56 | * @see #filter(org.springframework.integration.file.filters.FileListFilter)
57 | */
58 | @Override
59 | public FtpInboundChannelAdapterSpec regexFilter(String regex) {
60 | return filter(new FtpRegexPatternFileListFilter(regex));
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/core/PollerFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.core;
18 |
19 | import java.util.TimeZone;
20 | import java.util.concurrent.TimeUnit;
21 |
22 | import org.springframework.scheduling.Trigger;
23 |
24 | /**
25 | * An {@code Adapter} class for the {@link Pollers} factory.
26 | * Typically used with a Java 8 Lambda expression:
27 | *
28 | * {@code
29 | * c -> c.poller(p -> p.fixedRate(100))
30 | * }
31 | *
32 | *
33 | * @author Artem Bilan
34 | */
35 | public class PollerFactory {
36 |
37 | public PollerSpec trigger(Trigger trigger) {
38 | return Pollers.trigger(trigger);
39 | }
40 |
41 | public PollerSpec cron(String cronExpression) {
42 | return Pollers.cron(cronExpression);
43 | }
44 |
45 | public PollerSpec cron(String cronExpression, TimeZone timeZone) {
46 | return Pollers.cron(cronExpression, timeZone);
47 | }
48 |
49 | public PollerSpec fixedRate(long period) {
50 | return Pollers.fixedRate(period);
51 | }
52 |
53 | public PollerSpec fixedRate(long period, TimeUnit timeUnit) {
54 | return Pollers.fixedRate(period, timeUnit);
55 | }
56 |
57 | public PollerSpec fixedRate(long period, long initialDelay) {
58 | return Pollers.fixedRate(period, initialDelay);
59 | }
60 |
61 | public PollerSpec fixedDelay(long period, TimeUnit timeUnit, long initialDelay) {
62 | return Pollers.fixedDelay(period, timeUnit, initialDelay);
63 | }
64 |
65 | public PollerSpec fixedRate(long period, TimeUnit timeUnit, long initialDelay) {
66 | return Pollers.fixedRate(period, timeUnit, initialDelay);
67 | }
68 |
69 | public PollerSpec fixedDelay(long period, TimeUnit timeUnit) {
70 | return Pollers.fixedDelay(period, timeUnit);
71 | }
72 |
73 | public PollerSpec fixedDelay(long period, long initialDelay) {
74 | return Pollers.fixedDelay(period, initialDelay);
75 | }
76 |
77 | public PollerSpec fixedDelay(long period) {
78 | return Pollers.fixedDelay(period);
79 | }
80 |
81 | PollerFactory() {
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/SplitterEndpointSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl;
18 |
19 | import org.springframework.integration.dsl.core.ConsumerEndpointSpec;
20 | import org.springframework.integration.splitter.AbstractMessageSplitter;
21 | import org.springframework.integration.splitter.DefaultMessageSplitter;
22 |
23 | /**
24 | * A {@link ConsumerEndpointSpec} for a {@link AbstractMessageSplitter} implementations.
25 | *
26 | * @param the target {@link SplitterEndpointSpec} implementation type.
27 | *
28 | * @author Artem Bilan
29 | */
30 | public final class SplitterEndpointSpec
31 | extends ConsumerEndpointSpec, S> {
32 |
33 | SplitterEndpointSpec(S splitter) {
34 | super(splitter);
35 | }
36 |
37 | /**
38 | * Set the applySequence flag to the specified value. Defaults to {@code true}.
39 | * @param applySequence the applySequence.
40 | * @return the endpoint spec.
41 | * @see AbstractMessageSplitter#setApplySequence(boolean)
42 | */
43 | public SplitterEndpointSpec applySequence(boolean applySequence) {
44 | this.handler.setApplySequence(applySequence);
45 | return _this();
46 | }
47 |
48 | /**
49 | * Set delimiters to tokenize String values. The default is
50 | * null indicating that no tokenizing should occur.
51 | * If delimiters are provided, they will be applied to any String payload.
52 | * Only applied if provided {@code splitter} is instance of {@link DefaultMessageSplitter}.
53 | * @param delimiters The delimiters.
54 | * @return the endpoint spec.
55 | * @since 1.2
56 | * @see DefaultMessageSplitter#setDelimiters(String)
57 | */
58 | public SplitterEndpointSpec delimiters(String delimiters) {
59 | if (this.handler instanceof DefaultMessageSplitter) {
60 | ((DefaultMessageSplitter) this.handler).setDelimiters(delimiters);
61 | }
62 | else {
63 | logger.warn("'delimiters' can be applied only for the DefaultMessageSplitter");
64 | }
65 | return this;
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/core/IntegrationComponentSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.core;
18 |
19 | import org.apache.commons.logging.Log;
20 | import org.apache.commons.logging.LogFactory;
21 |
22 | import org.springframework.beans.factory.FactoryBean;
23 | import org.springframework.expression.spel.standard.SpelExpressionParser;
24 |
25 | /**
26 | * The common Builder abstraction. The {@link #get()} method returns the final component.
27 | *
28 | * @param the target {@link IntegrationComponentSpec} implementation type.
29 | * @param the target type.
30 | *
31 | * @author Artem Bilan
32 | */
33 | public abstract class IntegrationComponentSpec, T>
34 | implements FactoryBean {
35 |
36 | protected final static SpelExpressionParser PARSER = new SpelExpressionParser();
37 |
38 | protected final Log logger = LogFactory.getLog(getClass());
39 |
40 | protected volatile T target;
41 |
42 | private String id;
43 |
44 | /**
45 | * Configure the component identifier. Used as the {@code beanName} to register the
46 | * bean in the application context for this component.
47 | * @param id the id.
48 | * @return the spec.
49 | */
50 | protected S id(String id) {
51 | this.id = id;
52 | return _this();
53 | }
54 |
55 | public final String getId() {
56 | return this.id;
57 | }
58 |
59 | /**
60 | * @return the configured component.
61 | */
62 | public final T get() {
63 | if (this.target == null) {
64 | this.target = doGet();
65 | }
66 | return this.target;
67 | }
68 |
69 | @Override
70 | public T getObject() throws Exception {
71 | return get();
72 | }
73 |
74 | @Override
75 | public Class> getObjectType() {
76 | return get().getClass();
77 | }
78 |
79 | @Override
80 | public boolean isSingleton() {
81 | return true;
82 | }
83 |
84 | @SuppressWarnings("unchecked")
85 | protected final S _this() {
86 | return (S) this;
87 | }
88 |
89 | protected T doGet() {
90 | throw new UnsupportedOperationException();
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/sftp/SftpInboundChannelAdapterSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.sftp;
18 |
19 | import java.io.File;
20 | import java.util.Comparator;
21 |
22 | import org.springframework.integration.dsl.file.RemoteFileInboundChannelAdapterSpec;
23 | import org.springframework.integration.file.remote.session.SessionFactory;
24 | import org.springframework.integration.sftp.filters.SftpRegexPatternFileListFilter;
25 | import org.springframework.integration.sftp.filters.SftpSimplePatternFileListFilter;
26 | import org.springframework.integration.sftp.inbound.SftpInboundFileSynchronizer;
27 | import org.springframework.integration.sftp.inbound.SftpInboundFileSynchronizingMessageSource;
28 |
29 | import com.jcraft.jsch.ChannelSftp;
30 |
31 | /**
32 | * A {@link RemoteFileInboundChannelAdapterSpec} for a {@link SftpInboundFileSynchronizingMessageSource}.
33 | *
34 | * @author Artem Bilan
35 | */
36 | public class SftpInboundChannelAdapterSpec
37 | extends RemoteFileInboundChannelAdapterSpec {
39 |
40 | SftpInboundChannelAdapterSpec(SessionFactory sessionFactory, Comparator comparator) {
41 | super(new SftpInboundFileSynchronizer(sessionFactory));
42 | this.target = new SftpInboundFileSynchronizingMessageSource(this.synchronizer, comparator);
43 | }
44 |
45 | /**
46 | * @param pattern the Ant style pattern filter to use.
47 | * @see SftpSimplePatternFileListFilter
48 | * @see #filter(org.springframework.integration.file.filters.FileListFilter)
49 | */
50 | @Override
51 | public SftpInboundChannelAdapterSpec patternFilter(String pattern) {
52 | return filter(new SftpSimplePatternFileListFilter(pattern));
53 | }
54 |
55 | /**
56 | * @param regex the RegExp pattern to use.
57 | * @see SftpRegexPatternFileListFilter
58 | * @see #filter(org.springframework.integration.file.filters.FileListFilter)
59 | */
60 | @Override
61 | public SftpInboundChannelAdapterSpec regexFilter(String regex) {
62 | return filter(new SftpRegexPatternFileListFilter(regex));
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/src/test/java/org/springframework/integration/dsl/samples/file2file2/FileChangeLineSeparator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.samples.file2file2;
18 |
19 | import java.io.File;
20 |
21 | import org.springframework.boot.autoconfigure.SpringBootApplication;
22 | import org.springframework.boot.builder.SpringApplicationBuilder;
23 | import org.springframework.context.ConfigurableApplicationContext;
24 | import org.springframework.context.annotation.Bean;
25 | import org.springframework.integration.dsl.IntegrationFlow;
26 | import org.springframework.integration.dsl.IntegrationFlows;
27 | import org.springframework.integration.dsl.core.Pollers;
28 | import org.springframework.integration.dsl.file.Files;
29 | import org.springframework.integration.dsl.support.Transformers;
30 | import org.springframework.integration.handler.LoggingHandler;
31 |
32 | /**
33 | * Simple file to file, converting CRLF to LF, with logging
34 | *
35 | * @author Gary Russell
36 | * @author Artem Bilan
37 | * @since 1.1
38 | *
39 | */
40 | @SpringBootApplication
41 | public class FileChangeLineSeparator {
42 |
43 | public static void main(String[] args) throws Exception {
44 | ConfigurableApplicationContext context = new SpringApplicationBuilder(FileChangeLineSeparator.class)
45 | .web(false)
46 | .run(args);
47 | System.out.println("Put a windows file with a .txt extension in /tmp/in,"
48 | + "\nthe file will be converted to Un*x and placed in"
49 | + "\n/tmp/out"
50 | + "\n\nHit enter to terminate");
51 | System.in.read();
52 | context.close();
53 | }
54 |
55 | @Bean
56 | public IntegrationFlow fileToFile() {
57 | return IntegrationFlows.from(Files.inboundAdapter(new File("/tmp/in"))
58 | .autoCreateDirectory(true)
59 | .patternFilter("*.txt"),
60 | e -> e.poller(Pollers.fixedDelay(5000)))
61 | .transform(Transformers.fileToString())
62 | .transform("payload.replaceAll('\r\n', '\n')")
63 | .publishSubscribeChannel(c -> c
64 | .subscribe(s -> s.handle(Files.outboundAdapter("'/tmp/out'")
65 | .autoCreateDirectory(true)))
66 | .subscribe(s -> s.log(LoggingHandler.Level.WARN, null,
67 | "headers['file_originalFile'].absolutePath + ' transferred'")))
68 | .get();
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/support/tuple/Tuple.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.support.tuple;
18 |
19 | import java.io.Serializable;
20 | import java.util.Arrays;
21 | import java.util.Iterator;
22 | import java.util.List;
23 |
24 | /**
25 | * A {@literal Tuple} is an immutable {@link java.util.Collection} of objects,
26 | * each of which can be of an arbitrary type.
27 | *
28 | * @author Jon Brisbin
29 | * @author Stephane Maldini
30 | * @author Artem Bilan
31 | */
32 | public class Tuple implements Iterable, Serializable {
33 |
34 | private static final long serialVersionUID = 8777121214502020842L;
35 |
36 | private static final Object[] emptyArray = new Object[0];
37 | protected static final Tuple empty = new Tuple(0);
38 |
39 |
40 | protected final int size;
41 |
42 | /**
43 | * Creates a new {@code Tuple} that holds the given {@code values}.
44 | * @param size The number of values to hold
45 | */
46 | protected Tuple(int size) {
47 | this.size = size;
48 | }
49 |
50 |
51 | public Object get(int index) {
52 | return null;
53 | }
54 |
55 | /**
56 | * Turn this {@literal Tuple} into a plain Object array.
57 | * @return A new Object array.
58 | */
59 | public Object[] toArray() {
60 | return emptyArray;
61 | }
62 |
63 | /**
64 | * Turn this {@literal Tuple} into a plain Object list.
65 | * @return A new Object list.
66 | */
67 | public List toList() {
68 | return Arrays.asList(toArray());
69 | }
70 |
71 | /**
72 | * Return the number of elements in this {@literal Tuple}.
73 | * @return The size of this {@literal Tuple}.
74 | */
75 | public int size() {
76 | return this.size;
77 | }
78 |
79 | @Override
80 | public Iterator iterator() {
81 | return toList().iterator();
82 | }
83 |
84 | @Override
85 | public boolean equals(Object o) {
86 | if (this == o) {
87 | return true;
88 | }
89 | if (o == null || getClass() != o.getClass()) {
90 | return false;
91 | }
92 |
93 | Tuple tuple = (Tuple) o;
94 |
95 | return this.size == tuple.size;
96 |
97 | }
98 |
99 | @Override
100 | public int hashCode() {
101 | return this.size;
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/src/test/java/org/springframework/integration/dsl/test/handlers/MessageHandlerTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.test.handlers;
18 |
19 | import static org.hamcrest.Matchers.containsString;
20 | import static org.hamcrest.Matchers.instanceOf;
21 | import static org.junit.Assert.assertThat;
22 | import static org.junit.Assert.fail;
23 |
24 | import org.junit.Test;
25 |
26 | import org.springframework.beans.factory.BeanCreationException;
27 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
28 | import org.springframework.context.annotation.Bean;
29 | import org.springframework.context.annotation.Configuration;
30 | import org.springframework.integration.config.EnableIntegration;
31 | import org.springframework.integration.dsl.IntegrationFlow;
32 | import org.springframework.integration.dsl.IntegrationFlows;
33 | import org.springframework.integration.handler.AbstractMessageProducingHandler;
34 | import org.springframework.messaging.Message;
35 | import org.springframework.messaging.MessageHandler;
36 |
37 | /**
38 | * @author Artem Bilan
39 | * @since 1.2
40 | */
41 | public class MessageHandlerTests {
42 |
43 | @Test
44 | public void testWrongReuseOfAbstractMessageProducingHandler() {
45 | try {
46 | new AnnotationConfigApplicationContext(InvalidReuseOfAbstractMessageProducingHandlerContext.class).close();
47 | fail("BeanCreationException expected");
48 | }
49 | catch (Exception e) {
50 | assertThat(e, instanceOf(BeanCreationException.class));
51 | assertThat(e.getMessage(),
52 | containsString("An AbstractMessageProducingHandler may only be referenced once"));
53 | }
54 | }
55 |
56 | @Configuration
57 | @EnableIntegration
58 | public static class InvalidReuseOfAbstractMessageProducingHandlerContext {
59 |
60 | @Bean
61 | public IntegrationFlow wrongReuseOfAbstractMessageProducingHandler() {
62 | return IntegrationFlows.from("foo")
63 | .handle(testHandler())
64 | .handle(testHandler())
65 | .log()
66 | .get();
67 | }
68 |
69 | @Bean
70 | public MessageHandler testHandler() {
71 | return new AbstractMessageProducingHandler() {
72 |
73 | @Override
74 | protected void handleMessageInternal(Message> message) throws Exception {
75 |
76 | }
77 |
78 | };
79 | }
80 |
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/mail/MailSendingMessageHandlerSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.mail;
18 |
19 | import java.util.Properties;
20 |
21 | import javax.activation.FileTypeMap;
22 |
23 | import org.springframework.integration.dsl.core.MessageHandlerSpec;
24 | import org.springframework.integration.dsl.support.Consumer;
25 | import org.springframework.integration.dsl.support.PropertiesBuilder;
26 | import org.springframework.integration.mail.MailSendingMessageHandler;
27 | import org.springframework.mail.javamail.JavaMailSenderImpl;
28 |
29 | /**
30 | * @author Gary Russell
31 | * @author Artem Bilan
32 | */
33 | public class MailSendingMessageHandlerSpec
34 | extends MessageHandlerSpec {
35 |
36 | private final JavaMailSenderImpl sender = new JavaMailSenderImpl();
37 |
38 | MailSendingMessageHandlerSpec(String host) {
39 | this.sender.setHost(host);
40 | this.target = new MailSendingMessageHandler(this.sender);
41 | }
42 |
43 | public MailSendingMessageHandlerSpec javaMailProperties(Properties javaMailProperties) {
44 | this.sender.setJavaMailProperties(javaMailProperties);
45 | return this;
46 | }
47 |
48 | public MailSendingMessageHandlerSpec javaMailProperties(Consumer propertiesConfigurer) {
49 | PropertiesBuilder properties = new PropertiesBuilder();
50 | propertiesConfigurer.accept(properties);
51 | return javaMailProperties(properties.get());
52 | }
53 |
54 | public MailSendingMessageHandlerSpec protocol(String protocol) {
55 | this.sender.setProtocol(protocol);
56 | return this;
57 | }
58 |
59 | public MailSendingMessageHandlerSpec port(int port) {
60 | this.sender.setPort(port);
61 | return this;
62 | }
63 |
64 | public MailSendingMessageHandlerSpec credentials(String username, String password) {
65 | this.sender.setUsername(username);
66 | this.sender.setPassword(password);
67 | return this;
68 | }
69 |
70 | public MailSendingMessageHandlerSpec defaultEncoding(String defaultEncoding) {
71 | this.sender.setDefaultEncoding(defaultEncoding);
72 | return this;
73 | }
74 |
75 | public MailSendingMessageHandlerSpec defaultFileTypeMap(FileTypeMap defaultFileTypeMap) {
76 | this.sender.setDefaultFileTypeMap(defaultFileTypeMap);
77 | return this;
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/DelayerEndpointSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl;
18 |
19 | import java.util.Arrays;
20 | import java.util.LinkedList;
21 | import java.util.List;
22 |
23 | import org.aopalliance.aop.Advice;
24 |
25 | import org.springframework.integration.dsl.core.ConsumerEndpointSpec;
26 | import org.springframework.integration.handler.DelayHandler;
27 | import org.springframework.integration.store.MessageGroupStore;
28 | import org.springframework.util.Assert;
29 |
30 | /**
31 | * A {@link ConsumerEndpointSpec} for a {@link DelayHandler}.
32 | *
33 | * @author Artem Bilan
34 | */
35 | public final class DelayerEndpointSpec extends ConsumerEndpointSpec {
36 |
37 | private final List delayedAdvice = new LinkedList();
38 |
39 | DelayerEndpointSpec(DelayHandler delayHandler) {
40 | super(delayHandler);
41 | Assert.notNull(delayHandler, "'delayHandler' must not be null.");
42 | this.handler.setDelayedAdviceChain(this.delayedAdvice);
43 | }
44 |
45 | /**
46 | * @param defaultDelay the defaultDelay.
47 | * @return the endpoint spec.
48 | * @see DelayHandler#setDefaultDelay(long)
49 | */
50 | public DelayerEndpointSpec defaultDelay(long defaultDelay) {
51 | this.handler.setDefaultDelay(defaultDelay);
52 | return _this();
53 | }
54 |
55 | /**
56 | * @param ignoreExpressionFailures the ignoreExpressionFailures.
57 | * @return the endpoint spec.
58 | * @see DelayHandler#setIgnoreExpressionFailures(boolean)
59 | */
60 | public DelayerEndpointSpec ignoreExpressionFailures(boolean ignoreExpressionFailures) {
61 | this.handler.setIgnoreExpressionFailures(ignoreExpressionFailures);
62 | return _this();
63 | }
64 |
65 | /**
66 | * @param messageStore the message store.
67 | * @return the endpoint spec.
68 | */
69 | public DelayerEndpointSpec messageStore(MessageGroupStore messageStore) {
70 | this.handler.setMessageStore(messageStore);
71 | return _this();
72 | }
73 |
74 | /**
75 | * Configure a list of {@link Advice} objects that will be applied, in nested order,
76 | * when delayed messages are sent.
77 | * @param advice the advice chain.
78 | * @return the endpoint spec.
79 | */
80 | public DelayerEndpointSpec delayedAdvice(Advice... advice) {
81 | this.delayedAdvice.addAll(Arrays.asList(advice));
82 | return _this();
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/amqp/AmqpBaseInboundChannelAdapterSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.amqp;
18 |
19 | import org.springframework.amqp.support.converter.MessageConverter;
20 | import org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter;
21 | import org.springframework.integration.amqp.support.AmqpHeaderMapper;
22 | import org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper;
23 | import org.springframework.integration.dsl.core.MessageProducerSpec;
24 |
25 | /**
26 | * The base {@link MessageProducerSpec} implementation for a {@link AmqpInboundChannelAdapter}.
27 | *
28 | * @param the target {@link AmqpBaseInboundChannelAdapterSpec} implementation type.
29 | *
30 | * @author Artem Bilan
31 | */
32 | public class AmqpBaseInboundChannelAdapterSpec>
33 | extends MessageProducerSpec {
34 |
35 | private final DefaultAmqpHeaderMapper headerMapper = DefaultAmqpHeaderMapper.inboundMapper();
36 |
37 | AmqpBaseInboundChannelAdapterSpec(AmqpInboundChannelAdapter producer) {
38 | super(producer);
39 | this.target.setHeaderMapper(this.headerMapper);
40 | }
41 |
42 | /**
43 | * Configure the adapter's {@link MessageConverter};
44 | * defaults to {@link org.springframework.amqp.support.converter.SimpleMessageConverter}.
45 | * @param messageConverter the messageConverter.
46 | * @return the spec.
47 | * @see AmqpInboundChannelAdapter#setMessageConverter
48 | */
49 | public S messageConverter(MessageConverter messageConverter) {
50 | this.target.setMessageConverter(messageConverter);
51 | return _this();
52 | }
53 |
54 | /**
55 | * Configure the adapter's {@link AmqpHeaderMapper};
56 | * defaults to {@link DefaultAmqpHeaderMapper}.
57 | * @param headerMapper the headerMapper.
58 | * @return the spec.
59 | */
60 | public S headerMapper(AmqpHeaderMapper headerMapper) {
61 | this.target.setHeaderMapper(headerMapper);
62 | return _this();
63 | }
64 |
65 | /**
66 | * Only applies if the default header mapper is used.
67 | * @param headers the headers.
68 | * @return the spec.
69 | * @see DefaultAmqpHeaderMapper#setRequestHeaderNames(String[])
70 | */
71 | public S mappedRequestHeaders(String... headers) {
72 | this.headerMapper.setRequestHeaderNames(headers);
73 | return _this();
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/config/DslIntegrationConfigurationInitializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.config;
18 |
19 | import java.beans.Introspector;
20 |
21 | import org.springframework.beans.BeansException;
22 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
23 | import org.springframework.beans.factory.support.BeanDefinitionRegistry;
24 | import org.springframework.beans.factory.support.RootBeanDefinition;
25 | import org.springframework.integration.config.IntegrationConfigurationInitializer;
26 | import org.springframework.integration.dsl.context.IntegrationFlowContext;
27 | import org.springframework.integration.dsl.core.IntegrationComponentSpec;
28 | import org.springframework.util.Assert;
29 |
30 | /**
31 | * The Java DSL Integration infrastructure {@code beanFactory} initializer.
32 | * Registers {@link IntegrationFlowBeanPostProcessor} and checks if all
33 | * {@link IntegrationComponentSpec} are extracted to the target object using
34 | * {@link IntegrationComponentSpec#get()}.
35 | *
36 | * @author Artem Bilan
37 | *
38 | * @see org.springframework.integration.config.IntegrationConfigurationBeanFactoryPostProcessor
39 | */
40 | public class DslIntegrationConfigurationInitializer implements IntegrationConfigurationInitializer {
41 |
42 | private static final String INTEGRATION_FLOW_BPP_BEAN_NAME =
43 | Introspector.decapitalize(IntegrationFlowBeanPostProcessor.class.getName());
44 |
45 | private static final String INTEGRATION_FLOW_CONTEXT_BEAN_NAME =
46 | Introspector.decapitalize(IntegrationFlowContext.class.getName());
47 |
48 | @Override
49 | public void initialize(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
50 | Assert.isInstanceOf(BeanDefinitionRegistry.class, configurableListableBeanFactory,
51 | "To use Spring Integration Java DSL the 'beanFactory' has to be an instance of " +
52 | "'BeanDefinitionRegistry'. Consider using 'GenericApplicationContext' implementation."
53 | );
54 |
55 | BeanDefinitionRegistry registry = (BeanDefinitionRegistry) configurableListableBeanFactory;
56 | if (!registry.containsBeanDefinition(INTEGRATION_FLOW_BPP_BEAN_NAME)) {
57 | registry.registerBeanDefinition(INTEGRATION_FLOW_BPP_BEAN_NAME,
58 | new RootBeanDefinition(IntegrationFlowBeanPostProcessor.class));
59 | registry.registerBeanDefinition(INTEGRATION_FLOW_CONTEXT_BEAN_NAME,
60 | new RootBeanDefinition(IntegrationFlowContext.class));
61 | }
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/core/Pollers.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.core;
18 |
19 | import java.util.TimeZone;
20 | import java.util.concurrent.TimeUnit;
21 |
22 | import org.springframework.scheduling.Trigger;
23 | import org.springframework.scheduling.support.CronTrigger;
24 | import org.springframework.scheduling.support.PeriodicTrigger;
25 |
26 | /**
27 | * An utility class to provide {@link PollerSpec}s for
28 | * {@link org.springframework.integration.scheduling.PollerMetadata} configuration
29 | * variants.
30 | *
31 | * @author Artem Bilan
32 | */
33 | public final class Pollers {
34 |
35 | public static PollerSpec trigger(Trigger trigger) {
36 | return new PollerSpec(trigger);
37 | }
38 |
39 | public static PollerSpec fixedRate(long period) {
40 | return fixedRate(period, null);
41 | }
42 |
43 | public static PollerSpec fixedRate(long period, TimeUnit timeUnit) {
44 | return fixedRate(period, timeUnit, 0);
45 | }
46 | public static PollerSpec fixedRate(long period, long initialDelay) {
47 | return periodicTrigger(period, null, true, initialDelay);
48 | }
49 |
50 | public static PollerSpec fixedRate(long period, TimeUnit timeUnit, long initialDelay) {
51 | return periodicTrigger(period, timeUnit, true, initialDelay);
52 | }
53 |
54 | public static PollerSpec fixedDelay(long period) {
55 | return fixedDelay(period, null);
56 | }
57 |
58 | public static PollerSpec fixedDelay(long period, TimeUnit timeUnit) {
59 | return fixedDelay(period, timeUnit, 0);
60 | }
61 |
62 | public static PollerSpec fixedDelay(long period, long initialDelay) {
63 | return periodicTrigger(period, null, false, initialDelay);
64 | }
65 |
66 | public static PollerSpec fixedDelay(long period, TimeUnit timeUnit, long initialDelay) {
67 | return periodicTrigger(period, timeUnit, false, initialDelay);
68 | }
69 |
70 | private static PollerSpec periodicTrigger(long period, TimeUnit timeUnit, boolean fixedRate, long initialDelay) {
71 | PeriodicTrigger periodicTrigger = new PeriodicTrigger(period, timeUnit);
72 | periodicTrigger.setFixedRate(fixedRate);
73 | periodicTrigger.setInitialDelay(initialDelay);
74 | return new PollerSpec(periodicTrigger);
75 | }
76 |
77 | public static PollerSpec cron(String cronExpression) {
78 | return cron(cronExpression, TimeZone.getDefault());
79 | }
80 |
81 | public static PollerSpec cron(String cronExpression, TimeZone timeZone) {
82 | return new PollerSpec(new CronTrigger(cronExpression, timeZone));
83 | }
84 |
85 | private Pollers() {
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/jms/JmsTemplateSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.jms;
18 |
19 | import org.springframework.integration.jms.DynamicJmsTemplate;
20 | import org.springframework.jms.support.converter.MessageConverter;
21 |
22 | /**
23 | * A {@link JmsDestinationAccessorSpec} for a {@link DynamicJmsTemplate}.
24 | *
25 | * @author Artem Bilan
26 | */
27 | public class JmsTemplateSpec extends JmsDestinationAccessorSpec {
28 |
29 | JmsTemplateSpec() {
30 | super(new DynamicJmsTemplate());
31 | }
32 |
33 | /**
34 | * @param messageConverter the messageConverter.
35 | * @return the spec.
36 | * @see org.springframework.jms.core.JmsTemplate#setMessageConverter(MessageConverter)
37 | */
38 | public JmsTemplateSpec jmsMessageConverter(MessageConverter messageConverter) {
39 | this.target.setMessageConverter(messageConverter);
40 | return _this();
41 | }
42 |
43 | /**
44 | * @param deliveryPersistent the deliveryPersistent.
45 | * @return the spec.
46 | * @see org.springframework.jms.core.JmsTemplate#setDeliveryPersistent(boolean)
47 | */
48 | public JmsTemplateSpec deliveryPersistent(boolean deliveryPersistent) {
49 | this.target.setDeliveryPersistent(deliveryPersistent);
50 | return _this();
51 | }
52 |
53 | /**
54 | * @param explicitQosEnabled the explicitQosEnabled.
55 | * @return the spec.
56 | * @see org.springframework.jms.core.JmsTemplate#setExplicitQosEnabled(boolean)
57 | */
58 | public JmsTemplateSpec explicitQosEnabled(boolean explicitQosEnabled) {
59 | this.target.setExplicitQosEnabled(explicitQosEnabled);
60 | return _this();
61 | }
62 |
63 | /**
64 | * May be overridden at run time by the message priority header.
65 | * @param priority the priority.
66 | * @return the spec.
67 | * @see org.springframework.jms.core.JmsTemplate#setPriority(int)
68 | */
69 | public JmsTemplateSpec priority(int priority) {
70 | this.target.setPriority(priority);
71 | return _this();
72 | }
73 |
74 | /**
75 | * @param timeToLive the timeToLive.
76 | * @return the spec.
77 | * @see org.springframework.jms.core.JmsTemplate#setTimeToLive(long)
78 | */
79 | public JmsTemplateSpec timeToLive(long timeToLive) {
80 | this.target.setTimeToLive(timeToLive);
81 | return _this();
82 | }
83 |
84 | /**
85 | * @param receiveTimeout the receiveTimeout.
86 | * @return the spec.
87 | * @see org.springframework.jms.core.JmsTemplate#setReceiveTimeout(long)
88 | */
89 | public JmsTemplateSpec receiveTimeout(long receiveTimeout) {
90 | this.target.setReceiveTimeout(receiveTimeout);
91 | return _this();
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/jms/JmsPublishSubscribeMessageChannelSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.jms;
18 |
19 | import javax.jms.ConnectionFactory;
20 |
21 | import org.springframework.jms.listener.DefaultMessageListenerContainer;
22 |
23 | /**
24 | * A {@link JmsMessageChannelSpec} for a {@link org.springframework.integration.jms.SubscribableJmsChannel}
25 | * configured with a topic.
26 | *
27 | * @author Artem Bilan
28 | */
29 | public class JmsPublishSubscribeMessageChannelSpec
30 | extends JmsMessageChannelSpec {
31 |
32 | JmsPublishSubscribeMessageChannelSpec(ConnectionFactory connectionFactory) {
33 | super(connectionFactory);
34 | this.jmsChannelFactoryBean.setPubSubDomain(true);
35 | }
36 |
37 | /**
38 | * @param durable the durable.
39 | * @return the current {@link JmsPublishSubscribeMessageChannelSpec}.
40 | * @see org.springframework.jms.listener.AbstractMessageListenerContainer#setSubscriptionDurable(boolean)
41 | */
42 | public JmsPublishSubscribeMessageChannelSpec subscriptionDurable(boolean durable) {
43 | this.jmsChannelFactoryBean.setSubscriptionDurable(durable);
44 | return _this();
45 | }
46 |
47 | /**
48 | * @param durableSubscriptionName the durableSubscriptionName.
49 | * @return the current {@link JmsPublishSubscribeMessageChannelSpec}.
50 | * @see org.springframework.jms.listener.AbstractMessageListenerContainer#setDurableSubscriptionName(String)
51 | */
52 | public JmsPublishSubscribeMessageChannelSpec durableSubscriptionName(String durableSubscriptionName) {
53 | this.jmsChannelFactoryBean.setDurableSubscriptionName(durableSubscriptionName);
54 | return _this();
55 | }
56 |
57 | /**
58 | * @param clientId the clientId.
59 | * @return the current {@link JmsPublishSubscribeMessageChannelSpec}.
60 | * @see org.springframework.jms.listener.AbstractMessageListenerContainer#setClientId(String)
61 | */
62 | public JmsPublishSubscribeMessageChannelSpec clientId(String clientId) {
63 | this.jmsChannelFactoryBean.setClientId(clientId);
64 | return _this();
65 | }
66 |
67 | /**
68 | * Only applies if the {@link #containerType(Class)} is a {@link DefaultMessageListenerContainer}
69 | * or a {@link org.springframework.jms.listener.SimpleMessageListenerContainer}.
70 | * @param pubSubNoLocal the pubSubNoLocal.
71 | * @return the current {@link JmsPublishSubscribeMessageChannelSpec}.
72 | * @see org.springframework.jms.listener.DefaultMessageListenerContainer#setPubSubNoLocal(boolean)
73 | * @see org.springframework.jms.listener.SimpleMessageListenerContainer#setPubSubNoLocal(boolean)
74 | */
75 | public JmsPublishSubscribeMessageChannelSpec pubSubNoLocal(boolean pubSubNoLocal) {
76 | this.jmsChannelFactoryBean.setPubSubNoLocal(pubSubNoLocal);
77 | return _this();
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/file/FileSplitterSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.file;
18 |
19 | import java.nio.charset.Charset;
20 |
21 | import org.springframework.integration.dsl.core.MessageHandlerSpec;
22 | import org.springframework.integration.file.splitter.FileSplitter;
23 |
24 | /**
25 | * The {@link MessageHandlerSpec} for the {@link FileSplitter}.
26 | * @author Artem Bilan
27 | * @since 1.1
28 | */
29 | public class FileSplitterSpec extends MessageHandlerSpec {
30 |
31 | private final boolean iterator;
32 |
33 | private boolean markers;
34 |
35 | private boolean markersJson;
36 |
37 | private Charset charset;
38 |
39 | private boolean applySequence;
40 |
41 | FileSplitterSpec() {
42 | this(true);
43 | }
44 |
45 | FileSplitterSpec(boolean iterator) {
46 | this(iterator, false);
47 | }
48 |
49 | FileSplitterSpec(boolean iterator, boolean markers) {
50 | this.iterator = iterator;
51 | this.markers = markers;
52 | }
53 |
54 | public FileSplitterSpec charset(String charset) {
55 | return charset(Charset.forName(charset));
56 | }
57 |
58 | public FileSplitterSpec charset(Charset charset) {
59 | this.charset = charset;
60 | return this;
61 | }
62 |
63 | /**
64 | * Specify if {@link FileSplitter} should emit
65 | * {@link org.springframework.integration.file.splitter.FileSplitter.FileMarker}s
66 | * Defaults to {@code false}.
67 | * @return the FileSplitterSpec
68 | * @since 1.2
69 | * @see FileSplitter
70 | */
71 | public FileSplitterSpec markers() {
72 | return markers(false);
73 | }
74 |
75 | /**
76 | * Specify if {@link FileSplitter} should emit
77 | * {@link org.springframework.integration.file.splitter.FileSplitter.FileMarker}s
78 | * and if they should be converted to the JSON string representation.
79 | * Defaults to {@code false} for markers and {@code false} for markersJson.
80 | * @param asJson the asJson flag to use.
81 | * @return the FileSplitterSpec
82 | * @since 1.2
83 | * @see FileSplitter
84 | */
85 | public FileSplitterSpec markers(boolean asJson) {
86 | this.markers = true;
87 | this.markersJson = asJson;
88 | return this;
89 | }
90 |
91 | /**
92 | * A {@code boolean} flag to indicate if {@code sequenceDetails} should be
93 | * applied for messages based on the lines from file.
94 | * Defaults to {@code false}.
95 | * @param applySequence the applySequence flag to use.
96 | * @return the FileSplitterSpec
97 | * @since 1.2
98 | * @see org.springframework.integration.splitter.AbstractMessageSplitter#setApplySequence(boolean)
99 | */
100 | public FileSplitterSpec applySequence(boolean applySequence) {
101 | this.applySequence = applySequence;
102 | return this;
103 | }
104 |
105 |
106 | @Override
107 | protected FileSplitter doGet() {
108 | FileSplitter fileSplitter = new FileSplitter(this.iterator, this.markers, this.markersJson);
109 | fileSplitter.setApplySequence(this.applySequence);
110 | fileSplitter.setCharset(this.charset);
111 | return fileSplitter;
112 | }
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/jms/JmsDestinationAccessorSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.jms;
18 |
19 | import javax.jms.ConnectionFactory;
20 |
21 | import org.springframework.integration.dsl.core.IntegrationComponentSpec;
22 | import org.springframework.jms.support.destination.DestinationResolver;
23 | import org.springframework.jms.support.destination.JmsDestinationAccessor;
24 |
25 | /**
26 | * A base {@link IntegrationComponentSpec} for {@link JmsDestinationAccessor}s.
27 | *
28 | * @param the target {@link JmsDestinationAccessorSpec} implementation type.
29 | * @param the target {@link JmsDestinationAccessor} implementation type.
30 | *
31 | * @author Artem Bilan
32 | */
33 | public abstract class
34 | JmsDestinationAccessorSpec, A extends JmsDestinationAccessor>
35 | extends IntegrationComponentSpec {
36 |
37 | protected JmsDestinationAccessorSpec(A accessor) {
38 | this.target = accessor;
39 | }
40 |
41 | S connectionFactory(ConnectionFactory connectionFactory) {
42 | this.target.setConnectionFactory(connectionFactory);
43 | return _this();
44 | }
45 |
46 | /**
47 | * A {@link DestinationResolver} to use.
48 | * @param destinationResolver the {@link DestinationResolver} to use.
49 | * @return the spec
50 | * @see JmsDestinationAccessor#setDestinationResolver
51 | */
52 | public S destinationResolver(DestinationResolver destinationResolver) {
53 | this.target.setDestinationResolver(destinationResolver);
54 | return _this();
55 | }
56 |
57 | /**
58 | * A {@code pubSubDomain} flag.
59 | * @param pubSubDomain the {@code pubSubDomain} flag.
60 | * @return the spec
61 | * @see JmsDestinationAccessor#setPubSubDomain(boolean)
62 | */
63 | public S pubSubDomain(boolean pubSubDomain) {
64 | target.setPubSubDomain(pubSubDomain);
65 | return _this();
66 | }
67 |
68 | /**
69 | * A session acknowledgement mode.
70 | * @param sessionAcknowledgeMode the acknowledgement mode constant
71 | * @return the spec
72 | * @see javax.jms.Session#AUTO_ACKNOWLEDGE etc.
73 | * @see JmsDestinationAccessor#setSessionAcknowledgeMode
74 | */
75 | public S sessionAcknowledgeMode(int sessionAcknowledgeMode) {
76 | this.target.setSessionAcknowledgeMode(sessionAcknowledgeMode);
77 | return _this();
78 | }
79 |
80 | /**
81 | * A session acknowledgement mode name.
82 | * @param constantName the name of the {@link javax.jms.Session} acknowledge mode constant.
83 | * @return the spec.
84 | * @see JmsDestinationAccessor#setSessionAcknowledgeModeName
85 | */
86 | public S sessionAcknowledgeModeName(String constantName) {
87 | target.setSessionAcknowledgeModeName(constantName);
88 | return _this();
89 | }
90 |
91 | /**
92 | * A session transaction mode.
93 | * @param sessionTransacted the transaction mode.
94 | * @return the spec.
95 | * @see JmsDestinationAccessor#setSessionTransacted
96 | */
97 | public S sessionTransacted(boolean sessionTransacted) {
98 | this.target.setSessionTransacted(sessionTransacted);
99 | return _this();
100 | }
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/channel/WireTapSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.channel;
18 |
19 | import java.util.Arrays;
20 | import java.util.Collection;
21 | import java.util.Collections;
22 |
23 | import org.springframework.expression.Expression;
24 | import org.springframework.integration.channel.interceptor.WireTap;
25 | import org.springframework.integration.core.MessageSelector;
26 | import org.springframework.integration.dsl.core.ComponentsRegistration;
27 | import org.springframework.integration.dsl.core.IntegrationComponentSpec;
28 | import org.springframework.integration.filter.ExpressionEvaluatingSelector;
29 | import org.springframework.messaging.MessageChannel;
30 | import org.springframework.util.Assert;
31 |
32 | /**
33 | * The {@link IntegrationComponentSpec} implementation for the {@link WireTap} component.
34 | *
35 | * @author Gary Russell
36 | * @author Artem Bilan
37 | * @since 1.1.0
38 | *
39 | */
40 | public class WireTapSpec extends IntegrationComponentSpec implements ComponentsRegistration {
41 |
42 | private final MessageChannel channel;
43 |
44 | private final String channelName;
45 |
46 | private MessageSelector selector;
47 |
48 | private Long timeout;
49 |
50 | public WireTapSpec(MessageChannel channel) {
51 | Assert.notNull(channel, "'channel' must not be null");
52 | this.channel = channel;
53 | this.channelName = null;
54 | }
55 |
56 | public WireTapSpec(String channelName) {
57 | Assert.notNull(channelName, "'channelName' must not be null");
58 | this.channelName = channelName;
59 | this.channel = null;
60 | }
61 |
62 | public WireTapSpec selector(String selectorExpression) {
63 | return selector(new ExpressionEvaluatingSelector(selectorExpression));
64 | }
65 |
66 | /**
67 | * Specify an {@link Expression} for selector.
68 | * @param selectorExpression the expression for selector.
69 | * @return the current {@link WireTapSpec}
70 | * @since 1.2
71 | * @see WireTap#WireTap(MessageChannel, MessageSelector)
72 | */
73 | public WireTapSpec selector(Expression selectorExpression) {
74 | return selector(new ExpressionEvaluatingSelector(selectorExpression));
75 | }
76 |
77 | public WireTapSpec selector(MessageSelector selector) {
78 | this.selector = selector;
79 | return this;
80 | }
81 |
82 | public WireTapSpec timeout(long timeout) {
83 | this.timeout = timeout;
84 | return this;
85 | }
86 |
87 | @Override
88 | protected WireTap doGet() {
89 | WireTap wireTap;
90 | if (this.channel != null) {
91 | wireTap = new WireTap(this.channel, this.selector);
92 | }
93 | else {
94 | wireTap = new WireTap(this.channelName, this.selector);
95 | }
96 |
97 | if (this.timeout != null) {
98 | wireTap.setTimeout(this.timeout);
99 | }
100 | return wireTap;
101 | }
102 |
103 | @Override
104 | public Collection getComponentsToRegister() {
105 | if (this.selector != null) {
106 | return Arrays.asList(this.selector, this.target);
107 | }
108 | else {
109 | return Collections.singletonList(this.target);
110 | }
111 | }
112 |
113 | }
114 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/jpa/JpaRetrievingOutboundGatewaySpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.jpa;
18 |
19 | import org.springframework.expression.Expression;
20 | import org.springframework.integration.expression.ValueExpression;
21 | import org.springframework.integration.jpa.core.JpaExecutor;
22 | import org.springframework.integration.jpa.support.OutboundGatewayType;
23 |
24 | /**
25 | * A {@link JpaBaseOutboundEndpointSpec} extension for the
26 | * {@link org.springframework.integration.jpa.outbound.JpaOutboundGateway} with
27 | * {@link org.springframework.integration.jpa.support.OutboundGatewayType#RETRIEVING} mode.
28 | *
29 | * @author Artem Bilan
30 | * @since 1.2
31 | */
32 | public class JpaRetrievingOutboundGatewaySpec extends JpaBaseOutboundEndpointSpec {
33 |
34 | JpaRetrievingOutboundGatewaySpec(JpaExecutor jpaExecutor) {
35 | super(jpaExecutor);
36 | this.target.setGatewayType(OutboundGatewayType.RETRIEVING);
37 | this.target.setRequiresReply(true);
38 | }
39 |
40 |
41 | public JpaRetrievingOutboundGatewaySpec expectSingleResult(boolean expectSingleResult) {
42 | this.jpaExecutor.setExpectSingleResult(expectSingleResult);
43 | return this;
44 | }
45 |
46 | public JpaRetrievingOutboundGatewaySpec firstResult(int firstResult) {
47 | return firstResultExpression(new ValueExpression(firstResult));
48 | }
49 |
50 | public JpaRetrievingOutboundGatewaySpec firstResultExpression(String firstResultExpression) {
51 | return firstResultExpression(PARSER.parseExpression(firstResultExpression));
52 | }
53 |
54 | public JpaRetrievingOutboundGatewaySpec firstResultExpression(Expression firstResultExpression) {
55 | this.jpaExecutor.setFirstResultExpression(firstResultExpression);
56 | return this;
57 | }
58 |
59 | public JpaRetrievingOutboundGatewaySpec idExpression(String idExpression) {
60 | return idExpression(PARSER.parseExpression(idExpression));
61 | }
62 |
63 | public JpaRetrievingOutboundGatewaySpec idExpression(Expression idExpression) {
64 | this.jpaExecutor.setIdExpression(idExpression);
65 | return this;
66 | }
67 |
68 | public JpaRetrievingOutboundGatewaySpec maxResults(int maxResults) {
69 | return maxResultsExpression(new ValueExpression(maxResults));
70 | }
71 |
72 | public JpaRetrievingOutboundGatewaySpec maxResultsExpression(String maxResultsExpression) {
73 | return maxResultsExpression(PARSER.parseExpression(maxResultsExpression));
74 | }
75 |
76 | public JpaRetrievingOutboundGatewaySpec maxResultsExpression(Expression maxResultsExpression) {
77 | this.jpaExecutor.setMaxResultsExpression(maxResultsExpression);
78 | return this;
79 | }
80 |
81 | public JpaRetrievingOutboundGatewaySpec deleteAfterPoll(boolean deleteAfterPoll) {
82 | this.jpaExecutor.setDeleteAfterPoll(deleteAfterPoll);
83 | return this;
84 | }
85 |
86 | public JpaRetrievingOutboundGatewaySpec deleteInBatch(boolean deleteInBatch) {
87 | this.jpaExecutor.setDeleteInBatch(deleteInBatch);
88 | return this;
89 | }
90 |
91 | public JpaRetrievingOutboundGatewaySpec flushAfterDelete(boolean flush) {
92 | this.jpaExecutor.setFlush(flush);
93 | return this;
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/channel/QueueChannelSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.channel;
18 |
19 | import java.util.Queue;
20 | import java.util.concurrent.locks.Lock;
21 |
22 | import org.springframework.integration.channel.QueueChannel;
23 | import org.springframework.integration.store.ChannelMessageStore;
24 | import org.springframework.integration.store.MessageGroupQueue;
25 | import org.springframework.integration.store.PriorityCapableChannelMessageStore;
26 | import org.springframework.messaging.Message;
27 |
28 | /**
29 | * @author Artem Bilan
30 | */
31 | public class QueueChannelSpec extends MessageChannelSpec {
32 |
33 | protected Queue> queue;
34 |
35 | protected Integer capacity;
36 |
37 | QueueChannelSpec() {
38 | }
39 |
40 | QueueChannelSpec(Queue> queue) {
41 | this.queue = queue;
42 | }
43 |
44 | QueueChannelSpec(Integer capacity) {
45 | this.capacity = capacity;
46 | }
47 |
48 | @Override
49 | protected QueueChannel doGet() {
50 | if (this.queue != null) {
51 | this.channel = new QueueChannel(this.queue);
52 | }
53 | else if (this.capacity != null) {
54 | this.channel = new QueueChannel(this.capacity);
55 | }
56 | else {
57 | this.channel = new QueueChannel();
58 | }
59 | return super.doGet();
60 | }
61 |
62 | /**
63 | * The {@link ChannelMessageStore}-specific {@link QueueChannelSpec} extension.
64 | */
65 | public static class MessageStoreSpec extends QueueChannelSpec {
66 |
67 | private final ChannelMessageStore messageGroupStore;
68 |
69 | private final Object groupId;
70 |
71 | private Lock storeLock;
72 |
73 | MessageStoreSpec(ChannelMessageStore messageGroupStore, Object groupId) {
74 | super();
75 | this.messageGroupStore = messageGroupStore;
76 | this.groupId = groupId;
77 | }
78 |
79 | @Override
80 | protected MessageStoreSpec id(String id) {
81 | return (MessageStoreSpec) super.id(id);
82 | }
83 |
84 |
85 | public MessageStoreSpec capacity(Integer capacity) {
86 | this.capacity = capacity;
87 | return this;
88 | }
89 |
90 | public MessageStoreSpec storeLock(Lock storeLock) {
91 | this.storeLock = storeLock;
92 | return this;
93 | }
94 |
95 | @Override
96 | protected QueueChannel doGet() {
97 | if (this.capacity != null) {
98 | if (this.storeLock != null) {
99 | this.queue = new MessageGroupQueue(this.messageGroupStore, this.groupId, this.capacity,
100 | this.storeLock);
101 | }
102 | else {
103 | this.queue = new MessageGroupQueue(this.messageGroupStore, this.groupId, this.capacity);
104 | }
105 | }
106 | else if (this.storeLock != null) {
107 | this.queue = new MessageGroupQueue(this.messageGroupStore, this.groupId, this.storeLock);
108 | }
109 | else {
110 | this.queue = new MessageGroupQueue(this.messageGroupStore, this.groupId);
111 | }
112 |
113 | ((MessageGroupQueue) this.queue).setPriority(
114 | this.messageGroupStore instanceof PriorityCapableChannelMessageStore);
115 |
116 | return super.doGet();
117 | }
118 |
119 | }
120 |
121 | }
122 |
--------------------------------------------------------------------------------
/src/test/java/org/springframework/integration/dsl/test/transaction/TransactionInterceptorBuilderTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.test.transaction;
18 |
19 | import static org.hamcrest.Matchers.equalTo;
20 | import static org.junit.Assert.assertSame;
21 | import static org.junit.Assert.assertThat;
22 | import static org.junit.Assert.assertTrue;
23 |
24 | import org.junit.Test;
25 | import org.junit.runner.RunWith;
26 |
27 | import org.springframework.beans.factory.annotation.Autowired;
28 | import org.springframework.context.annotation.Bean;
29 | import org.springframework.context.annotation.Configuration;
30 | import org.springframework.integration.dsl.transaction.TransactionInterceptorBuilder;
31 | import org.springframework.integration.transaction.PseudoTransactionManager;
32 | import org.springframework.test.context.junit4.SpringRunner;
33 | import org.springframework.transaction.PlatformTransactionManager;
34 | import org.springframework.transaction.annotation.Isolation;
35 | import org.springframework.transaction.annotation.Propagation;
36 | import org.springframework.transaction.interceptor.TransactionAttribute;
37 | import org.springframework.transaction.interceptor.TransactionInterceptor;
38 |
39 | /**
40 | * @author Gary Russell
41 | * @author Artem Bilan
42 | * @since 1.2
43 | *
44 | */
45 | @RunWith(SpringRunner.class)
46 | public class TransactionInterceptorBuilderTests {
47 |
48 | @Autowired
49 | private PlatformTransactionManager txm;
50 |
51 | @Autowired
52 | private TransactionInterceptor interceptor1;
53 |
54 | @Autowired
55 | private TransactionInterceptor interceptor2;
56 |
57 | @Test
58 | public void test() throws Throwable {
59 | verify(this.interceptor1, this.txm);
60 | verify(this.interceptor2, null);
61 | }
62 |
63 | private void verify(TransactionInterceptor interceptor, PlatformTransactionManager txm) {
64 | assertSame(txm, interceptor.getTransactionManager());
65 | TransactionAttribute atts = interceptor.getTransactionAttributeSource()
66 | .getTransactionAttribute(null, null);
67 | assertThat(atts.getPropagationBehavior(), equalTo(Propagation.REQUIRES_NEW.value()));
68 | assertThat(atts.getIsolationLevel(), equalTo(Isolation.SERIALIZABLE.value()));
69 | assertThat(atts.getTimeout(), equalTo(42));
70 | assertTrue(atts.isReadOnly());
71 | }
72 |
73 | @Configuration
74 | public static class Config {
75 |
76 | @Bean
77 | public PseudoTransactionManager transactionManager() {
78 | return new PseudoTransactionManager();
79 | }
80 |
81 | @Bean
82 | public TransactionInterceptor interceptor1(PlatformTransactionManager transactionManager) {
83 | return new TransactionInterceptorBuilder()
84 | .propagation(Propagation.REQUIRES_NEW)
85 | .isolation(Isolation.SERIALIZABLE)
86 | .timeout(42)
87 | .readOnly(true)
88 | .transactionManager(transactionManager)
89 | .build();
90 | }
91 |
92 | @Bean
93 | public TransactionInterceptor interceptor2() {
94 | return new TransactionInterceptorBuilder()
95 | .propagation(Propagation.REQUIRES_NEW)
96 | .isolation(Isolation.SERIALIZABLE)
97 | .timeout(42)
98 | .readOnly(true)
99 | .build();
100 | }
101 |
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/core/MessageProducerSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.core;
18 |
19 | import org.springframework.integration.endpoint.MessageProducerSupport;
20 | import org.springframework.messaging.MessageChannel;
21 |
22 | /**
23 | * An {@link IntegrationComponentSpec} for
24 | * {@link org.springframework.integration.core.MessageProducer}s.
25 | *
26 | * @param the target {@link MessageProducerSpec} implementation type.
27 | * @param the target {@link MessageProducerSupport} implementation type.
28 | *
29 | * @author Artem Bilan
30 | */
31 | public abstract class MessageProducerSpec, P extends MessageProducerSupport>
32 | extends IntegrationComponentSpec {
33 |
34 | public MessageProducerSpec(P producer) {
35 | this.target = producer;
36 | }
37 |
38 | /**
39 | * {@inheritDoc}
40 | * Configure the message producer's bean name.
41 | */
42 | @Override
43 | public S id(String id) {
44 | this.target.setBeanName(id);
45 | return super.id(id);
46 | }
47 |
48 | /**
49 | * @param phase the phase.
50 | * @return the spec.
51 | * @see org.springframework.context.SmartLifecycle
52 | */
53 | public S phase(int phase) {
54 | this.target.setPhase(phase);
55 | return _this();
56 | }
57 |
58 | /**
59 | * @param autoStartup the autoStartup.
60 | * @return the spec.
61 | * @see org.springframework.context.SmartLifecycle
62 | */
63 | public S autoStartup(boolean autoStartup) {
64 | this.target.setAutoStartup(autoStartup);
65 | return _this();
66 | }
67 |
68 | /**
69 | * Specify the {@code outputChannel} for the
70 | * {@link org.springframework.integration.core.MessageProducer}
71 | * @param outputChannel the outputChannel.
72 | * @return the spec.
73 | * @see MessageProducerSupport#setOutputChannel(MessageChannel)
74 | */
75 | public S outputChannel(MessageChannel outputChannel) {
76 | target.setOutputChannel(outputChannel);
77 | return _this();
78 | }
79 |
80 | /**
81 | * Specify the bean name of the {@code outputChannel} for the
82 | * {@link org.springframework.integration.core.MessageProducer}
83 | * @param outputChannel the outputChannel bean name.
84 | * @return the spec.
85 | * @since 1.2
86 | * @see MessageProducerSupport#setOutputChannelName(String)
87 | */
88 | public S outputChannel(String outputChannel) {
89 | target.setOutputChannelName(outputChannel);
90 | return _this();
91 | }
92 |
93 | /**
94 | * Configure the {@link MessageChannel} to which error messages will be sent.
95 | * @param errorChannel the errorChannel.
96 | * @return the spec.
97 | * @see MessageProducerSupport#setErrorChannel(MessageChannel)
98 | */
99 | public S errorChannel(MessageChannel errorChannel) {
100 | target.setErrorChannel(errorChannel);
101 | return _this();
102 | }
103 |
104 | /**
105 | * Configure the bean name of the {@link MessageChannel} to which error messages will be sent.
106 | * @param errorChannel the errorChannel bean name.
107 | * @return the spec.
108 | * @since 1.2
109 | * @see MessageProducerSupport#setErrorChannelName(String)
110 | */
111 | public S errorChannel(String errorChannel) {
112 | target.setErrorChannelName(errorChannel);
113 | return _this();
114 | }
115 |
116 | }
117 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/jpa/JpaBaseOutboundEndpointSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.jpa;
18 |
19 | import java.util.Collection;
20 | import java.util.Collections;
21 | import java.util.LinkedList;
22 | import java.util.List;
23 |
24 | import org.springframework.integration.dsl.core.ComponentsRegistration;
25 | import org.springframework.integration.dsl.core.MessageHandlerSpec;
26 | import org.springframework.integration.jpa.core.JpaExecutor;
27 | import org.springframework.integration.jpa.outbound.JpaOutboundGateway;
28 | import org.springframework.integration.jpa.support.JpaParameter;
29 | import org.springframework.integration.jpa.support.parametersource.ParameterSourceFactory;
30 | import org.springframework.util.CollectionUtils;
31 |
32 | /**
33 | * The base {@link MessageHandlerSpec} for JPA Outbound endpoints.
34 | *
35 | * @param the target {@link JpaBaseOutboundEndpointSpec} implementation type.
36 | *
37 | * @author Artem Bilan
38 | * @since 1.2
39 | */
40 | public abstract class JpaBaseOutboundEndpointSpec>
41 | extends MessageHandlerSpec
42 | implements ComponentsRegistration {
43 |
44 | private final List jpaParameters = new LinkedList();
45 |
46 | protected final JpaExecutor jpaExecutor;
47 |
48 | protected JpaBaseOutboundEndpointSpec(JpaExecutor jpaExecutor) {
49 | this.jpaExecutor = jpaExecutor;
50 | this.target = new JpaOutboundGateway(this.jpaExecutor);
51 | }
52 |
53 | public S entityClass(Class> entityClass) {
54 | this.jpaExecutor.setEntityClass(entityClass);
55 | return _this();
56 | }
57 |
58 | public S jpaQuery(String jpaQuery) {
59 | this.jpaExecutor.setJpaQuery(jpaQuery);
60 | return _this();
61 | }
62 |
63 | public S nativeQuery(String nativeQuery) {
64 | this.jpaExecutor.setNativeQuery(nativeQuery);
65 | return _this();
66 | }
67 |
68 | public S namedQuery(String namedQuery) {
69 | this.jpaExecutor.setNamedQuery(namedQuery);
70 | return _this();
71 | }
72 |
73 | public S parameterSourceFactory(ParameterSourceFactory parameterSourceFactory) {
74 | this.jpaExecutor.setParameterSourceFactory(parameterSourceFactory);
75 | return _this();
76 | }
77 |
78 | public S parameter(Object value) {
79 | return parameter(new JpaParameter(value, null));
80 | }
81 |
82 | public S parameter(String name, Object value) {
83 | return parameter(new JpaParameter(name, value, null));
84 | }
85 |
86 | public S parameterExpression(String expression) {
87 | return parameter(new JpaParameter(null, expression));
88 | }
89 |
90 | public S parameterExpression(String name, String expression) {
91 | return parameter(new JpaParameter(name, null, expression));
92 | }
93 |
94 |
95 | public S parameter(JpaParameter jpaParameter) {
96 | this.jpaParameters.add(jpaParameter);
97 | return _this();
98 | }
99 |
100 | public S usePayloadAsParameterSource(Boolean usePayloadAsParameterSource) {
101 | this.jpaExecutor.setUsePayloadAsParameterSource(usePayloadAsParameterSource);
102 | return _this();
103 | }
104 |
105 | @Override
106 | public Collection getComponentsToRegister() {
107 | if (!CollectionUtils.isEmpty(this.jpaParameters)) {
108 | this.jpaExecutor.setJpaParameters(this.jpaParameters);
109 | }
110 | return Collections.singletonList(this.jpaExecutor);
111 | }
112 |
113 | }
114 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/jpa/Jpa.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.jpa;
18 |
19 | import javax.persistence.EntityManager;
20 | import javax.persistence.EntityManagerFactory;
21 |
22 | import org.springframework.integration.jpa.core.JpaExecutor;
23 | import org.springframework.integration.jpa.core.JpaOperations;
24 |
25 | /**
26 | * Factory class for JPA components.
27 | *
28 | * @author Artem Bilan
29 | *
30 | * @since 1.2
31 | */
32 | public final class Jpa {
33 |
34 | public static JpaInboundChannelAdapterSpec inboundAdapter(EntityManagerFactory entityManagerFactory) {
35 | return inboundAdapter(new JpaExecutor(entityManagerFactory));
36 | }
37 |
38 | public static JpaInboundChannelAdapterSpec inboundAdapter(EntityManager entityManager) {
39 | return inboundAdapter(new JpaExecutor(entityManager));
40 | }
41 |
42 | public static JpaInboundChannelAdapterSpec inboundAdapter(JpaOperations jpaOperations) {
43 | return inboundAdapter(new JpaExecutor(jpaOperations));
44 | }
45 |
46 | private static JpaInboundChannelAdapterSpec inboundAdapter(JpaExecutor jpaExecutor) {
47 | return new JpaInboundChannelAdapterSpec(jpaExecutor);
48 | }
49 |
50 | public static JpaUpdatingOutboundEndpointSpec outboundAdapter(EntityManagerFactory entityManagerFactory) {
51 | return outboundAdapter(new JpaExecutor(entityManagerFactory));
52 | }
53 |
54 | public static JpaUpdatingOutboundEndpointSpec outboundAdapter(EntityManager entityManager) {
55 | return outboundAdapter(new JpaExecutor(entityManager));
56 | }
57 |
58 | public static JpaUpdatingOutboundEndpointSpec outboundAdapter(JpaOperations jpaOperations) {
59 | return outboundAdapter(new JpaExecutor(jpaOperations));
60 | }
61 |
62 | private static JpaUpdatingOutboundEndpointSpec outboundAdapter(JpaExecutor jpaExecutor) {
63 | return new JpaUpdatingOutboundEndpointSpec(jpaExecutor)
64 | .producesReply(false);
65 | }
66 |
67 | public static JpaUpdatingOutboundEndpointSpec updatingGateway(EntityManagerFactory entityManagerFactory) {
68 | return updatingGateway(new JpaExecutor(entityManagerFactory));
69 | }
70 |
71 | public static JpaUpdatingOutboundEndpointSpec updatingGateway(EntityManager entityManager) {
72 | return updatingGateway(new JpaExecutor(entityManager));
73 | }
74 |
75 | public static JpaUpdatingOutboundEndpointSpec updatingGateway(JpaOperations jpaOperations) {
76 | return updatingGateway(new JpaExecutor(jpaOperations));
77 | }
78 |
79 | private static JpaUpdatingOutboundEndpointSpec updatingGateway(JpaExecutor jpaExecutor) {
80 | return new JpaUpdatingOutboundEndpointSpec(jpaExecutor)
81 | .producesReply(true);
82 | }
83 |
84 | public static JpaRetrievingOutboundGatewaySpec retrievingGateway(EntityManagerFactory entityManagerFactory) {
85 | return retrievingGateway(new JpaExecutor(entityManagerFactory));
86 | }
87 |
88 | public static JpaRetrievingOutboundGatewaySpec retrievingGateway(EntityManager entityManager) {
89 | return retrievingGateway(new JpaExecutor(entityManager));
90 | }
91 |
92 | public static JpaRetrievingOutboundGatewaySpec retrievingGateway(JpaOperations jpaOperations) {
93 | return retrievingGateway(new JpaExecutor(jpaOperations));
94 | }
95 |
96 | private static JpaRetrievingOutboundGatewaySpec retrievingGateway(JpaExecutor jpaExecutor) {
97 | return new JpaRetrievingOutboundGatewaySpec(jpaExecutor);
98 | }
99 |
100 |
101 | private Jpa() {
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/mail/Mail.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.mail;
18 |
19 | import org.springframework.integration.mail.ImapMailReceiver;
20 | import org.springframework.integration.mail.Pop3MailReceiver;
21 |
22 | /**
23 | * The factory for Spring Integration Mail components.
24 | *
25 | * @author Gary Russell
26 | * @author Artem Bilan
27 | */
28 | public final class Mail {
29 |
30 | public static MailSendingMessageHandlerSpec outboundAdapter(String host) {
31 | return new MailSendingMessageHandlerSpec(host);
32 | }
33 |
34 | public static Pop3MailInboundChannelAdapterSpec pop3InboundAdapter() {
35 | return new Pop3MailInboundChannelAdapterSpec();
36 | }
37 |
38 | /**
39 | * A {@link Pop3MailInboundChannelAdapterSpec} factory based on the provided {@link Pop3MailReceiver}.
40 | * @param pop3MailReceiver the {@link Pop3MailReceiver} to use.
41 | * @return the {@link Pop3MailInboundChannelAdapterSpec} instance.
42 | * @since 1.2
43 | */
44 | public static Pop3MailInboundChannelAdapterSpec pop3InboundAdapter(Pop3MailReceiver pop3MailReceiver) {
45 | return new Pop3MailInboundChannelAdapterSpec(pop3MailReceiver);
46 | }
47 |
48 | public static Pop3MailInboundChannelAdapterSpec pop3InboundAdapter(String url) {
49 | return new Pop3MailInboundChannelAdapterSpec(url);
50 | }
51 |
52 | public static Pop3MailInboundChannelAdapterSpec pop3InboundAdapter(String host, String username, String password) {
53 | return pop3InboundAdapter(host, -1, username, password);
54 | }
55 |
56 | public static Pop3MailInboundChannelAdapterSpec pop3InboundAdapter(String host, int port, String username,
57 | String password) {
58 | return new Pop3MailInboundChannelAdapterSpec(host, port, username, password);
59 | }
60 |
61 | public static ImapMailInboundChannelAdapterSpec imapInboundAdapter() {
62 | return new ImapMailInboundChannelAdapterSpec();
63 | }
64 |
65 | /**
66 | * An {@link ImapMailInboundChannelAdapterSpec} factory based on the provided {@link ImapMailReceiver}.
67 | * @param imapMailReceiver the {@link ImapMailReceiver} to use.
68 | * @return the {@link ImapMailInboundChannelAdapterSpec} instance.
69 | * @since 1.2
70 | */
71 | public static ImapMailInboundChannelAdapterSpec imapInboundAdapter(ImapMailReceiver imapMailReceiver) {
72 | return new ImapMailInboundChannelAdapterSpec(imapMailReceiver);
73 | }
74 |
75 | public static ImapMailInboundChannelAdapterSpec imapInboundAdapter(String url) {
76 | return new ImapMailInboundChannelAdapterSpec(url);
77 | }
78 |
79 | public static ImapIdleChannelAdapterSpec imapIdleAdapter() {
80 | return new ImapIdleChannelAdapterSpec(new ImapMailReceiver());
81 | }
82 |
83 | public static ImapIdleChannelAdapterSpec imapIdleAdapter(String url) {
84 | return new ImapIdleChannelAdapterSpec(new ImapMailReceiver(url));
85 | }
86 |
87 | /**
88 | * An {@link ImapIdleChannelAdapterSpec} factory based on the provided {@link ImapMailReceiver}.
89 | * @param imapMailReceiver the {@link ImapMailReceiver} to use.
90 | * @return the {@link ImapIdleChannelAdapterSpec} instance.
91 | * @since 1.2
92 | */
93 | public static ImapIdleChannelAdapterSpec imapIdleAdapter(ImapMailReceiver imapMailReceiver) {
94 | return new ImapIdleChannelAdapterSpec(imapMailReceiver, true);
95 | }
96 |
97 | public static MailHeadersBuilder headers() {
98 | return new MailHeadersBuilder();
99 | }
100 |
101 | private Mail() {
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/jpa/JpaInboundChannelAdapterSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.jpa;
18 |
19 | import java.util.Collection;
20 | import java.util.Collections;
21 |
22 | import org.springframework.expression.Expression;
23 | import org.springframework.integration.dsl.core.ComponentsRegistration;
24 | import org.springframework.integration.dsl.core.MessageSourceSpec;
25 | import org.springframework.integration.expression.ValueExpression;
26 | import org.springframework.integration.jpa.core.JpaExecutor;
27 | import org.springframework.integration.jpa.inbound.JpaPollingChannelAdapter;
28 | import org.springframework.integration.jpa.support.parametersource.ParameterSource;
29 |
30 | /**
31 | * A {@link MessageSourceSpec} for a {@link JpaPollingChannelAdapter}.
32 | *
33 | * @author Artem Bilan
34 | *
35 | * @since 1.2
36 | */
37 | public class JpaInboundChannelAdapterSpec
38 | extends MessageSourceSpec
39 | implements ComponentsRegistration {
40 |
41 | private final JpaExecutor jpaExecutor;
42 |
43 | JpaInboundChannelAdapterSpec(JpaExecutor jpaExecutor) {
44 | this.jpaExecutor = jpaExecutor;
45 | this.target = new JpaPollingChannelAdapter(this.jpaExecutor);
46 | }
47 |
48 | public JpaInboundChannelAdapterSpec entityClass(Class> entityClass) {
49 | this.jpaExecutor.setEntityClass(entityClass);
50 | return this;
51 | }
52 |
53 | public JpaInboundChannelAdapterSpec jpaQuery(String jpaQuery) {
54 | this.jpaExecutor.setJpaQuery(jpaQuery);
55 | return this;
56 | }
57 |
58 | public JpaInboundChannelAdapterSpec nativeQuery(String nativeQuery) {
59 | this.jpaExecutor.setNativeQuery(nativeQuery);
60 | return this;
61 | }
62 |
63 | public JpaInboundChannelAdapterSpec namedQuery(String namedQuery) {
64 | this.jpaExecutor.setNamedQuery(namedQuery);
65 | return this;
66 | }
67 |
68 | public JpaInboundChannelAdapterSpec deleteAfterPoll(boolean deleteAfterPoll) {
69 | this.jpaExecutor.setDeleteAfterPoll(deleteAfterPoll);
70 | return this;
71 | }
72 |
73 | public JpaInboundChannelAdapterSpec deleteInBatch(boolean deleteInBatch) {
74 | this.jpaExecutor.setDeleteInBatch(deleteInBatch);
75 | return this;
76 | }
77 |
78 | public JpaInboundChannelAdapterSpec flushAfterDelete(boolean flush) {
79 | this.jpaExecutor.setFlush(flush);
80 | return this;
81 | }
82 |
83 | public JpaInboundChannelAdapterSpec parameterSource(ParameterSource parameterSource) {
84 | this.jpaExecutor.setParameterSource(parameterSource);
85 | return this;
86 | }
87 |
88 | public JpaInboundChannelAdapterSpec expectSingleResult(boolean expectSingleResult) {
89 | this.jpaExecutor.setExpectSingleResult(expectSingleResult);
90 | return this;
91 | }
92 |
93 | public JpaInboundChannelAdapterSpec maxResults(int maxResults) {
94 | return maxResultsExpression(new ValueExpression(maxResults));
95 | }
96 |
97 | public JpaInboundChannelAdapterSpec maxResultsExpression(String maxResultsExpression) {
98 | return maxResultsExpression(PARSER.parseExpression(maxResultsExpression));
99 | }
100 |
101 | public JpaInboundChannelAdapterSpec maxResultsExpression(Expression maxResultsExpression) {
102 | this.jpaExecutor.setMaxResultsExpression(maxResultsExpression);
103 | return this;
104 | }
105 |
106 | @Override
107 | public Collection getComponentsToRegister() {
108 | return Collections.singletonList(this.jpaExecutor);
109 | }
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/jms/JmsInboundChannelAdapterSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.jms;
18 |
19 | import javax.jms.ConnectionFactory;
20 | import javax.jms.Destination;
21 |
22 | import org.springframework.integration.dsl.core.MessageSourceSpec;
23 | import org.springframework.integration.dsl.support.Consumer;
24 | import org.springframework.integration.jms.JmsDestinationPollingSource;
25 | import org.springframework.integration.jms.JmsHeaderMapper;
26 | import org.springframework.jms.core.JmsTemplate;
27 | import org.springframework.util.Assert;
28 |
29 | /**
30 | * A {@link MessageSourceSpec} for a {@link JmsDestinationPollingSource}.
31 | *
32 | * @param the target {@link JmsInboundChannelAdapterSpec} implementation type.
33 | *
34 | * @author Artem Bilan
35 | */
36 | public class JmsInboundChannelAdapterSpec>
37 | extends MessageSourceSpec {
38 |
39 | final JmsTemplateSpec jmsTemplateSpec = new JmsTemplateSpec();
40 |
41 | JmsInboundChannelAdapterSpec(JmsTemplate jmsTemplate) {
42 | this.target = new JmsDestinationPollingSource(jmsTemplate);
43 | }
44 |
45 | private JmsInboundChannelAdapterSpec(ConnectionFactory connectionFactory) {
46 | this.target = new JmsDestinationPollingSource(this.jmsTemplateSpec.connectionFactory(connectionFactory).get());
47 | }
48 |
49 | /**
50 | * @param messageSelector the messageSelector.
51 | * @return the spec.
52 | * @see JmsDestinationPollingSource#setMessageSelector(String)
53 | */
54 | public S messageSelector(String messageSelector) {
55 | this.target.setMessageSelector(messageSelector);
56 | return _this();
57 | }
58 |
59 | /**
60 | * Configure a {@link JmsHeaderMapper} to map from JMS headers and properties to
61 | * Spring Integration headers.
62 | * @param headerMapper the headerMapper.
63 | * @return the spec.
64 | */
65 | public S headerMapper(JmsHeaderMapper headerMapper) {
66 | this.target.setHeaderMapper(headerMapper);
67 | return _this();
68 | }
69 |
70 | /**
71 | * Configure the destination from which to receive messages.
72 | * @param destination the destination.
73 | * @return the spec.
74 | */
75 | public S destination(Destination destination) {
76 | this.target.setDestination(destination);
77 | return _this();
78 | }
79 |
80 | /**
81 | * Configure the name of destination from which to receive messages.
82 | * @param destination the destination.
83 | * @return the spec.
84 | */
85 | public S destination(String destination) {
86 | this.target.setDestinationName(destination);
87 | return _this();
88 | }
89 |
90 | /**
91 | * A {@link JmsTemplate}-based {@link JmsInboundChannelAdapterSpec} extension.
92 | */
93 | public static class JmsInboundChannelSpecTemplateAware extends
94 | JmsInboundChannelAdapterSpec {
95 |
96 | JmsInboundChannelSpecTemplateAware(ConnectionFactory connectionFactory) {
97 | super(connectionFactory);
98 | }
99 |
100 | /**
101 | * Configure the channel adapter to use the template specification created by invoking the
102 | * {@link Consumer} callback, passing in a {@link JmsTemplateSpec}.
103 | * @param configurer the configurer.
104 | * @return the spec.
105 | */
106 | public JmsInboundChannelSpecTemplateAware configureJmsTemplate(Consumer configurer) {
107 | Assert.notNull(configurer, "'configurer' must not be null");
108 | configurer.accept(this.jmsTemplateSpec);
109 | return _this();
110 | }
111 |
112 | }
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/BarrierSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl;
18 |
19 | import org.springframework.core.Ordered;
20 | import org.springframework.integration.IntegrationMessageHeaderAccessor;
21 | import org.springframework.integration.aggregator.BarrierMessageHandler;
22 | import org.springframework.integration.aggregator.CorrelationStrategy;
23 | import org.springframework.integration.aggregator.DefaultAggregatingMessageGroupProcessor;
24 | import org.springframework.integration.aggregator.HeaderAttributeCorrelationStrategy;
25 | import org.springframework.integration.aggregator.MessageGroupProcessor;
26 | import org.springframework.integration.config.ConsumerEndpointFactoryBean;
27 | import org.springframework.integration.dsl.core.ConsumerEndpointSpec;
28 | import org.springframework.integration.dsl.core.MessageHandlerSpec;
29 | import org.springframework.integration.dsl.support.tuple.Tuple2;
30 | import org.springframework.integration.dsl.support.tuple.Tuples;
31 | import org.springframework.util.Assert;
32 |
33 | /**
34 | * A {@link MessageHandlerSpec} for the {@link BarrierMessageHandler}.
35 | *
36 | * @author Artem Bilan
37 | * @since 1.2
38 | */
39 | public class BarrierSpec extends ConsumerEndpointSpec {
40 |
41 | private final long timeout;
42 |
43 | private MessageGroupProcessor outputProcessor = new DefaultAggregatingMessageGroupProcessor();
44 |
45 | private CorrelationStrategy correlationStrategy =
46 | new HeaderAttributeCorrelationStrategy(IntegrationMessageHeaderAccessor.CORRELATION_ID);
47 |
48 | private boolean requiresReply;
49 |
50 | private long sendTimeout = -1;
51 |
52 | private int order = Ordered.LOWEST_PRECEDENCE;
53 |
54 | private boolean async;
55 |
56 | BarrierSpec(long timeout) {
57 | super(null);
58 | this.timeout = timeout;
59 | }
60 |
61 | public BarrierSpec outputProcessor(MessageGroupProcessor outputProcessor) {
62 | Assert.notNull(outputProcessor, "'outputProcessor' must not be null.");
63 | this.outputProcessor = outputProcessor;
64 | return this;
65 | }
66 |
67 | public BarrierSpec correlationStrategy(CorrelationStrategy correlationStrategy) {
68 | Assert.notNull(correlationStrategy, "'correlationStrategy' must not be null.");
69 | this.correlationStrategy = correlationStrategy;
70 | return this;
71 | }
72 |
73 | @Override
74 | public BarrierSpec requiresReply(boolean requiresReply) {
75 | this.requiresReply = requiresReply;
76 | return this;
77 | }
78 |
79 | @Override
80 | public BarrierSpec sendTimeout(long sendTimeout) {
81 | this.sendTimeout = sendTimeout;
82 | return this;
83 | }
84 |
85 | @Override
86 | public BarrierSpec order(int order) {
87 | this.order = order;
88 | return this;
89 | }
90 |
91 | @Override
92 | public BarrierSpec async(boolean async) {
93 | this.async = async;
94 | return this;
95 | }
96 |
97 | @Override
98 | public Tuple2 doGet() {
99 | BarrierMessageHandler barrierMessageHandler =
100 | new BarrierMessageHandler(this.timeout, this.outputProcessor, this.correlationStrategy);
101 | barrierMessageHandler.setAdviceChain(this.adviceChain);
102 | barrierMessageHandler.setRequiresReply(this.requiresReply);
103 | barrierMessageHandler.setSendTimeout(this.sendTimeout);
104 | barrierMessageHandler.setAsync(this.async);
105 | barrierMessageHandler.setOrder(this.order);
106 | this.endpointFactoryBean.setHandler(barrierMessageHandler);
107 | return Tuples.of(this.endpointFactoryBean, barrierMessageHandler);
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/integration/dsl/jms/JmsInboundGateway.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.integration.dsl.jms;
18 |
19 | import org.springframework.beans.BeansException;
20 | import org.springframework.beans.factory.DisposableBean;
21 | import org.springframework.context.ApplicationContext;
22 | import org.springframework.integration.context.OrderlyShutdownCapable;
23 | import org.springframework.integration.gateway.MessagingGatewaySupport;
24 | import org.springframework.integration.jms.ChannelPublishingJmsMessageListener;
25 | import org.springframework.integration.jms.JmsMessageDrivenEndpoint;
26 | import org.springframework.jms.listener.AbstractMessageListenerContainer;
27 | import org.springframework.messaging.MessageChannel;
28 |
29 | /**
30 | * @author Artem Bilan
31 | */
32 | public class JmsInboundGateway extends MessagingGatewaySupport implements
33 | DisposableBean, OrderlyShutdownCapable {
34 |
35 | private final JmsMessageDrivenEndpoint endpoint;
36 |
37 | private final ChannelPublishingJmsMessageListener listener;
38 |
39 | public JmsInboundGateway(AbstractMessageListenerContainer listenerContainer,
40 | ChannelPublishingJmsMessageListener listener) {
41 | this.endpoint = new JmsMessageDrivenEndpoint(listenerContainer, listener);
42 | this.listener = listener;
43 | }
44 |
45 | @Override
46 | public void setRequestChannel(MessageChannel requestChannel) {
47 | super.setRequestChannel(requestChannel);
48 | this.listener.setRequestChannel(requestChannel);
49 | }
50 |
51 | @Override
52 | public void setReplyChannel(MessageChannel replyChannel) {
53 | this.listener.setReplyChannel(replyChannel);
54 | }
55 |
56 | @Override
57 | public void setErrorChannel(MessageChannel errorChannel) {
58 | this.listener.setErrorChannel(errorChannel);
59 | }
60 |
61 | @Override
62 | public void setRequestTimeout(long requestTimeout) {
63 | this.listener.setRequestTimeout(requestTimeout);
64 | }
65 |
66 | @Override
67 | public void setReplyTimeout(long replyTimeout) {
68 | this.listener.setReplyTimeout(replyTimeout);
69 | }
70 |
71 | @Override
72 | public void setShouldTrack(boolean shouldTrack) {
73 | this.listener.setShouldTrack(shouldTrack);
74 | }
75 |
76 | @Override
77 | public String getComponentType() {
78 | return "jms:inbound-gateway";
79 | }
80 |
81 | @Override
82 | public void setComponentName(String componentName) {
83 | super.setComponentName(componentName);
84 | this.endpoint.setComponentName(getComponentName());
85 | }
86 |
87 | @Override
88 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
89 | super.setApplicationContext(applicationContext);
90 | this.endpoint.setApplicationContext(applicationContext);
91 | this.endpoint.setBeanFactory(applicationContext);
92 | this.listener.setBeanFactory(applicationContext);
93 | }
94 |
95 | @Override
96 | protected void onInit() throws Exception {
97 | this.endpoint.afterPropertiesSet();
98 | }
99 |
100 | ChannelPublishingJmsMessageListener getListener() {
101 | return this.listener;
102 | }
103 |
104 | @Override
105 | protected void doStart() {
106 | this.endpoint.start();
107 | }
108 |
109 | @Override
110 | protected void doStop() {
111 | this.endpoint.stop();
112 | }
113 |
114 | @Override
115 | public void destroy() throws Exception {
116 | this.endpoint.destroy();
117 | }
118 |
119 | @Override
120 | public int beforeShutdown() {
121 | return this.endpoint.beforeShutdown();
122 | }
123 |
124 | @Override
125 | public int afterShutdown() {
126 | return this.endpoint.afterShutdown();
127 | }
128 |
129 | }
130 |
--------------------------------------------------------------------------------