You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/08/07 14:27:41 UTC
svn commit: r563472 - in /activemq/camel/trunk:
camel-core/src/main/java/org/apache/camel/model/
camel-core/src/main/java/org/apache/camel/processor/
components/camel-jing/src/main/resources/META-INF/services/org/apache/camel/component/
components/came...
Author: jstrachan
Date: Tue Aug 7 05:27:39 2007
New Revision: 563472
URL: http://svn.apache.org/viewvc?view=rev&rev=563472
Log:
patched the XML validation test cases to reuse a common base which uses the <try> <catch> notation in the XML to route based on whether or not validation exceptions occur
Added:
activemq/camel/trunk/components/camel-jing/src/main/resources/META-INF/services/org/apache/camel/component/rnc
- copied, changed from r563442, activemq/camel/trunk/components/camel-jing/src/main/resources/META-INF/services/org/apache/camel/component/jing
activemq/camel/trunk/components/camel-jing/src/main/resources/META-INF/services/org/apache/camel/component/rng
- copied unchanged from r563442, activemq/camel/trunk/components/camel-jing/src/main/resources/META-INF/services/org/apache/camel/component/jing
activemq/camel/trunk/components/camel-jing/src/test/java/org/apache/camel/component/validator/jing/RNCRouteTest.java (with props)
activemq/camel/trunk/components/camel-jing/src/test/java/org/apache/camel/component/validator/jing/RNGRouteTest.java
- copied, changed from r563442, activemq/camel/trunk/components/camel-msv/src/test/java/org/apache/camel/component/validator/relaxng/RelaxNGRouteTest.java
activemq/camel/trunk/components/camel-jing/src/test/resources/org/apache/camel/component/validator/jing/rnc-context.xml (with props)
activemq/camel/trunk/components/camel-jing/src/test/resources/org/apache/camel/component/validator/jing/rng-context.xml (with props)
activemq/camel/trunk/components/camel-msv/src/main/java/org/apache/camel/component/validator/msv/
- copied from r563442, activemq/camel/trunk/components/camel-msv/src/main/java/org/apache/camel/component/validator/relaxng/
activemq/camel/trunk/components/camel-msv/src/main/java/org/apache/camel/component/validator/msv/MsvComponent.java (with props)
activemq/camel/trunk/components/camel-msv/src/main/resources/META-INF/services/org/apache/camel/component/msv
- copied, changed from r563442, activemq/camel/trunk/components/camel-msv/src/main/resources/META-INF/services/org/apache/camel/component/relaxng
activemq/camel/trunk/components/camel-msv/src/test/java/org/apache/camel/component/validator/msv/
- copied from r563442, activemq/camel/trunk/components/camel-msv/src/test/java/org/apache/camel/component/validator/relaxng/
activemq/camel/trunk/components/camel-msv/src/test/resources/org/apache/camel/component/validator/msv/
- copied from r563442, activemq/camel/trunk/components/camel-msv/src/test/resources/org/apache/camel/component/validator/relaxng/
Removed:
activemq/camel/trunk/components/camel-jing/src/test/java/org/apache/camel/component/validator/jing/JingRouteTest.java
activemq/camel/trunk/components/camel-jing/src/test/resources/org/apache/camel/component/validator/jing/camelContext.xml
activemq/camel/trunk/components/camel-msv/src/main/java/org/apache/camel/component/validator/msv/RelaxNGComponent.java
activemq/camel/trunk/components/camel-msv/src/test/java/org/apache/camel/component/validator/relaxng/
activemq/camel/trunk/components/camel-msv/src/test/resources/org/apache/camel/component/validator/relaxng/
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchType.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryType.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/CatchProcessor.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java
activemq/camel/trunk/components/camel-msv/src/test/java/org/apache/camel/component/validator/msv/RelaxNGRouteTest.java
activemq/camel/trunk/components/camel-msv/src/test/resources/META-INF/services/org/apache/camel/component/rnc
activemq/camel/trunk/components/camel-msv/src/test/resources/META-INF/services/org/apache/camel/component/rng
activemq/camel/trunk/components/camel-msv/src/test/resources/log4j.properties
activemq/camel/trunk/components/camel-msv/src/test/resources/org/apache/camel/component/validator/msv/camelContext.xml
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/validator/ValidatorRouteTest.java
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/validator/camelContext.xml
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchType.java?view=diff&rev=563472&r1=563471&r2=563472
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchType.java Tue Aug 7 05:27:39 2007
@@ -39,7 +39,7 @@
public class CatchType extends ProcessorType {
@XmlElement(required = false)
private List<InterceptorRef> interceptors = new ArrayList<InterceptorRef>();
- @XmlElement
+ @XmlElement(name="exception")
private List<String> exceptions = new ArrayList<String>();
@XmlElementRef
private List<ProcessorType> outputs = new ArrayList<ProcessorType>();
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java?view=diff&rev=563472&r1=563471&r2=563472
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java Tue Aug 7 05:27:39 2007
@@ -69,21 +69,7 @@
public Processor createOutputsProcessor(RouteContext routeContext) throws Exception {
Collection<ProcessorType> outputs = getOutputs();
- List<Processor> list = new ArrayList<Processor>();
- for (ProcessorType output : outputs) {
- Processor processor = output.createProcessor(routeContext);
- list.add(processor);
- }
- Processor processor = null;
- if (!list.isEmpty()) {
- if (list.size() == 1) {
- processor = list.get(0);
- }
- else {
- processor = createCompositeProcessor(list);
- }
- }
- return processor;
+ return createOutputsProcessor(routeContext, outputs);
}
public void addRoutes(RouteContext routeContext, Collection<Route> routes) throws Exception {
@@ -653,5 +639,23 @@
protected Processor createCompositeProcessor(List<Processor> list) {
//return new MulticastProcessor(list);
return new Pipeline(list);
+ }
+
+ protected Processor createOutputsProcessor(RouteContext routeContext, Collection<ProcessorType> outputs) throws Exception {
+ List<Processor> list = new ArrayList<Processor>();
+ for (ProcessorType output : outputs) {
+ Processor processor = output.createProcessor(routeContext);
+ list.add(processor);
+ }
+ Processor processor = null;
+ if (!list.isEmpty()) {
+ if (list.size() == 1) {
+ processor = list.get(0);
+ }
+ else {
+ processor = createCompositeProcessor(list);
+ }
+ }
+ return processor;
}
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryType.java?view=diff&rev=563472&r1=563471&r2=563472
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryType.java Tue Aug 7 05:27:39 2007
@@ -20,17 +20,17 @@
import org.apache.camel.Endpoint;
import org.apache.camel.Processor;
import org.apache.camel.impl.RouteContext;
-import org.apache.camel.processor.TryProcessor;
import org.apache.camel.processor.CatchProcessor;
+import org.apache.camel.processor.TryProcessor;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
/**
@@ -38,29 +38,40 @@
*/
@XmlRootElement(name = "try")
@XmlAccessorType(XmlAccessType.FIELD)
-public class TryType extends ProcessorType {
+public class TryType extends OutputType {
+/*
@XmlElement(required = false)
private List<InterceptorRef> interceptors = new ArrayList<InterceptorRef>();
@XmlElementRef
- private List<CatchType> catchClauses = new ArrayList<CatchType>();
- @XmlElement(required = false)
+ private List<ProcessorType> outputs = new ArrayList<ProcessorType>();
+*/
+ @XmlTransient
+ private List<CatchType> catchClauses;
+ @XmlTransient
private FinallyType finallyClause;
+ @XmlTransient
+ private boolean initialized;
+ @XmlTransient
+ private List<ProcessorType> outputsWithoutCatches;
@Override
public String toString() {
- return "Try[ " + getCatchClauses() + " " + getFinallyClause() + "]";
+ return "Try[ " + getOutputs() + "]";
}
@Override
public Processor createProcessor(RouteContext routeContext) throws Exception {
- Processor tryProcessor = routeContext.createProcessor(this);
+ Processor tryProcessor = createOutputsProcessor(routeContext, getOutputsWithoutCatches());
+
Processor finallyProcessor = null;
if (finallyClause != null) {
finallyProcessor = finallyClause.createProcessor(routeContext);
}
List<CatchProcessor> catchProcessors = new ArrayList<CatchProcessor>();
- for (CatchType catchClause : catchClauses) {
- catchProcessors.add(catchClause.createProcessor(routeContext));
+ if (catchClauses != null) {
+ for (CatchType catchClause : catchClauses) {
+ catchProcessors.add(catchClause.createProcessor(routeContext));
+ }
}
return new TryProcessor(tryProcessor, catchProcessors, finallyProcessor);
}
@@ -68,13 +79,13 @@
// Fluent API
//-------------------------------------------------------------------------
public TryType when(Class exceptionType) {
- getCatchClauses().add(new CatchType(exceptionType));
+ getOutputs().add(new CatchType(exceptionType));
return this;
}
public FinallyType otherwise() {
FinallyType answer = new FinallyType();
- setFinallyClause(answer);
+ getOutputs().add(answer);
return answer;
}
@@ -105,40 +116,65 @@
// Properties
//-------------------------------------------------------------------------
- public List<CatchType> getCatchClauses() {
- return catchClauses;
- }
-
- public void setCatchClauses(List<CatchType> catchClauses) {
- this.catchClauses = catchClauses;
- }
- public List<ProcessorType> getOutputs() {
- if (finallyClause != null) {
- return finallyClause.getOutputs();
- }
- else if (catchClauses.isEmpty()) {
- return Collections.EMPTY_LIST;
- }
- else {
- CatchType when = catchClauses.get(catchClauses.size() - 1);
- return when.getOutputs();
+ public List<CatchType> getCatchClauses() {
+ if (catchClauses == null) {
+ checkInitialized();
}
+ return catchClauses;
}
public FinallyType getFinallyClause() {
+ if (finallyClause == null) {
+ checkInitialized();
+ }
return finallyClause;
}
- public void setFinallyClause(FinallyType finallyClause) {
- this.finallyClause = finallyClause;
+ public List<ProcessorType> getOutputsWithoutCatches() {
+ if (outputsWithoutCatches == null) {
+ checkInitialized();
+ }
+ return outputsWithoutCatches;
}
- public List<InterceptorRef> getInterceptors() {
- return interceptors;
+ public void setOutputs(List<ProcessorType> outputs) {
+ initialized = false;
+ super.setOutputs(outputs);
}
- public void setInterceptors(List<InterceptorRef> interceptors) {
- this.interceptors = interceptors;
+
+ public void addOutput(ProcessorType output) {
+ initialized = false;
+ getOutputs().add(output);
+ }
+
+ /**
+ * Checks whether or not this object has been initialized
+ */
+ protected void checkInitialized() {
+ if (!initialized) {
+ initialized = true;
+ outputsWithoutCatches = new ArrayList<ProcessorType>();
+ catchClauses = new ArrayList<CatchType>();
+ finallyClause = null;
+
+ for (ProcessorType output : outputs) {
+ if (output instanceof CatchType) {
+ catchClauses.add((CatchType) output);
+ }
+ else if (output instanceof FinallyType) {
+ if (finallyClause != null) {
+ throw new IllegalArgumentException("Multiple finally clauses added: " + finallyClause + " and " + output);
+ }
+ else {
+ finallyClause = (FinallyType) output;
+ }
+ }
+ else {
+ outputsWithoutCatches.add(output);
+ }
+ }
+ }
}
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/CatchProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/CatchProcessor.java?view=diff&rev=563472&r1=563471&r2=563472
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/CatchProcessor.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/CatchProcessor.java Tue Aug 7 05:27:39 2007
@@ -18,21 +18,25 @@
import org.apache.camel.Processor;
import org.apache.camel.Exchange;
+import org.apache.camel.impl.ServiceSupport;
import java.util.List;
/**
* @version $Revision: $
*/
-public class CatchProcessor implements Processor {
+public class CatchProcessor extends DelegateProcessor {
private List<Class> exceptions;
- private Processor processor;
public CatchProcessor(List<Class> exceptions, Processor processor) {
+ super(processor);
this.exceptions = exceptions;
- this.processor = processor;
}
+ @Override
+ public String toString() {
+ return "Catch[" + exceptions + " -> " + getProcessor() + "]";
+ }
public boolean catches(Exception e) {
for (Class type : exceptions) {
@@ -43,7 +47,7 @@
return false;
}
- public void process(Exchange exchange) throws Exception {
- processor.process(exchange);
+ public List<Class> getExceptions() {
+ return exceptions;
}
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java?view=diff&rev=563472&r1=563471&r2=563472
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java Tue Aug 7 05:27:39 2007
@@ -18,6 +18,8 @@
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
+import org.apache.camel.impl.ServiceSupport;
+import org.apache.camel.util.ServiceHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -28,7 +30,7 @@
*
* @version $Revision: $
*/
-public class TryProcessor implements Processor {
+public class TryProcessor extends ServiceSupport implements Processor {
private static final Log log = LogFactory.getLog(TryProcessor.class);
private final Processor tryProcessor;
@@ -41,6 +43,11 @@
this.finallyProcessor = finallyProcessor;
}
+ public String toString() {
+ String finallyText = (finallyProcessor == null) ? "" : " Finally {" + finallyProcessor + "}";
+ return "Try {" + tryProcessor + "} " + catchClauses + finallyText;
+ }
+
public void process(Exchange exchange) throws Exception {
boolean doneTry = false;
try {
@@ -65,9 +72,19 @@
}
}
+ protected void doStart() throws Exception {
+ ServiceHelper.startServices(tryProcessor, catchClauses, finallyProcessor);
+ }
+
+ protected void doStop() throws Exception {
+ ServiceHelper.stopServices(tryProcessor, catchClauses, finallyProcessor);
+ }
+
protected void handleException(Exchange exchange, Exception e) throws Exception {
for (CatchProcessor catchClause : catchClauses) {
if (catchClause.catches(e)) {
+ // lets attach the exception to the exchange
+ exchange.setException(e);
try {
catchClause.process(exchange);
}
@@ -75,8 +92,11 @@
log.warn("Caught exception inside catch clause: " + e1, e1);
throw e1;
}
- break;
+ return;
}
}
+
+ // unhandled exception
+ throw e;
}
}
Copied: activemq/camel/trunk/components/camel-jing/src/main/resources/META-INF/services/org/apache/camel/component/rnc (from r563442, activemq/camel/trunk/components/camel-jing/src/main/resources/META-INF/services/org/apache/camel/component/jing)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jing/src/main/resources/META-INF/services/org/apache/camel/component/rnc?view=diff&rev=563472&p1=activemq/camel/trunk/components/camel-jing/src/main/resources/META-INF/services/org/apache/camel/component/jing&r1=563442&p2=activemq/camel/trunk/components/camel-jing/src/main/resources/META-INF/services/org/apache/camel/component/rnc&r2=563472
==============================================================================
--- activemq/camel/trunk/components/camel-jing/src/main/resources/META-INF/services/org/apache/camel/component/jing (original)
+++ activemq/camel/trunk/components/camel-jing/src/main/resources/META-INF/services/org/apache/camel/component/rnc Tue Aug 7 05:27:39 2007
@@ -15,4 +15,4 @@
# limitations under the License.
#
-class=org.apache.camel.component.validator.jing.JingComponent
\ No newline at end of file
+class=org.apache.camel.component.validator.jing.RelaxNGCompactSyntaxComponent
\ No newline at end of file
Added: activemq/camel/trunk/components/camel-jing/src/test/java/org/apache/camel/component/validator/jing/RNCRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jing/src/test/java/org/apache/camel/component/validator/jing/RNCRouteTest.java?view=auto&rev=563472
==============================================================================
--- activemq/camel/trunk/components/camel-jing/src/test/java/org/apache/camel/component/validator/jing/RNCRouteTest.java (added)
+++ activemq/camel/trunk/components/camel-jing/src/test/java/org/apache/camel/component/validator/jing/RNCRouteTest.java Tue Aug 7 05:27:39 2007
@@ -0,0 +1,31 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.validator.jing;
+
+import org.apache.camel.component.validator.ValidatorRouteTest;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class RNCRouteTest extends ValidatorRouteTest {
+
+ protected ClassPathXmlApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/component/validator/jing/rnc-context.xml");
+ }
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/components/camel-jing/src/test/java/org/apache/camel/component/validator/jing/RNCRouteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied: activemq/camel/trunk/components/camel-jing/src/test/java/org/apache/camel/component/validator/jing/RNGRouteTest.java (from r563442, activemq/camel/trunk/components/camel-msv/src/test/java/org/apache/camel/component/validator/relaxng/RelaxNGRouteTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jing/src/test/java/org/apache/camel/component/validator/jing/RNGRouteTest.java?view=diff&rev=563472&p1=activemq/camel/trunk/components/camel-msv/src/test/java/org/apache/camel/component/validator/relaxng/RelaxNGRouteTest.java&r1=563442&p2=activemq/camel/trunk/components/camel-jing/src/test/java/org/apache/camel/component/validator/jing/RNGRouteTest.java&r2=563472
==============================================================================
--- activemq/camel/trunk/components/camel-msv/src/test/java/org/apache/camel/component/validator/relaxng/RelaxNGRouteTest.java (original)
+++ activemq/camel/trunk/components/camel-jing/src/test/java/org/apache/camel/component/validator/jing/RNGRouteTest.java Tue Aug 7 05:27:39 2007
@@ -15,79 +15,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.validator.relaxng;
+package org.apache.camel.component.validator.jing;
-import org.apache.camel.spring.SpringTestSupport;
-import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.processor.validation.SchemaValidationException;
+import org.apache.camel.component.validator.ValidatorRouteTest;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @version $Revision: 1.1 $
*/
-public class RelaxNGRouteTest extends SpringTestSupport {
- public void testValidMessageUsingRelaxNG() throws Exception {
- assertValidMessage("direct:rng");
- }
-
- public void testInvalidMessageUsingRelaxNG() throws Exception {
- assertInvalidMessage("direct:rng");
- }
-
-/*
- public void testValidMessageUsingRelaxNGCompactSyntax() throws Exception {
- assertValidMessage("direct:rnc");
- }
-
- public void testInvalidMessageUsingRelaxNGCompactSyntax() throws Exception {
- assertInvalidMessage("direct:rnc");
- }
-
-*/
-
- protected void assertValidMessage(String endpointUri) throws Exception {
- String body = "<mail xmlns='http://foo.com/bar'><subject>Hey</subject><body>Hello world!</body></mail>";
- try {
- template.sendBody(endpointUri, body);
- }
- catch (Throwable e) {
- log.error(e, e);
- fail("Caught: " + e);
- }
- }
-
- protected void assertInvalidMessage(String endpointUri) throws Exception {
- String body = "<mail xmlns='http://foo.com/bar'><body>Hello world!</body></mail>";
- try {
- template.sendBody(endpointUri, body);
- }
-
- // TODO ideally we'd not have to wrap validation exceptions!
- // TODO should we expose checked exceptions on CamelTemplate
- // or should we make validation errors be runtime exceptions?
- catch (RuntimeCamelException e) {
- Throwable cause = e.getCause();
- if (cause instanceof SchemaValidationException) {
- log.debug("Caught expected schema validation exception: " + e, e);
- }
- else {
- log.error(e, e);
- fail("Not a SchemaValidationException: " + e);
- }
- }
- catch (Throwable e) {
- log.error(e, e);
- fail("Caught: " + e);
- }
- }
-
- protected int getExpectedRouteCount() {
- // TODO why zero?
- return 0;
- }
+public class RNGRouteTest extends ValidatorRouteTest {
protected ClassPathXmlApplicationContext createApplicationContext() {
- return new ClassPathXmlApplicationContext("org/apache/camel/component/validator/relaxng/camelContext.xml");
+ return new ClassPathXmlApplicationContext("org/apache/camel/component/validator/jing/rng-context.xml");
}
-}
-
+}
\ No newline at end of file
Added: activemq/camel/trunk/components/camel-jing/src/test/resources/org/apache/camel/component/validator/jing/rnc-context.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jing/src/test/resources/org/apache/camel/component/validator/jing/rnc-context.xml?view=auto&rev=563472
==============================================================================
--- activemq/camel/trunk/components/camel-jing/src/test/resources/org/apache/camel/component/validator/jing/rnc-context.xml (added)
+++ activemq/camel/trunk/components/camel-jing/src/test/resources/org/apache/camel/component/validator/jing/rnc-context.xml Tue Aug 7 05:27:39 2007
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+ http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+ ">
+
+ <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <try>
+ <to uri="rnc:org/apache/camel/component/validator/jing/schema.rnc"/>
+ <to uri="mock:valid"/>
+
+ <catch>
+ <exception>org.apache.camel.ValidationException</exception>
+ <to uri="mock:invalid"/>
+ </catch>
+ </try>
+ </route>
+ </camelContext>
+
+</beans>
Propchange: activemq/camel/trunk/components/camel-jing/src/test/resources/org/apache/camel/component/validator/jing/rnc-context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-jing/src/test/resources/org/apache/camel/component/validator/jing/rng-context.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jing/src/test/resources/org/apache/camel/component/validator/jing/rng-context.xml?view=auto&rev=563472
==============================================================================
--- activemq/camel/trunk/components/camel-jing/src/test/resources/org/apache/camel/component/validator/jing/rng-context.xml (added)
+++ activemq/camel/trunk/components/camel-jing/src/test/resources/org/apache/camel/component/validator/jing/rng-context.xml Tue Aug 7 05:27:39 2007
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+ http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+ ">
+
+ <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <try>
+ <to uri="rng:org/apache/camel/component/validator/jing/schema.rng"/>
+ <to uri="mock:valid"/>
+
+ <catch>
+ <exception>org.apache.camel.ValidationException</exception>
+ <to uri="mock:invalid"/>
+ </catch>
+ </try>
+ </route>
+ </camelContext>
+
+</beans>
Propchange: activemq/camel/trunk/components/camel-jing/src/test/resources/org/apache/camel/component/validator/jing/rng-context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-msv/src/main/java/org/apache/camel/component/validator/msv/MsvComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-msv/src/main/java/org/apache/camel/component/validator/msv/MsvComponent.java?view=auto&rev=563472
==============================================================================
--- activemq/camel/trunk/components/camel-msv/src/main/java/org/apache/camel/component/validator/msv/MsvComponent.java (added)
+++ activemq/camel/trunk/components/camel-msv/src/main/java/org/apache/camel/component/validator/msv/MsvComponent.java Tue Aug 7 05:27:39 2007
@@ -0,0 +1,53 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.validator.msv;
+
+import org.apache.camel.component.validator.ValidatorComponent;
+import org.apache.camel.component.validator.SpringValidator;
+import org.iso_relax.verifier.jaxp.validation.RELAXNGSchemaFactoryImpl;
+import org.iso_relax.verifier.VerifierConfigurationException;
+
+import javax.xml.XMLConstants;
+import java.util.Map;
+
+/**
+ * The <a href="http://activemq.apache.org/camel/msv.html">MSV Component</a> uses the
+ * <a href="https://msv.dev.java.net/">MSV library</a> to perform XML validation using pluggable XML schema languages.
+ *
+ * @version $Revision: 1.1 $
+ */
+public class MsvComponent extends ValidatorComponent {
+ private RELAXNGSchemaFactoryImpl schemaFactory;
+
+ public RELAXNGSchemaFactoryImpl getSchemaFactory() throws VerifierConfigurationException {
+ if (schemaFactory == null) {
+ schemaFactory = new RELAXNGSchemaFactoryImpl();
+ }
+ return schemaFactory;
+ }
+
+ public void setSchemaFactory(RELAXNGSchemaFactoryImpl schemaFactory) {
+ this.schemaFactory = schemaFactory;
+ }
+
+ protected void configureValidator(SpringValidator validator, String uri, String remaining, Map parameters) throws Exception {
+ validator.setSchemaLanguage(XMLConstants.RELAXNG_NS_URI);
+ validator.setSchemaFactory(getSchemaFactory());
+ super.configureValidator(validator, uri, remaining, parameters);
+ }
+}
Propchange: activemq/camel/trunk/components/camel-msv/src/main/java/org/apache/camel/component/validator/msv/MsvComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied: activemq/camel/trunk/components/camel-msv/src/main/resources/META-INF/services/org/apache/camel/component/msv (from r563442, activemq/camel/trunk/components/camel-msv/src/main/resources/META-INF/services/org/apache/camel/component/relaxng)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-msv/src/main/resources/META-INF/services/org/apache/camel/component/msv?view=diff&rev=563472&p1=activemq/camel/trunk/components/camel-msv/src/main/resources/META-INF/services/org/apache/camel/component/relaxng&r1=563442&p2=activemq/camel/trunk/components/camel-msv/src/main/resources/META-INF/services/org/apache/camel/component/msv&r2=563472
==============================================================================
--- activemq/camel/trunk/components/camel-msv/src/main/resources/META-INF/services/org/apache/camel/component/relaxng (original)
+++ activemq/camel/trunk/components/camel-msv/src/main/resources/META-INF/services/org/apache/camel/component/msv Tue Aug 7 05:27:39 2007
@@ -15,4 +15,4 @@
# limitations under the License.
#
-class=org.apache.camel.component.validator.relaxng.RelaxNGComponent
\ No newline at end of file
+class=org.apache.camel.component.validator.msv.MsvComponent
\ No newline at end of file
Modified: activemq/camel/trunk/components/camel-msv/src/test/java/org/apache/camel/component/validator/msv/RelaxNGRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-msv/src/test/java/org/apache/camel/component/validator/msv/RelaxNGRouteTest.java?view=diff&rev=563472&r1=563442&r2=563472
==============================================================================
--- activemq/camel/trunk/components/camel-msv/src/test/java/org/apache/camel/component/validator/msv/RelaxNGRouteTest.java (original)
+++ activemq/camel/trunk/components/camel-msv/src/test/java/org/apache/camel/component/validator/msv/RelaxNGRouteTest.java Tue Aug 7 05:27:39 2007
@@ -15,79 +15,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.validator.relaxng;
+package org.apache.camel.component.validator.msv;
-import org.apache.camel.spring.SpringTestSupport;
-import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.processor.validation.SchemaValidationException;
+import org.apache.camel.component.validator.ValidatorRouteTest;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @version $Revision: 1.1 $
*/
-public class RelaxNGRouteTest extends SpringTestSupport {
- public void testValidMessageUsingRelaxNG() throws Exception {
- assertValidMessage("direct:rng");
- }
-
- public void testInvalidMessageUsingRelaxNG() throws Exception {
- assertInvalidMessage("direct:rng");
- }
-
-/*
- public void testValidMessageUsingRelaxNGCompactSyntax() throws Exception {
- assertValidMessage("direct:rnc");
- }
-
- public void testInvalidMessageUsingRelaxNGCompactSyntax() throws Exception {
- assertInvalidMessage("direct:rnc");
- }
-
-*/
-
- protected void assertValidMessage(String endpointUri) throws Exception {
- String body = "<mail xmlns='http://foo.com/bar'><subject>Hey</subject><body>Hello world!</body></mail>";
- try {
- template.sendBody(endpointUri, body);
- }
- catch (Throwable e) {
- log.error(e, e);
- fail("Caught: " + e);
- }
- }
-
- protected void assertInvalidMessage(String endpointUri) throws Exception {
- String body = "<mail xmlns='http://foo.com/bar'><body>Hello world!</body></mail>";
- try {
- template.sendBody(endpointUri, body);
- }
-
- // TODO ideally we'd not have to wrap validation exceptions!
- // TODO should we expose checked exceptions on CamelTemplate
- // or should we make validation errors be runtime exceptions?
- catch (RuntimeCamelException e) {
- Throwable cause = e.getCause();
- if (cause instanceof SchemaValidationException) {
- log.debug("Caught expected schema validation exception: " + e, e);
- }
- else {
- log.error(e, e);
- fail("Not a SchemaValidationException: " + e);
- }
- }
- catch (Throwable e) {
- log.error(e, e);
- fail("Caught: " + e);
- }
- }
-
- protected int getExpectedRouteCount() {
- // TODO why zero?
- return 0;
- }
+public class RelaxNGRouteTest extends ValidatorRouteTest {
protected ClassPathXmlApplicationContext createApplicationContext() {
- return new ClassPathXmlApplicationContext("org/apache/camel/component/validator/relaxng/camelContext.xml");
+ return new ClassPathXmlApplicationContext("org/apache/camel/component/validator/msv/camelContext.xml");
}
}
Modified: activemq/camel/trunk/components/camel-msv/src/test/resources/META-INF/services/org/apache/camel/component/rnc
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-msv/src/test/resources/META-INF/services/org/apache/camel/component/rnc?view=diff&rev=563472&r1=563471&r2=563472
==============================================================================
--- activemq/camel/trunk/components/camel-msv/src/test/resources/META-INF/services/org/apache/camel/component/rnc (original)
+++ activemq/camel/trunk/components/camel-msv/src/test/resources/META-INF/services/org/apache/camel/component/rnc Tue Aug 7 05:27:39 2007
@@ -15,4 +15,4 @@
# limitations under the License.
#
-class=org.apache.camel.component.validator.relaxng.RelaxNGComponent
\ No newline at end of file
+class=org.apache.camel.component.validator.msv.RelaxNGComponent
\ No newline at end of file
Modified: activemq/camel/trunk/components/camel-msv/src/test/resources/META-INF/services/org/apache/camel/component/rng
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-msv/src/test/resources/META-INF/services/org/apache/camel/component/rng?view=diff&rev=563472&r1=563471&r2=563472
==============================================================================
--- activemq/camel/trunk/components/camel-msv/src/test/resources/META-INF/services/org/apache/camel/component/rng (original)
+++ activemq/camel/trunk/components/camel-msv/src/test/resources/META-INF/services/org/apache/camel/component/rng Tue Aug 7 05:27:39 2007
@@ -15,4 +15,4 @@
# limitations under the License.
#
-class=org.apache.camel.component.validator.relaxng.RelaxNGComponent
\ No newline at end of file
+class=org.apache.camel.component.validator.msv.RelaxNGComponent
\ No newline at end of file
Modified: activemq/camel/trunk/components/camel-msv/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-msv/src/test/resources/log4j.properties?view=diff&rev=563472&r1=563471&r2=563472
==============================================================================
--- activemq/camel/trunk/components/camel-msv/src/test/resources/log4j.properties (original)
+++ activemq/camel/trunk/components/camel-msv/src/test/resources/log4j.properties Tue Aug 7 05:27:39 2007
@@ -20,7 +20,7 @@
#
log4j.rootLogger=INFO, out
-log4j.logger.org.apache.camel=DEBUG
+#log4j.logger.org.apache.camel=DEBUG
log4j.logger.org.springframework=WARN
# CONSOLE appender not used by default
Modified: activemq/camel/trunk/components/camel-msv/src/test/resources/org/apache/camel/component/validator/msv/camelContext.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-msv/src/test/resources/org/apache/camel/component/validator/msv/camelContext.xml?view=diff&rev=563472&r1=563442&r2=563472
==============================================================================
--- activemq/camel/trunk/components/camel-msv/src/test/resources/org/apache/camel/component/validator/msv/camelContext.xml (original)
+++ activemq/camel/trunk/components/camel-msv/src/test/resources/org/apache/camel/component/validator/msv/camelContext.xml Tue Aug 7 05:27:39 2007
@@ -24,12 +24,16 @@
<camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
<route>
- <from uri="direct:rng"/>
- <to uri="rnc:org/apache/camel/component/validator/relaxng/schema.rng"/>
- </route>
- <route>
- <from uri="direct:rnc"/>
- <to uri="rnc:org/apache/camel/component/validator/relaxng/schema.rnc"/>
+ <from uri="direct:start"/>
+ <try>
+ <to uri="msv:org/apache/camel/component/validator/msv/schema.rng"/>
+ <to uri="mock:valid"/>
+
+ <catch>
+ <exception>org.apache.camel.ValidationException</exception>
+ <to uri="mock:invalid"/>
+ </catch>
+ </try>
</route>
</camelContext>
Modified: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/validator/ValidatorRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/validator/ValidatorRouteTest.java?view=diff&rev=563472&r1=563471&r2=563472
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/validator/ValidatorRouteTest.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/validator/ValidatorRouteTest.java Tue Aug 7 05:27:39 2007
@@ -16,8 +16,7 @@
*/
package org.apache.camel.component.validator;
-import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.processor.validation.SchemaValidationException;
+import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.spring.SpringTestSupport;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -25,41 +24,33 @@
* @version $Revision: $
*/
public class ValidatorRouteTest extends SpringTestSupport {
+ protected MockEndpoint validEndpoint;
+ protected MockEndpoint invalidEndpoint;
public void testValidMessage() throws Exception {
- String body = "<mail xmlns='http://foo.com/bar'><subject>Hey</subject><body>Hello world!</body></mail>";
- try {
- template.sendBody("direct:start", body);
- }
- catch (Throwable e) {
- log.error(e, e);
- fail("Caught: " + e);
- }
+ validEndpoint.expectedMessageCount(1);
+
+ template.sendBody("direct:start",
+ "<mail xmlns='http://foo.com/bar'><subject>Hey</subject><body>Hello world!</body></mail>");
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint);
}
public void testInvalidMessage() throws Exception {
- String body = "<mail xmlns='http://foo.com/bar'><body>Hello world!</body></mail>";
- try {
- template.sendBody("direct:start", body);
- }
-
- // TODO ideally we'd not have to wrap validation exceptions!
- // TODO should we expose checked exceptions on CamelTemplate
- // or should we make validation errors be runtime exceptions?
- catch (RuntimeCamelException e) {
- Throwable cause = e.getCause();
- if (cause instanceof SchemaValidationException) {
- log.debug("Caught expected schema validation exception: " + e, e);
- }
- else {
- log.error(e, e);
- fail("Not a SchemaValidationException: " + e);
- }
- }
- catch (Throwable e) {
- log.error(e, e);
- fail("Caught: " + e);
- }
+ invalidEndpoint.expectedMessageCount(1);
+
+ template.sendBody("direct:start",
+ "<mail xmlns='http://foo.com/bar'><body>Hello world!</body></mail>");
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ validEndpoint = resolveMandatoryEndpoint("mock:valid", MockEndpoint.class);
+ invalidEndpoint = resolveMandatoryEndpoint("mock:invalid", MockEndpoint.class);
}
protected int getExpectedRouteCount() {
@@ -70,5 +61,4 @@
protected ClassPathXmlApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext("org/apache/camel/component/validator/camelContext.xml");
}
-
}
Modified: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/validator/camelContext.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/validator/camelContext.xml?view=diff&rev=563472&r1=563471&r2=563472
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/validator/camelContext.xml (original)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/validator/camelContext.xml Tue Aug 7 05:27:39 2007
@@ -25,7 +25,15 @@
<camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
<route>
<from uri="direct:start"/>
- <to uri="validator:org/apache/camel/component/validator/schema.xsd"/>
+ <try>
+ <to uri="validator:org/apache/camel/component/validator/schema.xsd"/>
+ <to uri="mock:valid"/>
+
+ <catch>
+ <exception>org.apache.camel.ValidationException</exception>
+ <to uri="mock:invalid"/>
+ </catch>
+ </try>
</route>
</camelContext>