Skip to content

Commit

Permalink
[resolves #1478] Add support for component stax
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnetherton committed Jan 13, 2017
1 parent 1172ac0 commit 88eb8c9
Show file tree
Hide file tree
Showing 16 changed files with 320 additions and 1 deletion.
2 changes: 1 addition & 1 deletion catalog/src/main/resources/component.roadmap
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ spring-event
sql
sql-stored
ssh
stax
stream
stub
test
Expand Down Expand Up @@ -155,7 +156,6 @@ spring-integration
spring-ldap
spring-redis
spring-ws
stax
websocket

[undecided]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ spring-event
sql
sql-stored
ssh
stax
stream
stub
test
Expand Down
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)." }
}
}

5 changes: 5 additions & 0 deletions docs/guide/components/camel-stax.adoc
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.

Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
<module name="org.apache.camel.component.sjms" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.sql" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.ssh" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.stax" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.stream" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.swagger" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.syslog" export="true" services="export" optional="true" />
Expand Down
12 changes: 12 additions & 0 deletions feature/etc/smartics/camel-modules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,18 @@
</dependencies>
</module>

<module name="org.apache.camel.component.stax">
<include artifact="org.apache.camel:camel-stax" />
<apply-to-dependencies skip="true">
<include module="org.apache.camel.apt" />
<include module="org.springframework.boot" />
</apply-to-dependencies>
<dependencies>
<module name="javax.api"/>
<module name="org.slf4j"/>
</dependencies>
</module>

<module name="org.apache.camel.component.stream">
<include artifact="org.apache.camel:camel-stream" />
<apply-to-dependencies skip="true">
Expand Down
4 changes: 4 additions & 0 deletions feature/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-ssh</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-stax</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-stream</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
<module name="org.apache.camel.component.sjms" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.sql" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.ssh" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.stax" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.stream" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.swagger" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.syslog" export="true" services="export" optional="true" />
Expand Down
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>
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 + "]";
}
}
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;
}
}
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();
}
}
}
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;
}
}
8 changes: 8 additions & 0 deletions itests/standalone/basic/src/main/resources/stax/records.xml
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>
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ org/apache/camel/component/sql/stored/template
org/apache/camel/component/sql/stored/template/ast
org/apache/camel/component/sql/stored/template/generated
org/apache/camel/component/ssh
org/apache/camel/component/stax
org/apache/camel/component/stream
org/apache/camel/component/syslog
org/apache/camel/component/syslog/netty
Expand Down
1 change: 1 addition & 0 deletions patch/etc/baseline/module-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
/org/apache/camel/component/spring/security/main/camel-spring-security-2.18.1.jar
/org/apache/camel/component/sql/main/camel-sql-2.18.1.jar
/org/apache/camel/component/ssh/main/camel-ssh-2.18.1.jar
/org/apache/camel/component/stax/main/camel-stax-2.18.1.jar
/org/apache/camel/component/stream/main/camel-stream-2.18.1.jar
/org/apache/camel/component/swagger/main/camel-swagger-java-2.18.1.jar
/org/apache/camel/component/swagger/main/reflections-0.9.10.jar
Expand Down

0 comments on commit 88eb8c9

Please sign in to comment.