Skip to content

Commit

Permalink
[resolves wildfly-extras#2041] Add support for dataformat ical
Browse files Browse the repository at this point in the history
  • Loading branch information
tdiesler committed Sep 18, 2017
1 parent a4d8475 commit 3d603cb
Show file tree
Hide file tree
Showing 13 changed files with 303 additions and 23 deletions.
4 changes: 2 additions & 2 deletions catalog/src/main/resources/dataformat.roadmap
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ crypto
csv
flatpack
gzip
hessian #2040
hessian
hl7
ical
jacksonxml
jaxb
json-gson
Expand All @@ -39,7 +40,6 @@ zip
zipfile

[planned]
ical #2041
jibx #2042
json-johnzon #2043
lzf #2044
Expand Down
1 change: 1 addition & 0 deletions docs/guide/dataformats/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The following lists supported Data Formats
* http://camel.apache.org/flatpack.html[Flatpack,window=_blank]
* http://camel.apache.org/gzip-data-format.html[GZip,window=_blank]
* http://camel.apache.org/hl7.html[HL7,window=_blank]
* http://camel.apache.org/ical.html[iCal,window=_blank]
* http://camel.apache.org/jaxb.html[JAXB,window=_blank]
* http://camel.apache.org/jackson-xml.html[JacksonXML,window=_blank]
* http://camel.apache.org/json.html[JSON,window=_blank]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<module name="org.apache.camel.component.hl7" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.http4" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.hystrix" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.ical" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.infinispan" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.influxdb" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.irc" export="true" services="export" optional="true" />
Expand Down
20 changes: 20 additions & 0 deletions feature/pack/etc/smartics/camel-modules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,26 @@
</dependencies>
</module>

<module name="org.apache.camel.component.ical">
<include artifact="org.apache.camel:camel-ical" />
<include artifact="org.mnode.ical4j:ical4j" />
<include artifact="backport-util-concurrent:backport-util-concurrent" />
<apply-to-dependencies skip="true">
<include module="org.apache.camel.apt" />
<include module="org.springframework.boot" />
<include module="org.mnode.skipped" />
</apply-to-dependencies>
<dependencies>
<module name="javax.api"/>
<module name="org.slf4j" />
</dependencies>
<exports>
<exclude path="edu/emory" />
<exclude path="edu/emory/**" />
<exclude path="net/fortuna" />
</exports>
</module>

<module name="org.apache.camel.component.infinispan">
<include artifact="org.apache.camel:camel-infinispan"/>
<apply-to-dependencies skip="true">
Expand Down
46 changes: 25 additions & 21 deletions feature/pack/etc/smartics/skipped-modules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@
<include artifact=":woodstox-core" />
</module>

<module name="org.eclipse.jetty.orbit" skip="true">
<include artifact="org.eclipse.jetty.orbit:javax.servlet" />
</module>

<module name="org.eclipse.jetty.server" skip="true">
<include artifact="org.eclipse.jetty:jetty-server" />
</module>

<module name="org.fusesource.hawtjni" skip="true">
<include artifact="org.fusesource.hawtjni:hawtjni-runtime" />
</module>
Expand All @@ -256,6 +264,15 @@
<include artifact="org.fusesource.leveldbjni:leveldbjni-all" />
</module>

<module name="org.glassfish.web" skip="true">
<include artifact="org.glassfish.web:javax.el" />
</module>

<module name="org.infinispan.cdi" skip="true">
<include artifact="org.infinispan:infinispan-cdi-common" />
<include artifact="org.infinispan:infinispan-cdi-embedded" />
</module>

<module name="org.iq80.leveldb" skip="true">
<include artifact="org.iq80.leveldb:leveldb-api" />
</module>
Expand All @@ -272,23 +289,6 @@
<include artifact="org.jboss.marshalling:jboss-marshalling-osgi" />
</module>

<module name="org.eclipse.jetty.orbit" skip="true">
<include artifact="org.eclipse.jetty.orbit:javax.servlet" />
</module>

<module name="org.eclipse.jetty.server" skip="true">
<include artifact="org.eclipse.jetty:jetty-server" />
</module>

<module name="org.glassfish.web" skip="true">
<include artifact="org.glassfish.web:javax.el" />
</module>

<module name="org.infinispan.cdi" skip="true">
<include artifact="org.infinispan:infinispan-cdi-common" />
<include artifact="org.infinispan:infinispan-cdi-embedded" />
</module>

<module name="org.jboss.interceptor" skip="true">
<include artifact="org.jboss.interceptor:jboss-interceptor-core" />
<include artifact="org.jboss.interceptor:jboss-interceptor-spi" />
Expand All @@ -311,10 +311,6 @@
<include artifact="org.jctools:(.*)" />
</module>

<module name="org.projectlombok" skip="true">
<include artifact="org.projectlombok:lombok" />
</module>

<module name="org.jruby" skip="true">
<include artifact="org.jruby:jruby" />
<include artifact="org.jruby:jruby-core" />
Expand All @@ -336,6 +332,10 @@
<include artifact="org.linkedin:(.*)" />
</module>

<module name="org.mnode.skipped" skip="true">
<include artifact="org.mnode:mnode-tools" />
</module>

<module name="org.mortbay.jetty" skip="true">
<include artifact="org.mortbay.jetty:(.*)" />
</module>
Expand All @@ -353,6 +353,10 @@
<include artifact="org.ow2.asm:asm-commons"/>
</module>

<module name="org.projectlombok" skip="true">
<include artifact="org.projectlombok:lombok" />
</module>

<module name="org.scala" skip="true">
<include artifact="org.scala-lang:scala-compiler" />
<include artifact="org.scala-lang:scala-reflect" />
Expand Down
4 changes: 4 additions & 0 deletions feature/pack/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-ical</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-infinispan</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.apache.camel.component.ical">
<resources>
<artifact name="${backport-util-concurrent:backport-util-concurrent}" />
<artifact name="${org.apache.camel:camel-ical}" />
<artifact name="${org.mnode.ical4j:ical4j}" />
</resources>
<dependencies>
<module name="javax.api" />
<module name="org.slf4j" />
<module name="javax.xml.bind.api" />
<module name="org.apache.camel.core" />
<module name="org.apache.commons.codec" />
<module name="org.apache.commons.lang" />
<module name="org.apache.commons.logging" />
</dependencies>
<exports>
<exclude path="edu/emory" />
<exclude path="edu/emory/**" />
<exclude path="net/fortuna" />
</exports>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<module name="org.apache.camel.component.hl7" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.http4" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.hystrix" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.ical" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.infinispan" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.influxdb" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.irc" export="true" services="export" optional="true" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/*
* #%L
* Wildfly Camel :: Testsuite
* %%
* Copyright (C) 2013 - 2014 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.ical;

import java.io.InputStream;
import java.net.URI;
import java.text.ParseException;
import java.util.GregorianCalendar;

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.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.extension.camel.CamelAware;

import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.model.DateTime;
import net.fortuna.ical4j.model.PropertyList;
import net.fortuna.ical4j.model.TimeZone;
import net.fortuna.ical4j.model.TimeZoneRegistry;
import net.fortuna.ical4j.model.TimeZoneRegistryFactory;
import net.fortuna.ical4j.model.component.VEvent;
import net.fortuna.ical4j.model.component.VTimeZone;
import net.fortuna.ical4j.model.parameter.Cn;
import net.fortuna.ical4j.model.parameter.Role;
import net.fortuna.ical4j.model.property.Attendee;
import net.fortuna.ical4j.model.property.CalScale;
import net.fortuna.ical4j.model.property.DtEnd;
import net.fortuna.ical4j.model.property.DtStamp;
import net.fortuna.ical4j.model.property.DtStart;
import net.fortuna.ical4j.model.property.ProdId;
import net.fortuna.ical4j.model.property.Summary;
import net.fortuna.ical4j.model.property.Uid;
import net.fortuna.ical4j.model.property.Version;

@CamelAware
@RunWith(Arquillian.class)
public class ICalFormatTest {

@Deployment
public static JavaArchive deployment() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "ical-dataformat-tests");
archive.addAsResource("ical/data.ics");
return archive;
}

@Test
public void testMarshal() throws Exception {

CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:marshal").marshal("ical").to("mock:result");
}
});

camelctx.start();
try {
ProducerTemplate producer = camelctx.createProducerTemplate();

Calendar calendar = createTestCalendar();
MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class);
mock.expectedBodiesReceived(calendar.toString());

producer.sendBody("direct:marshal", calendar);

mock.assertIsSatisfied();
} finally {
camelctx.stop();
}
}

@Test
public void testUnmarshal() throws Exception {

CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:unmarshal").unmarshal("ical").to("mock:result");
}
});

camelctx.start();
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
InputStream inStream = getClass().getResourceAsStream("/ical/data.ics");
Calendar response = producer.requestBody("direct:unmarshal", inStream, Calendar.class);
Assert.assertNotNull(response);
} finally {
camelctx.stop();
}
}

private Calendar createTestCalendar() throws ParseException {
// Create a TimeZone
TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
TimeZone timezone = registry.getTimeZone("America/New_York");
VTimeZone tz = timezone.getVTimeZone();

// Start Date is on: April 1, 2013, 9:00 am
java.util.Calendar startDate = new GregorianCalendar();
startDate.setTimeZone(timezone);
startDate.set(java.util.Calendar.MONTH, java.util.Calendar.APRIL);
startDate.set(java.util.Calendar.DAY_OF_MONTH, 1);
startDate.set(java.util.Calendar.YEAR, 2013);
startDate.set(java.util.Calendar.HOUR_OF_DAY, 17);
startDate.set(java.util.Calendar.MINUTE, 0);
startDate.set(java.util.Calendar.SECOND, 0);

// End Date is on: April 1, 2013, 13:00
java.util.Calendar endDate = new GregorianCalendar();
endDate.setTimeZone(timezone);
endDate.set(java.util.Calendar.MONTH, java.util.Calendar.APRIL);
endDate.set(java.util.Calendar.DAY_OF_MONTH, 1);
endDate.set(java.util.Calendar.YEAR, 2013);
endDate.set(java.util.Calendar.HOUR_OF_DAY, 21);
endDate.set(java.util.Calendar.MINUTE, 0);
endDate.set(java.util.Calendar.SECOND, 0);

// Create the event
PropertyList propertyList = new PropertyList();
propertyList.add(new DtStamp("20130324T180000Z"));
propertyList.add(new DtStart(new DateTime(startDate.getTime())));
propertyList.add(new DtEnd(new DateTime(endDate.getTime())));
propertyList.add(new Summary("Progress Meeting"));
VEvent meeting = new VEvent(propertyList);

// add timezone info..
meeting.getProperties().add(tz.getTimeZoneId());

// generate unique identifier..
meeting.getProperties().add(new Uid("00000000"));

// add attendees..
Attendee dev1 = new Attendee(URI.create("mailto:dev1@mycompany.com"));
dev1.getParameters().add(Role.REQ_PARTICIPANT);
dev1.getParameters().add(new Cn("Developer 1"));
meeting.getProperties().add(dev1);

Attendee dev2 = new Attendee(URI.create("mailto:dev2@mycompany.com"));
dev2.getParameters().add(Role.OPT_PARTICIPANT);
dev2.getParameters().add(new Cn("Developer 2"));
meeting.getProperties().add(dev2);

// Create a calendar
net.fortuna.ical4j.model.Calendar icsCalendar = new net.fortuna.ical4j.model.Calendar();
icsCalendar.getProperties().add(Version.VERSION_2_0);
icsCalendar.getProperties().add(new ProdId("-//Events Calendar//iCal4j 1.0//EN"));
icsCalendar.getProperties().add(CalScale.GREGORIAN);

// Add the event and print
icsCalendar.getComponents().add(meeting);
return icsCalendar;
}
}
15 changes: 15 additions & 0 deletions itests/standalone/basic/src/test/resources/ical/data.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Events Calendar//iCal4j 1.0//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTSTAMP:20130324T180000Z
DTSTART:20130401T170000
DTEND:20130401T210000
SUMMARY:Progress Meeting
TZID:America/New_York
UID:00000000
ATTENDEE;ROLE=REQ-PARTICIPANT;CN=Developer 1:mailto:dev1@mycompany.com
ATTENDEE;ROLE=OPT-PARTICIPANT;CN=Developer 2:mailto:dev2@mycompany.com
END:VEVENT
END:VCALENDAR
Loading

0 comments on commit 3d603cb

Please sign in to comment.