You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/12/08 10:07:16 UTC

svn commit: r888296 [1/2] - in /camel/trunk: apache-camel/ apache-camel/src/main/descriptors/ components/ components/camel-smpp/ components/camel-smpp/src/ components/camel-smpp/src/main/ components/camel-smpp/src/main/java/ components/camel-smpp/src/m...

Author: davsclaus
Date: Tue Dec  8 09:07:14 2009
New Revision: 888296

URL: http://svn.apache.org/viewvc?rev=888296&view=rev
Log:
CAMEL-1921: Added new camel-smpp component. Many thanks to Christian Mueller for contributing.

Added:
    camel/trunk/components/camel-smpp/
    camel/trunk/components/camel-smpp/pom.xml   (with props)
    camel/trunk/components/camel-smpp/src/
    camel/trunk/components/camel-smpp/src/main/
    camel/trunk/components/camel-smpp/src/main/java/
    camel/trunk/components/camel-smpp/src/main/java/org/
    camel/trunk/components/camel-smpp/src/main/java/org/apache/
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppBinding.java   (with props)
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppComponent.java   (with props)
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java   (with props)
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConsumer.java   (with props)
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppEndpoint.java   (with props)
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessage.java   (with props)
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java   (with props)
    camel/trunk/components/camel-smpp/src/main/resources/
    camel/trunk/components/camel-smpp/src/main/resources/META-INF/
    camel/trunk/components/camel-smpp/src/main/resources/META-INF/services/
    camel/trunk/components/camel-smpp/src/main/resources/META-INF/services/org/
    camel/trunk/components/camel-smpp/src/main/resources/META-INF/services/org/apache/
    camel/trunk/components/camel-smpp/src/main/resources/META-INF/services/org/apache/camel/
    camel/trunk/components/camel-smpp/src/main/resources/META-INF/services/org/apache/camel/component/
    camel/trunk/components/camel-smpp/src/main/resources/META-INF/services/org/apache/camel/component/smpp
    camel/trunk/components/camel-smpp/src/test/
    camel/trunk/components/camel-smpp/src/test/java/
    camel/trunk/components/camel-smpp/src/test/java/org/
    camel/trunk/components/camel-smpp/src/test/java/org/apache/
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppBindingTest.java   (with props)
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppComponentTest.java   (with props)
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConfigurationTest.java   (with props)
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConsumerTest.java   (with props)
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppEndpointTest.java   (with props)
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppMessageTest.java   (with props)
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppProducerTest.java   (with props)
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppComponentIntegrationTest.java   (with props)
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppComponentSpringIntegrationTest.java   (with props)
    camel/trunk/components/camel-smpp/src/test/resources/
    camel/trunk/components/camel-smpp/src/test/resources/log4j.properties   (with props)
    camel/trunk/components/camel-smpp/src/test/resources/org/
    camel/trunk/components/camel-smpp/src/test/resources/org/apache/
    camel/trunk/components/camel-smpp/src/test/resources/org/apache/camel/
    camel/trunk/components/camel-smpp/src/test/resources/org/apache/camel/component/
    camel/trunk/components/camel-smpp/src/test/resources/org/apache/camel/component/smpp/
    camel/trunk/components/camel-smpp/src/test/resources/org/apache/camel/component/smpp/integration/
    camel/trunk/components/camel-smpp/src/test/resources/org/apache/camel/component/smpp/integration/SmppComponentSpringIntegrationTest-context.xml   (with props)
Modified:
    camel/trunk/apache-camel/pom.xml
    camel/trunk/apache-camel/src/main/descriptors/common-bin.xml
    camel/trunk/components/pom.xml
    camel/trunk/parent/pom.xml
    camel/trunk/platforms/karaf/features/pom.xml
    camel/trunk/platforms/karaf/features/src/main/resources/bundles.properties
    camel/trunk/platforms/karaf/features/src/main/resources/features.xml

Modified: camel/trunk/apache-camel/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/apache-camel/pom.xml?rev=888296&r1=888295&r2=888296&view=diff
==============================================================================
--- camel/trunk/apache-camel/pom.xml (original)
+++ camel/trunk/apache-camel/pom.xml Tue Dec  8 09:07:14 2009
@@ -228,6 +228,10 @@
     </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>
+      <artifactId>camel-smpp</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
       <artifactId>camel-snmp</artifactId>
     </dependency>
     <dependency>

Modified: camel/trunk/apache-camel/src/main/descriptors/common-bin.xml
URL: http://svn.apache.org/viewvc/camel/trunk/apache-camel/src/main/descriptors/common-bin.xml?rev=888296&r1=888295&r2=888296&view=diff
==============================================================================
--- camel/trunk/apache-camel/src/main/descriptors/common-bin.xml (original)
+++ camel/trunk/apache-camel/src/main/descriptors/common-bin.xml Tue Dec  8 09:07:14 2009
@@ -80,6 +80,7 @@
         <include>org.apache.camel:camel-scala</include>
         <include>org.apache.camel:camel-script</include>
         <include>org.apache.camel:camel-servlet</include>
+        <include>org.apache.camel:camel-smpp</include>
         <include>org.apache.camel:camel-snmp</include>
         <include>org.apache.camel:camel-spring</include>
         <include>org.apache.camel:camel-spring-integration</include>

Added: camel/trunk/components/camel-smpp/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/pom.xml?rev=888296&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/pom.xml (added)
+++ camel/trunk/components/camel-smpp/pom.xml Tue Dec  8 09:07:14 2009
@@ -0,0 +1,91 @@
+<?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.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" 
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>camel-parent</artifactId>
+    <version>2.2-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>camel-smpp</artifactId>
+  <packaging>bundle</packaging>
+  <name>Camel :: SMPP</name>
+  <description>Camel SMPP support</description>
+
+  <properties>
+    <camel.osgi.export.pkg>org.apache.camel.component.smpp.*</camel.osgi.export.pkg>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicemix.bundles</groupId>
+      <artifactId>org.apache.servicemix.bundles.jsmpp</artifactId>
+      <version>2.0_2</version>
+      <type>bundle</type>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+    </dependency>
+
+    <!-- testing -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-test</artifactId>      
+      <scope>test</scope>
+    </dependency>
+      <dependency>
+        <groupId>org.apache.camel</groupId>
+        <artifactId>camel-spring</artifactId>
+        <scope>test</scope>
+      </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-test</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.easymock</groupId>
+      <artifactId>easymockclassextension</artifactId>
+      <version>2.4</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+</project>
\ No newline at end of file

Propchange: camel/trunk/components/camel-smpp/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-smpp/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-smpp/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppBinding.java?rev=888296&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppBinding.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppBinding.java Tue Dec  8 09:07:14 2009
@@ -0,0 +1,247 @@
+/**
+ * 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.smpp;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Date;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.jsmpp.bean.AlertNotification;
+import org.jsmpp.bean.Command;
+import org.jsmpp.bean.DeliverSm;
+import org.jsmpp.bean.DeliveryReceipt;
+import org.jsmpp.bean.SubmitSm;
+import org.jsmpp.util.AbsoluteTimeFormatter;
+import org.jsmpp.util.TimeFormatter;
+
+/**
+ * A Strategy used to convert between a Camel {@link Exchange} and
+ * {@link SmppMessage} to and from a SMPP {@link Command}
+ * 
+ * @version $Revision$
+ * @author muellerc
+ */
+public class SmppBinding {
+
+    public static final String SEQUENCE_NUMBER = "CamelSmppSequenceNumber";
+    public static final String SUBMITTED = "CamelSmppSubmitted";
+    public static final String SUBMIT_DATE = "CamelSmppSubmitDate";
+    public static final String ERROR = "CamelSmppError";
+    public static final String DONE_DATE = "CamelSmppDoneDate";
+    public static final String DELIVERED = "CamelSmppDelivered";
+    public static final String COMMAND_ID = "CamelSmppCommandId";
+    public static final String COMMAND_STATUS = "CamelSmppCommandStatus";
+    public static final String ID = "CamelSmppId";
+    public static final String REPLACE_IF_PRESENT_FLAG = "CamelSmppReplaceIfPresentFlag";
+    public static final String VALIDITY_PERIOD = "CamelSmppValidityPeriod";
+    public static final String SCHEDULE_DELIVERY_TIME = "CamelSmppScheduleDeliveryTime";
+    public static final String PRIORITY_FLAG = "CamelSmppPriorityFlag";
+    public static final String PROTOCOL_ID = "CamelSmppProtocolId";
+    public static final String REGISTERED_DELIVERY = "CamelSmppRegisteredDelivery";
+    public static final String SERVICE_TYPE = "CamelSmppServiceType";
+    public static final String SOURCE_ADDR_NPI = "CamelSmppSourceAddrNpi";
+    public static final String SOURCE_ADDR_TON = "CamelSmppSourceAddrTon";
+    public static final String SOURCE_ADDR = "CamelSmppSourceAddr";
+    public static final String DEST_ADDR_NPI = "CamelSmppDestAddrNpi";
+    public static final String DEST_ADDR_TON = "CamelSmppDestAddrTon";
+    public static final String DEST_ADDR = "CamelSmppDestAddr";
+    public static final String ESME_ADDR_NPI = "CamelSmppEsmeAddrNpi";
+    public static final String ESME_ADDR_TON = "CamelSmppEsmeAddrTon";
+    public static final String ESME_ADDR = "CamelSmppEsmeAddr";
+
+    private static TimeFormatter timeFormatter = new AbsoluteTimeFormatter();
+
+    private SmppConfiguration configuration;
+
+    public SmppBinding() {
+        this.configuration = new SmppConfiguration();
+    }
+
+    public SmppBinding(SmppConfiguration configuration) {
+        this.configuration = configuration;
+    }
+
+    /**
+     * Create the SubmitSm object from the inbound exchange
+     * 
+     * @throws UnsupportedEncodingException if the encoding is not supported
+     */
+    public SubmitSm createSubmitSm(Exchange exchange) throws UnsupportedEncodingException {
+        Message in = exchange.getIn();
+
+        SubmitSm submitSm = new SubmitSm();
+        submitSm.setShortMessage(exchange.getIn().getBody(String.class).getBytes("ISO-8859-1"));
+
+        if (in.getHeaders().containsKey(DEST_ADDR)) {
+            submitSm.setDestAddress((String) in.getHeader(DEST_ADDR));
+        } else {
+            submitSm.setDestAddress(configuration.getDestAddr());
+        }
+
+        if (in.getHeaders().containsKey(DEST_ADDR_TON)) {
+            submitSm.setDestAddrTon((Byte) in.getHeader(DEST_ADDR_TON));
+        } else {
+            submitSm.setDestAddrTon(configuration.getDestAddrTon());
+        }
+
+        if (in.getHeaders().containsKey(DEST_ADDR_NPI)) {
+            submitSm.setDestAddrNpi((Byte) in.getHeader(DEST_ADDR_NPI));
+        } else {
+            submitSm.setDestAddrNpi(configuration.getDestAddrNpi());
+        }
+
+        if (in.getHeaders().containsKey(SOURCE_ADDR)) {
+            submitSm.setSourceAddr((String) in.getHeader(SOURCE_ADDR));
+        } else {
+            submitSm.setSourceAddr(configuration.getSourceAddr());
+        }
+
+        if (in.getHeaders().containsKey(SOURCE_ADDR_TON)) {
+            submitSm.setSourceAddrTon((Byte) in.getHeader(SOURCE_ADDR_TON));
+        } else {
+            submitSm.setSourceAddrTon(configuration.getSourceAddrTon());
+        }
+
+        if (in.getHeaders().containsKey(SOURCE_ADDR_NPI)) {
+            submitSm.setSourceAddrNpi((Byte) in.getHeader(SOURCE_ADDR_NPI));
+        } else {
+            submitSm.setSourceAddrNpi(configuration.getDestAddrNpi());
+        }
+
+        if (in.getHeaders().containsKey(SERVICE_TYPE)) {
+            submitSm.setServiceType((String) in.getHeader(SERVICE_TYPE));
+        } else {
+            submitSm.setServiceType(configuration.getServiceType());
+        }
+
+        if (in.getHeaders().containsKey(REGISTERED_DELIVERY)) {
+            submitSm.setRegisteredDelivery((Byte) in.getHeader(REGISTERED_DELIVERY));
+        } else {
+            submitSm.setRegisteredDelivery(configuration.getRegisteredDelivery());
+        }
+
+        if (in.getHeaders().containsKey(PROTOCOL_ID)) {
+            submitSm.setProtocolId((Byte) in.getHeader(PROTOCOL_ID));
+        } else {
+            submitSm.setProtocolId(configuration.getProtocolId());
+        }
+
+        if (in.getHeaders().containsKey(PRIORITY_FLAG)) {
+            submitSm.setPriorityFlag((Byte) in.getHeader(PRIORITY_FLAG));
+        } else {
+            submitSm.setPriorityFlag(configuration.getPriorityFlag());
+        }
+
+        if (in.getHeaders().containsKey(SCHEDULE_DELIVERY_TIME)) {
+            submitSm.setScheduleDeliveryTime(timeFormatter.format((Date) in.getHeader(SCHEDULE_DELIVERY_TIME)));
+        } else {
+            submitSm.setScheduleDeliveryTime(timeFormatter.format(getCurrentDate()));
+        }
+
+        if (in.getHeaders().containsKey(VALIDITY_PERIOD)) {
+            submitSm.setValidityPeriod(timeFormatter.format((Date) in.getHeader(VALIDITY_PERIOD)));
+        }
+
+        if (in.getHeaders().containsKey(REPLACE_IF_PRESENT_FLAG)) {
+            submitSm.setReplaceIfPresent((Byte) in.getHeader(REPLACE_IF_PRESENT_FLAG));
+        } else {
+            submitSm.setReplaceIfPresent(configuration.getReplaceIfPresentFlag());
+        }
+
+        return submitSm;
+    }
+
+    /**
+     * Create a new SmppMessage from the inbound alert notification
+     */
+    public SmppMessage createSmppMessage(AlertNotification alertNotification) {
+        SmppMessage smppMessage = new SmppMessage(alertNotification);
+
+        smppMessage.setHeader(SEQUENCE_NUMBER, alertNotification.getSequenceNumber());
+        smppMessage.setHeader(COMMAND_ID, alertNotification.getCommandId());
+        smppMessage.setHeader(COMMAND_STATUS, alertNotification.getCommandStatus());
+        smppMessage.setHeader(SOURCE_ADDR, alertNotification.getSourceAddr());
+        smppMessage.setHeader(SOURCE_ADDR_NPI, alertNotification.getSourceAddrNpi());
+        smppMessage.setHeader(SOURCE_ADDR_TON, alertNotification.getSourceAddrNpi());
+        smppMessage.setHeader(ESME_ADDR, alertNotification.getEsmeAddr());
+        smppMessage.setHeader(ESME_ADDR_NPI, alertNotification.getEsmeAddrNpi());
+        smppMessage.setHeader(ESME_ADDR_TON, alertNotification.getEsmeAddrNpi());
+
+        return smppMessage;
+    }
+
+    /**
+     * Create a new SmppMessage from the inbound deliver sm or deliver receipt
+     */
+    public SmppMessage createSmppMessage(DeliverSm deliverSm) throws Exception {
+        SmppMessage smppMessage = new SmppMessage(deliverSm);
+
+        if (deliverSm.isSmscDeliveryReceipt()) {
+            DeliveryReceipt smscDeliveryReceipt = deliverSm.getShortMessageAsDeliveryReceipt();
+            smppMessage.setBody(smscDeliveryReceipt.getText());
+
+            smppMessage.setHeader(ID, smscDeliveryReceipt.getId());
+            smppMessage.setHeader(DELIVERED, smscDeliveryReceipt.getDelivered());
+            smppMessage.setHeader(DONE_DATE, smscDeliveryReceipt.getDoneDate());
+            if (!"000".equals(smscDeliveryReceipt.getError())) {
+                smppMessage.setHeader(ERROR, smscDeliveryReceipt.getError());
+            }
+            smppMessage.setHeader(SUBMIT_DATE, smscDeliveryReceipt.getSubmitDate());
+            smppMessage.setHeader(SUBMITTED, smscDeliveryReceipt.getSubmitted());
+        } else {
+            smppMessage.setBody(String.valueOf(new String(deliverSm.getShortMessage(),
+                    configuration.getEncoding())));
+
+            smppMessage.setHeader(SEQUENCE_NUMBER, deliverSm.getSequenceNumber());
+            smppMessage.setHeader(COMMAND_ID, deliverSm.getCommandId());
+            smppMessage.setHeader(SOURCE_ADDR, deliverSm.getSourceAddr());
+            smppMessage.setHeader(DEST_ADDR, deliverSm.getDestAddress());
+            smppMessage.setHeader(SCHEDULE_DELIVERY_TIME, deliverSm.getScheduleDeliveryTime());
+            smppMessage.setHeader(VALIDITY_PERIOD, deliverSm.getValidityPeriod());
+        }
+
+        return smppMessage;
+    }
+    
+    /**
+     * Returns the current date. Externalized for better test support.
+     * 
+     * @return the current date
+     */
+    Date getCurrentDate() {
+        return new Date();
+    }
+
+    /**
+     * Returns the smpp configuration
+     * 
+     * @return the configuration
+     */
+    public SmppConfiguration getConfiguration() {
+        return configuration;
+    }
+
+    /**
+     * Set the smpp configuration.
+     * 
+     * @param configuration smppConfiguration
+     */
+    public void setConfiguration(SmppConfiguration configuration) {
+        this.configuration = configuration;
+    }
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppBinding.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppBinding.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppComponent.java?rev=888296&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppComponent.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppComponent.java Tue Dec  8 09:07:14 2009
@@ -0,0 +1,87 @@
+/**
+ * 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.smpp;
+
+import java.net.URI;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.util.IntrospectionSupport;
+
+/**
+ * @version $Revision$
+ * @author muellerc
+ */
+public class SmppComponent extends DefaultComponent {
+
+    private SmppConfiguration configuration;
+
+    public SmppComponent() {
+    }
+
+    public SmppComponent(SmppConfiguration configuration) {
+        this.configuration = configuration;
+    }
+
+    public SmppComponent(CamelContext context) {
+        super(context);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception {
+        if (this.configuration == null) {
+            this.configuration = new SmppConfiguration();
+        }
+
+        // create a copy of the configuration as other endpoints can adjust their copy as well
+        SmppConfiguration config = this.configuration.copy();
+
+        config.configureFromURI(new URI(uri));
+        if (getCamelContext() != null) {
+            IntrospectionSupport.setProperties(getCamelContext().getTypeConverter(), config, parameters);
+        } else {
+            IntrospectionSupport.setProperties(config, parameters);
+        }
+
+        return createEndpoint(uri, config);
+    }
+
+    /**
+     * Create a new smpp endpoint with the provided smpp configuration
+     */
+    protected Endpoint createEndpoint(SmppConfiguration config) throws Exception {
+        return createEndpoint(null, config);
+    }
+
+    /**
+     * Create a new smpp endpoint with the provided uri and smpp configuration
+     */
+    protected Endpoint createEndpoint(String uri, SmppConfiguration config) throws Exception {
+        return new SmppEndpoint(uri, this, config);
+    }
+
+    public SmppConfiguration getConfiguration() {
+        return configuration;
+    }
+
+    public void setConfiguration(SmppConfiguration configuration) {
+        this.configuration = configuration;
+    }
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppComponent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppComponent.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java?rev=888296&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java Tue Dec  8 09:07:14 2009
@@ -0,0 +1,259 @@
+/**
+ * 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.smpp;
+
+import java.net.URI;
+
+import org.apache.camel.RuntimeCamelException;
+import org.jsmpp.bean.NumberingPlanIndicator;
+import org.jsmpp.bean.SMSCDeliveryReceipt;
+import org.jsmpp.bean.TypeOfNumber;
+
+/**
+ * Contains the SMPP component configuration properties</a>
+ * 
+ * @version $Revision$
+ * @author muellerc
+ */
+public class SmppConfiguration implements Cloneable {
+
+    private String host = "localhost";
+    private Integer port = new Integer(2775);
+    private String systemId = "smppclient";
+    private String password = "password";
+    private String systemType = "cp";
+    private String encoding = "ISO-8859-1";
+    private Integer enquireLinkTimer = new Integer(5000);
+    private Integer transactionTimer = new Integer(10000);
+    private byte registeredDelivery = SMSCDeliveryReceipt.SUCCESS_FAILURE
+            .value();
+    private String serviceType = "CMT";
+    private String sourceAddr = "1616";
+    private String destAddr = "1717";
+    private byte sourceAddrTon = TypeOfNumber.UNKNOWN.value();
+    private byte destAddrTon = TypeOfNumber.UNKNOWN.value();
+    private byte sourceAddrNpi = NumberingPlanIndicator.UNKNOWN.value();
+    private byte destAddrNpi = NumberingPlanIndicator.UNKNOWN.value();
+    private byte protocolId = (byte) 0;
+    private byte priorityFlag = (byte) 1;
+    private byte replaceIfPresentFlag = (byte) 0;
+    private byte typeOfNumber = TypeOfNumber.UNKNOWN.value();
+    private byte numberingPlanIndicator = NumberingPlanIndicator.UNKNOWN.value();
+
+    /**
+     * A POJO which contains all necessary configuration parameters for the SMPP connection
+     * 
+     * @param uri the full URI of the endpoint
+     */
+    public void configureFromURI(URI uri) {
+        setSystemId(uri.getUserInfo());
+        setHost(uri.getHost());
+        setPort(uri.getPort());
+    }
+
+    public SmppConfiguration copy() {
+        try {
+            return (SmppConfiguration) clone();
+        } catch (CloneNotSupportedException e) {
+            throw new RuntimeCamelException(e);
+        }
+    }
+
+    public String getHost() {
+        return host;
+    }
+
+    public void setHost(String host) {
+        this.host = host;
+    }
+
+    public Integer getPort() {
+        return port;
+    }
+
+    public void setPort(Integer port) {
+        this.port = port;
+    }
+
+    public String getSystemId() {
+        return systemId;
+    }
+
+    public void setSystemId(String systemId) {
+        this.systemId = systemId;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+    
+    public String getEncoding() {
+        return encoding;
+    }
+
+    public void setEncoding(String encoding) {
+        this.encoding = encoding;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public Integer getEnquireLinkTimer() {
+        return enquireLinkTimer;
+    }
+
+    public void setEnquireLinkTimer(Integer enquireLinkTimer) {
+        this.enquireLinkTimer = enquireLinkTimer;
+    }
+
+    public Integer getTransactionTimer() {
+        return transactionTimer;
+    }
+
+    public void setTransactionTimer(Integer transactionTimer) {
+        this.transactionTimer = transactionTimer;
+    }
+
+    public String getSystemType() {
+        return systemType;
+    }
+
+    public void setSystemType(String systemType) {
+        this.systemType = systemType;
+    }
+
+    public byte getRegisteredDelivery() {
+        return registeredDelivery;
+    }
+
+    public void setRegisteredDelivery(byte registeredDelivery) {
+        this.registeredDelivery = registeredDelivery;
+    }
+
+    public String getServiceType() {
+        return serviceType;
+    }
+
+    public void setServiceType(String serviceType) {
+        this.serviceType = serviceType;
+    }
+
+    public byte getSourceAddrTon() {
+        return sourceAddrTon;
+    }
+
+    public void setSourceAddrTon(byte sourceAddrTon) {
+        this.sourceAddrTon = sourceAddrTon;
+    }
+
+    public byte getDestAddrTon() {
+        return destAddrTon;
+    }
+
+    public void setDestAddrTon(byte destAddrTon) {
+        this.destAddrTon = destAddrTon;
+    }
+
+    public byte getSourceAddrNpi() {
+        return sourceAddrNpi;
+    }
+
+    public void setSourceAddrNpi(byte sourceAddrNpi) {
+        this.sourceAddrNpi = sourceAddrNpi;
+    }
+
+    public byte getDestAddrNpi() {
+        return destAddrNpi;
+    }
+
+    public void setDestAddrNpi(byte destAddrNpi) {
+        this.destAddrNpi = destAddrNpi;
+    }
+
+    public byte getProtocolId() {
+        return protocolId;
+    }
+
+    public void setProtocolId(byte protocolId) {
+        this.protocolId = protocolId;
+    }
+
+    public byte getPriorityFlag() {
+        return priorityFlag;
+    }
+
+    public void setPriorityFlag(byte priorityFlag) {
+        this.priorityFlag = priorityFlag;
+    }
+
+    public byte getReplaceIfPresentFlag() {
+        return replaceIfPresentFlag;
+    }
+
+    public void setReplaceIfPresentFlag(byte replaceIfPresentFlag) {
+        this.replaceIfPresentFlag = replaceIfPresentFlag;
+    }
+
+    public String getSourceAddr() {
+        return sourceAddr;
+    }
+
+    public void setSourceAddr(String sourceAddr) {
+        this.sourceAddr = sourceAddr;
+    }
+
+    public String getDestAddr() {
+        return destAddr;
+    }
+
+    public void setDestAddr(String destAddr) {
+        this.destAddr = destAddr;
+    }
+    
+    public byte getTypeOfNumber() {
+        return typeOfNumber;
+    }
+
+    public void setTypeOfNumber(byte typeOfNumber) {
+        this.typeOfNumber = typeOfNumber;
+    }
+
+    public byte getNumberingPlanIndicator() {
+        return numberingPlanIndicator;
+    }
+
+    public void setNumberingPlanIndicator(byte numberingPlanIndicator) {
+        this.numberingPlanIndicator = numberingPlanIndicator;
+    }
+
+    @Override
+    public String toString() {
+        return "SmppConfiguration[" + "enquireLinkTimer=" + enquireLinkTimer
+                + ", host=" + host + ", password=" + password + ", port="
+                + port + ", systemId=" + systemId + ", systemType="
+                + systemType + ", transactionTimer=" + transactionTimer
+                + ", registeredDelivery=" + registeredDelivery
+                + ", serviceType=" + serviceType + ", sourceAddrTon="
+                + sourceAddrTon + ", destAddrTon=" + destAddrTon
+                + ", sourceAddrNpi=" + sourceAddrNpi + ", destAddrNpi="
+                + destAddrNpi + ", protocolId=" + protocolId
+                + ", priorityFlag=" + priorityFlag + ", replaceIfPresentFlag="
+                + replaceIfPresentFlag + ", sourceAddr=" + sourceAddr 
+                + ", destAddr=" + destAddr + "]";
+    }
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConsumer.java?rev=888296&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConsumer.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConsumer.java Tue Dec  8 09:07:14 2009
@@ -0,0 +1,157 @@
+/**
+ * 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.smpp;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.DefaultConsumer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jsmpp.bean.AlertNotification;
+import org.jsmpp.bean.BindType;
+import org.jsmpp.bean.DeliverSm;
+import org.jsmpp.bean.NumberingPlanIndicator;
+import org.jsmpp.bean.TypeOfNumber;
+import org.jsmpp.session.BindParameter;
+import org.jsmpp.session.MessageReceiverListener;
+import org.jsmpp.session.SMPPSession;
+
+/**
+ * An implementation of @{link Consumer} which use the SMPP protocol
+ * 
+ * @version $Revision$
+ * @author muellerc
+ */
+public class SmppConsumer extends DefaultConsumer {
+
+    private static final transient Log LOG = LogFactory.getLog(SmppConsumer.class);
+
+    private SmppConfiguration configuration;
+    private SMPPSession session;
+
+    /**
+     * The constructor which gets a smpp endpoint, a smpp configuration and a processor
+     */
+    public SmppConsumer(SmppEndpoint endpoint, SmppConfiguration configuration, Processor processor) {
+        super(endpoint, processor);
+        this.configuration = configuration;
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Connecting to: " + getEndpoint().getConnectionString() + "...");
+        }
+
+        super.doStart();
+
+        session = createSMPPSession();
+        session.setEnquireLinkTimer(this.configuration.getEnquireLinkTimer());
+        session.setTransactionTimer(this.configuration.getTransactionTimer());
+        session.setMessageReceiverListener(new MessageReceiverListener() {
+            public void onAcceptAlertNotification(AlertNotification alertNotification) {
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Received an alertNotification " + alertNotification);
+                }
+
+                try {
+                    Exchange exchange = getEndpoint().createOnAcceptAlertNotificationExchange(alertNotification);
+
+                    LOG.trace("Processing the new smpp exchange...");
+                    getProcessor().process(exchange);
+                    LOG.trace("Processed the new smpp exchange");
+                } catch (Exception e) {
+                    getExceptionHandler().handleException(e);
+                }
+            }
+
+            public void onAcceptDeliverSm(DeliverSm deliverSm) {
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Received a deliverSm " + deliverSm);
+                }
+
+                try {
+                    Exchange exchange = getEndpoint().createOnAcceptDeliverSmExchange(deliverSm);
+
+                    LOG.trace("processing the new smpp exchange...");
+                    getProcessor().process(exchange);
+                    LOG.trace("processed the new smpp exchange");
+                } catch (Exception e) {
+                    getExceptionHandler().handleException(e);
+                }
+            }
+
+        });
+
+        session.connectAndBind(
+                this.configuration.getHost(),
+                this.configuration.getPort(),
+                new BindParameter(
+                        BindType.BIND_RX,
+                        this.configuration.getSystemId(),
+                        this.configuration.getPassword(),
+                        this.configuration.getSystemType(),
+                        TypeOfNumber.UNKNOWN,
+                        NumberingPlanIndicator.UNKNOWN,
+                        ""));
+
+        LOG.info("Connected to: " + getEndpoint().getConnectionString());
+    }
+
+    /**
+     * Factory method to easily instantiate a mock SMPPSession
+     * 
+     * @return the SMPPSession
+     */
+    SMPPSession createSMPPSession() {
+        return new SMPPSession();
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        LOG.debug("Disconnecting from: " + getEndpoint().getConnectionString() + "...");
+
+        super.doStop();
+
+        if (session != null) {
+            session.close();
+            session = null;
+        }
+
+        LOG.info("Disconnected from: " + getEndpoint().getConnectionString());
+    }
+
+    @Override
+    public String toString() {
+        return "SmppConsumer[" + getEndpoint().getConnectionString() + "]";
+    }
+
+    @Override
+    public SmppEndpoint getEndpoint() {
+        return (SmppEndpoint) super.getEndpoint();
+    }
+
+    /**
+     * Returns the smpp configuration
+     * 
+     * @return the configuration
+     */
+    public SmppConfiguration getConfiguration() {
+        return configuration;
+    }
+
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConsumer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConsumer.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppEndpoint.java?rev=888296&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppEndpoint.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppEndpoint.java Tue Dec  8 09:07:14 2009
@@ -0,0 +1,156 @@
+/**
+ * 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.smpp;
+
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jsmpp.bean.AlertNotification;
+import org.jsmpp.bean.DeliverSm;
+
+/**
+ * A SMPP Endpoint
+ * 
+ * @version $Revision$
+ * @author muellerc
+ */
+public class SmppEndpoint extends DefaultEndpoint {
+
+    private static final transient Log LOG = LogFactory.getLog(SmppEndpoint.class);
+
+    private SmppBinding binding;
+    private SmppConfiguration configuration;
+
+    public SmppEndpoint(String endpointUri, Component component, SmppConfiguration configuration) {
+        super(endpointUri, component);
+        this.configuration = configuration;
+    }
+
+    public boolean isSingleton() {
+        return true;
+    }
+    
+    @Override
+    protected String createEndpointUri() {
+        return getConnectionString();
+    }
+    
+    @Override
+    public boolean isLenientProperties() {
+        return true;
+    }
+
+    public Consumer createConsumer(Processor processor) throws Exception {
+        return new SmppConsumer(this, configuration, processor);
+    }
+
+    public Producer createProducer() throws Exception {
+        return new SmppProducer(this, configuration);
+    }
+
+    /**
+     * Create a new exchange for communicating with this endpoint from a SMSC
+     *
+     * @param alertNotification the received message from the SMSC
+     * @return a new exchange
+     */
+    public Exchange createOnAcceptAlertNotificationExchange(AlertNotification alertNotification) {
+        return createOnAcceptAlertNotificationExchange(getExchangePattern(), alertNotification);
+    }
+    
+    /**
+     * Create a new exchange for communicating with this endpoint from a SMSC
+     * with the specified {@link ExchangePattern} such as whether its going
+     * to be an {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut} exchange
+     *
+     * @param exchangePattern the message exchange pattern for the exchange
+     * @param alertNotification the received message from the SMSC
+     * @return a new exchange
+     */
+    public Exchange createOnAcceptAlertNotificationExchange(ExchangePattern exchangePattern,
+                                                            AlertNotification alertNotification) {
+        Exchange exchange = createExchange(exchangePattern);
+        exchange.setProperty(Exchange.BINDING, getBinding());
+        exchange.setIn(getBinding().createSmppMessage(alertNotification));
+        return exchange;
+    }
+
+    /**
+     * Create a new exchange for communicating with this endpoint from a SMSC
+     *
+     * @param deliverSm the received message from the SMSC
+     * @return a new exchange
+     */
+    public Exchange createOnAcceptDeliverSmExchange(DeliverSm deliverSm) throws Exception {
+        return createOnAcceptDeliverSmExchange(getExchangePattern(), deliverSm);
+    }
+    
+    /**
+     * Create a new exchange for communicating with this endpoint from a SMSC
+     * with the specified {@link ExchangePattern} such as whether its going
+     * to be an {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut} exchange
+     *
+     * @param exchangePattern the message exchange pattern for the exchange
+     * @param deliverSm the received message from the SMSC
+     * @return a new exchange
+     */
+    public Exchange createOnAcceptDeliverSmExchange(ExchangePattern exchangePattern,
+                                                    DeliverSm deliverSm) throws Exception {
+        Exchange exchange = createExchange(exchangePattern);
+        exchange.setProperty(Exchange.BINDING, getBinding());
+        exchange.setIn(getBinding().createSmppMessage(deliverSm));
+        return exchange;
+    }
+
+    /**
+     * Returns the connection string for the current connection which has the form:
+     * smpp://<user>@<host>:<port>
+     * 
+     * @return the connection string
+     */
+    public String getConnectionString() {
+        return "smpp://" + getConfiguration().getSystemId() + "@"
+                + getConfiguration().getHost() + ":"
+                + getConfiguration().getPort();
+    }
+
+    /**
+     * Returns the smpp configuration
+     * 
+     * @return the configuration
+     */
+    public SmppConfiguration getConfiguration() {
+        return configuration;
+    }
+
+    public SmppBinding getBinding() {
+        if (binding == null) {
+            binding = new SmppBinding(getConfiguration());
+        }
+        return binding;
+    }
+
+    public void setBinding(SmppBinding binding) {
+        this.binding = binding;
+    }
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppEndpoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppEndpoint.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessage.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessage.java?rev=888296&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessage.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessage.java Tue Dec  8 09:07:14 2009
@@ -0,0 +1,84 @@
+/**
+ * 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.smpp;
+
+import java.io.UnsupportedEncodingException;
+
+import org.apache.camel.impl.DefaultMessage;
+import org.jsmpp.bean.AlertNotification;
+import org.jsmpp.bean.Command;
+import org.jsmpp.bean.DeliverSm;
+import org.jsmpp.bean.MessageRequest;
+
+/**
+ * Represents a {@link org.apache.camel.Message} for working with SMPP
+ * 
+ * @author muellerc
+ * @version $Revision$
+ */
+public class SmppMessage extends DefaultMessage {
+
+    private Command command;
+    
+    public SmppMessage() {
+    }
+
+    public SmppMessage(AlertNotification command) {
+        this.command = command;
+    }
+    
+    public SmppMessage(DeliverSm command) {
+        this.command = command;
+    }
+
+    @Override
+    public SmppMessage newInstance() {
+        return new SmppMessage();
+    }
+
+    @Override
+    protected Object createBody() {
+        if (command instanceof MessageRequest) {
+            byte[] shortMessage = ((MessageRequest) command).getShortMessage();
+            try {
+                return new String(shortMessage, "ISO-8859-1");
+            } catch (UnsupportedEncodingException e) {
+                return new String(shortMessage);
+            }
+        }
+
+        return null;
+    }
+
+    @Override
+    public String toString() {
+        if (command != null) {
+            return "SmppMessage: " + command;
+        } else {
+            return "SmppMessage: " + getBody();
+        }
+    }
+
+    /**
+     * Returns the underlying jSMPP command
+     * 
+     * @return command
+     */
+    public Command getCommand() {
+        return command;
+    }
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessage.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java?rev=888296&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java Tue Dec  8 09:07:14 2009
@@ -0,0 +1,188 @@
+/**
+ * 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.smpp;
+
+import java.io.IOException;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultProducer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jsmpp.InvalidResponseException;
+import org.jsmpp.PDUException;
+import org.jsmpp.bean.Alphabet;
+import org.jsmpp.bean.BindType;
+import org.jsmpp.bean.ESMClass;
+import org.jsmpp.bean.GeneralDataCoding;
+import org.jsmpp.bean.MessageClass;
+import org.jsmpp.bean.NumberingPlanIndicator;
+import org.jsmpp.bean.RegisteredDelivery;
+import org.jsmpp.bean.SubmitSm;
+import org.jsmpp.bean.TypeOfNumber;
+import org.jsmpp.extra.NegativeResponseException;
+import org.jsmpp.extra.ResponseTimeoutException;
+import org.jsmpp.session.BindParameter;
+import org.jsmpp.session.SMPPSession;
+
+/**
+ * An implementation of @{link Producer} which use the SMPP protocol
+ * 
+ * @version $Revision$
+ * @author muellerc
+ */
+public class SmppProducer extends DefaultProducer {
+
+    private static final transient Log LOG = LogFactory.getLog(SmppProducer.class);
+
+    private SmppConfiguration configuration;
+    private SMPPSession session;
+
+    public SmppProducer(SmppEndpoint endpoint, SmppConfiguration configuration) {
+        super(endpoint);
+        this.configuration = configuration;
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Connecting to: " + getEndpoint().getConnectionString() + "...");
+        }
+
+        super.doStart();
+
+        session = createSMPPSession();
+        session.setEnquireLinkTimer(this.configuration.getEnquireLinkTimer());
+        session.setTransactionTimer(this.configuration.getTransactionTimer());
+        session.connectAndBind(
+                this.configuration.getHost(),
+                this.configuration.getPort(),
+                new BindParameter(
+                        BindType.BIND_TX,
+                        this.configuration.getSystemId(),
+                        this.configuration.getPassword(), 
+                        this.configuration.getSystemType(),
+                        TypeOfNumber.valueOf(configuration.getTypeOfNumber()),
+                        NumberingPlanIndicator.valueOf(configuration.getNumberingPlanIndicator()),
+                        ""));
+
+        LOG.info("Connected to: " + getEndpoint().getConnectionString());
+    }
+    
+    /**
+     * Factory method to easily instantiate a mock SMPPSession
+     * 
+     * @return the SMPPSession
+     */
+    SMPPSession createSMPPSession() {
+        return new SMPPSession();
+    }
+
+    public void process(Exchange exchange) throws Exception {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Sending a short message for exchange id '"
+                    + exchange.getExchangeId() + "'...");
+        }
+
+        SubmitSm submitSm = getEndpoint().getBinding().createSubmitSm(exchange);
+        String messageId;
+        try {
+            messageId = doProcess(submitSm);
+        } catch (Exception e) {
+            // TODO: Add some DEBUG logging that we retry one more time
+            doStop();
+            doStart();
+            
+            messageId = doProcess(submitSm);
+        }
+
+        LOG.info("Sent a short message for exchange id '"
+                + exchange.getExchangeId() + "' and received message id '"
+                + messageId + "'");
+
+        if (exchange.getPattern().isOutCapable()) {
+            exchange.getOut().setHeader(SmppBinding.ID, messageId);
+        } else {
+            exchange.getIn().setHeader(SmppBinding.ID, messageId);
+        }
+    }
+
+    private String doProcess(SubmitSm submitSm) throws PDUException,
+            ResponseTimeoutException, InvalidResponseException,
+            NegativeResponseException, IOException {
+
+        String messageId = session.submitShortMessage(
+                submitSm.getServiceType(), 
+                TypeOfNumber.valueOf(submitSm.getSourceAddrTon()),
+                NumberingPlanIndicator.valueOf(submitSm.getSourceAddrNpi()),
+                submitSm.getSourceAddr(),
+                TypeOfNumber.valueOf(submitSm.getDestAddrTon()),
+                NumberingPlanIndicator.valueOf(submitSm.getDestAddrNpi()),
+                submitSm.getDestAddress(),
+                new ESMClass(),
+                submitSm.getProtocolId(),
+                submitSm.getPriorityFlag(),
+                submitSm.getScheduleDeliveryTime(),
+                submitSm.getValidityPeriod(),
+                new RegisteredDelivery(submitSm.getRegisteredDelivery()),
+                submitSm.getReplaceIfPresent(),
+                new GeneralDataCoding(
+                        false,
+                        false,
+                        MessageClass.CLASS1,
+                        Alphabet.ALPHA_DEFAULT),
+                (byte) 0,
+                submitSm.getShortMessage());
+
+        return messageId;
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Disconnecting from: " + getEndpoint().getConnectionString() + "...");
+        }
+
+        super.doStop();
+
+        if (session != null) {
+            session.close();
+            session = null;
+        }
+
+        LOG.info("Disconnected from: " + getEndpoint().getConnectionString());
+    }
+
+    @Override
+    public SmppEndpoint getEndpoint() {
+        return (SmppEndpoint) super.getEndpoint();
+    }
+
+    /**
+     * Returns the smppConfiguration for this producer
+     * 
+     * @return the configuration
+     */
+    public SmppConfiguration getConfiguration() {
+        return configuration;
+    }
+
+    @Override
+    public String toString() {
+        return "SmppProducer[" + getEndpoint().getConnectionString() + "]";
+    }
+
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-smpp/src/main/resources/META-INF/services/org/apache/camel/component/smpp
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/resources/META-INF/services/org/apache/camel/component/smpp?rev=888296&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/resources/META-INF/services/org/apache/camel/component/smpp (added)
+++ camel/trunk/components/camel-smpp/src/main/resources/META-INF/services/org/apache/camel/component/smpp Tue Dec  8 09:07:14 2009
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.component.smpp.SmppComponent
\ No newline at end of file

Added: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppBindingTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppBindingTest.java?rev=888296&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppBindingTest.java (added)
+++ camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppBindingTest.java Tue Dec  8 09:07:14 2009
@@ -0,0 +1,207 @@
+/**
+ * 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.smpp;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Date;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultExchange;
+import org.jsmpp.bean.AlertNotification;
+import org.jsmpp.bean.DeliverSm;
+import org.jsmpp.bean.NumberingPlanIndicator;
+import org.jsmpp.bean.SubmitSm;
+import org.jsmpp.bean.TypeOfNumber;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+
+/**
+ * JUnit test class for <code>org.apache.camel.component.smpp.SmppBinding</code>
+ * 
+ * @version $Revision$
+ * @author muellerc
+ */
+public class SmppBindingTest {
+    
+    private SmppBinding binding;
+
+    @Before
+    public void setUp() {
+        binding = new SmppBinding() {
+            Date getCurrentDate() {
+                return new Date(1251666387000L);
+            }
+        };
+    }
+
+    @Test
+    public void emptyConstructorShouldSetTheSmppConfiguration() {
+        assertNotNull(binding.getConfiguration());
+    }
+
+    @Test
+    public void constructorSmppConfigurationShouldSetTheSmppConfiguration() {
+        SmppConfiguration configuration = new SmppConfiguration();
+        binding = new SmppBinding(configuration);
+        
+        assertSame(configuration, binding.getConfiguration());
+    }
+
+    @Test
+    public void createSubmitSmShouldCreateASubmitSmFromDefaults() throws UnsupportedEncodingException {
+        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
+        exchange.getIn().setBody("Hello SMPP world!");
+        SubmitSm submitSm = binding.createSubmitSm(exchange);
+        
+        assertEquals("Hello SMPP world!", new String(submitSm.getShortMessage()));
+        assertEquals("1717", submitSm.getDestAddress());
+        assertEquals(0x00, submitSm.getDestAddrNpi());
+        assertEquals(0x00, submitSm.getDestAddrTon());
+        assertEquals(0x01, submitSm.getPriorityFlag());
+        assertEquals(0x00, submitSm.getProtocolId());
+        assertEquals(0x01, submitSm.getRegisteredDelivery());
+        assertEquals(0x00, submitSm.getReplaceIfPresent());
+        assertEquals("090830230627004+", submitSm.getScheduleDeliveryTime());
+        assertEquals("CMT", submitSm.getServiceType());
+        assertEquals("1616", submitSm.getSourceAddr());
+        assertEquals(0x00, submitSm.getSourceAddrNpi());
+        assertEquals(0x00, submitSm.getSourceAddrTon());
+        assertNull(submitSm.getValidityPeriod());
+        // not relevant
+        //assertEquals(0, submitSm.getCommandId());
+        //assertEquals(0, submitSm.getCommandStatus());
+        //assertEquals(0, submitSm.getSequenceNumber());
+    }
+    
+    @Test
+    public void createSubmitSmShouldCreateASubmitSmFromHeaders() throws UnsupportedEncodingException {
+        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
+        exchange.getIn().setBody("Hello SMPP world!");
+        exchange.getIn().setHeader(SmppBinding.DEST_ADDR, "1919");
+        exchange.getIn().setHeader(SmppBinding.DEST_ADDR_NPI, NumberingPlanIndicator.NATIONAL.value());
+        exchange.getIn().setHeader(SmppBinding.DEST_ADDR_TON, TypeOfNumber.NATIONAL.value());
+        exchange.getIn().setHeader(SmppBinding.PRIORITY_FLAG, (byte) 0);
+        exchange.getIn().setHeader(SmppBinding.PROTOCOL_ID, (byte) 1);
+        exchange.getIn().setHeader(SmppBinding.REGISTERED_DELIVERY, (byte) 0);
+        exchange.getIn().setHeader(SmppBinding.REPLACE_IF_PRESENT_FLAG, (byte) 1);
+        exchange.getIn().setHeader(SmppBinding.SCHEDULE_DELIVERY_TIME, new Date(1251753000000L));
+        exchange.getIn().setHeader(SmppBinding.SERVICE_TYPE, "XXX");
+        exchange.getIn().setHeader(SmppBinding.VALIDITY_PERIOD, new Date(1251753600000L));
+        exchange.getIn().setHeader(SmppBinding.SOURCE_ADDR, "1818");
+        exchange.getIn().setHeader(SmppBinding.SOURCE_ADDR_NPI, NumberingPlanIndicator.NATIONAL.value());
+        exchange.getIn().setHeader(SmppBinding.SOURCE_ADDR_TON, TypeOfNumber.NATIONAL.value());
+        SubmitSm submitSm = binding.createSubmitSm(exchange);
+        
+        assertEquals("Hello SMPP world!", new String(submitSm.getShortMessage()));
+        assertEquals("1919", submitSm.getDestAddress());
+        assertEquals(0x08, submitSm.getDestAddrNpi());
+        assertEquals(0x02, submitSm.getDestAddrTon());
+        assertEquals(0x00, submitSm.getPriorityFlag());
+        assertEquals(0x01, submitSm.getProtocolId());
+        assertEquals(0x00, submitSm.getRegisteredDelivery());
+        assertEquals(0x01, submitSm.getReplaceIfPresent());
+        assertEquals("090831231000004+", submitSm.getScheduleDeliveryTime());
+        assertEquals("XXX", submitSm.getServiceType());
+        assertEquals("1818", submitSm.getSourceAddr());
+        assertEquals(0x08, submitSm.getSourceAddrNpi());
+        assertEquals(0x02, submitSm.getSourceAddrTon());
+        assertEquals("090831232000004+", submitSm.getValidityPeriod());
+        // not relevant
+        //assertEquals(0, submitSm.getCommandId());
+        //assertEquals(0, submitSm.getCommandStatus());
+        //assertEquals(0, submitSm.getSequenceNumber());
+    }
+
+    @Test
+    public void createSmppMessageFromAlertNotificationShouldReturnASmppMessage() {
+        AlertNotification alertNotification = new AlertNotification();
+        alertNotification.setCommandId(1);
+        alertNotification.setSequenceNumber(1);
+        alertNotification.setSourceAddr("1616");
+        alertNotification.setSourceAddrNpi(NumberingPlanIndicator.NATIONAL.value());
+        alertNotification.setSourceAddrTon(TypeOfNumber.NATIONAL.value());
+        alertNotification.setEsmeAddr("1717");
+        alertNotification.setEsmeAddrNpi(NumberingPlanIndicator.NATIONAL.value());
+        alertNotification.setEsmeAddrTon(TypeOfNumber.NATIONAL.value());
+        SmppMessage smppMessage = binding.createSmppMessage(alertNotification);
+        
+        assertNull(smppMessage.getBody());
+        assertEquals(9, smppMessage.getHeaders().size());
+        assertEquals(1, smppMessage.getHeader(SmppBinding.SEQUENCE_NUMBER));
+        assertEquals(1, smppMessage.getHeader(SmppBinding.COMMAND_ID));
+        assertEquals(0, smppMessage.getHeader(SmppBinding.COMMAND_STATUS));
+        assertEquals("1616", smppMessage.getHeader(SmppBinding.SOURCE_ADDR));
+        assertEquals((byte) 8, smppMessage.getHeader(SmppBinding.SOURCE_ADDR_NPI));
+        assertEquals((byte) 8, smppMessage.getHeader(SmppBinding.SOURCE_ADDR_TON));
+        assertEquals("1717", smppMessage.getHeader(SmppBinding.ESME_ADDR));
+        assertEquals((byte) 8, smppMessage.getHeader(SmppBinding.ESME_ADDR_NPI));
+        assertEquals((byte) 8, smppMessage.getHeader(SmppBinding.ESME_ADDR_TON));
+    }
+
+    @Test
+    public void createSmppMessageFromDeliveryReceiptShouldReturnASmppMessage() throws Exception {
+        DeliverSm deliverSm = new DeliverSm();
+        deliverSm.setSmscDeliveryReceipt();
+        deliverSm.setShortMessage("id:2 sub:001 dlvrd:001 submit date:0908312310 done date:0908312311 stat:DELIVRD err:xxx Text:Hello SMPP world!".getBytes());
+        SmppMessage smppMessage = binding.createSmppMessage(deliverSm);
+        
+        assertEquals("Hello SMPP world!", smppMessage.getBody());
+        assertEquals(6, smppMessage.getHeaders().size());
+        assertEquals("2", smppMessage.getHeader(SmppBinding.ID));
+        assertEquals(1, smppMessage.getHeader(SmppBinding.DELIVERED));
+        assertEquals(new Date(1251753060000L), smppMessage.getHeader(SmppBinding.DONE_DATE));
+        assertEquals("xxx", smppMessage.getHeader(SmppBinding.ERROR));
+        assertEquals(new Date(1251753000000L), smppMessage.getHeader(SmppBinding.SUBMIT_DATE));
+        assertEquals(1, smppMessage.getHeader(SmppBinding.SUBMITTED));
+    }
+    
+    @Test
+    public void createSmppMessageFromDeliverSmShouldReturnASmppMessage() throws Exception {
+        DeliverSm deliverSm = new DeliverSm();
+        deliverSm.setShortMessage("Hello SMPP world!".getBytes());
+        deliverSm.setSequenceNumber(1);
+        deliverSm.setCommandId(1);
+        deliverSm.setSourceAddr("1818");
+        deliverSm.setDestAddress("1919");
+        deliverSm.setScheduleDeliveryTime("090831230627004+");
+        deliverSm.setValidityPeriod("090901230627004+");
+        SmppMessage smppMessage = binding.createSmppMessage(deliverSm);
+        
+        assertEquals("Hello SMPP world!", smppMessage.getBody());
+        assertEquals(6, smppMessage.getHeaders().size());
+        assertEquals(1, smppMessage.getHeader(SmppBinding.SEQUENCE_NUMBER));
+        assertEquals(1, smppMessage.getHeader(SmppBinding.COMMAND_ID));
+        assertEquals("1818", smppMessage.getHeader(SmppBinding.SOURCE_ADDR));
+        assertEquals("1919", smppMessage.getHeader(SmppBinding.DEST_ADDR));
+        assertEquals("090831230627004+", smppMessage.getHeader(SmppBinding.SCHEDULE_DELIVERY_TIME));
+        assertEquals("090901230627004+", smppMessage.getHeader(SmppBinding.VALIDITY_PERIOD));
+    }
+
+    @Test
+    public void getterShouldReturnTheSetValues() {
+        SmppConfiguration configuration = new SmppConfiguration();
+        binding.setConfiguration(configuration);
+        
+        assertSame(configuration, binding.getConfiguration());
+    }
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppBindingTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppBindingTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppComponentTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppComponentTest.java?rev=888296&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppComponentTest.java (added)
+++ camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppComponentTest.java Tue Dec  8 09:07:14 2009
@@ -0,0 +1,143 @@
+/**
+ * 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.smpp;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * JUnit test class for <code>org.apache.camel.component.smpp.SmppComponent</code>
+ * 
+ * @version $Revision$
+ * @author muellerc
+ */
+public class SmppComponentTest {
+    
+    private SmppComponent component;
+
+    @Before
+    public void setUp() {
+        component = new SmppComponent();
+    }
+
+    @Test
+    public void constructorSmppConfigurationShouldSetTheConfiguration() {
+        SmppConfiguration configuration = new SmppConfiguration();
+        component = new SmppComponent(configuration);
+        
+        assertSame(configuration, component.getConfiguration());
+    }
+
+    @Test
+    public void constructorCamelContextShouldSetTheContext() {
+        CamelContext context = new DefaultCamelContext();
+        component = new SmppComponent(context);
+        
+        assertSame(context, component.getCamelContext());
+    }
+
+    @Test
+    public void createEndpointStringStringMapShouldReturnASmppEndpoint() throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        component = new SmppComponent(context);
+        Map<String, String> parameters = new HashMap<String, String>();
+        parameters.put("password", "secret");
+        Endpoint endpoint = component.createEndpoint("smpp://smppclient@localhost:2775", "?password=secret", parameters);
+        SmppEndpoint smppEndpoint = (SmppEndpoint) endpoint;
+        
+        assertEquals("smpp://smppclient@localhost:2775", smppEndpoint.getEndpointUri());
+        assertEquals("smpp://smppclient@localhost:2775", smppEndpoint.getEndpointKey());
+        assertSame(component, smppEndpoint.getComponent());
+        assertNotNull(smppEndpoint.getConfiguration());
+        assertEquals("secret", smppEndpoint.getConfiguration().getPassword());
+        assertEquals("smpp://smppclient@localhost:2775", smppEndpoint.getConnectionString());
+        assertEquals(ExchangePattern.InOnly, smppEndpoint.getExchangePattern());
+        assertTrue(smppEndpoint.getBinding() instanceof SmppBinding);
+        assertNotNull(smppEndpoint.getCamelContext());
+    }
+    
+    @Test
+    public void createEndpointStringStringMapWithoutACamelContextShouldReturnASmppEndpoint() throws Exception {
+        Map<String, String> parameters = new HashMap<String, String>();
+        parameters.put("password", "secret");
+        Endpoint endpoint = component.createEndpoint("smpp://smppclient@localhost:2775", "?password=secret", parameters);
+        SmppEndpoint smppEndpoint = (SmppEndpoint) endpoint;
+        
+        assertEquals("smpp://smppclient@localhost:2775", smppEndpoint.getEndpointUri());
+        assertEquals("smpp://smppclient@localhost:2775", smppEndpoint.getEndpointKey());
+        assertSame(component, smppEndpoint.getComponent());
+        assertNotNull(smppEndpoint.getConfiguration());
+        assertEquals("secret", smppEndpoint.getConfiguration().getPassword());
+        assertEquals("smpp://smppclient@localhost:2775", smppEndpoint.getConnectionString());
+        assertEquals(ExchangePattern.InOnly, smppEndpoint.getExchangePattern());
+        assertTrue(smppEndpoint.getBinding() instanceof SmppBinding);
+        assertNull(smppEndpoint.getCamelContext());
+    }
+
+    @Test
+    public void createEndpointSmppConfigurationShouldReturnASmppEndpoint() throws Exception {
+        SmppConfiguration configuration = new SmppConfiguration();
+        Endpoint endpoint = component.createEndpoint(configuration);
+        SmppEndpoint smppEndpoint = (SmppEndpoint) endpoint;
+        
+        assertEquals("smpp://smppclient@localhost:2775", smppEndpoint.getEndpointUri());
+        assertEquals("smpp://smppclient@localhost:2775", smppEndpoint.getEndpointKey());
+        assertSame(component, smppEndpoint.getComponent());
+        assertSame(configuration, smppEndpoint.getConfiguration());
+        assertEquals("smpp://smppclient@localhost:2775", smppEndpoint.getConnectionString());
+        assertEquals(ExchangePattern.InOnly, smppEndpoint.getExchangePattern());
+        assertTrue(smppEndpoint.getBinding() instanceof SmppBinding);
+        assertNull(smppEndpoint.getCamelContext());
+    }
+
+    @Test
+    public void createEndpointStringSmppConfigurationShouldReturnASmppEndpoint() throws Exception {
+        SmppConfiguration configuration = new SmppConfiguration();
+        Endpoint endpoint = component.createEndpoint("smpp://smppclient@localhost:2775?password=password", configuration);
+        SmppEndpoint smppEndpoint = (SmppEndpoint) endpoint;
+        
+        assertEquals("smpp://smppclient@localhost:2775?password=password", smppEndpoint.getEndpointUri());
+        assertEquals("smpp://smppclient@localhost:2775", smppEndpoint.getEndpointKey());
+        assertSame(component, smppEndpoint.getComponent());
+        assertSame(configuration, smppEndpoint.getConfiguration());
+        assertEquals("smpp://smppclient@localhost:2775", smppEndpoint.getConnectionString());
+        assertEquals(ExchangePattern.InOnly, smppEndpoint.getExchangePattern());
+        assertTrue(smppEndpoint.getBinding() instanceof SmppBinding);
+        assertNull(smppEndpoint.getCamelContext());
+    }
+
+    @Test
+    public void getterShouldReturnTheSetValues() {
+        SmppConfiguration configuration = new SmppConfiguration();
+        component.setConfiguration(configuration);
+        
+        assertSame(configuration, component.getConfiguration());
+    }
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppComponentTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppComponentTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConfigurationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConfigurationTest.java?rev=888296&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConfigurationTest.java (added)
+++ camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConfigurationTest.java Tue Dec  8 09:07:14 2009
@@ -0,0 +1,157 @@
+/**
+ * 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.smpp;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.jsmpp.bean.NumberingPlanIndicator;
+import org.jsmpp.bean.SMSCDeliveryReceipt;
+import org.jsmpp.bean.TypeOfNumber;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * JUnit test class for <code>org.apache.camel.component.smpp.SmppConfiguration</code>
+ * 
+ * @version $Revision$
+ * @author muellerc
+ */
+public class SmppConfigurationTest {
+    
+    private SmppConfiguration configuration;
+
+    @Before
+    public void setUp() {
+        configuration = new SmppConfiguration();
+    }
+
+    @Test
+    public void getterShouldReturnTheDefaultValues() {
+        assertEquals("1717", configuration.getDestAddr());
+        assertEquals(0x00, configuration.getDestAddrNpi());
+        assertEquals(0x00, configuration.getDestAddrTon());
+        assertEquals(new Integer(5000), configuration.getEnquireLinkTimer());
+        assertEquals("localhost", configuration.getHost());
+        assertEquals("password", configuration.getPassword());
+        assertEquals(new Integer(2775), configuration.getPort());
+        assertEquals(0x01, configuration.getPriorityFlag());
+        assertEquals(0x00, configuration.getProtocolId());
+        assertEquals(0x01, configuration.getRegisteredDelivery());
+        assertEquals(0x00, configuration.getReplaceIfPresentFlag());
+        assertEquals("CMT", configuration.getServiceType());
+        assertEquals("1616", configuration.getSourceAddr());
+        assertEquals(0x00, configuration.getSourceAddrNpi());
+        assertEquals(0x00, configuration.getSourceAddrTon());
+        assertEquals("smppclient", configuration.getSystemId());
+        assertEquals("cp", configuration.getSystemType());
+        assertEquals(new Integer(10000), configuration.getTransactionTimer());
+        assertEquals("ISO-8859-1", configuration.getEncoding());
+        assertEquals(0x00, configuration.getNumberingPlanIndicator());
+        assertEquals(0x00, configuration.getTypeOfNumber());
+    }
+    
+    @Test
+    public void getterShouldReturnTheSetValues() {
+        setNoneDefaultValues(configuration);
+        
+        assertEquals("1919", configuration.getDestAddr());
+        assertEquals(0x08, configuration.getDestAddrNpi());
+        assertEquals(0x02, configuration.getDestAddrTon());
+        assertEquals(new Integer(5001), configuration.getEnquireLinkTimer());
+        assertEquals("127.0.0.1", configuration.getHost());
+        assertEquals("secret", configuration.getPassword());
+        assertEquals(new Integer(2776), configuration.getPort());
+        assertEquals(0x00, configuration.getPriorityFlag());
+        assertEquals(0x01, configuration.getProtocolId());
+        assertEquals(0x00, configuration.getRegisteredDelivery());
+        assertEquals(0x01, configuration.getReplaceIfPresentFlag());
+        assertEquals("XXX", configuration.getServiceType());
+        assertEquals("1818", configuration.getSourceAddr());
+        assertEquals(0x08, configuration.getSourceAddrNpi());
+        assertEquals(0x02, configuration.getSourceAddrTon());
+        assertEquals("client", configuration.getSystemId());
+        assertEquals("xx", configuration.getSystemType());
+        assertEquals(new Integer(10001), configuration.getTransactionTimer());
+        assertEquals("UTF-8", configuration.getEncoding());
+        assertEquals(0x08, configuration.getNumberingPlanIndicator());
+        assertEquals(0x02, configuration.getTypeOfNumber());
+    }
+
+    @Test
+    public void getterShouldReturnTheConfigureValuesFromURI() throws URISyntaxException {
+        configuration.configureFromURI(new URI("smpp://client@127.0.0.1:2776"));
+        
+        assertEquals("127.0.0.1", configuration.getHost());
+        assertEquals(new Integer(2776), configuration.getPort());
+        assertEquals("client", configuration.getSystemId());
+    }
+    
+    @Test
+    public void cloneShouldReturnAnEqualInstance() {
+        setNoneDefaultValues(configuration);
+        SmppConfiguration config = configuration.copy();
+        
+        assertEquals(config.getDestAddr(), configuration.getDestAddr());
+        assertEquals(config.getDestAddrNpi(), configuration.getDestAddrNpi());
+        assertEquals(config.getDestAddrTon(), configuration.getDestAddrTon());
+        assertEquals(config.getEnquireLinkTimer(), configuration.getEnquireLinkTimer());
+        assertEquals(config.getHost(), configuration.getHost());
+        assertEquals(config.getPassword(), configuration.getPassword());
+        assertEquals(config.getPort(), configuration.getPort());
+        assertEquals(config.getPriorityFlag(), configuration.getPriorityFlag());
+        assertEquals(config.getProtocolId(), configuration.getProtocolId());
+        assertEquals(config.getRegisteredDelivery(), configuration.getRegisteredDelivery());
+        assertEquals(config.getReplaceIfPresentFlag(), configuration.getReplaceIfPresentFlag());
+        assertEquals(config.getServiceType(), configuration.getServiceType());
+        assertEquals(config.getSourceAddr(), configuration.getSourceAddr());
+        assertEquals(config.getSourceAddrNpi(), configuration.getSourceAddrNpi());
+        assertEquals(config.getSourceAddrTon(), configuration.getSourceAddrTon());
+        assertEquals(config.getSystemId(), configuration.getSystemId());
+        assertEquals(config.getSystemType(), configuration.getSystemType());
+        assertEquals(config.getTransactionTimer(), configuration.getTransactionTimer());
+        assertEquals(config.getEncoding(), configuration.getEncoding());
+        assertEquals(config.getNumberingPlanIndicator(), configuration.getNumberingPlanIndicator());
+        assertEquals(config.getTypeOfNumber(), configuration.getTypeOfNumber());
+    }
+
+    private void setNoneDefaultValues(SmppConfiguration config) {
+        config.setDestAddr("1919");
+        config.setDestAddrNpi(NumberingPlanIndicator.NATIONAL.value());
+        config.setDestAddrTon(TypeOfNumber.NATIONAL.value());
+        config.setEnquireLinkTimer(new Integer(5001));
+        config.setHost("127.0.0.1");
+        config.setPassword("secret");
+        config.setPort(new Integer(2776));
+        config.setPriorityFlag((byte) 0);
+        config.setProtocolId((byte) 1);
+        config.setRegisteredDelivery(SMSCDeliveryReceipt.DEFAULT.value());
+        config.setReplaceIfPresentFlag((byte) 1);
+        config.setServiceType("XXX");
+        config.setSourceAddr("1818");
+        config.setSourceAddrNpi(NumberingPlanIndicator.NATIONAL.value());
+        config.setSourceAddrTon(TypeOfNumber.NATIONAL.value());
+        config.setSystemId("client");
+        config.setSystemType("xx");
+        config.setTransactionTimer(new Integer(10001));
+        config.setEncoding("UTF-8");
+        config.setNumberingPlanIndicator(NumberingPlanIndicator.NATIONAL.value());
+        config.setTypeOfNumber(TypeOfNumber.NATIONAL.value());
+    }
+}

Propchange: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConfigurationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConfigurationTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date