001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.camel.component.smpp;
018
019 import java.io.UnsupportedEncodingException;
020
021 import org.apache.camel.impl.DefaultMessage;
022 import org.jsmpp.bean.AlertNotification;
023 import org.jsmpp.bean.Command;
024 import org.jsmpp.bean.DeliverSm;
025 import org.jsmpp.bean.MessageRequest;
026
027 /**
028 * Represents a {@link org.apache.camel.Message} for working with SMPP
029 *
030 * @author muellerc
031 * @version $Revision: 889123 $
032 */
033 public class SmppMessage extends DefaultMessage {
034
035 private Command command;
036 private SmppConfiguration configuration;
037
038 public SmppMessage(SmppConfiguration configuration) {
039 this.configuration = configuration;
040 }
041
042 public SmppMessage(AlertNotification command, SmppConfiguration configuration) {
043 this.command = command;
044 this.configuration = configuration;
045 }
046
047 public SmppMessage(DeliverSm command, SmppConfiguration configuration) {
048 this.command = command;
049 this.configuration = configuration;
050 }
051
052 @Override
053 public SmppMessage newInstance() {
054 return new SmppMessage(this.configuration);
055 }
056
057 @Override
058 protected Object createBody() {
059 if (command instanceof MessageRequest) {
060 byte[] shortMessage = ((MessageRequest) command).getShortMessage();
061 try {
062 return new String(shortMessage, configuration.getEncoding());
063 } catch (UnsupportedEncodingException e) {
064 return new String(shortMessage);
065 }
066 }
067
068 return null;
069 }
070
071 @Override
072 public String toString() {
073 if (command != null) {
074 return "SmppMessage: " + command;
075 } else {
076 return "SmppMessage: " + getBody();
077 }
078 }
079
080 /**
081 * Returns the underlying jSMPP command
082 *
083 * @return command
084 */
085 public Command getCommand() {
086 return command;
087 }
088 }