use of org.mobicents.smsc.slee.services.http.server.tx.exceptions.UnauthorizedException in project smscgateway by RestComm.
the class TxHttpServerSbb method onHttpGet.
public void onHttpGet(HttpServletRequestEvent event, ActivityContextInterface aci) {
logger.fine("onHttpGet");
HttpServletRequest request = event.getRequest();
String remoteAddrAndPort = null;
if (request != null)
remoteAddrAndPort = request.getRemoteAddr() + ":" + request.getRemotePort();
long timestampB = 0L;
// decision if getStatus or sendMessage
try {
if (checkCharging()) {
final String message = "The operation is forbidden";
HttpUtils.sendErrorResponse(logger, event.getResponse(), HttpServletResponse.SC_FORBIDDEN, message);
timestampB = System.currentTimeMillis();
if (smscPropertiesManagement.isGenerateRejectionCdr()) {
generateCDR(request, CdrGenerator.CDR_SUBMIT_FAILED_HTTP, message, true);
}
CdrDetailedGenerator.generateDetailedCdr(false, null, null, null, timestampB, null, null, null, EventType.IN_HTTP_REJECT_FORBIDDEN, ErrorCode.REJECT_INCOMING, CdrDetailedGenerator.CDR_MSG_TYPE_HTTP, HttpServletResponse.SC_FORBIDDEN, -1, remoteAddrAndPort, null, -1, smscPropertiesManagement.getGenerateReceiptCdr(), smscPropertiesManagement.getGenerateDetailedCdr());
} else {
String requestURL = request.getRequestURL().toString();
String[] tmp = requestURL.split("\\?");
if (tmp[0].endsWith(SEND_SMS)) {
processHttpSendMessageEvent(event, aci);
} else if (tmp[0].endsWith(MSG_QUERY)) {
processHttpGetMessageIdStatusEvent(event, aci);
} else {
throw new HttpApiException("Unknown operation on the HTTP API");
}
}
} catch (HttpApiException e) {
try {
if (logger.isWarningEnabled()) {
logger.warning(e.getMessage());
}
sendErrorResponse(event, e);
} catch (Exception ex) {
logger.severe("Error while sending error response", ex);
}
} catch (UnauthorizedException e) {
try {
if (logger.isWarningEnabled()) {
logger.warning(e.getMessage() + " UserName:" + e.getUserName() + " Password:" + e.getPassword());
}
HttpUtils.sendErrorResponse(logger, event.getResponse(), HttpServletResponse.SC_UNAUTHORIZED, e.getMessage());
timestampB = System.currentTimeMillis();
if (smscPropertiesManagement.isGenerateRejectionCdr()) {
generateCDR(request, CdrGenerator.CDR_SUBMIT_FAILED_HTTP, e.getMessage(), true);
}
CdrDetailedGenerator.generateDetailedCdr(false, null, null, null, timestampB, null, null, null, EventType.IN_HTTP_REJECT_FORBIDDEN, ErrorCode.REJECT_INCOMING, CdrDetailedGenerator.CDR_MSG_TYPE_HTTP, HttpServletResponse.SC_UNAUTHORIZED, -1, remoteAddrAndPort, null, -1, smscPropertiesManagement.getGenerateReceiptCdr(), smscPropertiesManagement.getGenerateDetailedCdr());
} catch (Exception ex) {
logger.severe("Error while sending error response", ex);
}
} catch (Exception e) {
try {
if (logger.isWarningEnabled()) {
logger.warning(e.getMessage());
}
sendErrorResponse(event, e);
} catch (Exception ex) {
logger.severe("Error while sending error response", ex);
}
}
}
use of org.mobicents.smsc.slee.services.http.server.tx.exceptions.UnauthorizedException in project smscgateway by RestComm.
the class TxHttpServerSbb method onHttpPost.
public void onHttpPost(HttpServletRequestEvent event, ActivityContextInterface aci) {
logger.fine("onHttpPost");
HttpServletRequest request = event.getRequest();
String remoteAddrAndPort = null;
if (request != null)
remoteAddrAndPort = request.getRemoteAddr() + ":" + request.getRemotePort();
long timestampB = 0L;
// decision if getStatus or sendMessage
try {
if (checkCharging()) {
final String message = "The operation is forbidden";
HttpUtils.sendErrorResponse(logger, event.getResponse(), HttpServletResponse.SC_FORBIDDEN, message);
timestampB = System.currentTimeMillis();
if (smscPropertiesManagement.isGenerateRejectionCdr()) {
generateCDR(request, CdrGenerator.CDR_SUBMIT_FAILED_HTTP, message, true);
}
CdrDetailedGenerator.generateDetailedCdr(false, null, null, null, timestampB, null, null, null, EventType.IN_HTTP_REJECT_FORBIDDEN, ErrorCode.REJECT_INCOMING, CdrDetailedGenerator.CDR_MSG_TYPE_HTTP, HttpServletResponse.SC_FORBIDDEN, -1, remoteAddrAndPort, null, -1, smscPropertiesManagement.getGenerateReceiptCdr(), smscPropertiesManagement.getGenerateDetailedCdr());
} else {
String requestURL = request.getRequestURL().toString();
requestURL.endsWith(SEND_SMS);
if (requestURL.endsWith(SEND_SMS)) {
processHttpSendMessageEvent(event, aci);
} else if (requestURL.endsWith(MSG_QUERY)) {
processHttpGetMessageIdStatusEvent(event, aci);
} else {
throw new HttpApiException("Unknown operation on the HTTP API. Parameter set from the request does not match any of the HTTP API services.");
}
}
} catch (HttpApiException e) {
try {
if (logger.isWarningEnabled()) {
logger.warning(e.getMessage());
}
sendErrorResponse(event, e);
} catch (Exception ex) {
logger.severe("Error while sending error response", ex);
}
} catch (UnauthorizedException e) {
try {
if (logger.isWarningEnabled()) {
logger.warning(e.getMessage() + " UserName:" + e.getUserName() + " Password:" + e.getPassword());
}
HttpUtils.sendErrorResponse(logger, event.getResponse(), HttpServletResponse.SC_UNAUTHORIZED, e.getMessage());
timestampB = System.currentTimeMillis();
if (smscPropertiesManagement.isGenerateRejectionCdr()) {
generateCDR(request, CdrGenerator.CDR_SUBMIT_FAILED_HTTP, e.getMessage(), true);
}
CdrDetailedGenerator.generateDetailedCdr(false, null, null, null, timestampB, null, null, null, EventType.IN_HTTP_REJECT_FORBIDDEN, ErrorCode.REJECT_INCOMING, CdrDetailedGenerator.CDR_MSG_TYPE_HTTP, HttpServletResponse.SC_UNAUTHORIZED, -1, remoteAddrAndPort, null, -1, smscPropertiesManagement.getGenerateReceiptCdr(), smscPropertiesManagement.getGenerateDetailedCdr());
} catch (Exception ex) {
logger.severe("Error while sending error response", ex);
}
} catch (Exception e) {
logger.warning("Unable to handle HttpPost. Message: " + e.getMessage() + ".", e);
try {
sendErrorResponse(event, e);
} catch (Exception ex) {
logger.severe("Error while sending error response. Message: " + ex.getMessage() + ".", ex);
}
}
}
Aggregations