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 org.apache.camel.Component;
020 import org.apache.camel.Consumer;
021 import org.apache.camel.Exchange;
022 import org.apache.camel.ExchangePattern;
023 import org.apache.camel.Processor;
024 import org.apache.camel.Producer;
025 import org.apache.camel.impl.DefaultEndpoint;
026 import org.jsmpp.bean.AlertNotification;
027 import org.jsmpp.bean.DataSm;
028 import org.jsmpp.bean.DeliverSm;
029
030 /**
031 * A SMPP Endpoint
032 *
033 * @version $Revision: 954209 $
034 * @author muellerc
035 */
036 public class SmppEndpoint extends DefaultEndpoint {
037
038 private SmppBinding binding;
039 private SmppConfiguration configuration;
040
041 public SmppEndpoint(String endpointUri, Component component, SmppConfiguration configuration) {
042 super(endpointUri, component);
043 this.configuration = configuration;
044 }
045
046 public boolean isSingleton() {
047 return true;
048 }
049
050 @Override
051 protected String createEndpointUri() {
052 return getConnectionString();
053 }
054
055 @Override
056 public boolean isLenientProperties() {
057 return true;
058 }
059
060 public Consumer createConsumer(Processor processor) throws Exception {
061 return new SmppConsumer(this, configuration, processor);
062 }
063
064 public Producer createProducer() throws Exception {
065 return new SmppProducer(this, configuration);
066 }
067
068 /**
069 * Create a new exchange for communicating with this endpoint from a SMSC
070 *
071 * @param alertNotification the received message from the SMSC
072 * @return a new exchange
073 */
074 public Exchange createOnAcceptAlertNotificationExchange(AlertNotification alertNotification) {
075 return createOnAcceptAlertNotificationExchange(getExchangePattern(), alertNotification);
076 }
077
078 /**
079 * Create a new exchange for communicating with this endpoint from a SMSC
080 * with the specified {@link ExchangePattern} such as whether its going
081 * to be an {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut} exchange
082 *
083 * @param exchangePattern the message exchange pattern for the exchange
084 * @param alertNotification the received message from the SMSC
085 * @return a new exchange
086 */
087 public Exchange createOnAcceptAlertNotificationExchange(ExchangePattern exchangePattern,
088 AlertNotification alertNotification) {
089 Exchange exchange = createExchange(exchangePattern);
090 exchange.setProperty(Exchange.BINDING, getBinding());
091 exchange.setIn(getBinding().createSmppMessage(alertNotification));
092 return exchange;
093 }
094
095 /**
096 * Create a new exchange for communicating with this endpoint from a SMSC
097 *
098 * @param deliverSm the received message from the SMSC
099 * @return a new exchange
100 */
101 public Exchange createOnAcceptDeliverSmExchange(DeliverSm deliverSm) throws Exception {
102 return createOnAcceptDeliverSmExchange(getExchangePattern(), deliverSm);
103 }
104
105 /**
106 * Create a new exchange for communicating with this endpoint from a SMSC
107 * with the specified {@link ExchangePattern} such as whether its going
108 * to be an {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut} exchange
109 *
110 * @param exchangePattern the message exchange pattern for the exchange
111 * @param deliverSm the received message from the SMSC
112 * @return a new exchange
113 */
114 public Exchange createOnAcceptDeliverSmExchange(ExchangePattern exchangePattern,
115 DeliverSm deliverSm) throws Exception {
116 Exchange exchange = createExchange(exchangePattern);
117 exchange.setProperty(Exchange.BINDING, getBinding());
118 exchange.setIn(getBinding().createSmppMessage(deliverSm));
119 return exchange;
120 }
121
122 /**
123 * Create a new exchange for communicating with this endpoint from a SMSC
124 *
125 * @param dataSm the received message from the SMSC
126 * @param smppMessageId the smpp message id which will be used in the response
127 * @return a new exchange
128 */
129 public Exchange createOnAcceptDataSm(DataSm dataSm, String smppMessageId) {
130 return createOnAcceptDataSm(getExchangePattern(), dataSm, smppMessageId);
131 }
132
133 /**
134 * Create a new exchange for communicating with this endpoint from a SMSC
135 * with the specified {@link ExchangePattern} such as whether its going
136 * to be an {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut} exchange
137 *
138 * @param exchangePattern the message exchange pattern for the exchange
139 * @param dataSm the received message from the SMSC
140 * @param smppMessageId the smpp message id which will be used in the response
141 * @return a new exchange
142 */
143 public Exchange createOnAcceptDataSm(ExchangePattern exchangePattern, DataSm dataSm, String smppMessageId) {
144 Exchange exchange = createExchange(exchangePattern);
145 exchange.setProperty(Exchange.BINDING, getBinding());
146 exchange.setIn(getBinding().createSmppMessage(dataSm, smppMessageId));
147 return exchange;
148 }
149
150 /**
151 * Returns the connection string for the current connection which has the form:
152 * smpp://<user>@<host>:<port>
153 *
154 * @return the connection string
155 */
156 public String getConnectionString() {
157 return (configuration.getUsingSSL() ? "smpps://" : "smpp://")
158 + getConfiguration().getSystemId() + "@"
159 + getConfiguration().getHost() + ":"
160 + getConfiguration().getPort();
161 }
162
163 /**
164 * Returns the smpp configuration
165 *
166 * @return the configuration
167 */
168 public SmppConfiguration getConfiguration() {
169 return configuration;
170 }
171
172 public SmppBinding getBinding() {
173 if (binding == null) {
174 binding = new SmppBinding(getConfiguration());
175 }
176 return binding;
177 }
178
179 public void setBinding(SmppBinding binding) {
180 this.binding = binding;
181 }
182 }