www in docker support
This commit is contained in:
parent
539a848e95
commit
c227fce036
2145 changed files with 399596 additions and 58 deletions
|
|
@ -0,0 +1,169 @@
|
|||
package it.acxent.rd.servlet.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.newsletter.CodaMessaggi;
|
||||
import it.acxent.newsletter.CodaMessaggiCR;
|
||||
import it.acxent.rd.RemoteDevice;
|
||||
import it.acxent.rd.json.RdRequestJ;
|
||||
import it.acxent.rd.json.RdResponseJ;
|
||||
import it.acxent.rd.json.smsgateway.DataSmsMsgJ;
|
||||
import it.acxent.rd.json.smsgateway.RdRequestSmsGatewayJ;
|
||||
import it.acxent.rd.json.smsgateway.RdResponseSmsGatewayJ;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.util.Vector;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@WebServlet(urlPatterns = {"/rdRest/Ma.abl"})
|
||||
public class MobileApiSvlt extends _RdApiSvlt {
|
||||
private static final long serialVersionUID = -8266400675249237394L;
|
||||
|
||||
private static final String TAG = "MobileApiSvlt ";
|
||||
|
||||
protected boolean isSimpleServlet(HttpServletRequest req) {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void search(HttpServletRequest req, HttpServletResponse res) {
|
||||
sendHtmlMsgResponse(req, res, "ERRORE invio ");
|
||||
}
|
||||
|
||||
protected void otherCommands(HttpServletRequest req, HttpServletResponse res) {
|
||||
_recordDevice(req, res);
|
||||
}
|
||||
|
||||
protected boolean isSecureServlet(HttpServletRequest req) {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void showBean(HttpServletRequest req, HttpServletResponse res) {
|
||||
sendHtmlMsgResponse(req, res, "ERRORE!!");
|
||||
}
|
||||
|
||||
public void _recordDevice(HttpServletRequest req, HttpServletResponse res) {
|
||||
ApplParmFull apFull = getApFull(req);
|
||||
String requestIp = req.getRemoteAddr();
|
||||
Gson gson = new Gson();
|
||||
try {
|
||||
String responseBody = req.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
|
||||
RdRequestJ deviceRequest = (RdRequestJ)gson.fromJson(responseBody, RdRequestJ.class);
|
||||
boolean authOk = checkBasicAuth(req, res);
|
||||
if (authOk) {
|
||||
RemoteDevice rd = new RemoteDevice(apFull);
|
||||
rd.findByToken(deviceRequest.getToken());
|
||||
if (rd.getId_remoteDevice() > 0L) {
|
||||
if (rd.getFcmToken().isEmpty() || rd.getFcmToken().equals(deviceRequest.getFcmToken())) {
|
||||
rd.setImei(deviceRequest.getImei());
|
||||
rd.setToken(deviceRequest.getToken());
|
||||
rd.setFcmToken(deviceRequest.getFcmToken());
|
||||
rd.setIpAddress(requestIp);
|
||||
rd.setUpdTmst(DBAdapter.getTimestamp());
|
||||
ResParm rp = rd.save();
|
||||
System.out.println(rp.getMsg());
|
||||
if (deviceRequest.getAct().isEmpty()) {
|
||||
RdResponseJ rdJ = new RdResponseJ(0L, "Dispositivo registrato correttamente");
|
||||
String rdJson = gson.toJson(rdJ);
|
||||
System.out.println("MobileApiSvlt " + rdJson);
|
||||
sendHtmlMsgResponse(req, res, rdJson);
|
||||
} else if (deviceRequest.getAct().equals("sms")) {
|
||||
_smsGateway(req, res, responseBody, rd);
|
||||
} else {
|
||||
RdResponseJ rdJ = new RdResponseJ(99L, "Dispositivo registrato correttamente ma implementazione non trovata: " +
|
||||
deviceRequest.getAct());
|
||||
String rdJson = gson.toJson(rdJ);
|
||||
System.out.println("MobileApiSvlt " + rdJson);
|
||||
sendHtmlMsgResponse(req, res, rdJson);
|
||||
}
|
||||
} else {
|
||||
RdResponseJ rdJ = new RdResponseJ(2L, "Token già assegnato");
|
||||
sendHtmlMsgResponse(req, res, gson.toJson(rdJ));
|
||||
}
|
||||
} else {
|
||||
RdResponseJ rdJ = new RdResponseJ(1L, "Token non trovato!");
|
||||
sendHtmlMsgResponse(req, res, gson.toJson(rdJ));
|
||||
}
|
||||
} else {
|
||||
RdResponseJ rdJ = new RdResponseJ(99L, "Autenticazione fallita");
|
||||
sendHtmlMsgResponse(req, res, gson.toJson(rdJ));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
RdResponseJ rdJ = new RdResponseJ(99L, e.getMessage());
|
||||
sendHtmlMsgResponse(req, res, gson.toJson(rdJ));
|
||||
}
|
||||
}
|
||||
|
||||
public void __templateChiamata(HttpServletRequest req, HttpServletResponse res) {
|
||||
ApplParmFull apFull = getApFull(req);
|
||||
boolean debug = false;
|
||||
try {
|
||||
long l_id_user = getRequestLongParameter(req, "id_user");
|
||||
boolean authOk = checkBasicAuth(req, res);
|
||||
if (!authOk)
|
||||
sendHtmlMsgResponse(req, res, "testina di vitello, _elencofoto");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
sendHtmlMsgResponse(req, res, "testina di vitello,_elencofoto eccezione: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void _smsGateway(HttpServletRequest req, HttpServletResponse res, String responseBody, RemoteDevice rd) {
|
||||
ApplParmFull apFull = getApFull(req);
|
||||
Gson gson = new Gson();
|
||||
try {
|
||||
RdRequestSmsGatewayJ deviceRequest = (RdRequestSmsGatewayJ)gson.fromJson(responseBody, RdRequestSmsGatewayJ.class);
|
||||
RdResponseSmsGatewayJ rdJ = new RdResponseSmsGatewayJ(0L, "Dispositivo registrato correttamente: SmsGateway");
|
||||
String smsToTest = getParm("RD_TEST_SMS").getTesto();
|
||||
CodaMessaggi cm = new CodaMessaggi(apFull);
|
||||
CodaMessaggiCR cmCR = new CodaMessaggiCR();
|
||||
cmCR.setFlgTipo(99L);
|
||||
cmCR.setFlgStatoInvio(3L);
|
||||
cmCR.setId_remoteDevice(rd.getId_remoteDevice());
|
||||
Vectumerator<CodaMessaggi> vecCm = cm.findByCR(cmCR, 1, 10);
|
||||
Vector<DataSmsMsgJ> dataVector = new Vector<>();
|
||||
if (vecCm.hasMoreElements()) {
|
||||
while (vecCm.hasMoreElements()) {
|
||||
CodaMessaggi cmRow = (CodaMessaggi)vecCm.nextElement();
|
||||
DataSmsMsgJ dataJ = new DataSmsMsgJ();
|
||||
System.out.println("MobileApiSvlt invio al gateway--->" + cmRow.getId_codaMessaggi() + " " + cmRow.getCellulare());
|
||||
dataJ.setCellulare(cmRow.getCellulare());
|
||||
dataJ.setId_codaMessaggi(cmRow.getId_codaMessaggi());
|
||||
dataJ.setTestoMessaggio(cmRow.getTestoMessaggio());
|
||||
dataJ.setSmsToTest(smsToTest);
|
||||
dataJ.setFlgTipo(cmRow.getFlgTipo());
|
||||
dataVector.add(dataJ);
|
||||
cmRow.setFlgStatoInvio(4L);
|
||||
cmRow.save();
|
||||
}
|
||||
rdJ.setData(dataVector);
|
||||
}
|
||||
if (deviceRequest.getData() != null) {
|
||||
Vector<DataSmsMsgJ> vec = deviceRequest.getData();
|
||||
CodaMessaggi cmRow = new CodaMessaggi(apFull);
|
||||
for (int i = 0; i < vec.size(); i++) {
|
||||
DataSmsMsgJ row = vec.elementAt(i);
|
||||
cmRow.findByPrimaryKey(row.getId_codaMessaggi());
|
||||
if (cmRow.getId_codaMessaggi() > 0L) {
|
||||
System.out.println("MobileApiSvlt ricevuto dal gateway e imposto a inviato <----- " + cmRow.getId_codaMessaggi() + " " +
|
||||
cmRow.getCellulare());
|
||||
cmRow.setFlgStatoInvio(1L);
|
||||
cmRow.setDataInvio(DBAdapter.getToday());
|
||||
cmRow.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
String rdJson = gson.toJson(rdJ);
|
||||
System.out.println("MobileApiSvlt " + rdJson);
|
||||
sendHtmlMsgResponse(req, res, rdJson);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
RdResponseJ rdJ = new RdResponseJ(99L, e.getMessage());
|
||||
sendHtmlMsgResponse(req, res, gson.toJson(rdJ));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
package it.acxent.rd.servlet.api;
|
||||
|
||||
import it.acxent.anag.servlet._AnagAdapterSvlt;
|
||||
import it.acxent.db.CRAdapter;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.rd.RemoteDevice;
|
||||
import it.acxent.rd.RemoteDeviceCR;
|
||||
import java.util.Base64;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class _RdApiSvlt extends _AnagAdapterSvlt {
|
||||
private static final long serialVersionUID = 9062130951824536369L;
|
||||
|
||||
protected void addRows(HttpServletRequest req, HttpServletResponse res) {}
|
||||
|
||||
protected void fillComboAfterDetail(DBAdapter bean, HttpServletRequest req, HttpServletResponse res) {}
|
||||
|
||||
protected void fillComboAfterSearch(CRAdapter CR, HttpServletRequest req, HttpServletResponse res) {}
|
||||
|
||||
protected DBAdapter getBean(HttpServletRequest req) {
|
||||
return new RemoteDevice(getApFull(req));
|
||||
}
|
||||
|
||||
protected CRAdapter getBeanCR(HttpServletRequest req) {
|
||||
return new RemoteDeviceCR(getApFull(req));
|
||||
}
|
||||
|
||||
protected void prepareNewRecord(HttpServletRequest req, HttpServletResponse res) {}
|
||||
|
||||
protected boolean isSimpleServlet(HttpServletRequest req) {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected String getBeanPageName(HttpServletRequest req) {
|
||||
return "testTicket";
|
||||
}
|
||||
|
||||
protected void search(HttpServletRequest req, HttpServletResponse res) {}
|
||||
|
||||
protected boolean checkBasicAuth(HttpServletRequest req, HttpServletResponse res) {
|
||||
boolean authOk = true;
|
||||
String apiLogin = getApFull().getParm("RD_API_LOGIN").getTesto().trim();
|
||||
String apiPwd = getApFull().getParm("RD_API_PWD").getTesto().trim();
|
||||
apiLogin = "rd1";
|
||||
apiPwd = "rdp";
|
||||
try {
|
||||
String[] auth = getBasicAuthorizationHeaders(req, res);
|
||||
if (auth != null)
|
||||
if (auth[0].equals(apiLogin) && auth[1].equals(apiPwd))
|
||||
authOk = true;
|
||||
} catch (Exception e) {}
|
||||
return authOk;
|
||||
}
|
||||
|
||||
protected boolean allowUser(String auth) {
|
||||
try {
|
||||
if (auth == null)
|
||||
return false;
|
||||
if (!auth.toUpperCase().startsWith("BASIC "))
|
||||
return false;
|
||||
String userpassEncoded = auth.substring(6);
|
||||
String userpassDecoded = new String(Base64.getDecoder().decode(userpassEncoded));
|
||||
String[] account = userpassDecoded.split(":");
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void otherCommands(HttpServletRequest req, HttpServletResponse res) {}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
package it.acxent.rd.servlet.api;
|
||||
Loading…
Add table
Add a link
Reference in a new issue