├── .gitignore ├── src └── site │ ├── resources │ ├── images │ │ ├── chain-logo-white.png │ │ └── chain-logo-white.xcf │ └── download_chain.cgi │ ├── site.xml │ └── xdoc │ └── building.xml ├── NOTICE.txt ├── apps ├── example1 │ ├── README.txt │ ├── src │ │ └── main │ │ │ ├── webapp │ │ │ ├── WEB-INF │ │ │ │ ├── classes │ │ │ │ │ └── log4j.properties │ │ │ │ └── web.xml │ │ │ ├── pathinfo.jsp │ │ │ ├── servletpath.jsp │ │ │ ├── reqparam.jsp │ │ │ └── index.jsp │ │ │ └── java │ │ │ └── org │ │ │ └── apache │ │ │ └── commons │ │ │ └── chain2 │ │ │ └── apps │ │ │ └── example │ │ │ └── CountCommand.java │ └── pom.xml ├── example2 │ ├── README.txt │ ├── src │ │ └── main │ │ │ ├── webapp │ │ │ ├── WEB-INF │ │ │ │ ├── classes │ │ │ │ │ └── log4j.properties │ │ │ │ └── web.xml │ │ │ ├── pathinfo.jsp │ │ │ ├── servletpath.jsp │ │ │ ├── reqparam.jsp │ │ │ └── index.jsp │ │ │ └── java │ │ │ └── org │ │ │ └── apache │ │ │ └── commons │ │ │ └── chain2 │ │ │ └── apps │ │ │ └── example │ │ │ └── CountCommand.java │ └── pom.xml ├── cookbook-examples │ ├── src │ │ ├── main │ │ │ ├── java │ │ │ │ └── org │ │ │ │ │ └── apache │ │ │ │ │ └── commons │ │ │ │ │ └── chain2 │ │ │ │ │ └── cookbook │ │ │ │ │ ├── agility │ │ │ │ │ ├── Response.java │ │ │ │ │ ├── RequestHandler.java │ │ │ │ │ ├── Request.java │ │ │ │ │ ├── ProcessException.java │ │ │ │ │ ├── Controller.java │ │ │ │ │ └── impl │ │ │ │ │ │ ├── ResponseContext.java │ │ │ │ │ │ ├── RequestContext.java │ │ │ │ │ │ ├── ControllerCatalog.java │ │ │ │ │ │ └── HandlerCommand.java │ │ │ │ │ ├── profile │ │ │ │ │ ├── Profile.java │ │ │ │ │ ├── ProfileContext.java │ │ │ │ │ └── ProfileCheck.java │ │ │ │ │ └── mailreader │ │ │ │ │ ├── commands │ │ │ │ │ ├── LogonUser.java │ │ │ │ │ ├── ProfileCheck.java │ │ │ │ │ └── LocaleChange.java │ │ │ │ │ ├── MailReader.java │ │ │ │ │ └── MailReaderServlet.java │ │ │ ├── resources │ │ │ │ └── chain │ │ │ │ │ └── catalog.xml │ │ │ └── webapp │ │ │ │ └── WEB-INF │ │ │ │ └── web.xml │ │ └── test │ │ │ └── java │ │ │ └── org │ │ │ └── apache │ │ │ └── commons │ │ │ └── chain2 │ │ │ └── cookbook │ │ │ ├── profile │ │ │ └── ProfileCheckTest.java │ │ │ ├── agility │ │ │ └── ProcessingTest.java │ │ │ └── mailreader │ │ │ └── LocaleValueTest.java │ └── pom.xml └── pom.xml ├── dist ├── src │ └── main │ │ └── assembly │ │ ├── NOTICE.txt │ │ ├── src.xml │ │ └── bin.xml └── pom.xml ├── SECURITY.md ├── CODE_OF_CONDUCT.md ├── .github ├── GH-ROBOTS.txt └── workflows │ └── maven.yml ├── base ├── src │ ├── main │ │ └── java │ │ │ └── org │ │ │ └── apache │ │ │ └── commons │ │ │ └── chain2 │ │ │ ├── impl │ │ │ ├── package-info.java │ │ │ └── ContextMap.java │ │ │ └── base │ │ │ ├── package-info.java │ │ │ ├── DispatchException.java │ │ │ ├── RemoveCommand.java │ │ │ └── OverrideCommand.java │ └── test │ │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── chain2 │ │ ├── impl │ │ └── TestContext.java │ │ └── base │ │ ├── RemoveCommandTestCase.java │ │ └── OverrideCommandTestCase.java └── pom.xml ├── configuration ├── xml │ ├── src │ │ ├── main │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── apache │ │ │ │ └── commons │ │ │ │ └── chain2 │ │ │ │ └── config │ │ │ │ └── xml │ │ │ │ └── package-info.java │ │ └── test │ │ │ └── java │ │ │ └── org │ │ │ └── apache │ │ │ └── commons │ │ │ └── chain2 │ │ │ └── config │ │ │ └── xml │ │ │ ├── TestChain.java │ │ │ └── TestCommand.java │ └── pom.xml └── api │ ├── src │ └── main │ │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── chain2 │ │ └── config │ │ ├── package-info.java │ │ ├── ChainConfigurationException.java │ │ └── ConfigParser.java │ └── pom.xml ├── web └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── chain2 │ │ └── web │ │ ├── portlet │ │ ├── package-info.java │ │ ├── PortletGetLocaleCommand.java │ │ └── PortletSetLocaleCommand.java │ │ ├── servlet │ │ ├── package-info.java │ │ ├── ServletGetLocaleCommand.java │ │ └── ServletSetLocaleCommand.java │ │ ├── faces │ │ ├── package-info.java │ │ ├── FacesGetLocaleCommand.java │ │ └── FacesSetLocaleCommand.java │ │ ├── package-info.java │ │ └── WebContextBase.java │ └── test │ └── java │ └── org │ └── apache │ └── commons │ └── chain2 │ └── web │ ├── MockEnumeration.java │ ├── MockPrincipal.java │ └── ChainResourcesTestCase.java ├── api ├── src │ └── main │ │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── chain2 │ │ ├── NamedCommandSetter.java │ │ ├── ToExecutorCommandSetter.java │ │ ├── package-info.java │ │ ├── NameSetter.java │ │ ├── CommandSetter.java │ │ ├── Processing.java │ │ ├── ChainExecutor.java │ │ └── Catalog.java └── pom.xml ├── test-utils ├── src │ ├── test │ │ └── java │ │ │ └── org │ │ │ └── apache │ │ │ └── commons │ │ │ └── chain2 │ │ │ └── testutils │ │ │ ├── TestContext.java │ │ │ ├── TestCatalog.java │ │ │ ├── HasLogTestCase.java │ │ │ ├── HasCommandCountTestCase.java │ │ │ └── NonDelegatingCommandTestCase.java │ └── main │ │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── chain2 │ │ └── testutils │ │ ├── DelegatingCommand.java │ │ ├── ExceptionCommand.java │ │ ├── DelegatingFilter.java │ │ ├── NullReturningCommand.java │ │ ├── ExceptionFilter.java │ │ ├── AddingCommand.java │ │ ├── HasLog.java │ │ ├── NonDelegatingFilter.java │ │ └── HasCommandCount.java └── pom.xml ├── .asf.yaml └── maven.yml /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | **/.settings/ 3 | **/.project 4 | **/.classpath 5 | **/*.iml 6 | -------------------------------------------------------------------------------- /src/site/resources/images/chain-logo-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-chain/HEAD/src/site/resources/images/chain-logo-white.png -------------------------------------------------------------------------------- /src/site/resources/images/chain-logo-white.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-chain/HEAD/src/site/resources/images/chain-logo-white.xcf -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | Apache Commons Chain 2 | Copyright 2003-2023 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | -------------------------------------------------------------------------------- /src/site/resources/download_chain.cgi: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Just call the standard mirrors.cgi script. It will use download.html 3 | # as the input template. 4 | exec /www/www.apache.org/dyn/mirrors/mirrors.cgi $* -------------------------------------------------------------------------------- /apps/example1/README.txt: -------------------------------------------------------------------------------- 1 | Example 1 2 | ========= 3 | An example using the ChainProcessor servlet and showing examples of 4 | using the PathInfoMapper, RequestParameterMapper and ServletPathMapper 5 | Commands to map requests to Commands. 6 | 7 | BUILDING 8 | ======== 9 | To build the example webapp you need Maven 2 installed: 10 | http://maven.apache.org/ 11 | 12 | Run the the following command to build the webapp war file: 13 | 14 | mvn package -------------------------------------------------------------------------------- /dist/src/main/assembly/NOTICE.txt: -------------------------------------------------------------------------------- 1 | Apache Commons Chain 2 | Copyright 2001-2023 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | This product includes software - CGLIB - developed by 8 | Juozas Baliuka, Chris Nokleberg and Sam Berlin (http://cglib.sourceforge.net/) 9 | 10 | ASM - Copyright (c) 2000-2011 INRIA, France Telecom 11 | All rights reserved. (http://asm.ow2.org/) 12 | -------------------------------------------------------------------------------- /apps/example2/README.txt: -------------------------------------------------------------------------------- 1 | Example 2 2 | ========= 3 | An example using the ChainListener to load configuration data and a custom 4 | servlet (ExampleServlet) and showing examples of using the PathInfoMapper, 5 | RequestParameterMapper and ServletPathMapper Commands to map requests to Commands. 6 | 7 | BUILDING 8 | ======== 9 | To build the example webapp you need Maven 2 installed: 10 | http://maven.apache.org/ 11 | 12 | Run the the following command to build the webapp war file: 13 | 14 | mvn package -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 17 | The Apache Commons security page is [https://commons.apache.org/security.html](https://commons.apache.org/security.html). 18 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 17 | The Apache code of conduct page is [https://www.apache.org/foundation/policies/conduct.html](https://www.apache.org/foundation/policies/conduct.html). 18 | -------------------------------------------------------------------------------- /.github/GH-ROBOTS.txt: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://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 | # Keeps on creating FUD PRs in test code 17 | # Does not follow Apache disclosure policies 18 | User-agent: JLLeitschuh/security-research 19 | Disallow: * 20 | -------------------------------------------------------------------------------- /apps/cookbook-examples/src/main/java/org/apache/commons/chain2/cookbook/agility/Response.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.cookbook.agility; 18 | 19 | /** 20 | */ 21 | public interface Response { 22 | 23 | String getName(); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /base/src/main/java/org/apache/commons/chain2/impl/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Convenient base implementations of Chain of Responsibility Pattern 20 | * contracts from org.apache.commons.chain2. 21 | */ 22 | package org.apache.commons.chain2.impl; 23 | -------------------------------------------------------------------------------- /apps/cookbook-examples/src/main/java/org/apache/commons/chain2/cookbook/profile/Profile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.cookbook.profile; 18 | 19 | /** 20 | */ 21 | public class Profile { 22 | 23 | public static final String PROFILE_KEY = "profile"; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /configuration/xml/src/main/java/org/apache/commons/chain2/config/xml/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Optional package for configuring command chains in a catalog 20 | * (using Digester) from an XML configuration file. 21 | */ 22 | package org.apache.commons.chain2.config.xml; 23 | -------------------------------------------------------------------------------- /web/src/main/java/org/apache/commons/chain2/web/portlet/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Specialized Context and Command implementations 20 | * suitable for use in a Portlet API environment. 21 | */ 22 | package org.apache.commons.chain2.web.portlet; 23 | -------------------------------------------------------------------------------- /web/src/main/java/org/apache/commons/chain2/web/servlet/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Specialized Context and Command implementations 20 | * suitable for use in a Servlet API environment. 21 | */ 22 | package org.apache.commons.chain2.web.servlet; 23 | -------------------------------------------------------------------------------- /base/src/main/java/org/apache/commons/chain2/base/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Concrete implementations of generic Commands that are useful in many 20 | * different environments, not tied to a particular tier such as Servlets). 21 | */ 22 | package org.apache.commons.chain2.base; 23 | -------------------------------------------------------------------------------- /web/src/main/java/org/apache/commons/chain2/web/faces/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Specialized Context and Command implementations 20 | * suitable for use in a JavaServer Faces API environment. 21 | */ 22 | package org.apache.commons.chain2.web.faces; 23 | -------------------------------------------------------------------------------- /apps/cookbook-examples/src/main/java/org/apache/commons/chain2/cookbook/agility/RequestHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.cookbook.agility; 18 | 19 | /** 20 | */ 21 | public interface RequestHandler { 22 | 23 | String getName(); 24 | 25 | void handle(Request request); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /configuration/api/src/main/java/org/apache/commons/chain2/config/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Compile-time only API package that acts as a facade. This package provides 20 | * an implementation used for compile only that provides no functionality. 21 | */ 22 | package org.apache.commons.chain2.config; 23 | -------------------------------------------------------------------------------- /apps/cookbook-examples/src/main/java/org/apache/commons/chain2/cookbook/agility/Request.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.cookbook.agility; 18 | 19 | /** 20 | */ 21 | public interface Request { 22 | 23 | String getName(); 24 | 25 | Response getResponse(); 26 | 27 | void setResponse(Response response); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /web/src/main/java/org/apache/commons/chain2/web/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Basis for specialized Context implementations suitable for use 20 | * in web applications, and generic Command implementations useful 21 | * across web application environments. 22 | */ 23 | package org.apache.commons.chain2.web; 24 | -------------------------------------------------------------------------------- /apps/cookbook-examples/src/main/java/org/apache/commons/chain2/cookbook/agility/ProcessException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.cookbook.agility; 18 | 19 | /** 20 | */ 21 | public class ProcessException extends RuntimeException { 22 | 23 | public ProcessException(Throwable cause) { 24 | super(cause); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /apps/cookbook-examples/src/main/java/org/apache/commons/chain2/cookbook/agility/Controller.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.cookbook.agility; 18 | 19 | /** 20 | */ 21 | public interface Controller { 22 | 23 | void addHandler(RequestHandler handler); 24 | 25 | RequestHandler getHandler(String name); 26 | 27 | void process(Request request); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /apps/cookbook-examples/src/main/resources/chain/catalog.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /api/src/main/java/org/apache/commons/chain2/NamedCommandSetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2; 18 | 19 | import java.util.Map; 20 | 21 | /** 22 | * Allows adding a command in a {@link Catalog} identified by a name. 23 | * 24 | * @param Context key type 25 | * @param Context value type 26 | * @param Type of the context associated with this command setter 27 | * @since 2.0 28 | */ 29 | public interface NamedCommandSetter> 30 | extends CommandSetter> { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /api/src/main/java/org/apache/commons/chain2/ToExecutorCommandSetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2; 18 | 19 | import java.util.Map; 20 | 21 | /** 22 | * First builder that allows adding a command in the target chain. 23 | * 24 | * @param Context key type 25 | * @param Context value type 26 | * @param Type of the context associated with this chain executor 27 | * @since 2.0 28 | */ 29 | public interface ToExecutorCommandSetter> 30 | extends CommandSetter> { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /apps/cookbook-examples/src/main/java/org/apache/commons/chain2/cookbook/profile/ProfileContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.cookbook.profile; 18 | 19 | import org.apache.commons.chain2.impl.ContextBase; 20 | 21 | /** 22 | */ 23 | public class ProfileContext extends ContextBase { 24 | 25 | private Profile profile; 26 | 27 | public ProfileContext() { 28 | } 29 | 30 | public Profile getProfile() { 31 | return profile; 32 | } 33 | 34 | public void setProfile(Profile profile) { 35 | this.profile = profile; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /test-utils/src/test/java/org/apache/commons/chain2/testutils/TestContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.chain2.testutils; 19 | 20 | import java.util.HashMap; 21 | import org.apache.commons.chain2.Context; 22 | 23 | /** 24 | * Since we can not import classes from modules that depend on test utils (eg chain2-base) 25 | * we have to implement a test context here. 26 | * 27 | */ 28 | public class TestContext extends HashMap implements Context { 29 | @Override 30 | public T retrieve(K key) { 31 | return (T) get(key); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /api/src/main/java/org/apache/commons/chain2/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * The fundamental API contracts for the Chain of Responsibilty Pattern as 20 | * implemented in this package. See 21 | * org.apache.commons.chain2.impl for 22 | * convenient base implementations of Chain and Context, 23 | * and see org.apache.commons.chain2.web for 24 | * specialized Context implementations suitable for use in web 25 | * applications. 26 | */ 27 | package org.apache.commons.chain2; 28 | -------------------------------------------------------------------------------- /apps/cookbook-examples/src/main/java/org/apache/commons/chain2/cookbook/agility/impl/ResponseContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.cookbook.agility.impl; 18 | 19 | import org.apache.commons.chain2.cookbook.agility.Response; 20 | import org.apache.commons.chain2.impl.ContextBase; 21 | 22 | /** 23 | */ 24 | public class ResponseContext extends ContextBase implements Response { 25 | 26 | private final String name; 27 | 28 | public ResponseContext(String name) { 29 | this.name = name; 30 | } 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /configuration/xml/src/test/java/org/apache/commons/chain2/config/xml/TestChain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.config.xml; 18 | 19 | 20 | import org.apache.commons.chain2.Context; 21 | import org.apache.commons.chain2.impl.ChainBase; 22 | 23 | 24 | /** 25 | *

Test implementation of Chain that exposes the 26 | * getCommands() method publicy.

27 | */ 28 | 29 | public class TestChain extends ChainBase> { 30 | 31 | 32 | /*public Command[] getCommands() { 33 | 34 | return (commands); 35 | 36 | }*/ 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /.asf.yaml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://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 | github: 17 | description: "Apache Commons Chain (Dormant)" 18 | homepage: https://commons.apache.org/chain/ 19 | 20 | notifications: 21 | commits: commits@commons.apache.org 22 | issues: issues@commons.apache.org 23 | pullrequests: issues@commons.apache.org 24 | jira_options: link label 25 | jobs: notifications@commons.apache.org 26 | issues_bot_dependabot: notifications@commons.apache.org 27 | pullrequests_bot_dependabot: notifications@commons.apache.org 28 | issues_bot_codecov-commenter: notifications@commons.apache.org 29 | pullrequests_bot_codecov-commenter: notifications@commons.apache.org 30 | -------------------------------------------------------------------------------- /apps/cookbook-examples/src/main/java/org/apache/commons/chain2/cookbook/profile/ProfileCheck.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.cookbook.profile; 18 | 19 | import org.apache.commons.chain2.Command; 20 | import org.apache.commons.chain2.Processing; 21 | 22 | /** 23 | */ 24 | public class ProfileCheck implements Command { 25 | 26 | public Profile newProfile(ProfileContext context) { return new Profile(); } 27 | 28 | public Processing execute(ProfileContext context) { 29 | Profile profile = context.getProfile(); 30 | 31 | if (null == profile) { 32 | context.setProfile(newProfile(context)); 33 | } 34 | return Processing.CONTINUE; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /apps/cookbook-examples/src/test/java/org/apache/commons/chain2/cookbook/profile/ProfileCheckTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.cookbook.profile; 18 | 19 | import org.apache.commons.chain2.Command; 20 | import org.junit.Test; 21 | import static org.junit.Assert.assertNotNull; 22 | 23 | public class ProfileCheckTest { 24 | 25 | @Test 26 | public void testProfileCheckNeed() { 27 | 28 | ProfileContext context = new ProfileContext(); 29 | Command command = new ProfileCheck(); 30 | 31 | command.execute(context); 32 | 33 | Profile profile = context.getProfile(); 34 | assertNotNull("Missing org.apache.commons.chain2.cookbook.profile.Profile", profile); 35 | } 36 | } -------------------------------------------------------------------------------- /configuration/api/src/main/java/org/apache/commons/chain2/config/ChainConfigurationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.config; 18 | 19 | /** 20 | * Runtime exception representing an exception that occurred during a 21 | * configuration phase within a chain component. 22 | * 23 | */ 24 | public class ChainConfigurationException extends RuntimeException { 25 | 26 | public ChainConfigurationException() { 27 | } 28 | 29 | public ChainConfigurationException(String message) { 30 | super(message); 31 | } 32 | 33 | public ChainConfigurationException(String message, Throwable cause) { 34 | super(message, cause); 35 | } 36 | 37 | public ChainConfigurationException(Throwable cause) { 38 | super(cause); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /api/src/main/java/org/apache/commons/chain2/NameSetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2; 18 | 19 | import java.util.Map; 20 | 21 | /** 22 | * Allows specifying a name for a {@link Command} in a {@link Catalog} instance. 23 | * 24 | * @param Context key type 25 | * @param Context value type 26 | * @param Type of the context associated with this name setter 27 | * @since 2.0 28 | */ 29 | public interface NameSetter> { 30 | 31 | /** 32 | * Specifies a name for a {@link Command} in a {@link Catalog} instance. 33 | * 34 | * @param name the name of the previous set {@link Command} 35 | * @return a new builder to add a new {@link Command} 36 | */ 37 | NamedCommandSetter identifiedBy(String name); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /web/src/test/java/org/apache/commons/chain2/web/MockEnumeration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.web; 18 | 19 | 20 | import java.util.Enumeration; 21 | import java.util.Iterator; 22 | 23 | 24 | /** 25 | *

General purpose Enumeration wrapper around an 26 | * Iterator specified to our controller.

27 | */ 28 | 29 | public class MockEnumeration implements Enumeration { 30 | 31 | 32 | public MockEnumeration(Iterator iterator) { 33 | this.iterator = iterator; 34 | } 35 | 36 | 37 | protected Iterator iterator; 38 | 39 | 40 | public boolean hasMoreElements() { 41 | return (iterator.hasNext()); 42 | } 43 | 44 | 45 | public E nextElement() { 46 | return (iterator.next()); 47 | } 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /dist/src/main/assembly/src.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | src 21 | 22 | tar.gz 23 | zip 24 | 25 | ${project.build.finalName}-src 26 | 27 | 28 | ${basedir}/../ 29 | 30 | **/.classpath 31 | **/.project 32 | **/.settings/ 33 | **/target/ 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /apps/cookbook-examples/src/main/java/org/apache/commons/chain2/cookbook/mailreader/commands/LogonUser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.cookbook.mailreader.commands; 18 | 19 | import org.apache.commons.chain2.Command; 20 | import org.apache.commons.chain2.Processing; 21 | import org.apache.commons.chain2.cookbook.mailreader.MailReader; 22 | 23 | import java.io.IOException; 24 | 25 | /** 26 | */ 27 | public class LogonUser implements Command { 28 | 29 | public LogonUser() { 30 | } 31 | 32 | public Processing execute(MailReader mailReader) { 33 | try { 34 | mailReader.getLogger().write("LogonUser.execute"); 35 | } catch (IOException ioe) { 36 | throw new RuntimeException(ioe); 37 | } 38 | 39 | return Processing.CONTINUE; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /apps/cookbook-examples/src/main/java/org/apache/commons/chain2/cookbook/mailreader/commands/ProfileCheck.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.cookbook.mailreader.commands; 18 | 19 | import org.apache.commons.chain2.Command; 20 | import org.apache.commons.chain2.Processing; 21 | import org.apache.commons.chain2.cookbook.mailreader.MailReader; 22 | 23 | import java.io.IOException; 24 | 25 | /** 26 | */ 27 | public class ProfileCheck implements Command { 28 | 29 | public ProfileCheck() { 30 | } 31 | 32 | public Processing execute(MailReader mailReader) { 33 | try { 34 | mailReader.getLogger().write("ProfileCheck.execute\n"); 35 | } catch (IOException ioe) { 36 | throw new RuntimeException(ioe); 37 | } 38 | 39 | return Processing.CONTINUE; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /apps/cookbook-examples/src/main/java/org/apache/commons/chain2/cookbook/agility/impl/RequestContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.cookbook.agility.impl; 18 | 19 | import org.apache.commons.chain2.cookbook.agility.Request; 20 | import org.apache.commons.chain2.cookbook.agility.Response; 21 | import org.apache.commons.chain2.impl.ContextBase; 22 | 23 | /** 24 | */ 25 | public class RequestContext extends ContextBase implements Request { 26 | 27 | private final String name; 28 | 29 | private Response response; 30 | 31 | public RequestContext(String name) { 32 | this.name = name; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public Response getResponse() { 40 | return response; 41 | } 42 | 43 | public void setResponse(Response response) { 44 | this.response = response; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /apps/cookbook-examples/src/main/java/org/apache/commons/chain2/cookbook/mailreader/MailReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.cookbook.mailreader; 18 | 19 | import org.apache.commons.chain2.impl.ContextBase; 20 | 21 | import java.io.Writer; 22 | import java.util.Locale; 23 | 24 | /** 25 | */ 26 | public class MailReader extends ContextBase { 27 | 28 | public static final String LOCALE_KEY = "locale"; 29 | 30 | private Writer logger; 31 | 32 | private Locale locale; 33 | 34 | public MailReader() { 35 | 36 | } 37 | 38 | public Locale getLocale() { 39 | return locale; 40 | } 41 | public void setLocale(Locale locale) { 42 | this.locale = locale; 43 | } 44 | 45 | public Writer getLogger() { 46 | return logger; 47 | } 48 | 49 | public void setLogger(Writer logger) { 50 | this.logger = logger; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /api/src/main/java/org/apache/commons/chain2/CommandSetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2; 18 | 19 | import java.util.Map; 20 | 21 | /** 22 | * Generic builder that allows adding commands to the target {@link Chain} has to be executed. 23 | * 24 | * @param Context key type 25 | * @param Context value type 26 | * @param Type of the context associated with this command setter 27 | * @param Type of the next chain builder 28 | * @since 2.0 29 | */ 30 | public interface CommandSetter, R> { 31 | 32 | /** 33 | * Add the given command to the target {@link Chain} has to be executed. 34 | * 35 | * @param Type of the command has to be added 36 | * @param command the command has to be added in the target chain 37 | * @return next chain builder 38 | * @see Chain#addCommand(Command) 39 | */ 40 | > R add(CMD command); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /apps/cookbook-examples/src/main/java/org/apache/commons/chain2/cookbook/mailreader/commands/LocaleChange.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.cookbook.mailreader.commands; 18 | 19 | import org.apache.commons.chain2.Command; 20 | import org.apache.commons.chain2.Processing; 21 | import org.apache.commons.chain2.cookbook.mailreader.MailReader; 22 | 23 | import java.io.IOException; 24 | import java.io.Writer; 25 | 26 | /** 27 | */ 28 | public class LocaleChange implements Command { 29 | 30 | public LocaleChange() { 31 | } 32 | 33 | public Processing execute(MailReader mailReader) { 34 | try { 35 | Writer logger = mailReader.getLogger(); 36 | logger.write("LocaleChange.execute "); 37 | logger.write("[Locale is: " + mailReader.getLocale() + "]\n"); 38 | } catch (IOException ioe) { 39 | throw new RuntimeException(ioe); 40 | } 41 | 42 | return Processing.CONTINUE; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /test-utils/src/test/java/org/apache/commons/chain2/testutils/TestCatalog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.chain2.testutils; 19 | 20 | import java.util.HashMap; 21 | import java.util.Iterator; 22 | import java.util.Map; 23 | 24 | import org.apache.commons.chain2.Catalog; 25 | import org.apache.commons.chain2.Command; 26 | import org.apache.commons.chain2.Context; 27 | 28 | /** 29 | */ 30 | public class TestCatalog> implements Catalog { 31 | 32 | Map commands = new HashMap(); 33 | 34 | @Override 35 | public > void addCommand(String name, CMD command) { 36 | commands.put(name, command); 37 | } 38 | 39 | @Override 40 | public > CMD getCommand(String name) { 41 | return (CMD) commands.get(name); 42 | } 43 | 44 | @Override 45 | public Iterator getNames() { 46 | return commands.keySet().iterator(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /configuration/xml/src/test/java/org/apache/commons/chain2/config/xml/TestCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.config.xml; 18 | 19 | 20 | import org.apache.commons.chain2.Command; 21 | import org.apache.commons.chain2.Context; 22 | import org.apache.commons.chain2.Processing; 23 | 24 | 25 | /** 26 | *

Test implementation of Command that exposes 27 | * configurable properties.

28 | */ 29 | 30 | public class TestCommand implements Command> { 31 | 32 | 33 | private String bar = null; 34 | public String getBar() { 35 | return (this.bar); 36 | } 37 | public void setBar(String bar) { 38 | this.bar = bar; 39 | } 40 | 41 | 42 | private String foo = null; 43 | public String getFoo() { 44 | return (this.foo); 45 | } 46 | public void setFoo(String foo) { 47 | this.foo = foo; 48 | } 49 | 50 | 51 | public Processing execute(Context context) { 52 | return Processing.CONTINUE; 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /api/src/main/java/org/apache/commons/chain2/Processing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2; 18 | 19 | /** 20 | * A Processing encapsulates states that can be returned by 21 | * commands. 22 | *

23 | * {@link Command}s should either return FINISHED if the 24 | * processing of the given context has been completed, or return 25 | * CONTINUE if the processing of the given {@link Context} should 26 | * be delegated to a subsequent command in an enclosing {@link Chain}. 27 | * 28 | */ 29 | public enum Processing { 30 | 31 | /** 32 | * Commands should return continue if the processing of the given 33 | * context should be delegated to a subsequent command in an enclosing chain. 34 | * 35 | * @since 2.0 36 | */ 37 | CONTINUE, 38 | 39 | /** 40 | * Commands should return finished if the processing of the given context 41 | * has been completed. 42 | * 43 | * @since 2.0 44 | */ 45 | FINISHED; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /api/src/main/java/org/apache/commons/chain2/ChainExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2; 18 | 19 | import java.util.Map; 20 | 21 | /** 22 | * Builder that allows continue adding a command in the target chain and execute it. 23 | * 24 | * @param Context key type 25 | * @param Context value type 26 | * @param Type of the context associated with this chain executor 27 | * @since 2.0 28 | */ 29 | public interface ChainExecutor> extends CommandSetter> { 30 | 31 | /** 32 | * Execute the processing represented by the target chain. 33 | * 34 | * @param context the context processed by the target chain 35 | * @return {@link Processing#FINISHED} if the processing of this context 36 | * has been completed. Returns {@link Processing#CONTINUE} if the processing 37 | * of this context should be delegated to a subsequent command in an 38 | * enclosing chain. 39 | * 40 | * @see Chain#execute(Map) 41 | */ 42 | Processing execute(C context); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /apps/cookbook-examples/src/test/java/org/apache/commons/chain2/cookbook/agility/ProcessingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.cookbook.agility; 18 | 19 | import org.apache.commons.chain2.cookbook.agility.impl.ControllerCatalog; 20 | import org.apache.commons.chain2.cookbook.agility.impl.HandlerCommand; 21 | import org.apache.commons.chain2.cookbook.agility.impl.RequestContext; 22 | import org.junit.Test; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.junit.Assert.assertNotNull; 26 | 27 | public class ProcessingTest { 28 | 29 | @Test 30 | public void testRequestResponseName() { 31 | String NAME = "TestProcessing"; 32 | 33 | Controller controller = new ControllerCatalog(); 34 | 35 | RequestHandler handler = new HandlerCommand(NAME); 36 | controller.addHandler(handler); 37 | Request request = new RequestContext(NAME); 38 | controller.process(request); 39 | Response response = request.getResponse(); 40 | 41 | assertNotNull(response); 42 | assertEquals(NAME, response.getName()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /web/src/main/java/org/apache/commons/chain2/web/portlet/PortletGetLocaleCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.web.portlet; 18 | 19 | import org.apache.commons.chain2.Context; 20 | import org.apache.commons.chain2.web.AbstractGetLocaleCommand; 21 | 22 | import javax.portlet.PortletRequest; 23 | import java.util.Locale; 24 | 25 | /** 26 | *

Concrete implementation of {@link AbstractGetLocaleCommand} for 27 | * the Portlet API.

28 | * 29 | */ 30 | public class PortletGetLocaleCommand 31 | extends AbstractGetLocaleCommand { 32 | 33 | // ------------------------------------------------------- Protected Methods 34 | 35 | /** 36 | *

Retrieve and return the Locale for this request.

37 | * 38 | * @param context The {@link Context} we are operating on. 39 | * @return The Locale for the request. 40 | */ 41 | @Override 42 | protected Locale getLocale(PortletWebContext context) { 43 | PortletRequest request = (PortletRequest)context.get("request"); 44 | return (request.getLocale()); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /web/src/main/java/org/apache/commons/chain2/web/faces/FacesGetLocaleCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.web.faces; 18 | 19 | import org.apache.commons.chain2.Context; 20 | import org.apache.commons.chain2.web.AbstractGetLocaleCommand; 21 | 22 | import javax.faces.context.FacesContext; 23 | import java.util.Locale; 24 | 25 | /** 26 | *

Concrete implementation of {@link AbstractGetLocaleCommand} for 27 | * the JavaServer Faces API.

28 | * 29 | */ 30 | public class FacesGetLocaleCommand 31 | extends AbstractGetLocaleCommand { 32 | 33 | // ------------------------------------------------------- Protected Methods 34 | 35 | /** 36 | *

Retrieve and return the Locale for this request.

37 | * 38 | * @param context The {@link Context} we are operating on. 39 | * @return The Locale for the request. 40 | */ 41 | @Override 42 | protected Locale getLocale(FacesWebContext context) { 43 | FacesContext fcontext = (FacesContext)context.get("context"); 44 | return (fcontext.getViewRoot().getLocale()); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /base/src/main/java/org/apache/commons/chain2/base/DispatchException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.base; 18 | 19 | import org.apache.commons.chain2.ChainException; 20 | import org.apache.commons.chain2.Command; 21 | 22 | import java.util.Map; 23 | 24 | /** 25 | * Runtime Exception that wraps an underlying exception thrown during the 26 | * execution of a {@link org.apache.commons.chain2.Command} or {@link org.apache.commons.chain2.Chain}. 27 | * 28 | */ 29 | public class DispatchException extends ChainException { 30 | 31 | /** 32 | * 33 | */ 34 | private static final long serialVersionUID = 20120724L; 35 | 36 | public DispatchException(String message) { 37 | super(message); 38 | } 39 | 40 | public DispatchException(String message, Throwable cause) { 41 | super(message, cause); 42 | } 43 | 44 | public > DispatchException(String message, Throwable cause, 45 | C context, Command failedCommand) { 46 | super(message, cause, context, failedCommand); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /maven.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://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 | name: Java CI 17 | 18 | on: [push, pull_request] 19 | 20 | permissions: 21 | contents: read 22 | 23 | jobs: 24 | build: 25 | 26 | runs-on: ubuntu-latest 27 | continue-on-error: ${{ matrix.experimental }} 28 | strategy: 29 | matrix: 30 | java: [ 8, 11, 17 ] 31 | experimental: [false] 32 | # include: 33 | # - java: 18-ea 34 | # experimental: true 35 | 36 | steps: 37 | - uses: actions/checkout@v3.0.2 38 | with: 39 | persist-credentials: false 40 | - uses: actions/cache@v3.0.3 41 | with: 42 | path: ~/.m2/repository 43 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} 44 | restore-keys: | 45 | ${{ runner.os }}-maven- 46 | - name: Set up JDK ${{ matrix.java }} 47 | uses: actions/setup-java@v3.5.1 48 | with: 49 | distribution: 'temurin' 50 | java-version: ${{ matrix.java }} 51 | - name: Build with Maven 52 | run: mvn -V -e --no-transfer-progress 53 | 54 | # For Java 11, you can be more strict: -DadditionalJOption=-Xdoclint/package:-org.apache.commons.configuration2.plist 55 | -------------------------------------------------------------------------------- /web/src/main/java/org/apache/commons/chain2/web/faces/FacesSetLocaleCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.web.faces; 18 | 19 | import org.apache.commons.chain2.Context; 20 | import org.apache.commons.chain2.web.AbstractSetLocaleCommand; 21 | 22 | import javax.faces.context.FacesContext; 23 | import java.util.Locale; 24 | 25 | /** 26 | *

Concrete implementation of {@link AbstractSetLocaleCommand} for 27 | * the JavaServer Faces API.

28 | * 29 | * 30 | */ 31 | public class FacesSetLocaleCommand 32 | extends AbstractSetLocaleCommand { 33 | 34 | // ------------------------------------------------------- Protected Methods 35 | 36 | /** 37 | *

Establish the specified Locale for this response.

38 | * 39 | * @param context The {@link Context} we are operating on. 40 | * @param locale The Locale for the request. 41 | */ 42 | @Override 43 | protected void setLocale(FacesWebContext context, Locale locale) { 44 | FacesContext fcontext = (FacesContext)context.get("context"); 45 | fcontext.getViewRoot().setLocale(locale); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /apps/cookbook-examples/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | Apache Commons Chain Cookbook Examples 23 | 24 | 25 | 26 | org.apache.commons.chain2.CONFIG_CLASS_RESOURCE 27 | resources/chain/catalog.xml 28 | 29 | 30 | org.apache.commons.chain2.web.ChainListener 31 | 32 | 33 | 34 | mailReaderServlet 35 | org.apache.commons.chain2.cookbook.mailreader.MailReaderServlet 36 | 37 | 38 | 39 | mailReaderServlet 40 | / 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /web/src/main/java/org/apache/commons/chain2/web/servlet/ServletGetLocaleCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.web.servlet; 18 | 19 | import org.apache.commons.chain2.Context; 20 | import org.apache.commons.chain2.web.AbstractGetLocaleCommand; 21 | 22 | import javax.servlet.http.HttpServletRequest; 23 | import java.util.Locale; 24 | 25 | /** 26 | *

Concrete implementation of {@link AbstractGetLocaleCommand} for 27 | * the Servlet API.

28 | * 29 | */ 30 | public class ServletGetLocaleCommand 31 | extends AbstractGetLocaleCommand> { 32 | 33 | // ------------------------------------------------------- Protected Methods 34 | 35 | /** 36 | *

Retrieve and return the Locale for this request.

37 | * 38 | * @param context The {@link Context} we are operating on. 39 | * @return The Locale for the request. 40 | */ 41 | @Override 42 | protected Locale getLocale(ServletWebContext context) { 43 | HttpServletRequest request = (HttpServletRequest) 44 | context.get("request"); 45 | return (request.getLocale()); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /base/src/test/java/org/apache/commons/chain2/impl/TestContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.impl; 18 | 19 | /** 20 | * Subclass of ContextBase to exercize the automatic 21 | * delegation to properties of the Context class. 22 | * 23 | */ 24 | public class TestContext extends ContextBase { 25 | 26 | private static final long serialVersionUID = 20120724L; 27 | 28 | // Read-only property 29 | private String readOnly = "readOnly"; 30 | 31 | public String getReadOnly() { 32 | return (this.readOnly); 33 | } 34 | 35 | // Read-write property 36 | private String readWrite = "readWrite"; 37 | 38 | public String getReadWrite() { 39 | return (this.readWrite); 40 | } 41 | 42 | public void setReadWrite(String readWrite) { 43 | this.readWrite = readWrite; 44 | } 45 | 46 | // Write-only property 47 | private String writeOnly = "writeOnly"; 48 | 49 | // Not a JavaBeans getter 50 | public String returnWriteOnly() { 51 | return (this.writeOnly); 52 | } 53 | 54 | public void setWriteOnly(String writeOnly) { 55 | this.writeOnly = writeOnly; 56 | } 57 | 58 | } 59 | 60 | -------------------------------------------------------------------------------- /test-utils/src/main/java/org/apache/commons/chain2/testutils/DelegatingCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.testutils; 18 | 19 | 20 | import org.apache.commons.chain2.Command; 21 | import org.apache.commons.chain2.Context; 22 | import org.apache.commons.chain2.Processing; 23 | 24 | 25 | /** 26 | *

Implementation of {@link Command} that logs its identifier and 27 | * and delegates to the rest of the chain.

28 | * 29 | */ 30 | 31 | public class DelegatingCommand extends NonDelegatingCommand { 32 | 33 | 34 | // ------------------------------------------------------------ Constructor 35 | 36 | 37 | public DelegatingCommand() { 38 | this(""); 39 | } 40 | 41 | 42 | // Construct an instance that will log the specified identifier 43 | public DelegatingCommand(String id) { 44 | super(id); 45 | } 46 | 47 | 48 | // -------------------------------------------------------- Command Methods 49 | 50 | 51 | // Execution method for this Command 52 | @Override 53 | public Processing execute(Context context) { 54 | 55 | super.execute(context); 56 | return Processing.CONTINUE; 57 | 58 | } 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /web/src/main/java/org/apache/commons/chain2/web/servlet/ServletSetLocaleCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.web.servlet; 18 | 19 | import org.apache.commons.chain2.Context; 20 | import org.apache.commons.chain2.web.AbstractSetLocaleCommand; 21 | 22 | import javax.servlet.http.HttpServletResponse; 23 | import java.util.Locale; 24 | 25 | /** 26 | *

Concrete implementation of {@link AbstractSetLocaleCommand} for 27 | * the Servlet API.

28 | * 29 | */ 30 | public class ServletSetLocaleCommand 31 | extends AbstractSetLocaleCommand> { 32 | 33 | // ------------------------------------------------------- Protected Methods 34 | 35 | /** 36 | *

Establish the specified Locale for this response.

37 | * 38 | * @param context The {@link Context} we are operating on. 39 | * @param locale The Locale for the request. 40 | */ 41 | @Override 42 | protected void setLocale(ServletWebContext context, Locale locale) { 43 | HttpServletResponse response = (HttpServletResponse) 44 | context.get("response"); 45 | response.setLocale(locale); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 22 | 4.0.0 23 | 24 | 25 | org.apache.commons 26 | commons-chain-parent 27 | 2.0-SNAPSHOT 28 | ../ 29 | 30 | 31 | commons-chain2-api 32 | 33 | Apache Commons Chain :: APIs 34 | 35 | 36 | 37 | commons-logging 38 | commons-logging 39 | 40 | 41 | 42 | 43 | 44 | 45 | ${basedir}/../ 46 | META-INF 47 | 48 | NOTICE.txt 49 | LICENSE.txt 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /test-utils/src/main/java/org/apache/commons/chain2/testutils/ExceptionCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.testutils; 18 | 19 | 20 | import org.apache.commons.chain2.Chain; 21 | import org.apache.commons.chain2.Command; 22 | import org.apache.commons.chain2.Context; 23 | 24 | 25 | /** 26 | *

Implementation of {@link Command} that logs its identifier and 27 | * and throws an Exception.

28 | * 29 | */ 30 | public class ExceptionCommand extends NonDelegatingCommand { 31 | 32 | 33 | // ------------------------------------------------------------ Constructor 34 | 35 | 36 | public ExceptionCommand() { 37 | this(""); 38 | } 39 | 40 | 41 | // Construct an instance that will log the specified identifier 42 | public ExceptionCommand(String id) { 43 | super(id); 44 | } 45 | 46 | 47 | // -------------------------------------------------------- Command Methods 48 | 49 | 50 | // Execution method for this Command 51 | public void execute(Context context, Chain> chain) { 52 | 53 | super.execute(context); 54 | throw new ArithmeticException(this.id); 55 | 56 | } 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /test-utils/src/main/java/org/apache/commons/chain2/testutils/DelegatingFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.testutils; 18 | 19 | 20 | import org.apache.commons.chain2.Context; 21 | import org.apache.commons.chain2.Filter; 22 | import org.apache.commons.chain2.Processing; 23 | 24 | 25 | /** 26 | *

Implementation of {@link Filter} that logs its identifier and 27 | * and delegates to the rest of the chain.

28 | * 29 | */ 30 | 31 | public class DelegatingFilter extends NonDelegatingFilter { 32 | 33 | 34 | // ------------------------------------------------------------ Constructor 35 | 36 | 37 | public DelegatingFilter() { 38 | this("", ""); 39 | } 40 | 41 | 42 | // Construct an instance that will log the specified identifier 43 | public DelegatingFilter(String id1, String id2) { 44 | super(id1, id2); 45 | } 46 | 47 | 48 | // -------------------------------------------------------- Command Methods 49 | 50 | 51 | // Execution method for this Command 52 | @Override 53 | public Processing execute(Context context) { 54 | 55 | super.execute(context); 56 | return Processing.CONTINUE; 57 | 58 | } 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /web/src/main/java/org/apache/commons/chain2/web/portlet/PortletSetLocaleCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.web.portlet; 18 | 19 | import org.apache.commons.chain2.Context; 20 | import org.apache.commons.chain2.web.AbstractSetLocaleCommand; 21 | 22 | import java.util.Locale; 23 | 24 | //import javax.portlet.PortletResponse; 25 | 26 | /** 27 | *

Concrete implementation of {@link AbstractSetLocaleCommand} for 28 | * the Portlet API.

29 | * 30 | */ 31 | public class PortletSetLocaleCommand 32 | extends AbstractSetLocaleCommand { 33 | 34 | // ------------------------------------------------------- Protected Methods 35 | 36 | /** 37 | *

Establish the specified Locale for this response.

38 | * 39 | * @param context The {@link Context} we are operating on. 40 | * @param locale The Locale for the request. 41 | */ 42 | @Override 43 | protected void setLocale(PortletWebContext context, Locale locale) { 44 | // PortletResponse response = (PortletResponse) 45 | // context.get("response"); 46 | // response.setLocale(locale); 47 | // Not supported by the Portlet API 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://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 | name: Java CI 17 | 18 | # on: [push, pull_request] 19 | 20 | on: workflow_dispatch 21 | 22 | permissions: 23 | contents: read 24 | 25 | jobs: 26 | build: 27 | 28 | runs-on: ubuntu-latest 29 | continue-on-error: ${{ matrix.experimental }} 30 | strategy: 31 | matrix: 32 | java: [ 8, 11, 17 ] 33 | experimental: [false] 34 | # include: 35 | # - java: 22-ea 36 | # experimental: true 37 | 38 | steps: 39 | - uses: actions/checkout@v3.0.2 40 | with: 41 | persist-credentials: false 42 | - uses: actions/cache@v3.0.3 43 | with: 44 | path: ~/.m2/repository 45 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} 46 | restore-keys: | 47 | ${{ runner.os }}-maven- 48 | - name: Set up JDK ${{ matrix.java }} 49 | uses: actions/setup-java@v3.5.1 50 | with: 51 | distribution: 'temurin' 52 | java-version: ${{ matrix.java }} 53 | - name: Build with Maven 54 | run: mvn -V -e --no-transfer-progress 55 | 56 | # For Java 11, you can be more strict: -DadditionalJOption=-Xdoclint/package:-org.apache.commons.configuration2.plist 57 | -------------------------------------------------------------------------------- /apps/example1/src/main/webapp/WEB-INF/classes/log4j.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://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 | # Properties File to control logging by Log4j # 18 | #---------------------------------------------------------# 19 | log4j.logger.org.apache.commons.chain=INFO, STD 20 | log4j.logger.org.apache.commons.digester=INFO, STD 21 | log4j.logger.org.apache.commons.beanutils=WARN, STD 22 | 23 | #---------------------------------------------------------# 24 | # Direct 'STD' logger to the 'Console' # 25 | #---------------------------------------------------------# 26 | log4j.appender.STD=org.apache.log4j.ConsoleAppender 27 | log4j.appender.STD.layout=org.apache.log4j.PatternLayout 28 | log4j.appender.STD.layout.ConversionPattern=[%c] %-5p: %m%n 29 | 30 | #---------------------------------------------------------# 31 | # Direct 'STD' logger to a log file # 32 | #---------------------------------------------------------# 33 | #log4j.appender.STD=org.apache.log4j.DailyRollingFileAppender 34 | #log4j.appender.STD.File=../logs/chain-example-log.txt 35 | #log4j.appender.STD.DatePattern='.'yyyy-MM-dd 36 | #log4j.appender.STD.layout=org.apache.log4j.PatternLayout 37 | #log4j.appender.STD.layout.ConversionPattern=%d [%c] %-5p: %m%n 38 | -------------------------------------------------------------------------------- /apps/example2/src/main/webapp/WEB-INF/classes/log4j.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://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 | # Properties File to control logging by Log4j # 18 | #---------------------------------------------------------# 19 | log4j.logger.org.apache.commons.chain=INFO, STD 20 | log4j.logger.org.apache.commons.digester=INFO, STD 21 | log4j.logger.org.apache.commons.beanutils=WARN, STD 22 | 23 | #---------------------------------------------------------# 24 | # Direct 'STD' logger to the 'Console' # 25 | #---------------------------------------------------------# 26 | log4j.appender.STD=org.apache.log4j.ConsoleAppender 27 | log4j.appender.STD.layout=org.apache.log4j.PatternLayout 28 | log4j.appender.STD.layout.ConversionPattern=[%c] %-5p: %m%n 29 | 30 | #---------------------------------------------------------# 31 | # Direct 'STD' logger to a log file # 32 | #---------------------------------------------------------# 33 | #log4j.appender.STD=org.apache.log4j.DailyRollingFileAppender 34 | #log4j.appender.STD.File=../logs/chain-example-log.txt 35 | #log4j.appender.STD.DatePattern='.'yyyy-MM-dd 36 | #log4j.appender.STD.layout=org.apache.log4j.PatternLayout 37 | #log4j.appender.STD.layout.ConversionPattern=%d [%c] %-5p: %m%n 38 | -------------------------------------------------------------------------------- /test-utils/src/main/java/org/apache/commons/chain2/testutils/NullReturningCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.testutils; 18 | 19 | 20 | import org.apache.commons.chain2.Chain; 21 | import org.apache.commons.chain2.Command; 22 | import org.apache.commons.chain2.Context; 23 | import org.apache.commons.chain2.Processing; 24 | 25 | 26 | /** 27 | * Implementation of {@link Command} that always returns null if it's executed. 28 | * 29 | */ 30 | public class NullReturningCommand extends DelegatingCommand { 31 | 32 | 33 | // ------------------------------------------------------------ Constructor 34 | 35 | 36 | public NullReturningCommand() { 37 | this(""); 38 | } 39 | 40 | 41 | // Construct an instance that will log the specified identifier 42 | public NullReturningCommand(String id) { 43 | super(id); 44 | } 45 | 46 | 47 | // -------------------------------------------------------- Command Methods 48 | 49 | @Override 50 | public Processing execute(Context context) { 51 | return null; 52 | } 53 | 54 | 55 | public Processing execute(Context context, Chain> chain) { 56 | return null; 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /apps/cookbook-examples/src/main/java/org/apache/commons/chain2/cookbook/agility/impl/ControllerCatalog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.cookbook.agility.impl; 18 | 19 | import org.apache.commons.chain2.Command; 20 | import org.apache.commons.chain2.cookbook.agility.Controller; 21 | import org.apache.commons.chain2.cookbook.agility.Request; 22 | import org.apache.commons.chain2.cookbook.agility.RequestHandler; 23 | import org.apache.commons.chain2.impl.CatalogBase; 24 | 25 | /** 26 | */ 27 | public class ControllerCatalog extends CatalogBase 28 | implements Controller { 29 | 30 | public RequestHandler getHandler(String name) { 31 | 32 | return (RequestHandler) getCommand(name); 33 | } 34 | 35 | public void addHandler(RequestHandler handler) { 36 | @SuppressWarnings("unchecked") 37 | Command command = 38 | (Command)handler; 39 | 40 | this.addCommand(handler.getName(), command); 41 | } 42 | 43 | public void process(Request request) { 44 | RequestHandler handler = getHandler(request.getName()); 45 | 46 | if (handler != null) { 47 | handler.handle(request); 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /web/src/main/java/org/apache/commons/chain2/web/WebContextBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.web; 18 | 19 | import org.apache.commons.chain2.impl.ContextBase; 20 | 21 | /** 22 | *

Abstract base implementation of {@link org.apache.commons.chain2.Context} that 23 | * provides web based applications that use it a "generic" view of HTTP related 24 | * requests and responses, without tying the application to a particular underlying 25 | * Java API (such as servlets). It is expected that a concrete subclass 26 | * of {@link WebContextBase} for each API (such as 27 | * {@link org.apache.commons.chain2.web.servlet.ServletWebContext}) 28 | * will support adapting that particular API's implementation of request 29 | * and response objects into this generic framework.

30 | * 31 | *

The characteristics of a web request/response are made visible via 32 | * a series of JavaBeans properties (and mapped to read-only attributes 33 | * of the same name, as supported by {@link ContextBase}.

34 | * 35 | */ 36 | public abstract class WebContextBase extends ContextBase 37 | implements WebContext { 38 | 39 | /** 40 | * 41 | */ 42 | private static final long serialVersionUID = 20120724L; 43 | 44 | // ---------------------------------------------------------- Public Methods 45 | 46 | } 47 | -------------------------------------------------------------------------------- /test-utils/src/test/java/org/apache/commons/chain2/testutils/HasLogTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.chain2.testutils; 19 | 20 | import static org.junit.Assert.assertFalse; 21 | import static org.junit.Assert.assertTrue; 22 | import org.apache.commons.chain2.Context; 23 | import org.hamcrest.StringDescription; 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | 27 | /** 28 | */ 29 | public class HasLogTestCase { 30 | 31 | private Context context; 32 | private HasLog matcher; 33 | 34 | @Before 35 | public void setUp() throws Exception { 36 | context = new TestContext(); 37 | matcher = new HasLog("content"); 38 | } 39 | 40 | @Test 41 | public void noLogFails() throws Exception { 42 | assertFalse(matcher.matchesSafely(context, new StringDescription())); 43 | } 44 | 45 | @Test 46 | public void logWithWrongContentFails() throws Exception { 47 | context.put("log", new StringBuilder("wrong content")); 48 | assertFalse(matcher.matchesSafely(context, new StringDescription())); 49 | } 50 | 51 | @Test 52 | public void correctContent() throws Exception { 53 | context.put("log", new StringBuilder("content")); 54 | assertTrue(matcher.matchesSafely(context, new StringDescription())); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /apps/cookbook-examples/src/main/java/org/apache/commons/chain2/cookbook/agility/impl/HandlerCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.cookbook.agility.impl; 18 | 19 | import org.apache.commons.chain2.Command; 20 | import org.apache.commons.chain2.Processing; 21 | import org.apache.commons.chain2.cookbook.agility.ProcessException; 22 | import org.apache.commons.chain2.cookbook.agility.Request; 23 | import org.apache.commons.chain2.cookbook.agility.RequestHandler; 24 | import org.apache.commons.chain2.cookbook.agility.Response; 25 | 26 | /** 27 | */ 28 | public class HandlerCommand implements Command, 29 | RequestHandler { 30 | 31 | private final String name; 32 | 33 | public HandlerCommand(String name) { 34 | this.name = name; 35 | } 36 | 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | public void handle(Request request) { 42 | try { 43 | String name = request.getName(); 44 | Response response = new ResponseContext(name); 45 | request.setResponse(response); 46 | } catch (Exception e) { 47 | throw new ProcessException(e); 48 | } 49 | } 50 | 51 | public Processing execute(RequestContext requestContext) { 52 | handle(requestContext); 53 | 54 | return Processing.CONTINUE; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /dist/src/main/assembly/bin.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | bin 21 | 22 | tar.gz 23 | zip 24 | 25 | ${project.build.finalName}-bin 26 | false 27 | 28 | 29 | 30 | ${basedir}/src/main/assembly/LICENSE.txt 31 | LICENSE.txt 32 | 33 | 34 | ${basedir}/src/main/assembly/NOTICE.txt 35 | NOTICE.txt 36 | 37 | 38 | ${basedir}/../RELEASE-NOTES.txt 39 | 40 | 41 | 42 | 43 | ${basedir}/../target/site/apidocs 44 | apidocs 45 | 46 | 47 | 48 | 49 | 50 | false 51 | true 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /apps/example1/src/main/webapp/pathinfo.jsp: -------------------------------------------------------------------------------- 1 | 19 | <%@ page language="java"%> 20 | <%@ page contentType="text/html;charset=ISO-8859-1"%> 21 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 22 | 23 | 24 | 25 | 26 | Path Info Example 27 | 28 | 29 | 30 |

Path Info Example

31 | 32 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |
ExampleCommandCount
Path Info/foo
/bar
Request Parameterfoo
bar
Servlet path/foo.execute
/bar.execute
48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /apps/example2/src/main/webapp/pathinfo.jsp: -------------------------------------------------------------------------------- 1 | 19 | <%@ page language="java"%> 20 | <%@ page contentType="text/html;charset=ISO-8859-1"%> 21 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 22 | 23 | 24 | 25 | 26 | Path Info Example 27 | 28 | 29 | 30 |

Path Info Example

31 | 32 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |
ExampleCommandCount
Path Info/foo
/bar
Request Parameterfoo
bar
Servlet path/foo.execute
/bar.execute
48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /apps/example1/src/main/webapp/servletpath.jsp: -------------------------------------------------------------------------------- 1 | 19 | <%@ page language="java"%> 20 | <%@ page contentType="text/html;charset=ISO-8859-1"%> 21 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 22 | 23 | 24 | 25 | 26 | Servlet Path Example 27 | 28 | 29 | 30 |

Servlet Path Example

31 | 32 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |
ExampleCommandCount
Path Info/foo
/bar
Request Parameterfoo
bar
Servlet path/foo.execute
/bar.execute
47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /apps/example2/src/main/webapp/servletpath.jsp: -------------------------------------------------------------------------------- 1 | 19 | <%@ page language="java"%> 20 | <%@ page contentType="text/html;charset=ISO-8859-1"%> 21 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 22 | 23 | 24 | 25 | 26 | Servlet Path Example 27 | 28 | 29 | 30 |

Servlet Path Example

31 | 32 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |
ExampleCommandCount
Path Info/foo
/bar
Request Parameterfoo
bar
Servlet path/foo.execute
/bar.execute
47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /apps/cookbook-examples/src/test/java/org/apache/commons/chain2/cookbook/mailreader/LocaleValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.cookbook.mailreader; 18 | 19 | import org.junit.Before; 20 | import org.junit.Test; 21 | import java.util.Locale; 22 | import static org.junit.Assert.*; 23 | 24 | public class LocaleValueTest { 25 | 26 | MailReader context; 27 | 28 | @Before 29 | public void setUp() { 30 | context = new MailReader(); 31 | } 32 | 33 | @Test 34 | public void testLocaleSetPropertyGetMap() { 35 | Locale expected = Locale.CANADA_FRENCH; 36 | context.setLocale(expected); 37 | // the retrieve() method is a nice type-safe alternative to get() 38 | Locale locale = context.retrieve(MailReader.LOCALE_KEY); 39 | assertNotNull(locale); 40 | assertEquals(expected, locale); 41 | } 42 | 43 | @Test 44 | public void testLocalePutMapGetProperty() { 45 | Locale expected = Locale.ITALIAN; 46 | context.put(MailReader.LOCALE_KEY, expected); 47 | Locale locale = context.getLocale(); 48 | assertNotNull(locale); 49 | assertEquals(expected, locale); 50 | } 51 | 52 | @Test(expected = UnsupportedOperationException.class) 53 | public void testLocaleSetTypedWithStringException() { 54 | String localeString = Locale.US.toString(); 55 | // Expected 'argument type mismatch' error 56 | context.put(MailReader.LOCALE_KEY, localeString); 57 | } 58 | } -------------------------------------------------------------------------------- /test-utils/src/main/java/org/apache/commons/chain2/testutils/ExceptionFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.testutils; 18 | 19 | 20 | import org.apache.commons.chain2.Context; 21 | import org.apache.commons.chain2.Filter; 22 | 23 | 24 | /** 25 | *

Implementation of {@link Filter} that logs its identifier and 26 | * and throws an Exception.

27 | * 28 | */ 29 | public class ExceptionFilter 30 | extends ExceptionCommand implements Filter> { 31 | 32 | 33 | // ------------------------------------------------------------- Constructor 34 | 35 | 36 | public ExceptionFilter() { 37 | this("", ""); 38 | } 39 | 40 | 41 | // Construct an instance that will log the specified identifier 42 | public ExceptionFilter(String id1, String id2) { 43 | super(id1); 44 | this.id2 = id2; 45 | } 46 | 47 | 48 | // -------------------------------------------------------------- Properties 49 | 50 | protected String id2 = null; 51 | public String getId2() { 52 | return (this.id2); 53 | } 54 | public void setId2(String id2) { 55 | this.id2 = id2; 56 | } 57 | 58 | 59 | // --------------------------------------------------------- Command Methods 60 | 61 | 62 | // Postprocess command for this Filter 63 | public boolean postprocess(Context context, Exception exception) { 64 | log(context, id2); 65 | return (false); 66 | } 67 | 68 | 69 | } 70 | -------------------------------------------------------------------------------- /apps/example1/pom.xml: -------------------------------------------------------------------------------- 1 | 21 | 23 | 4.0.0 24 | 25 | 26 | org.apache.commons 27 | commons-chain-examples 28 | 2.0-SNAPSHOT 29 | ../ 30 | 31 | 32 | chain-example1 33 | war 34 | 35 | Apache Commons Chain :: Examples :: Chain Example 1 App 36 | 37 | 38 | 39 | javax.servlet 40 | servlet-api 41 | 2.4 42 | provided 43 | 44 | 45 | 46 | org.apache.commons 47 | commons-chain2-base 48 | ${project.version} 49 | 50 | 51 | 52 | org.apache.commons 53 | commons-chain2-web 54 | ${project.version} 55 | 56 | 57 | 58 | commons-logging 59 | commons-logging 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /apps/example1/src/main/webapp/reqparam.jsp: -------------------------------------------------------------------------------- 1 | 19 | <%@ page language="java"%> 20 | <%@ page contentType="text/html;charset=ISO-8859-1"%> 21 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 22 | 23 | 24 | 25 | 26 | Request Parameter Example 27 | 28 | 29 | 30 |

Request Parameter Example

31 | 32 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |
ExampleCommandCount
Path Info/foo
/bar
Request Parameterfoo
bar
Servlet path/foo.execute
/bar.execute
48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /apps/example2/src/main/webapp/reqparam.jsp: -------------------------------------------------------------------------------- 1 | 19 | <%@ page language="java"%> 20 | <%@ page contentType="text/html;charset=ISO-8859-1"%> 21 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 22 | 23 | 24 | 25 | 26 | Request Parameter Example 27 | 28 | 29 | 30 |

Request Parameter Example

31 | 32 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |
ExampleCommandCount
Path Info/foo
/bar
Request Parameterfoo
bar
Servlet path/foo.execute
/bar.execute
48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | 23 | Commons Chain 24 | /images/chain-logo-white.png 25 | /index.html 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /apps/example2/pom.xml: -------------------------------------------------------------------------------- 1 | 21 | 23 | 4.0.0 24 | 25 | 26 | org.apache.commons 27 | commons-chain-examples 28 | 2.0-SNAPSHOT 29 | ../ 30 | 31 | 32 | chain-example2 33 | war 34 | 35 | Apache Commons Chain :: Examples :: Chain Example 2 App 36 | 37 | 38 | 39 | javax.servlet 40 | servlet-api 41 | 2.4 42 | provided 43 | 44 | 45 | 46 | org.apache.commons 47 | commons-chain2-base 48 | ${project.version} 49 | 50 | 51 | 52 | org.apache.commons 53 | commons-chain2-web 54 | ${project.version} 55 | 56 | 57 | 58 | commons-logging 59 | commons-logging 60 | 1.1.1 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /base/src/test/java/org/apache/commons/chain2/base/RemoveCommandTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.chain2.base; 19 | 20 | import static org.hamcrest.collection.IsMapContaining.hasKey; 21 | import static org.hamcrest.core.IsNot.not; 22 | import static org.junit.Assert.assertThat; 23 | 24 | import org.apache.commons.chain2.Context; 25 | import org.apache.commons.chain2.impl.TestContext; 26 | import org.junit.Before; 27 | import org.junit.Test; 28 | 29 | /** 30 | */ 31 | public class RemoveCommandTestCase { 32 | 33 | 34 | private RemoveCommand> command; 35 | private Context context; 36 | 37 | @Before 38 | public void setUp() throws Exception { 39 | command = new RemoveCommand>(); 40 | context = new TestContext(); 41 | 42 | context.put("Key", "Value"); 43 | context.put("another Key", "another Value"); 44 | } 45 | 46 | @Test 47 | public void nonExistingKeyDoesNotAlterContext() throws Exception { 48 | command.setFromKey("yet another Key"); 49 | command.execute(context); 50 | 51 | assertThat(context, hasKey("Key")); 52 | assertThat(context, hasKey("another Key")); 53 | } 54 | 55 | @Test 56 | public void existingKeyIsRemoved() throws Exception { 57 | command.setFromKey("Key"); 58 | command.execute(context); 59 | 60 | assertThat(context, not(hasKey("Key"))); 61 | assertThat(context, hasKey("another Key")); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /test-utils/src/test/java/org/apache/commons/chain2/testutils/HasCommandCountTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.chain2.testutils; 19 | 20 | import static org.junit.Assert.assertFalse; 21 | import static org.junit.Assert.assertTrue; 22 | 23 | import org.apache.commons.chain2.Catalog; 24 | import org.apache.commons.chain2.Context; 25 | import org.hamcrest.StringDescription; 26 | import org.junit.Before; 27 | import org.junit.Test; 28 | 29 | /** 30 | */ 31 | public class HasCommandCountTestCase { 32 | 33 | private Catalog> catalog; 34 | private HasCommandCount matcher; 35 | 36 | @Before 37 | public void setUp() throws Exception { 38 | catalog = new TestCatalog>(); 39 | matcher = new HasCommandCount(2); 40 | } 41 | 42 | @Test 43 | public void wrongCountFails() throws Exception { 44 | assertFalse(matcher.matchesSafely(catalog, new StringDescription())); 45 | } 46 | 47 | @Test 48 | public void correctCount() throws Exception { 49 | catalog.addCommand("addingCMD", new AddingCommand()); 50 | catalog.addCommand("DelegatingCMD", new DelegatingCommand()); 51 | 52 | assertTrue(matcher.matchesSafely(catalog, new StringDescription())); 53 | } 54 | 55 | @Test(expected = IllegalStateException.class) 56 | public void inconsistentCatalogThrowsException() throws Exception { 57 | catalog.addCommand("key for null", null); 58 | 59 | matcher.matchesSafely(catalog, new StringDescription()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /base/src/test/java/org/apache/commons/chain2/base/OverrideCommandTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.chain2.base; 19 | 20 | import static org.hamcrest.collection.IsCollectionWithSize.hasSize; 21 | import static org.hamcrest.collection.IsMapContaining.hasEntry; 22 | import static org.junit.Assert.assertThat; 23 | 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | 27 | import org.junit.Before; 28 | import org.junit.Test; 29 | 30 | /** 31 | */ 32 | public class OverrideCommandTestCase { 33 | 34 | 35 | private OverrideCommand> command; 36 | private Map context; 37 | 38 | @Before 39 | public void setUp() throws Exception { 40 | command = new OverrideCommand>(); 41 | 42 | context = new HashMap(); 43 | context.put("Key", "Value"); 44 | } 45 | 46 | @Test 47 | public void nonExistingKeyDoesNotAlterContext() throws Exception { 48 | command.setKey("another Key"); 49 | command.setValue("another Value"); 50 | 51 | command.execute(context); 52 | 53 | assertThat(context, hasEntry("Key", (Object) "Value")); 54 | assertThat(context.keySet(), hasSize(1)); 55 | } 56 | 57 | @Test 58 | public void existingKeyWillBeOverridden() throws Exception { 59 | command.setKey("Key"); 60 | command.setValue("new Value"); 61 | 62 | command.execute(context); 63 | 64 | assertThat(context, hasEntry("Key", (Object) "new Value")); 65 | assertThat(context.keySet(), hasSize(1)); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /test-utils/src/main/java/org/apache/commons/chain2/testutils/AddingCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.testutils; 18 | 19 | import org.apache.commons.chain2.Chain; 20 | import org.apache.commons.chain2.Command; 21 | import org.apache.commons.chain2.Context; 22 | 23 | /** 24 | *

Implementation of {@link Command} that logs its identifier and 25 | * and attempts to add a new {@link Command} to the {@link Chain}. This 26 | * should cause an IllegalStateException if the {@link Chain} implementation 27 | * subclasses ChainBase.

28 | * 29 | */ 30 | public class AddingCommand extends NonDelegatingCommand { 31 | 32 | 33 | // ------------------------------------------------------------ Constructor 34 | 35 | 36 | public AddingCommand() { 37 | this("", null); 38 | } 39 | 40 | // Construct an instance that will log the specified identifier 41 | public AddingCommand(String id, Chain> parent) { 42 | super(id); 43 | this.parent = parent; 44 | } 45 | 46 | 47 | // The parent Chain 48 | private Chain> parent = null; 49 | 50 | 51 | // -------------------------------------------------------- Command Methods 52 | 53 | 54 | // Execution method for this Command 55 | public boolean execute(Context context, Chain> chain) { 56 | 57 | super.execute(context); 58 | parent.addCommand(new NonDelegatingCommand("NEW")); // Should cause ISE 59 | return (true); 60 | 61 | } 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /configuration/api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 22 | 4.0.0 23 | 24 | 25 | org.apache.commons 26 | commons-chain-parent 27 | 2.0-SNAPSHOT 28 | ../../ 29 | 30 | 31 | commons-chain2-configuration-api 32 | 33 | Apache Commons Chain :: Configuration :: API 34 | 35 | 36 | 37 | ${project.groupId} 38 | commons-chain2-base 39 | ${project.parent.version} 40 | 41 | 42 | 43 | ${project.groupId} 44 | commons-chain2-base 45 | ${project.parent.version} 46 | test-jar 47 | test 48 | 49 | 50 | 51 | commons-logging 52 | commons-logging 53 | 54 | 55 | 56 | 57 | 58 | 59 | ${basedir}/../../ 60 | META-INF 61 | 62 | NOTICE.txt 63 | LICENSE.txt 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /configuration/api/src/main/java/org/apache/commons/chain2/config/ConfigParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.config; 18 | 19 | import java.net.URL; 20 | import java.util.Map; 21 | 22 | import org.apache.commons.chain2.Catalog; 23 | import org.apache.commons.chain2.CatalogFactory; 24 | 25 | /** 26 | *

Facade class to abstract the functionality of parsing an arbitrary 27 | * configuration file that defines and configures commands and command chains 28 | * to be registered in a {@link Catalog}. It is legal to call the 29 | * parse() method more than once, in order 30 | * to parse more than one configuration document.

31 | * 32 | */ 33 | public interface ConfigParser { 34 | 35 | // --------------------------------------------------------- Public Methods 36 | 37 | /** 38 | *

Parse the configuration at the specified URL using the configured 39 | * rule set, registering catalogs with nested chains and 40 | * commands as they are encountered. Use this method only 41 | * if you have included one or more factory elements in your 42 | * configuration resource.

43 | * 44 | * @param the type of keys maintained by the context associated with this command 45 | * @param the type of mapped values 46 | * @param Type of the context associated with this command 47 | * @param url URL of the configuration document to be parsed 48 | * @return a CatalogFactory instance parsed from the given location 49 | * @throws ChainConfigurationException if a parsing error occurs 50 | */ 51 | > CatalogFactory parse(URL url) throws ChainConfigurationException; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /test-utils/src/main/java/org/apache/commons/chain2/testutils/HasLog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.chain2.testutils; 19 | 20 | import org.apache.commons.chain2.Context; 21 | import org.hamcrest.Description; 22 | import org.hamcrest.Factory; 23 | import org.hamcrest.Matcher; 24 | import org.hamcrest.TypeSafeDiagnosingMatcher; 25 | 26 | /** 27 | * A matcher that checks if a {@link Context} contains a log with the given contents. 28 | * This matcher assumes that the context has a context value of type {@link StringBuilder} 29 | * registered for key {@code log}. 30 | * 31 | */ 32 | public class HasLog extends TypeSafeDiagnosingMatcher { 33 | 34 | private String expectedContent; 35 | 36 | public HasLog(String expectedContent) { 37 | this.expectedContent = expectedContent; 38 | } 39 | 40 | @Factory 41 | public static Matcher hasLog(final String logContent) { 42 | return new HasLog(logContent); 43 | } 44 | 45 | @Override 46 | protected boolean matchesSafely(Context item, Description mismatchDescription) { 47 | StringBuilder log = (StringBuilder) item.get("log"); 48 | if (log == null) { 49 | mismatchDescription.appendText("context has no log "); 50 | return false; 51 | } 52 | String actualContent = log.toString(); 53 | if (!actualContent.equals(expectedContent)) { 54 | mismatchDescription.appendText("log has content ").appendValue(actualContent); 55 | return false; 56 | } 57 | return true; 58 | } 59 | 60 | @Override 61 | public void describeTo(Description description) { 62 | description.appendText("log has content ").appendValue(expectedContent); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /apps/example2/src/main/java/org/apache/commons/chain2/apps/example/CountCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.apps.example; 18 | 19 | import org.apache.commons.chain2.Command; 20 | import org.apache.commons.chain2.Processing; 21 | import org.apache.commons.chain2.web.WebContext; 22 | import org.apache.commons.logging.Log; 23 | import org.apache.commons.logging.LogFactory; 24 | 25 | /** 26 | *

Bar Command

27 | * 28 | */ 29 | public class CountCommand implements Command> { 31 | 32 | private Log log = LogFactory.getLog(CountCommand.class); 33 | 34 | private int count; 35 | 36 | private String attribute = "count"; 37 | 38 | /** 39 | * Return the request attribute name to store the count under. 40 | * 41 | * @return The name of the request attribute 42 | */ 43 | public String getAttribute() { 44 | return attribute; 45 | } 46 | 47 | /** 48 | * Set the request attribute name to store the count under. 49 | * 50 | * @param attribute The name of the request attribute 51 | */ 52 | public void setAttribute(String attribute) { 53 | this.attribute = attribute; 54 | } 55 | 56 | /** 57 | *

Execute the command.

58 | * 59 | * 60 | * @param context The {@link org.apache.commons.chain2.Context} we are operating on 61 | * @return {@link Processing#CONTINUE} so that processing will continue. 62 | */ 63 | public Processing execute(WebContext context) { 64 | count++; 65 | log.info("Executing: " + attribute + "=" + count); 66 | 67 | context.getSessionScope().put(attribute, new Integer(count)); 68 | 69 | return Processing.CONTINUE; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /apps/example1/src/main/java/org/apache/commons/chain2/apps/example/CountCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.apps.example; 18 | 19 | import org.apache.commons.chain2.Command; 20 | import org.apache.commons.chain2.Context; 21 | import org.apache.commons.chain2.Processing; 22 | import org.apache.commons.chain2.web.WebContext; 23 | import org.apache.commons.logging.Log; 24 | import org.apache.commons.logging.LogFactory; 25 | 26 | /** 27 | *

Bar Command

28 | * 29 | */ 30 | public class CountCommand implements Command> { 32 | 33 | private Log log = LogFactory.getLog(CountCommand.class); 34 | 35 | private int count; 36 | 37 | private String attribute = "count"; 38 | 39 | /** 40 | * Return the request attribute name to store the count under. 41 | * 42 | * @return The name of the request attribute 43 | */ 44 | public String getAttribute() { 45 | return attribute; 46 | } 47 | 48 | /** 49 | * Set the request attribute name to store the count under. 50 | * 51 | * @param attribute The name of the request attribute 52 | */ 53 | public void setAttribute(String attribute) { 54 | this.attribute = attribute; 55 | } 56 | 57 | /** 58 | *

Execute the command.

59 | * 60 | * @param context The {@link Context} we are operating on 61 | * @return {@link Processing#CONTINUE} so that processing will continue. 62 | */ 63 | public Processing execute(WebContext context) { 64 | count++; 65 | log.info("Executing: " + attribute + "=" + count); 66 | 67 | context.getSessionScope().put(attribute, new Integer(count)); 68 | 69 | return Processing.CONTINUE; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/site/xdoc/building.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | Building 21 | Commons Documentation Team 22 | 23 | 24 | 25 |
26 |

27 | Commons Chain uses Maven 2 or 28 | Ant as a build system. 29 |

30 |

31 | Chain 2.0 requires a minimum of JDK 1.5 to build. 32 |

33 |
34 |
35 |

36 | The following Maven 2 commands can be used to build Chain: 37 |

38 |
    39 |
  • mvn clean - clean up
  • 40 |
  • mvn test - compile and run the unit tests
  • 41 |
  • mvn site - create the documentation
  • 42 |
  • mvn package - build the jar
  • 43 |
  • mvn install - build the jar and install in local maven repository
  • 44 |
  • mvn site assembly:assembly - Create the source and binary distributions
  • 45 |
46 |
47 | 48 |
49 |

50 | The following Ant commands can be used to build Chain: 51 |

52 |
    53 |
  • ant clean - clean up
  • 54 |
  • ant test - compile and run the unit tests
  • 55 |
  • ant javadoc - create javadocs
  • 56 |
  • ant jar - build the jar
  • 57 |
  • ant dist - Create the source and binary distributions
  • 58 |
59 |
60 | 61 | 62 |
63 | -------------------------------------------------------------------------------- /test-utils/src/main/java/org/apache/commons/chain2/testutils/NonDelegatingFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.testutils; 18 | 19 | 20 | import org.apache.commons.chain2.Context; 21 | import org.apache.commons.chain2.Filter; 22 | import org.apache.commons.chain2.Processing; 23 | 24 | 25 | /** 26 | *

Implementation of {@link Filter} that logs its identifier and 27 | * and returns true.

28 | * 29 | */ 30 | 31 | public class NonDelegatingFilter 32 | extends NonDelegatingCommand implements Filter> { 33 | 34 | 35 | // ------------------------------------------------------------- Constructor 36 | 37 | 38 | public NonDelegatingFilter() { 39 | this("", ""); 40 | } 41 | 42 | 43 | // Construct an instance that will log the specified identifier 44 | public NonDelegatingFilter(String id1, String id2) { 45 | super(id1); 46 | this.id2 = id2; 47 | } 48 | 49 | 50 | // -------------------------------------------------------------- Properties 51 | 52 | 53 | protected String id2 = null; 54 | public String getId2() { 55 | return (this.id2); 56 | } 57 | public void setId2(String id2) { 58 | this.id2 = id2; 59 | } 60 | 61 | 62 | // --------------------------------------------------------- Command Methods 63 | 64 | 65 | // Execution method for this Command 66 | @Override 67 | public Processing execute(Context context) { 68 | 69 | super.execute(context); 70 | return Processing.FINISHED; 71 | 72 | } 73 | 74 | 75 | // Postprocess method for this Filter 76 | public boolean postprocess(Context context, Exception exception) { 77 | log(context, id2); 78 | return (false); 79 | } 80 | 81 | 82 | } 83 | -------------------------------------------------------------------------------- /apps/cookbook-examples/src/main/java/org/apache/commons/chain2/cookbook/mailreader/MailReaderServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.cookbook.mailreader; 18 | 19 | import org.apache.commons.chain2.Catalog; 20 | import org.apache.commons.chain2.CatalogFactory; 21 | import org.apache.commons.chain2.Command; 22 | import org.apache.commons.chain2.impl.CatalogFactoryBase; 23 | 24 | import javax.servlet.ServletException; 25 | import javax.servlet.http.HttpServlet; 26 | import javax.servlet.http.HttpServletRequest; 27 | import javax.servlet.http.HttpServletResponse; 28 | import java.io.IOException; 29 | 30 | /** 31 | */ 32 | public class MailReaderServlet extends HttpServlet { 33 | 34 | public MailReaderServlet() { 35 | } 36 | 37 | @Override 38 | protected void doGet(HttpServletRequest request, HttpServletResponse response) 39 | throws ServletException, IOException { 40 | response.setContentType("text/plain"); 41 | 42 | MailReader context = new MailReader(); 43 | context.setLocale(request.getLocale()); 44 | context.setLogger(response.getWriter()); 45 | 46 | CatalogFactory catalogFactory = 47 | CatalogFactoryBase.getInstance(); 48 | 49 | Catalog catalog = 50 | catalogFactory.getCatalog(); 51 | 52 | if (catalog == null) { 53 | String msg = String.format("No catalog returned from factory: %s", 54 | catalogFactory.getClass().getName()); 55 | throw new IllegalArgumentException(msg); 56 | } 57 | 58 | Command profileCheckCmd = 59 | catalog.>getCommand("LocaleChange"); 60 | 61 | profileCheckCmd.execute(context); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /test-utils/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | commons-chain-parent 23 | org.apache.commons 24 | 2.0-SNAPSHOT 25 | 26 | 4.0.0 27 | 28 | commons-chain2-test-utils 29 | 30 | Apache Commons Chain :: Test utilities 31 | 32 | 33 | 34 | org.hamcrest 35 | hamcrest-core 36 | 1.3 37 | compile 38 | 39 | 40 | org.hamcrest 41 | hamcrest-library 42 | 1.3 43 | compile 44 | 45 | 46 | 47 | ${project.groupId} 48 | commons-chain2-api 49 | ${project.version} 50 | 51 | 52 | 53 | 54 | 55 | 56 | ${basedir}/../ 57 | META-INF 58 | 59 | NOTICE.txt 60 | LICENSE.txt 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /web/src/test/java/org/apache/commons/chain2/web/MockPrincipal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.web; 18 | 19 | 20 | import java.security.Principal; 21 | 22 | 23 | /** 24 | *

Mock Principal object for low-level unit tests.

25 | */ 26 | 27 | public class MockPrincipal implements Principal { 28 | 29 | 30 | public MockPrincipal() { 31 | this.name = ""; 32 | this.roles = new String[0]; 33 | } 34 | 35 | 36 | public MockPrincipal(String name) { 37 | this.name = name; 38 | this.roles = new String[0]; 39 | } 40 | 41 | 42 | public MockPrincipal(String name, String roles[]) { 43 | this.name = name; 44 | this.roles = roles; 45 | } 46 | 47 | 48 | protected String name = null; 49 | 50 | 51 | protected String roles[] = null; 52 | 53 | 54 | public String getName() { 55 | return (this.name); 56 | } 57 | 58 | 59 | public boolean isUserInRole(String role) { 60 | for (int i = 0; i < roles.length; i++) { 61 | if (role.equals(roles[i])) { 62 | return (true); 63 | } 64 | } 65 | return (false); 66 | } 67 | 68 | 69 | public boolean equals(Object o) { 70 | if (o == null) { 71 | return (false); 72 | } 73 | if (!(o instanceof Principal)) { 74 | return (false); 75 | } 76 | Principal p = (Principal) o; 77 | if (name == null) { 78 | return (p.getName() == null); 79 | } else { 80 | return (name.equals(p.getName())); 81 | } 82 | } 83 | 84 | 85 | public int hashCode() { 86 | if (name == null) { 87 | return ("".hashCode()); 88 | } else { 89 | return (name.hashCode()); 90 | } 91 | } 92 | 93 | 94 | } 95 | -------------------------------------------------------------------------------- /apps/example1/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 19 | <%@ page language="java"%> 20 | <%@ page contentType="text/html;charset=ISO-8859-1"%> 21 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 22 | 23 | 24 | 25 | 26 | Chain Example Index Page 27 | 28 | 29 | 30 |

Chain Example Index Page

31 | 32 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 |
ExampleCommandCount
Path Info/foo
/bar
Request Parameterfoo
bar
Servlet path/foo.execute
/bar.execute
59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /apps/example2/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 19 | <%@ page language="java"%> 20 | <%@ page contentType="text/html;charset=ISO-8859-1"%> 21 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 22 | 23 | 24 | 25 | 26 | Chain Example Index Page 27 | 28 | 29 | 30 |

Chain Example Index Page

31 | 32 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 |
ExampleCommandCount
Path Info/foo
/bar
Request Parameterfoo
bar
Servlet path/foo.execute
/bar.execute
59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /base/src/main/java/org/apache/commons/chain2/base/RemoveCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.base; 18 | 19 | import org.apache.commons.chain2.Command; 20 | import org.apache.commons.chain2.Context; 21 | import org.apache.commons.chain2.Processing; 22 | 23 | /** 24 | *

Remove any context attribute stored under the fromKey.

25 | * 26 | * @param the type of keys maintained by the context associated with this catalog 27 | * @param the type of mapped values 28 | * @param Type of the context associated with this command 29 | * 30 | */ 31 | public class RemoveCommand> implements Command { 32 | 33 | // -------------------------------------------------------------- Properties 34 | 35 | private K fromKey = null; 36 | 37 | /** 38 | *

Return the context attribute key for the attribute.

39 | * @return The context attribute key. 40 | */ 41 | public K getFromKey() { 42 | return this.fromKey; 43 | } 44 | 45 | /** 46 | *

Set the context attribute key for the attribute.

47 | * 48 | * @param fromKey The new key 49 | */ 50 | public void setFromKey(K fromKey) { 51 | this.fromKey = fromKey; 52 | } 53 | 54 | // ---------------------------------------------------------- Filter Methods 55 | 56 | /** 57 | *

Copy the specified source attribute to the specified destination 58 | * attribute.

59 | * 60 | * @param context {@link Context} in which we are operating 61 | * 62 | * @return {@link Processing#CONTINUE} so that processing will continue. 63 | * @throws org.apache.commons.chain2.ChainException if and error occurs. 64 | */ 65 | public Processing execute(C context) { 66 | context.remove(getFromKey()); 67 | return Processing.CONTINUE; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /test-utils/src/test/java/org/apache/commons/chain2/testutils/NonDelegatingCommandTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.chain2.testutils; 19 | 20 | import static org.apache.commons.chain2.testutils.HasLog.hasLog; 21 | import static org.hamcrest.collection.IsCollectionWithSize.hasSize; 22 | import static org.hamcrest.collection.IsMapContaining.hasKey; 23 | import static org.junit.Assert.assertThat; 24 | import static org.junit.Assert.assertEquals; 25 | 26 | import java.util.UUID; 27 | 28 | import org.apache.commons.chain2.Context; 29 | import org.apache.commons.chain2.Processing; 30 | import org.junit.Before; 31 | import org.junit.Test; 32 | 33 | /** 34 | */ 35 | public class NonDelegatingCommandTestCase { 36 | 37 | private static final String ID = UUID.randomUUID().toString(); 38 | 39 | private NonDelegatingCommand command; 40 | private Context context; 41 | 42 | @Before 43 | public void setUp() throws Exception { 44 | command = new NonDelegatingCommand(ID); 45 | context = new TestContext(); 46 | } 47 | 48 | @Test(expected = IllegalArgumentException.class) 49 | public void executeNullThrowsException() throws Exception { 50 | command.execute(null); 51 | } 52 | 53 | @Test 54 | public void createsLogInEmptyContext() throws Exception { 55 | execute(); 56 | 57 | assertThat(context.keySet(), hasSize(1)); 58 | assertThat(context, hasKey("log")); 59 | assertThat(context, hasLog(ID)); 60 | } 61 | 62 | @Test 63 | public void existingLogIsReused() throws Exception { 64 | context.put("log", new StringBuilder("some content")); 65 | execute(); 66 | 67 | assertThat(context, hasLog("some content/" + ID)); 68 | } 69 | 70 | private void execute() { 71 | assertEquals(Processing.FINISHED, command.execute(context)); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /configuration/xml/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 4.0.0 22 | 23 | 24 | commons-chain-parent 25 | org.apache.commons 26 | 2.0-SNAPSHOT 27 | ../../ 28 | 29 | 30 | org.apache.commons 31 | commons-chain2-xml-configuration 32 | Apache Commons Chain :: Configuration :: XML 33 | 34 | 35 | 36 | ${project.groupId} 37 | commons-chain2-base 38 | ${project.parent.version} 39 | 40 | 41 | 42 | ${project.groupId} 43 | commons-chain2-configuration-api 44 | ${project.parent.version} 45 | 46 | 47 | 48 | ${project.groupId} 49 | commons-digester3 50 | 51 | 52 | 53 | ${project.groupId} 54 | commons-chain2-test-utils 55 | ${project.parent.version} 56 | test 57 | 58 | 59 | 60 | 61 | 62 | 63 | ${basedir}/../../ 64 | META-INF 65 | 66 | NOTICE.txt 67 | LICENSE.txt 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /base/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 22 | 4.0.0 23 | 24 | 25 | org.apache.commons 26 | commons-chain-parent 27 | 2.0-SNAPSHOT 28 | ../ 29 | 30 | 31 | commons-chain2-base 32 | 33 | Apache Commons Chain :: Base 34 | 35 | 36 | 37 | commons-logging 38 | commons-logging 39 | 40 | 41 | 42 | ${project.groupId} 43 | commons-chain2-api 44 | ${project.version} 45 | 46 | 47 | ${project.groupId} 48 | commons-chain2-test-utils 49 | ${project.version} 50 | test 51 | 52 | 53 | 54 | 55 | 56 | 57 | ${basedir}/../ 58 | META-INF 59 | 60 | NOTICE.txt 61 | LICENSE.txt 62 | 63 | 64 | 65 | 66 | 67 | org.apache.maven.plugins 68 | maven-jar-plugin 69 | 70 | 71 | 72 | test-jar 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /test-utils/src/main/java/org/apache/commons/chain2/testutils/HasCommandCount.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.chain2.testutils; 19 | 20 | import java.util.Iterator; 21 | 22 | import org.apache.commons.chain2.Catalog; 23 | import org.hamcrest.Description; 24 | import org.hamcrest.Factory; 25 | import org.hamcrest.Matcher; 26 | import org.hamcrest.TypeSafeDiagnosingMatcher; 27 | 28 | /** 29 | * A matchers that checks if a catalog has an expected count of commands. 30 | * 31 | */ 32 | public class HasCommandCount extends TypeSafeDiagnosingMatcher { 33 | 34 | private int expected; 35 | 36 | public HasCommandCount(int count) { 37 | this.expected = count; 38 | } 39 | 40 | @Factory 41 | public static Matcher hasCommandCount(int expectedCount) { 42 | return new HasCommandCount(expectedCount); 43 | } 44 | 45 | @Override 46 | protected boolean matchesSafely(Catalog catalog, Description mismatchDescription) { 47 | int actual = countCommands(catalog); 48 | if (actual != expected) { 49 | mismatchDescription.appendText(" catalog contains ").appendValue(actual).appendText(" commands "); 50 | return false; 51 | } 52 | return true; 53 | } 54 | 55 | private int countCommands(Catalog catalog) { 56 | int count = 0; 57 | Iterator names = catalog.getNames(); 58 | while (names.hasNext()) { 59 | checkExists(catalog, names.next()); 60 | count++; 61 | } 62 | return count; 63 | } 64 | 65 | private void checkExists(Catalog catalog, String name) { 66 | if (catalog.getCommand(name) == null) { 67 | String msg = String.format("Catalog contains a command with name %s but getCommand(%s) returned null!", name, name); 68 | throw new IllegalStateException(msg); 69 | } 70 | } 71 | 72 | @Override 73 | public void describeTo(Description description) { 74 | description.appendText(" catalog contains ").appendValue(expected).appendText(" commands "); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /web/src/test/java/org/apache/commons/chain2/web/ChainResourcesTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.web; 18 | 19 | import org.junit.Test; 20 | import org.junit.runner.RunWith; 21 | import org.junit.runners.Parameterized; 22 | import org.junit.runners.Parameterized.Parameters; 23 | 24 | import java.util.Arrays; 25 | import java.util.Collection; 26 | 27 | import static org.junit.Assert.assertArrayEquals; 28 | import static org.junit.Assert.assertNotNull; 29 | 30 | // Test case for org.apache.commons.chain2.web.ChainResources 31 | 32 | @RunWith(Parameterized.class) 33 | public class ChainResourcesTestCase { 34 | 35 | 36 | // ----------------------------------------------------- Test data source 37 | 38 | @Parameters 39 | public static Collection data() { 40 | return Arrays.asList(new Object[][] { 41 | { "a,b,c", new String[] {"a", "b", "c"} }, 42 | { "a , b , c ", new String[] {"a", "b", "c"} }, 43 | { "a,\tb,\tc ", new String[] {"a", "b", "c"} }, 44 | { "\na,\nb,\nc\n", new String[] {"a", "b", "c"} }, 45 | { "a,,b,c ", new String[] {"a", "b", "c"} }, 46 | { ",a,b,,c,,", new String[] {"a", "b", "c"} }, 47 | { null, new String[] {} }, 48 | { "", new String[] {} }, 49 | { ",", new String[] {} }, 50 | { ",,", new String[] {} } 51 | }); 52 | } 53 | 54 | // ----------------------------------------------------- Public constructor 55 | 56 | private final String input; 57 | 58 | private final String[] expected; 59 | 60 | public ChainResourcesTestCase(String input, String[] expected) 61 | { 62 | this.input = input; 63 | this.expected = expected; 64 | } 65 | 66 | // ------------------------------------------------ Individual Test Methods 67 | 68 | 69 | @Test 70 | public void testGetPaths() throws Exception { 71 | String[] actual = ChainResources.getResourcePaths(input); 72 | 73 | assertNotNull(actual); 74 | assertArrayEquals(expected, actual); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /apps/example2/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | Chain Example 21 | 22 | 23 | org.apache.commons.chain2.CONFIG_WEB_RESOURCE 24 | /WEB-INF/chain-config.xml 25 | 26 | 27 | 28 | 29 | org.apache.commons.chain2.web.ChainListener 30 | 31 | 32 | 33 | 34 | pathinfo 35 | org.apache.commons.chain2.apps.example.ExampleServlet 36 | 1 37 | 38 | 39 | 40 | 41 | reqparam 42 | org.apache.commons.chain2.apps.example.ExampleServlet 43 | 2 44 | 45 | 46 | 47 | 48 | servletpath 49 | org.apache.commons.chain2.apps.example.ExampleServlet 50 | 3 51 | 52 | 53 | 54 | 55 | pathinfo 56 | /exec/* 57 | 58 | 59 | 60 | 61 | reqparam 62 | /execute 63 | 64 | 65 | 66 | 67 | servletpath 68 | *.execute 69 | 70 | 71 | 72 | 73 | index.jsp 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /dist/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 22 | 4.0.0 23 | 24 | 25 | org.apache.commons 26 | commons-chain-parent 27 | 2.0-SNAPSHOT 28 | ../ 29 | 30 | 31 | commons-chain2 32 | pom 33 | 34 | Apache Commons Chain :: Distribution Packages 35 | 36 | 37 | 38 | ${project.groupId} 39 | commons-chain2-api 40 | ${project.parent.version} 41 | 42 | 43 | ${project.groupId} 44 | commons-chain2-base 45 | ${project.parent.version} 46 | 47 | 48 | ${project.groupId} 49 | commons-chain2-configuration 50 | ${project.parent.version} 51 | 52 | 53 | ${project.groupId} 54 | commons-chain2-web 55 | ${project.parent.version} 56 | 57 | 58 | 59 | 60 | 61 | 62 | maven-assembly-plugin 63 | 64 | 65 | 66 | single 67 | 68 | package 69 | 70 | 71 | 72 | 73 | ${basedir}/src/main/assembly/bin.xml 74 | ${basedir}/src/main/assembly/src.xml 75 | 76 | gnu 77 | false 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /apps/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 4.0.0 22 | 23 | 24 | org.apache.commons 25 | commons-chain-parent 26 | 2.0-SNAPSHOT 27 | ../ 28 | 29 | 30 | commons-chain-examples 31 | pom 32 | 33 | Apache Commons Chain :: Examples 34 | 35 | Example modules using the chain of responsibility pattern. 36 | 37 | 38 | 39 | example1 40 | example2 41 | cookbook-examples 42 | 43 | 44 | 45 | true 46 | true 47 | 48 | 49 | 50 | 51 | 52 | commons-logging 53 | commons-logging 54 | 1.1.1 55 | 56 | 57 | 58 | 59 | 60 | 61 | junit 62 | junit 63 | 4.10 64 | test 65 | 66 | 67 | 68 | 69 | 70 | 71 | org.apache.maven.plugins 72 | maven-checkstyle-plugin 73 | 2.9.1 74 | 75 | 76 | org.apache.commons 77 | commons-chain2-build-tools 78 | ${project.version} 79 | 80 | 81 | 82 | 83 | 84 | checkstyle-aggregate 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /base/src/main/java/org/apache/commons/chain2/impl/ContextMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2.impl; 18 | 19 | import org.apache.commons.chain2.Context; 20 | 21 | import java.util.Map; 22 | import java.util.concurrent.ConcurrentHashMap; 23 | 24 | /** 25 | * Convenience base class for {@link Context} implementations. 26 | * 27 | * @param the type of keys maintained by the context associated with this context 28 | * @param the type of mapped values 29 | * 30 | * @since 2.0 31 | */ 32 | public class ContextMap extends ConcurrentHashMap implements Context { 33 | 34 | /** 35 | * 36 | */ 37 | private static final long serialVersionUID = 20120724L; 38 | 39 | /** 40 | * Creates a new, empty Context with a default initial capacity, load factor, and concurrencyLevel. 41 | */ 42 | public ContextMap() { 43 | } 44 | 45 | /** 46 | * Creates a new, empty Context with the specified initial capacity, and with default load factor and concurrencyLevel 47 | * 48 | * @param initialCapacity the initial capacity. 49 | */ 50 | public ContextMap(int initialCapacity) { 51 | super(initialCapacity); 52 | } 53 | 54 | /** 55 | * Creates a new, empty Context with the specified initial capacity, load factor, and concurrency level. 56 | * 57 | * @param initialCapacity the initial capacity. 58 | * @param loadFactor the load factor threshold, used to control resizing. 59 | * @param concurrencyLevel the estimated number of concurrently updating threads. 60 | */ 61 | public ContextMap(int initialCapacity, float loadFactor, int concurrencyLevel) { 62 | super(initialCapacity, loadFactor, concurrencyLevel); 63 | } 64 | 65 | /** 66 | * Creates a new Context with the same mappings as the given map. 67 | * 68 | * @param t Map whose key-value pairs are added 69 | */ 70 | public ContextMap(Map t) { 71 | super(t); 72 | } 73 | 74 | /** 75 | * {@inheritDoc} 76 | */ 77 | public T retrieve(K key) { 78 | V valueObject = get(key); 79 | if (valueObject == null) { 80 | return null; 81 | } 82 | // will throw ClassCastException if type are not assignable anyway 83 | @SuppressWarnings("unchecked") 84 | T value = (T) valueObject; 85 | return value; 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /api/src/main/java/org/apache/commons/chain2/Catalog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.chain2; 18 | 19 | import java.util.Iterator; 20 | import java.util.Map; 21 | 22 | /** 23 | *

A {@link Catalog} is a collection of named {@link Command}s (or 24 | * {@link Chain}s) that can be used to retrieve the set of commands that 25 | * should be performed based on a symbolic identifier. Use of catalogs 26 | * is optional, but convenient when there are multiple possible chains 27 | * that can be selected and executed based on environmental conditions.

28 | * 29 | * @param the type of keys maintained by the context associated with this command 30 | * @param the type of mapped values 31 | * @param Type of the context associated with this command 32 | * 33 | */ 34 | public interface Catalog> { 35 | 36 | /** 37 | *

A default context attribute for storing a default {@link Catalog}, 38 | * provided as a convenience only.

39 | */ 40 | String CATALOG_KEY = "org.apache.commons.chain2.CATALOG"; 41 | 42 | /** 43 | *

Add a new name and associated {@link Command} or {@link Chain} 44 | * to the set of named commands known to this {@link Catalog}, 45 | * replacing any previous command for that name. 46 | * 47 | * @param the {@link Command} type to be added in the {@link Catalog} 48 | * @param name Name of the new command 49 | * @param command {@link Command} or {@link Chain} to be returned 50 | * for later lookups on this name 51 | */ 52 | > void addCommand(String name, CMD command); 53 | 54 | /** 55 | *

Return the {@link Command} or {@link Chain} associated with the 56 | * specified name, if any; otherwise, return null.

57 | * 58 | * @param the expected {@link Command} type to be returned 59 | * @param name Name for which a {@link Command} or {@link Chain} 60 | * should be retrieved 61 | * @return The Command associated with the specified name. 62 | */ 63 | > CMD getCommand(String name); 64 | 65 | /** 66 | *

Return an Iterator over the set of named commands 67 | * known to this {@link Catalog}. If there are no known commands, 68 | * an empty Iterator is returned.

69 | * @return An iterator of the names in this Catalog. 70 | */ 71 | Iterator getNames(); 72 | 73 | } 74 | -------------------------------------------------------------------------------- /apps/cookbook-examples/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 20 | 4.0.0 21 | 22 | 23 | org.apache.commons 24 | commons-chain-examples 25 | 2.0-SNAPSHOT 26 | ../ 27 | 28 | 29 | chain-cookbook-examples 30 | war 31 | 32 | Apache Commons Chain :: Examples :: Cookbook 33 | 34 | 35 | 36 | org.apache.commons 37 | commons-chain2-base 38 | ${project.version} 39 | 40 | 41 | 42 | org.apache.commons 43 | commons-chain2-web 44 | ${project.version} 45 | 46 | 47 | 48 | org.apache.commons 49 | commons-chain2-xml-configuration 50 | ${project.version} 51 | 52 | 53 | 54 | org.mockito 55 | mockito-all 56 | 1.8.5 57 | test 58 | 59 | 60 | 61 | javax.servlet 62 | servlet-api 63 | 2.5 64 | provided 65 | 66 | 67 | 68 | 69 | 70 | 71 | ${basedir}/src/main/resources/chain 72 | resources/chain 73 | 74 | catalog.xml 75 | 76 | 77 | 78 | 79 | 80 | 81 | org.apache.tomcat.maven 82 | tomcat7-maven-plugin 83 | 2.0-beta-1 84 | 85 | 86 | 8080 87 | / 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /base/src/main/java/org/apache/commons/chain2/base/OverrideCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.chain2.base; 19 | 20 | import java.util.Map; 21 | 22 | import org.apache.commons.chain2.Command; 23 | import org.apache.commons.chain2.Processing; 24 | 25 | /** 26 | *

Override any context attribute stored under the key with value.

27 | * 28 | * @param the type of keys maintained by the context associated with this catalog 29 | * @param the type of mapped values 30 | * @param Type of the context associated with this command 31 | * 32 | */ 33 | public class OverrideCommand> implements Command { 34 | 35 | // -------------------------------------------------------------- Properties 36 | 37 | private K key = null; 38 | private V value = null; 39 | 40 | /** 41 | *

Return the context attribute key for the attribute to override.

42 | * @return The context attribute key. 43 | */ 44 | public K getKey() { 45 | return key; 46 | } 47 | 48 | /** 49 | *

Set the context attribute key for the attribute to override.

50 | * 51 | * @param key The new key 52 | */ 53 | public void setKey(K key) { 54 | this.key = key; 55 | } 56 | 57 | /** 58 | *

Return the value that should override context attribute with key key.

59 | * @return The value. 60 | */ 61 | public V getValue() { 62 | return value; 63 | } 64 | 65 | /** 66 | *

Set the value that should override context attribute with key key.

67 | * 68 | * @param value The new value 69 | */ 70 | public void setValue(V value) { 71 | this.value = value; 72 | } 73 | 74 | // ---------------------------------------------------------- Filter Methods 75 | 76 | /** 77 | *

Override the attribute specified by key with value.

78 | * 79 | * @param context {@link org.apache.commons.chain2.Context} in which we are operating 80 | * 81 | * @return {@link Processing#CONTINUE} so that {@link Processing} will continue. 82 | * @throws org.apache.commons.chain2.ChainException if and error occurs. 83 | */ 84 | public Processing execute(C context) { 85 | if (context.containsKey(getKey())) { 86 | context.put(getKey(), getValue()); 87 | } 88 | return Processing.CONTINUE; 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /apps/example1/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | Chain Example 21 | 22 | 23 | org.apache.commons.chain2.CONFIG_WEB_RESOURCE 24 | /WEB-INF/chain-config.xml 25 | 26 | 27 | 28 | 29 | pathinfo 30 | org.apache.commons.chain2.web.servlet.ChainProcessor 31 | 1 32 | 33 | 34 | 35 | 36 | reqparam 37 | org.apache.commons.chain2.web.servlet.ChainProcessor 38 | 39 | 40 | org.apache.commons.chain2.CATALOG 41 | reqparam 42 | 43 | 2 44 | 45 | 46 | 47 | 48 | servletpath 49 | org.apache.commons.chain2.web.servlet.ChainProcessor 50 | 51 | 52 | org.apache.commons.chain2.CATALOG 53 | servletpath 54 | 55 | 3 56 | 57 | 58 | 59 | 60 | pathinfo 61 | /exec/* 62 | 63 | 64 | 65 | 66 | reqparam 67 | /execute 68 | 69 | 70 | 71 | 72 | servletpath 73 | *.execute 74 | 75 | 76 | 77 | 78 | index.jsp 79 | 80 | 81 | 82 | --------------------------------------------------------------------------------