SMPP SMS sender refactoring, API docs
This commit is contained in:
parent
f7911cc1ac
commit
7b0309ca68
@ -1,3 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* Copyright © 2016-2021 The Thingsboard Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
package org.thingsboard.server.service.sms.smpp;
|
package org.thingsboard.server.service.sms.smpp;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -32,7 +47,26 @@ public class SmppSmsSender extends AbstractSmsSender {
|
|||||||
private Session smppSession;
|
private Session smppSession;
|
||||||
|
|
||||||
public SmppSmsSender(SmppSmsProviderConfiguration config) {
|
public SmppSmsSender(SmppSmsProviderConfiguration config) {
|
||||||
|
if (config.getBindType() == null) {
|
||||||
|
config.setBindType(SmppSmsProviderConfiguration.SmppBindType.TX);
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotEmpty(config.getSourceAddress())) {
|
||||||
|
if (config.getSourceTon() == null) {
|
||||||
|
config.setSourceTon((byte) 5);
|
||||||
|
}
|
||||||
|
if (config.getSourceNpi() == null) {
|
||||||
|
config.setSourceNpi((byte) 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (config.getDestinationTon() == null) {
|
||||||
|
config.setDestinationTon((byte) 5);
|
||||||
|
}
|
||||||
|
if (config.getDestinationNpi() == null) {
|
||||||
|
config.setDestinationNpi((byte) 0);
|
||||||
|
}
|
||||||
|
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
initSmppSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -45,10 +79,9 @@ public class SmppSmsSender extends AbstractSmsSender {
|
|||||||
request.setServiceType(config.getServiceType());
|
request.setServiceType(config.getServiceType());
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotEmpty(config.getSourceAddress())) {
|
if (StringUtils.isNotEmpty(config.getSourceAddress())) {
|
||||||
request.setSourceAddr(new Address(config.getTon(), config.getNpi(), config.getSourceAddress()));
|
request.setSourceAddr(new Address(config.getSourceTon(), config.getSourceNpi(), config.getSourceAddress()));
|
||||||
}
|
}
|
||||||
numberTo = prepareNumber(numberTo);
|
request.setDestAddr(new Address(config.getDestinationTon(), config.getDestinationNpi(), prepareNumber(numberTo)));
|
||||||
request.setDestAddr(new Address(config.getDestinationTon(), config.getDestinationNpi(), numberTo));
|
|
||||||
request.setShortMessage(message);
|
request.setShortMessage(message);
|
||||||
request.setDataCoding(Optional.ofNullable(config.getCodingScheme()).orElse((byte) 0));
|
request.setDataCoding(Optional.ofNullable(config.getCodingScheme()).orElse((byte) 0));
|
||||||
request.setReplaceIfPresentFlag((byte) 0);
|
request.setReplaceIfPresentFlag((byte) 0);
|
||||||
@ -69,7 +102,7 @@ public class SmppSmsSender extends AbstractSmsSender {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void checkSmppSession() {
|
public synchronized void checkSmppSession() {
|
||||||
if (smppSession == null || !smppSession.isOpened()) {
|
if (!smppSession.isOpened()) {
|
||||||
smppSession = initSmppSession();
|
smppSession = initSmppSession();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,9 +113,6 @@ public class SmppSmsSender extends AbstractSmsSender {
|
|||||||
Session session = new Session(connection);
|
Session session = new Session(connection);
|
||||||
|
|
||||||
BindRequest bindRequest;
|
BindRequest bindRequest;
|
||||||
if (config.getBindType() == null) {
|
|
||||||
bindRequest = new BindTransmitter();
|
|
||||||
} else {
|
|
||||||
switch (config.getBindType()) {
|
switch (config.getBindType()) {
|
||||||
case TX:
|
case TX:
|
||||||
bindRequest = new BindTransmitter();
|
bindRequest = new BindTransmitter();
|
||||||
@ -96,7 +126,6 @@ public class SmppSmsSender extends AbstractSmsSender {
|
|||||||
default:
|
default:
|
||||||
throw new UnsupportedOperationException("Unsupported bind type " + config.getBindType());
|
throw new UnsupportedOperationException("Unsupported bind type " + config.getBindType());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
bindRequest.setSystemId(config.getSystemId());
|
bindRequest.setSystemId(config.getSystemId());
|
||||||
bindRequest.setPassword(config.getPassword());
|
bindRequest.setPassword(config.getPassword());
|
||||||
|
|||||||
@ -1,3 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* Copyright © 2016-2021 The Thingsboard Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
package org.thingsboard.server.common.data.sms.config;
|
package org.thingsboard.server.common.data.sms.config;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
@ -5,34 +20,73 @@ import lombok.Data;
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class SmppSmsProviderConfiguration implements SmsProviderConfiguration {
|
public class SmppSmsProviderConfiguration implements SmsProviderConfiguration {
|
||||||
@ApiModelProperty(allowableValues = "3.3, 3.4")
|
@ApiModelProperty(value = "SMPP version", allowableValues = "3.3, 3.4", required = true)
|
||||||
private String protocolVersion;
|
private String protocolVersion;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "SMPP host", required = true)
|
||||||
private String host;
|
private String host;
|
||||||
|
@ApiModelProperty(value = "SMPP port", required = true)
|
||||||
private Integer port;
|
private Integer port;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "System ID", required = true)
|
||||||
private String systemId;
|
private String systemId;
|
||||||
|
@ApiModelProperty(value = "Password", required = true)
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@ApiModelProperty(required = false)
|
@ApiModelProperty(value = "System type", required = false)
|
||||||
private String systemType;
|
private String systemType;
|
||||||
@ApiModelProperty(value = "TX - Transmitter, RX - Receiver, TRX - Transciever. By default TX is used", required = false)
|
@ApiModelProperty(value = "TX - Transmitter, RX - Receiver, TRX - Transciever. By default TX is used", required = false)
|
||||||
private SmppBindType bindType;
|
private SmppBindType bindType;
|
||||||
@ApiModelProperty(required = false)
|
@ApiModelProperty(value = "Service type", required = false)
|
||||||
private String serviceType;
|
private String serviceType;
|
||||||
|
|
||||||
@ApiModelProperty(required = false)
|
@ApiModelProperty(value = "Source address", required = false)
|
||||||
private Byte ton;
|
|
||||||
@ApiModelProperty(required = false)
|
|
||||||
private Byte npi;
|
|
||||||
@ApiModelProperty(required = false)
|
|
||||||
private String sourceAddress;
|
private String sourceAddress;
|
||||||
|
@ApiModelProperty(value = "Source TON (Type of Number). Needed is source address is set. 5 by default.\n" +
|
||||||
|
"0 - Unknown\n" +
|
||||||
|
"1 - International\n" +
|
||||||
|
"2 - National\n" +
|
||||||
|
"3 - Network Specific\n" +
|
||||||
|
"4 - Subscriber Number\n" +
|
||||||
|
"5 - Alphanumeric\n" +
|
||||||
|
"6 - Abbreviated", required = false)
|
||||||
|
private Byte sourceTon;
|
||||||
|
@ApiModelProperty(value = "Source NPI (Numbering Plan Identification). Needed is source address is set. 0 by default.\n" +
|
||||||
|
"0 - Unknown\n" +
|
||||||
|
"1 - ISDN/telephone numbering plan (E163/E164)\n" +
|
||||||
|
"3 - Data numbering plan (X.121)\n" +
|
||||||
|
"4 - Telex numbering plan (F.69)\n" +
|
||||||
|
"6 - Land Mobile (E.212) =6\n" +
|
||||||
|
"8 - National numbering plan\n" +
|
||||||
|
"9 - Private numbering plan\n" +
|
||||||
|
"10 - ERMES numbering plan (ETSI DE/PS 3 01-3)\n" +
|
||||||
|
"13 - Internet (IP)\n" +
|
||||||
|
"18 - WAP Client Id (to be defined by WAP Forum)", required = false)
|
||||||
|
private Byte sourceNpi;
|
||||||
|
|
||||||
@ApiModelProperty(required = false)
|
@ApiModelProperty(value = "Destination TON (Type of Number). 5 by default.\n" +
|
||||||
|
"0 - Unknown\n" +
|
||||||
|
"1 - International\n" +
|
||||||
|
"2 - National\n" +
|
||||||
|
"3 - Network Specific\n" +
|
||||||
|
"4 - Subscriber Number\n" +
|
||||||
|
"5 - Alphanumeric\n" +
|
||||||
|
"6 - Abbreviated", required = false)
|
||||||
private Byte destinationTon;
|
private Byte destinationTon;
|
||||||
@ApiModelProperty(required = false)
|
@ApiModelProperty(value = "Destination NPI (Numbering Plan Identification). 0 by default.\n" +
|
||||||
|
"0 - Unknown\n" +
|
||||||
|
"1 - ISDN/telephone numbering plan (E163/E164)\n" +
|
||||||
|
"3 - Data numbering plan (X.121)\n" +
|
||||||
|
"4 - Telex numbering plan (F.69)\n" +
|
||||||
|
"6 - Land Mobile (E.212) =6\n" +
|
||||||
|
"8 - National numbering plan\n" +
|
||||||
|
"9 - Private numbering plan\n" +
|
||||||
|
"10 - ERMES numbering plan (ETSI DE/PS 3 01-3)\n" +
|
||||||
|
"13 - Internet (IP)\n" +
|
||||||
|
"18 - WAP Client Id (to be defined by WAP Forum)", required = false)
|
||||||
private Byte destinationNpi;
|
private Byte destinationNpi;
|
||||||
@ApiModelProperty(required = false)
|
|
||||||
|
@ApiModelProperty(value = "Address range", required = false)
|
||||||
private String addressRange;
|
private String addressRange;
|
||||||
|
|
||||||
@ApiModelProperty(allowableValues = "0-10,13-14",
|
@ApiModelProperty(allowableValues = "0-10,13-14",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user