-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[resolves #1478] Add support for component stax
- Loading branch information
1 parent
1172ac0
commit 88eb8c9
Showing
16 changed files
with
320 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,7 @@ spring-event | |
sql | ||
sql-stored | ||
ssh | ||
stax | ||
stream | ||
stub | ||
test | ||
|
24 changes: 24 additions & 0 deletions
24
catalog/src/main/resources/org/apache/camel/catalog/components/stax.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"component": { | ||
"kind": "component", | ||
"scheme": "stax", | ||
"syntax": "stax:contentHandlerClass", | ||
"title": "StAX", | ||
"description": "The stax component allows messages to be process through a SAX ContentHandler.", | ||
"label": "transformation", | ||
"deprecated": "false", | ||
"async": "false", | ||
"producerOnly": "true", | ||
"javaType": "org.apache.camel.component.stax.StAXComponent", | ||
"groupId": "org.apache.camel", | ||
"artifactId": "camel-stax", | ||
"version": "2.18.1" | ||
}, | ||
"componentProperties": { | ||
}, | ||
"properties": { | ||
"contentHandlerClass": { "kind": "path", "group": "producer", "required": "true", "type": "string", "javaType": "java.lang.String", "deprecated": "false", "secret": "false", "description": "The FQN class name for the ContentHandler implementation to use." }, | ||
"synchronous": { "kind": "parameter", "group": "advanced", "label": "advanced", "type": "boolean", "javaType": "boolean", "deprecated": "false", "secret": "false", "defaultValue": "false", "description": "Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported)." } | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
### camel-stax | ||
|
||
The http://camel.apache.org/stax.html[StAX,window=_blank] component enables messages to be passed | ||
through a SAX ContentHandler. It can also iterate over JAXB records using StAX. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...main/resources/modules/system/layers/fuse/org/apache/camel/component/stax/main/module.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module xmlns="urn:jboss:module:1.1" name="org.apache.camel.component.stax"> | ||
<resources> | ||
<artifact name="${org.apache.camel:camel-stax}" /> | ||
</resources> | ||
<dependencies> | ||
<module name="javax.api" /> | ||
<module name="org.slf4j" /> | ||
<module name="javax.xml.bind.api" /> | ||
<module name="org.apache.camel.core" /> | ||
</dependencies> | ||
</module> |
57 changes: 57 additions & 0 deletions
57
itests/common/src/main/java/org/wildfly/camel/test/common/types/Record.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* #%L | ||
* Wildfly Camel :: Testsuite | ||
* %% | ||
* Copyright (C) 2013 - 2017 RedHat | ||
* %% | ||
* Licensed 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. | ||
* #L% | ||
*/ | ||
|
||
package org.wildfly.camel.test.common.types; | ||
|
||
import javax.xml.bind.annotation.XmlAccessType; | ||
import javax.xml.bind.annotation.XmlAccessorType; | ||
import javax.xml.bind.annotation.XmlAttribute; | ||
import javax.xml.bind.annotation.XmlType; | ||
|
||
@XmlAccessorType(XmlAccessType.FIELD) | ||
@XmlType(name = "record", propOrder = { "key", "value" }) | ||
public class Record { | ||
@XmlAttribute(required = true) | ||
protected String key; | ||
|
||
@XmlAttribute(required = true) | ||
protected String value; | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public void setKey(String key) { | ||
this.key = key; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Record[" + key + "]"; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
itests/common/src/main/java/org/wildfly/camel/test/common/types/Records.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* #%L | ||
* Wildfly Camel :: Testsuite | ||
* %% | ||
* Copyright (C) 2013 - 2017 RedHat | ||
* %% | ||
* Licensed 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. | ||
* #L% | ||
*/ | ||
|
||
package org.wildfly.camel.test.common.types; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.xml.bind.annotation.XmlAccessType; | ||
import javax.xml.bind.annotation.XmlAccessorType; | ||
import javax.xml.bind.annotation.XmlElement; | ||
import javax.xml.bind.annotation.XmlRootElement; | ||
|
||
@XmlAccessorType(XmlAccessType.FIELD) | ||
@XmlRootElement(name = "records") | ||
public class Records { | ||
@XmlElement(required = true) | ||
protected List<Record> record; | ||
|
||
public List<Record> getRecord() { | ||
if (record == null) { | ||
record = new ArrayList<Record>(); | ||
} | ||
return record; | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
itests/standalone/basic/src/main/java/org/wildfly/camel/test/stax/StaxIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* #%L | ||
* Wildfly Camel :: Testsuite | ||
* %% | ||
* Copyright (C) 2013 - 2017 RedHat | ||
* %% | ||
* Licensed 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. | ||
* #L% | ||
*/ | ||
|
||
package org.wildfly.camel.test.stax; | ||
|
||
import java.io.InputStream; | ||
|
||
import org.apache.camel.CamelContext; | ||
import org.apache.camel.ProducerTemplate; | ||
import org.apache.camel.builder.RouteBuilder; | ||
import org.apache.camel.component.mock.MockEndpoint; | ||
import org.apache.camel.impl.DefaultCamelContext; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.gravia.resource.ManifestBuilder; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.wildfly.camel.test.common.types.Record; | ||
import org.wildfly.camel.test.common.types.Records; | ||
import org.wildfly.camel.test.common.utils.XMLUtils; | ||
import org.wildfly.camel.test.stax.subA.ElementCountingHandler; | ||
import org.wildfly.extension.camel.CamelAware; | ||
|
||
import static org.apache.camel.component.stax.StAXBuilder.stax; | ||
|
||
@CamelAware | ||
@RunWith(Arquillian.class) | ||
public class StaxIntegrationTest { | ||
|
||
private static final String RECORDS_XML = "records.xml"; | ||
|
||
@Deployment | ||
public static JavaArchive createDeployment() { | ||
return ShrinkWrap.create(JavaArchive.class, "camel-stax-tests.jar") | ||
.addClasses(ElementCountingHandler.class, XMLUtils.class, Record.class, Records.class) | ||
.addAsResource("stax/" + RECORDS_XML, RECORDS_XML) | ||
.setManifest(() -> { | ||
ManifestBuilder builder = new ManifestBuilder(); | ||
builder.addManifestHeader("Dependencies", "org.jdom"); | ||
return builder.openStream(); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testStaxHandler() throws Exception { | ||
CamelContext camelctx = new DefaultCamelContext(); | ||
camelctx.addRoutes(new RouteBuilder() { | ||
@Override | ||
public void configure() throws Exception { | ||
from("direct:start") | ||
.toF("stax:%s", ElementCountingHandler.class.getName()); | ||
} | ||
}); | ||
|
||
camelctx.start(); | ||
try { | ||
InputStream input = getClass().getResourceAsStream("/" + RECORDS_XML); | ||
ProducerTemplate template = camelctx.createProducerTemplate(); | ||
ElementCountingHandler handler = template.requestBody("direct:start", input, ElementCountingHandler.class); | ||
Assert.assertEquals(6, handler.getCount()); | ||
} finally { | ||
camelctx.stop(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testStaxJAXBSplit() throws Exception { | ||
CamelContext camelctx = new DefaultCamelContext(); | ||
camelctx.addRoutes(new RouteBuilder() { | ||
@Override | ||
public void configure() throws Exception { | ||
from("direct:start") | ||
.split(stax(Record.class)).streaming() | ||
.to("mock:result"); | ||
} | ||
}); | ||
|
||
MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); | ||
mockEndpoint.expectedMessageCount(5); | ||
mockEndpoint.allMessages().body().isInstanceOf(Record.class); | ||
|
||
camelctx.start(); | ||
try { | ||
InputStream input = getClass().getResourceAsStream("/" + RECORDS_XML); | ||
ProducerTemplate template = camelctx.createProducerTemplate(); | ||
template.sendBody("direct:start", input); | ||
mockEndpoint.assertIsSatisfied(); | ||
} finally { | ||
camelctx.stop(); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...andalone/basic/src/main/java/org/wildfly/camel/test/stax/subA/ElementCountingHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* #%L | ||
* Wildfly Camel :: Testsuite | ||
* %% | ||
* Copyright (C) 2013 - 2017 RedHat | ||
* %% | ||
* Licensed 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. | ||
* #L% | ||
*/ | ||
|
||
package org.wildfly.camel.test.stax.subA; | ||
|
||
import org.xml.sax.Attributes; | ||
import org.xml.sax.SAXException; | ||
import org.xml.sax.helpers.DefaultHandler; | ||
|
||
public class ElementCountingHandler extends DefaultHandler { | ||
private int count; | ||
|
||
@Override | ||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { | ||
count++; | ||
} | ||
|
||
public int getCount() { | ||
return count; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<records> | ||
<record value="v1" key="1"/> | ||
<record value="v2" key="2"/> | ||
<record value="v3" key="3"/> | ||
<record value="v4" key="4"/> | ||
<record value="v5" key="5"/> | ||
</records> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters