camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1302111 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/validator/ test/java/org/apache/camel/component/validator/ test/resources/org/apache/camel/component/validator/
Date Sun, 18 Mar 2012 11:15:22 GMT
Author: davsclaus
Date: Sun Mar 18 11:15:21 2012
New Revision: 1302111

URL: http://svn.apache.org/viewvc?rev=1302111&view=rev
Log:
CAMEL-5063: Validator component now has better error reporing if cannot resolve resource from
schema.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorIllegalImportTest.java
    camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/BroadcastMonitor.xsd
  (with props)
    camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/BroadcastMonitorFixed.xsd
  (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/validator/DefaultLSResourceResolver.java
    camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/health.xsd
    camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/person.xsd

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/validator/DefaultLSResourceResolver.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/validator/DefaultLSResourceResolver.java?rev=1302111&r1=1302110&r2=1302111&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/validator/DefaultLSResourceResolver.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/validator/DefaultLSResourceResolver.java
Sun Mar 18 11:15:21 2012
@@ -34,15 +34,22 @@ import org.apache.camel.util.ResourceHel
 public class DefaultLSResourceResolver implements LSResourceResolver {
 
     private final CamelContext camelContext;
+    private final String resourceUri;
     private final String resourcePath;
 
     public DefaultLSResourceResolver(CamelContext camelContext, String resourceUri) {
         this.camelContext = camelContext;
+        this.resourceUri = resourceUri;
         this.resourcePath = FileUtil.onlyPath(resourceUri);
     }
 
     @Override
     public LSInput resolveResource(String type, String namespaceURI, String publicId, String
systemId, String baseURI) {
+        // systemId should be mandatory
+        if (systemId == null) {
+            throw new IllegalArgumentException(String.format("Resource: %s refers an invalid
resource without SystemId."
+                    + " Invalid resource has type: %s, namespaceURI: %s, publicId: %s, systemId:
%s, baseURI: %s", resourceUri, type, namespaceURI, publicId, systemId, baseURI));
+        }
         return new DefaultLSInput(publicId, systemId, baseURI);
     }
     
@@ -57,7 +64,7 @@ public class DefaultLSResourceResolver i
             this.publicId = publicId;
             this.systemId = systemId;
             this.baseURI = baseURI;
-
+            
             if (resourcePath != null) {
                 uri = resourcePath + "/" + systemId;
             } else {

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorIllegalImportTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorIllegalImportTest.java?rev=1302111&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorIllegalImportTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorIllegalImportTest.java
Sun Mar 18 11:15:21 2012
@@ -0,0 +1,94 @@
+/**
+ * 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;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.FailedToCreateRouteException;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ *
+ */
+public class ValidatorIllegalImportTest extends ContextTestSupport {
+
+    private final String broadCastEvent = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
+            + "<BroadcastMonitor> "
+            + "<updated>2012-03-01T03:46:26</updated>"
+            + "<stationName>P7 Mix</stationName>"
+            + "<Current>"
+            + "<startTime>2012-03-01T03:46:26</startTime>"
+            + "<itemId>1000736343:8505553</itemId>"
+            + "<titleId>785173</titleId>"
+            + "<itemCode>9004342-0101</itemCode>"
+            + "<itemReference></itemReference>"
+            + "<titleName>Part Of Me</titleName>"
+            + "<artistName>Katy Perry</artistName>"
+            + "<albumName></albumName>"
+            + "</Current>"
+            + "<Next>"
+            + "<startTime>2012-03-01T03:50:00</startTime>"
+            + "<itemId>1000736343:8505554</itemId>"
+            + "<titleId>780319</titleId>"
+            + "<itemCode>2318050-0101</itemCode>"
+            + "<itemReference></itemReference>"
+            + "<titleName>Fine</titleName>"
+            + "<artistName>Whitney Houston</artistName>"
+            + "<albumName></albumName>"
+            + "</Next>"
+            + "</BroadcastMonitor>";
+
+    public void testOk() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:test")
+                    .to("validator:org/apache/camel/component/validator/BroadCastMonitorFixed.xsd")
+                    .to("mock:result");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+        template.sendBody("direct:test", broadCastEvent);
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testIllegalImport() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:test")
+                    .to("validator:org/apache/camel/component/validator/BroadCastMonitor.xsd")
+                    .to("mock:result");
+            }
+        });
+        try {
+            context.start();
+            fail("Should have thrown exception");
+        } catch (FailedToCreateRouteException e) {
+            ResolveEndpointFailedException cause = assertIsInstanceOf(ResolveEndpointFailedException.class,
e.getCause());
+            IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class,
cause.getCause());
+            assertTrue(iae.getMessage().startsWith("Resource: org/apache/camel/component/validator/BroadCastMonitor.xsd
refers an invalid resource without SystemId."));
+        }
+    }
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+}

Added: camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/BroadcastMonitor.xsd
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/BroadcastMonitor.xsd?rev=1302111&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/BroadcastMonitor.xsd
(added)
+++ camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/BroadcastMonitor.xsd
Sun Mar 18 11:15:21 2012
@@ -0,0 +1,56 @@
+<?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.
+-->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
+	<xs:import namespace="http://www.w3.org/XML/1998/namespace" />
+	<xs:element name="BroadcastMonitor">
+		<xs:complexType>
+			<xs:sequence>
+	    		<xs:element name="updated" type="xs:dateTime" maxOccurs="1" minOccurs="0"></xs:element>
+	    		<xs:element name="stationName" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+				<xs:element name="Current">
+					<xs:complexType>
+						<xs:sequence>
+	    					<xs:element name="startTime" type="xs:dateTime" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="itemId" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="titleId" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="itemCode" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="itemReference" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="titleName" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="artistName" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="albumName" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+						</xs:sequence>
+					</xs:complexType>
+				</xs:element>
+				<xs:element name="Next">
+					<xs:complexType>
+						<xs:sequence>
+	    					<xs:element name="startTime" type="xs:dateTime" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="itemId" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="titleId" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="itemCode" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="itemReference" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="titleName" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="artistName" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="albumName" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+						</xs:sequence>
+					</xs:complexType>
+				</xs:element>
+			</xs:sequence>
+		</xs:complexType>
+	</xs:element>
+</xs:schema>
\ No newline at end of file

Propchange: camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/BroadcastMonitor.xsd
------------------------------------------------------------------------------
    svn:executable = *

Added: camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/BroadcastMonitorFixed.xsd
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/BroadcastMonitorFixed.xsd?rev=1302111&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/BroadcastMonitorFixed.xsd
(added)
+++ camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/BroadcastMonitorFixed.xsd
Sun Mar 18 11:15:21 2012
@@ -0,0 +1,55 @@
+<?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.
+-->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
+	<xs:element name="BroadcastMonitor">
+		<xs:complexType>
+			<xs:sequence>
+	    		<xs:element name="updated" type="xs:dateTime" maxOccurs="1" minOccurs="0"></xs:element>
+	    		<xs:element name="stationName" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+				<xs:element name="Current">
+					<xs:complexType>
+						<xs:sequence>
+	    					<xs:element name="startTime" type="xs:dateTime" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="itemId" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="titleId" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="itemCode" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="itemReference" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="titleName" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="artistName" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="albumName" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+						</xs:sequence>
+					</xs:complexType>
+				</xs:element>
+				<xs:element name="Next">
+					<xs:complexType>
+						<xs:sequence>
+	    					<xs:element name="startTime" type="xs:dateTime" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="itemId" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="titleId" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="itemCode" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="itemReference" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="titleName" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="artistName" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+	    					<xs:element name="albumName" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
+						</xs:sequence>
+					</xs:complexType>
+				</xs:element>
+			</xs:sequence>
+		</xs:complexType>
+	</xs:element>
+</xs:schema>
\ No newline at end of file

Propchange: camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/BroadcastMonitorFixed.xsd
------------------------------------------------------------------------------
    svn:executable = *

Modified: camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/health.xsd
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/health.xsd?rev=1302111&r1=1302110&r2=1302111&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/health.xsd
(original)
+++ camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/health.xsd
Sun Mar 18 11:15:21 2012
@@ -1,4 +1,20 @@
 <?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.
+-->
 <xs:schema
         attributeFormDefault="unqualified"
         elementFormDefault="qualified"

Modified: camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/person.xsd
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/person.xsd?rev=1302111&r1=1302110&r2=1302111&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/person.xsd
(original)
+++ camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/person.xsd
Sun Mar 18 11:15:21 2012
@@ -1,4 +1,20 @@
 <?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.
+-->
 <xs:schema attributeFormDefault="unqualified"
            elementFormDefault="qualified"
            xmlns:xs="http://www.w3.org/2001/XMLSchema"



Mime
View raw message