You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2016/12/02 09:44:27 UTC

[3/3] camel git commit: fixed typos failing with -Psourcecheck added ASF license headers invalid splitter throws exception

fixed typos failing with -Psourcecheck
added ASF license headers
invalid splitter throws exception


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/82490dbe
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/82490dbe
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/82490dbe

Branch: refs/heads/master
Commit: 82490dbe3b5969d7740c0ebd22afe86475be9a70
Parents: b1b67bd
Author: Engin Dumlu <en...@gmail.com>
Authored: Thu Dec 1 20:21:16 2016 +0300
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Fri Dec 2 10:40:52 2016 +0100

----------------------------------------------------------------------
 .../camel/component/smpp/SmppNLSTSplitter.java  | 97 +++++++++++++++-----
 .../camel/component/smpp/SmppSmCommand.java     |  9 +-
 .../component/smpp/SmppSubmitSmCommand.java     |  2 +-
 .../component/smpp/SmppNLSTSplitterTest.java    | 45 +++++----
 4 files changed, 108 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/82490dbe/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppNLSTSplitter.java
----------------------------------------------------------------------
diff --git a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppNLSTSplitter.java b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppNLSTSplitter.java
index 4e0bd39..91cbadb 100644
--- a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppNLSTSplitter.java
+++ b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppNLSTSplitter.java
@@ -1,48 +1,99 @@
+/**
+ * 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.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Created by engin on 30/11/2016.
+ * Splitter for messages use National Language Lock Table
+ * <p/>
+ * @see 3GPP 23.038 Reference
  */
-class SmppNLSTSplitter extends SmppSplitter{
-
+public class SmppNLSTSplitter extends SmppSplitter {
+    /**
+     * The length of the UDH for single short message in bytes.
+     * 0x25 - UDHIE_NLI_IDENTIFIER
+     * 0x01 - Length of the header
+     * 0xXX - Locking shift table indicator the Language
+     */
     protected static final int UDHIE_NLI_SINGLE_MSG_HEADER_LENGTH = 0x03; // header length for single message
+    /**
+     * The real length of the UDH for single short message
+     */
     protected static final int UDHIE_NLI_SINGLE_MSG_HEADER_REAL_LENGTH = UDHIE_NLI_SINGLE_MSG_HEADER_LENGTH + 1;
 
-    protected static final int UDHIE_NLI_MULTI_MSG_HEADER_LENGTH = 0x08; // header length for multi message
+    /**
+     * The length of the UDH for splitted short messages, in bytes.
+     * 0x08 Overall header length
+     * 0x00 The value that identifier length of the SAR fragment. (8bit reference number only)
+     * 0x03 The length of the SAR fragment
+     * 0xXX The reference number for SAR
+     * 0xXX Total number of splitted / segmented messages
+     * 0xXX Segment number
+     * 0x25 National language locking shift element identifier
+     * 0x01 Length of the header
+     * 0xXX Locking shift table indicator for the Language (ie: 0x01 for Turkish)
+     */
+    protected static final int UDHIE_NLI_MULTI_MSG_HEADER_LENGTH = 0x08;
+
+    /**
+     * The real length of the UDH for segmentet short messages
+     */
     protected static final int UDHIE_NLI_MULTI_MSG_HEADER_REAL_LENGTH = UDHIE_NLI_MULTI_MSG_HEADER_LENGTH + 1;
 
-
-    protected static final int UDHIE_SAR_REF_NUM_LENGTH = 1;
-//        protected static final byte UDHIE_IDENTIFIER_SAR = 0x00;
-//        protected static final byte UDHIE_SAR_LENGTH = 0x03;
-//        protected static final int MAX_SEG_COUNT = 255;
-
+    /**
+     * The element identifier value for the National Language Locking Table
+     */
     protected static final int UDHIE_NLI_IDENTIFIER = 0x25;
+    /**
+     * The length of the NLI header
+     */
     protected static final int UDHIE_NLI_HEADER_LENGTH = 0x01;
 
-    public static final int MAX_MSG_CHAR_SIZE = (MAX_MSG_BYTE_LENGTH * 8 / 7) - (UDHIE_NLI_SINGLE_MSG_HEADER_REAL_LENGTH + 1); // 155 for NLST
+    /**
+     * The maximum length in chars of the NLI messages.
+     * <p/>
+     * Each letter will be represented as 7 bit (like GSM8)
+     */
+    public static final int MAX_MSG_CHAR_SIZE = (MAX_MSG_BYTE_LENGTH * 8 / 7) - (UDHIE_NLI_SINGLE_MSG_HEADER_REAL_LENGTH + 1);
+
     public static final int MAX_SEG_BYTE_SIZE = (MAX_MSG_BYTE_LENGTH - UDHIE_NLI_MULTI_MSG_HEADER_REAL_LENGTH) * 8 / 7;
 
+    /**
+     * Locking shift table indicator for the Language, single byte
+     */
     private byte languageIdentifier;
     private final Logger logger = LoggerFactory.getLogger(SmppNLSTSplitter.class);
 
-    SmppNLSTSplitter(int currentLength, byte languageIdentifier) {
+    public SmppNLSTSplitter(int currentLength, byte languageIdentifier) {
         super(MAX_MSG_CHAR_SIZE, MAX_SEG_BYTE_SIZE, currentLength);
         this.languageIdentifier = languageIdentifier;
     }
 
     public byte[][] split(byte[] message) {
         if (!isSplitRequired()) {
-            byte[] nli_message = new byte[UDHIE_NLI_SINGLE_MSG_HEADER_REAL_LENGTH + message.length];
-            nli_message[0] = (byte) UDHIE_NLI_SINGLE_MSG_HEADER_LENGTH;
-            nli_message[1] = (byte) UDHIE_NLI_IDENTIFIER;
-            nli_message[2] = (byte) UDHIE_NLI_HEADER_LENGTH;
-            nli_message[3] = this.languageIdentifier;
-            System.arraycopy(message, 0, nli_message, 4, message.length);
-            return new byte[][]{nli_message};
+            byte[] nliMessage = new byte[UDHIE_NLI_SINGLE_MSG_HEADER_REAL_LENGTH + message.length];
+            nliMessage[0] = (byte) UDHIE_NLI_SINGLE_MSG_HEADER_LENGTH;
+            nliMessage[1] = (byte) UDHIE_NLI_IDENTIFIER;
+            nliMessage[2] = (byte) UDHIE_NLI_HEADER_LENGTH;
+            nliMessage[3] = this.languageIdentifier;
+            System.arraycopy(message, 0, nliMessage, 4, message.length);
+            return new byte[][]{nliMessage};
         }
 
         int segmentLength = getSegmentLength();
@@ -64,16 +115,16 @@ class SmppNLSTSplitter extends SmppSplitter{
         int lengthOfData;
         byte refNum = getReferenceNumber();
         for (int i = 0; i < segmentNum; i++) {
-            logger.info("segment number = {}", i);
+            logger.debug("segment number = {}", i);
             if (segmentNum - i == 1) {
                 lengthOfData = messageLength - i * segmentLength;
             } else {
                 lengthOfData = segmentLength;
             }
-            logger.info("Length of data = {}", lengthOfData);
+            logger.debug("Length of data = {}", lengthOfData);
 
             segments[i] = new byte[UDHIE_NLI_MULTI_MSG_HEADER_REAL_LENGTH + lengthOfData];
-            logger.info("segments[{}].length = {}", i, segments[i].length);
+            logger.debug("segments[{}].length = {}", i, segments[i].length);
 
             segments[i][0] = UDHIE_NLI_MULTI_MSG_HEADER_LENGTH; // doesn't include itself, is header length
             // SAR identifier
@@ -87,7 +138,7 @@ class SmppNLSTSplitter extends SmppSplitter{
             // segment #
             segments[i][5] = (byte) (i + 1);
 
-            // language stuff
+            // national language locking shift table, element identifier
             segments[i][6] = (byte) UDHIE_NLI_IDENTIFIER;
             segments[i][7] = (byte) UDHIE_NLI_HEADER_LENGTH;
             segments[i][8] = this.languageIdentifier;

http://git-wip-us.apache.org/repos/asf/camel/blob/82490dbe/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSmCommand.java
----------------------------------------------------------------------
diff --git a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSmCommand.java b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSmCommand.java
index 71b2171..eb9cd94 100644
--- a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSmCommand.java
+++ b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSmCommand.java
@@ -75,16 +75,16 @@ public abstract class SmppSmCommand extends AbstractSmppCommand {
         return config.getSplittingPolicy();
     }
 
-    protected SmppSplitter createSplitter(Message message) {
+    protected SmppSplitter createSplitter(Message message) throws SmppException {
 
         SmppSplitter splitter;
         // use the splitter if provided via header
-        if (message.getHeaders().containsKey(SmppConstants.DATA_SPLITTER)){
+        if (message.getHeaders().containsKey(SmppConstants.DATA_SPLITTER)) {
             splitter = message.getHeader(SmppConstants.DATA_SPLITTER, SmppSplitter.class);
-            if (null != splitter){
+            if (null != splitter) {
                 return splitter;
             }
-            logger.warn("Invalid splitter given. Must be instance of SmppSplitter");
+            throw new SmppException("Invalid splitter given. Must be instance of SmppSplitter");
         }
         Alphabet alphabet = determineAlphabet(message);
         String body = message.getBody(String.class);
@@ -96,7 +96,6 @@ public abstract class SmppSmCommand extends AbstractSmppCommand {
         } else {
             splitter = new SmppDefaultSplitter(body.length());
         }
-
         return splitter;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/82490dbe/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitSmCommand.java
----------------------------------------------------------------------
diff --git a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitSmCommand.java b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitSmCommand.java
index 7ac8955..7392cda 100644
--- a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitSmCommand.java
+++ b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitSmCommand.java
@@ -99,7 +99,7 @@ public class SmppSubmitSmCommand extends SmppSmCommand {
         if (null != esmClass) {
             template.setEsmClass(esmClass.value());
             // multipart message
-        }else if (segments.length > 1) {
+        } else if (segments.length > 1) {
             template.setEsmClass(new ESMClass(MessageMode.DEFAULT, MessageType.DEFAULT, GSMSpecificFeature.UDHI).value());
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/82490dbe/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppNLSTSplitterTest.java
----------------------------------------------------------------------
diff --git a/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppNLSTSplitterTest.java b/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppNLSTSplitterTest.java
index 2dfcabc..b3cacd1 100644
--- a/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppNLSTSplitterTest.java
+++ b/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppNLSTSplitterTest.java
@@ -1,3 +1,19 @@
+/**
+ * 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.nio.charset.Charset;
@@ -9,9 +25,6 @@ import org.slf4j.LoggerFactory;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 
-/**
- * Created by engin on 30/11/2016.
- */
 public class SmppNLSTSplitterTest {
 
     @Test
@@ -26,10 +39,10 @@ public class SmppNLSTSplitterTest {
 
         assertEquals(1, result.length);
         assertArrayEquals(new byte[]{SmppNLSTSplitter.UDHIE_NLI_SINGLE_MSG_HEADER_LENGTH, SmppNLSTSplitter.UDHIE_NLI_IDENTIFIER, SmppNLSTSplitter.UDHIE_NLI_HEADER_LENGTH, turkishLanguageIdentifier,
-                49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48,
-                49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53,
-                54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48,
-                49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53}, result[0]);
+            49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48,
+            49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53,
+            54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48,
+            49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53}, result[0]);
     }
 
     @Test
@@ -44,17 +57,17 @@ public class SmppNLSTSplitterTest {
 
         assertEquals(2, result.length);
         assertArrayEquals(new byte[]{
-                SmppNLSTSplitter.UDHIE_NLI_MULTI_MSG_HEADER_LENGTH, SmppNLSTSplitter.UDHIE_IDENTIFIER_SAR, SmppNLSTSplitter.UDHIE_SAR_LENGTH, 1, 2, 1,
-                SmppNLSTSplitter.UDHIE_NLI_IDENTIFIER, SmppNLSTSplitter.UDHIE_NLI_HEADER_LENGTH, turkishLanguageIdentifier,
-                49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48,
-                49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53,
-                54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48,
-                49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57}, result[0]);
+            SmppNLSTSplitter.UDHIE_NLI_MULTI_MSG_HEADER_LENGTH, SmppNLSTSplitter.UDHIE_IDENTIFIER_SAR, SmppNLSTSplitter.UDHIE_SAR_LENGTH, 1, 2, 1,
+            SmppNLSTSplitter.UDHIE_NLI_IDENTIFIER, SmppNLSTSplitter.UDHIE_NLI_HEADER_LENGTH, turkishLanguageIdentifier,
+            49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48,
+            49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53,
+            54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48,
+            49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57}, result[0]);
 
         assertArrayEquals(new byte[]{
-                SmppNLSTSplitter.UDHIE_NLI_MULTI_MSG_HEADER_LENGTH, SmppNLSTSplitter.UDHIE_IDENTIFIER_SAR, SmppNLSTSplitter.UDHIE_SAR_LENGTH, 1, 2, 2,
-                SmppNLSTSplitter.UDHIE_NLI_IDENTIFIER, SmppNLSTSplitter.UDHIE_NLI_HEADER_LENGTH, turkishLanguageIdentifier,
-                48, 49, 50, 51, 52, 53, 54}, result[1]);
+            SmppNLSTSplitter.UDHIE_NLI_MULTI_MSG_HEADER_LENGTH, SmppNLSTSplitter.UDHIE_IDENTIFIER_SAR, SmppNLSTSplitter.UDHIE_SAR_LENGTH, 1, 2, 2,
+            SmppNLSTSplitter.UDHIE_NLI_IDENTIFIER, SmppNLSTSplitter.UDHIE_NLI_HEADER_LENGTH, turkishLanguageIdentifier,
+            48, 49, 50, 51, 52, 53, 54}, result[1]);
 
         String firstShortMessage = new String(result[0], SmppNLSTSplitter.UDHIE_NLI_MULTI_MSG_HEADER_REAL_LENGTH, result[0].length - SmppNLSTSplitter.UDHIE_NLI_MULTI_MSG_HEADER_REAL_LENGTH);
         String secondShortMessage = new String(result[1], SmppNLSTSplitter.UDHIE_NLI_MULTI_MSG_HEADER_REAL_LENGTH, result[1].length - SmppNLSTSplitter.UDHIE_NLI_MULTI_MSG_HEADER_REAL_LENGTH);