www in docker support

This commit is contained in:
MaddoScientisto 2026-04-22 18:41:37 +02:00
commit c227fce036
2145 changed files with 399596 additions and 58 deletions

View file

@ -0,0 +1,305 @@
package it.acxent.api.amz;
import java.math.BigInteger;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
import java.util.TreeMap;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
public class AWSV4Auth {
private String accessKeyID;
private String secretAccessKey;
private String regionName;
private String serviceName;
private String httpMethodName;
private String canonicalURI;
private TreeMap<String, String> queryParametes;
private TreeMap<String, String> awsHeaders;
private String payload;
private AWSV4Auth() {}
public static void main(String[] args) {
String url = "xxxxx-yyyyy-r6nvlhpscgdwms5.ap-northeast-1.es.amazonaws.com/inventory/simple/123";
TreeMap<String, String> awsHeaders = new TreeMap<>();
awsHeaders.put("host", "xxxxx-yyyyy-r6nvlhpscgdwms5.ap-northeast-1.es.amazonaws.com");
AWSV4Auth aWSV4Auth = new Builder("exampleKey", "exampleSecret").regionName("xx-yy-zzz").serviceName("es")
.httpMethodName("GET")
.canonicalURI("/inventory/simple/123")
.queryParametes(null)
.awsHeaders(awsHeaders)
.payload(null)
.debug()
.build();
Map<String, String> header = aWSV4Auth.getHeaders();
for (Map.Entry<String, String> entrySet : header.entrySet()) {
String key = entrySet.getKey();
String value = entrySet.getValue();
System.out.println(key + ":" + key);
}
}
public static class Builder {
private String accessKeyID;
private String secretAccessKey;
private String regionName;
private String serviceName;
private String httpMethodName;
private String canonicalURI;
private TreeMap<String, String> queryParametes;
private TreeMap<String, String> awsHeaders;
private String payload;
private boolean debug = false;
public Builder(String accessKeyID, String secretAccessKey) {
this.accessKeyID = accessKeyID;
this.secretAccessKey = secretAccessKey;
}
public Builder regionName(String regionName) {
this.regionName = regionName;
return this;
}
public Builder serviceName(String serviceName) {
this.serviceName = serviceName;
return this;
}
public Builder httpMethodName(String httpMethodName) {
this.httpMethodName = httpMethodName;
return this;
}
public Builder canonicalURI(String canonicalURI) {
this.canonicalURI = canonicalURI;
return this;
}
public Builder queryParametes(TreeMap<String, String> queryParametes) {
this.queryParametes = queryParametes;
return this;
}
public Builder awsHeaders(TreeMap<String, String> awsHeaders) {
this.awsHeaders = awsHeaders;
return this;
}
public Builder payload(String payload) {
this.payload = payload;
return this;
}
public Builder debug() {
this.debug = true;
return this;
}
public AWSV4Auth build() {
return new AWSV4Auth(this);
}
}
private boolean debug = false;
private final String HMACAlgorithm = "AWS4-HMAC-SHA256";
private final String aws4Request = "aws4_request";
private String strSignedHeader;
private String xAmzDate;
private String currentDate;
private AWSV4Auth(Builder builder) {
this.accessKeyID = builder.accessKeyID;
this.secretAccessKey = builder.secretAccessKey;
this.regionName = builder.regionName;
this.serviceName = builder.serviceName;
this.httpMethodName = builder.httpMethodName;
this.canonicalURI = builder.canonicalURI;
this.queryParametes = builder.queryParametes;
this.awsHeaders = builder.awsHeaders;
this.payload = builder.payload;
this.debug = builder.debug;
this.xAmzDate = getTimeStamp();
this.currentDate = getDate();
}
private String prepareCanonicalRequest() {
StringBuilder canonicalURL = new StringBuilder("");
canonicalURL.append(this.httpMethodName).append("\n");
this.canonicalURI = (this.canonicalURI == null || this.canonicalURI.trim().isEmpty()) ? "/" : this.canonicalURI;
canonicalURL.append(this.canonicalURI).append("\n");
StringBuilder queryString = new StringBuilder("");
if (this.queryParametes != null && !this.queryParametes.isEmpty()) {
for (Map.Entry<String, String> entrySet : this.queryParametes.entrySet()) {
String key = entrySet.getKey();
String value = entrySet.getValue();
queryString.append(key).append("=").append(encodeParameter(value)).append("&");
}
queryString.deleteCharAt(queryString.lastIndexOf("&"));
queryString.append("\n");
} else {
queryString.append("\n");
}
canonicalURL.append((CharSequence)queryString);
StringBuilder signedHeaders = new StringBuilder("");
if (this.awsHeaders != null && !this.awsHeaders.isEmpty()) {
for (Map.Entry<String, String> entrySet : this.awsHeaders.entrySet()) {
String key = entrySet.getKey();
String value = entrySet.getValue();
signedHeaders.append(key).append(";");
canonicalURL.append(key).append(":").append(value).append("\n");
}
canonicalURL.append("\n");
} else {
canonicalURL.append("\n");
}
this.strSignedHeader = signedHeaders.substring(0, signedHeaders.length() - 1);
canonicalURL.append(this.strSignedHeader).append("\n");
this.payload = (this.payload == null) ? "" : this.payload;
canonicalURL.append(generateHex(this.payload));
if (this.debug)
System.out.println("##Canonical Request:\n" + canonicalURL.toString());
return canonicalURL.toString();
}
private String prepareStringToSign(String canonicalURL) {
String stringToSign = "";
stringToSign = "AWS4-HMAC-SHA256\n";
stringToSign = stringToSign + stringToSign + "\n";
stringToSign = stringToSign + stringToSign + "/" + this.currentDate + "/" + this.regionName + "/aws4_request\n";
stringToSign = stringToSign + stringToSign;
if (this.debug)
System.out.println("##String to sign:\n" + stringToSign);
return stringToSign;
}
private String calculateSignature(String stringToSign) {
try {
byte[] signatureKey = getSignatureKey(this.secretAccessKey, this.currentDate, this.regionName, this.serviceName);
byte[] signature = HmacSHA256(signatureKey, stringToSign);
String strHexSignature = bytesToHex(signature);
return strHexSignature;
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
public Map<String, String> getHeaders() {
this.awsHeaders.put("x-amz-date", this.xAmzDate);
String canonicalURL = prepareCanonicalRequest();
String stringToSign = prepareStringToSign(canonicalURL);
String signature = calculateSignature(stringToSign);
if (signature != null) {
Map<String, String> header = new HashMap<>(0);
header.put("Authorization", buildAuthorizationString(signature));
if (this.debug) {
System.out.println("##Signature:\n" + signature);
System.out.println("##Header:");
for (Map.Entry<String, String> entrySet : header.entrySet())
System.out.println((String)entrySet.getKey() + " = " + (String)entrySet.getKey());
System.out.println("================================");
}
return header;
}
if (this.debug)
System.out.println("##Signature:\n" + signature);
return null;
}
private String buildAuthorizationString(String strSignature) {
return "AWS4-HMAC-SHA256 Credential=" + this.accessKeyID + "/" + getDate() + "/" + this.regionName + "/" + this.serviceName + "/aws4_request,SignedHeaders=" + this.strSignedHeader + ",Signature=" + strSignature;
}
public static String generateHex(String data) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
messageDigest.update(data.getBytes("UTF-8"));
byte[] digest = messageDigest.digest();
return String.format("%064x", new BigInteger(1, digest));
} catch (NoSuchAlgorithmException|java.io.UnsupportedEncodingException e) {
e.printStackTrace();
return null;
}
}
private byte[] HmacSHA256(byte[] key, String data) throws Exception {
String algorithm = "HmacSHA256";
Mac mac = Mac.getInstance(algorithm);
mac.init(new SecretKeySpec(key, algorithm));
return mac.doFinal(data.getBytes("UTF8"));
}
private byte[] getSignatureKey(String key, String date, String regionName, String serviceName) throws Exception {
byte[] kSecret = ("AWS4" + key).getBytes("UTF8");
byte[] kDate = HmacSHA256(kSecret, date);
byte[] kRegion = HmacSHA256(kDate, regionName);
byte[] kService = HmacSHA256(kRegion, serviceName);
byte[] kSigning = HmacSHA256(kService, "aws4_request");
return kSigning;
}
protected static final char[] hexArray = "0123456789ABCDEF".toCharArray();
private String bytesToHex(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
for (int j = 0; j < bytes.length; j++) {
int v = bytes[j] & 0xFF;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0xF];
}
return new String(hexChars).toLowerCase();
}
private String getTimeStamp() {
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return dateFormat.format(new Date());
}
private String getDate() {
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return dateFormat.format(new Date());
}
private String encodeParameter(String param) {
try {
return URLEncoder.encode(param, "UTF-8");
} catch (Exception e) {
return URLEncoder.encode(param);
}
}
}

View file

@ -0,0 +1,41 @@
package it.acxent.api.amz;
public class AmzResult {
private String msg;
public AmzResult(String msg, boolean status, Object result) {
this.msg = msg;
this.ok = status;
this.result = result;
}
private boolean ok = true;
private Object result;
public AmzResult() {}
public String getMsg() {
return this.msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public boolean isOk() {
return this.ok;
}
public void setOk(boolean status) {
this.ok = status;
}
public Object getResult() {
return this.result;
}
public void setResult(Object result) {
this.result = result;
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1 @@
package it.acxent.api.amz.json;

View file

@ -0,0 +1 @@
package it.acxent.api.amz.servlet;

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,25 @@
package it.acxent.api.ebay;
import java.sql.Date;
public class EbayAuthNAuthToken {
private String token;
private Date expirationDate;
public String getToken() {
return this.token;
}
public void setToken(String token) {
this.token = token;
}
public Date getExpirationDate() {
return this.expirationDate;
}
public void setExpirationDate(Date expirationDate) {
this.expirationDate = expirationDate;
}
}

View file

@ -0,0 +1,63 @@
package it.acxent.api.ebay;
public class EbayOrder {
private String buyerId;
private String orderId;
private String buyerTaxId;
private String taxIdType;
private double amount;
public EbayOrder(String buyerId, String orderId, String buyerTaxId, String taxIdType, double amount) {
this.buyerId = buyerId;
this.orderId = orderId;
this.buyerTaxId = buyerTaxId;
this.taxIdType = taxIdType;
this.amount = amount;
}
public EbayOrder() {}
public String getBuyerId() {
return (this.buyerId == null) ? "" : this.buyerId.trim();
}
public void setBuyerId(String buyerId) {
this.buyerId = buyerId;
}
public String getOrderId() {
return (this.orderId == null) ? "" : this.orderId.trim();
}
public void setOrderId(String orderId) {
this.orderId = orderId;
}
public String getBuyerTaxId() {
return (this.buyerTaxId == null) ? "" : this.buyerTaxId.trim();
}
public void setBuyerTaxId(String buyerTaxId) {
this.buyerTaxId = buyerTaxId;
}
public String getTaxIdType() {
return (this.taxIdType == null) ? "" : this.taxIdType.trim();
}
public void setTaxIdType(String taxIdType) {
this.taxIdType = taxIdType;
}
public double getAmount() {
return this.amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
}

View file

@ -0,0 +1,41 @@
package it.acxent.api.ebay;
public class EbayResult {
private String msg;
public EbayResult(String msg, boolean status, Object result) {
this.msg = msg;
this.ok = status;
this.result = result;
}
private boolean ok = true;
private Object result;
public EbayResult() {}
public String getMsg() {
return this.msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public boolean isOk() {
return this.ok;
}
public void setOk(boolean status) {
this.ok = status;
}
public Object getResult() {
return this.result;
}
public void setResult(Object result) {
this.result = result;
}
}

View file

@ -0,0 +1,68 @@
package it.acxent.api.ebay;
import com.ebay.sdk.ApiContext;
import com.ebay.sdk.ApiCredential;
import com.ebay.sdk.call.GetOrdersCall;
import com.ebay.soap.eBLBaseComponents.DetailLevelCodeType;
import com.ebay.soap.eBLBaseComponents.OrderType;
import com.ebay.soap.eBLBaseComponents.TaxIdentifierType;
import com.ebay.soap.eBLBaseComponents.TradingRoleCodeType;
import com.ebay.soap.eBLBaseComponents.TransactionType;
import java.io.IOException;
public class EbayTrading {
public String getPivaCf(String token, String ordine) {
String ret = "";
try {
System.out.print("\n");
System.out.print("+++++++++++++++++++++++++++++++++++++++\n");
System.out.print("+ Welcome to eBay SDK for Java Sample +\n");
System.out.print("+ - ConsoleAddItem +\n");
System.out.print("+++++++++++++++++++++++++++++++++++++++\n");
System.out.print("\n");
System.out.println("===== [1] Account Information ====");
ApiContext apiContext = getApiContext();
GetOrdersCall call = new GetOrdersCall(apiContext);
DetailLevelCodeType[] detailLevels = { DetailLevelCodeType.RETURN_ALL };
call.setDetailLevel(detailLevels);
call.setOrderRole(TradingRoleCodeType.SELLER);
call.setNumberOfDays(Integer.valueOf(30));
System.out.println("getOrders");
OrderType[] orders = call.getOrders();
for (OrderType order : orders) {
System.out.println(order.getBuyerUserID());
TaxIdentifierType[] tit = order.getBuyerTaxIdentifier();
for (int i = 0; i < tit.length; i++) {
TaxIdentifierType ti = tit[i];
System.out.println("TaxIdentifierType");
System.out.println("ID: " + ti.getID());
System.out.println("Type: " + String.valueOf(ti.getType()));
System.out.println(" ");
}
TransactionType[] tp = order.getTransactionArray().getTransaction();
for (int j = 0; j < tp.length; j++) {
TransactionType tp1 = tp[j];
System.out.println("TransactionType");
System.out.println("Email: " + tp1.getBuyer().getEmail());
System.out.println("Codice Fiscale: " + tp1.getCodiceFiscale());
System.out.println("Partita Iva: " + tp1.getBuyer().getVATID());
System.out.println(" ");
}
System.out.println("--------------------");
}
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
return ret;
}
private static ApiContext getApiContext() throws IOException {
String token = "AgAAAA**AQAAAA**aAAAAA**8X0lWA**nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6AEloqgCJCLpg+dj6x9nY+seQ**s38DAA**AAMAAA**lknSsx7ror8sUli5r9aVZwFIVw/c6wznYbOjChsXzBnST1dqjWSFxdAHO3NNNlOA58OCDwWYQoyzmREXuXnPFhhxxwqn0re7ri7CzR3oHlSX9ZR1mv/CTIThDycFkD9rK9CCqzYZgpiW7SLwgQt5hPSOYuIejdVA+NL4GWl+zy413Tinu9eS5WF5XeIODQnFAuQHAKcLa7NqKg7BtohzN7l4UNxw7+Ibm7acX5MLsvqquTYNBLQuYhSsNJV2jhM8LuIotg11vMPvJx5dx6oG0f4X2KvlmEP1mF8LlgqcocYJPvc5sg+aMCRG6WKGpeXepbvsh0SWwyGQUL9Xqpwmqrk8RZU3SjgZPHlYDMHJVeJ5c+5g8gcjSk1seJzcWiH48ZGDr6ShgS95zt6wuFZ+ZqRo28I07dNWGGvdY+DAS6Orx0zmhAywjrFFnf8gcqLMIVLzsepHkJqBAno+rK/cGhaxyTAurnTpZUNeT5sv4U/S0AhgO9npRqcYENU7mmdJrTknz3BIeZJzJSWAVgIS1PlyeLAMiXGj8wJaEuX8y4PYfXAO8eOINxGd6Z4h7Ta/Iq7jhIltRR4xryUH/j1c8XpR5RIxFvcwOhE+z10JFaVr4x4pUto5SfnLh+Ig3GClEM7kRaeCSgeoe8/yhc7zLlj1AX0oViae2wbwYDJZvv77hkXeiNUCllHbsnt5Y4dI5y18z1h/a4K+gqZH+7bTLNuVUkKD4dfeoPiaqyZHlfqfmo0nVACO+S9AtghL8+NC";
ApiContext apiContext = new ApiContext();
ApiCredential cred = apiContext.getApiCredential();
cred.seteBayToken(token);
apiContext.setApiServerUrl("https://api.ebay.com/wsapi");
return apiContext;
}
}

View file

@ -0,0 +1,63 @@
package it.acxent.api.ebay.json;
public class EbayOrder {
private String buyerId;
private String orderId;
private String buyerTaxId;
private String taxIdType;
private double amount;
public EbayOrder(String buyerId, String orderId, String buyerTaxId, String taxIdType, double amount) {
this.buyerId = buyerId;
this.orderId = orderId;
this.buyerTaxId = buyerTaxId;
this.taxIdType = taxIdType;
this.amount = amount;
}
public EbayOrder() {}
public String getBuyerId() {
return (this.buyerId == null) ? "" : this.buyerId.trim();
}
public void setBuyerId(String buyerId) {
this.buyerId = buyerId;
}
public String getOrderId() {
return (this.orderId == null) ? "" : this.orderId.trim();
}
public void setOrderId(String orderId) {
this.orderId = orderId;
}
public String getBuyerTaxId() {
return (this.buyerTaxId == null) ? "" : this.buyerTaxId.trim();
}
public void setBuyerTaxId(String buyerTaxId) {
this.buyerTaxId = buyerTaxId;
}
public String getTaxIdType() {
return (this.taxIdType == null) ? "" : this.taxIdType.trim();
}
public void setTaxIdType(String taxIdType) {
this.taxIdType = taxIdType;
}
public double getAmount() {
return this.amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
}

View file

@ -0,0 +1 @@
package it.acxent.api.ebay.json;

View file

@ -0,0 +1,74 @@
package it.acxent.api.ebay.servlet;
import it.acxent.db.ApplParmFull;
import it.acxent.db.CRAdapter;
import it.acxent.db.DBAdapter;
import it.acxent.servlet.AblServletSvlt;
import it.acxent.servlet.SavedHttpRequest;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class EbayAccessKoSvlt extends AblServletSvlt {
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 null;
}
protected CRAdapter getBeanCR(HttpServletRequest req) {
return null;
}
protected void prepareNewRecord(HttpServletRequest req, HttpServletResponse res) {}
protected boolean isSimpleServlet(HttpServletRequest req) {
return false;
}
protected void search(HttpServletRequest req, HttpServletResponse res) {
ApplParmFull apFull = getApFull(req);
req.setAttribute("status", "ko");
sendMessage(req, "Attenzione! Non è stata data l'autorizzazione all'accesso ebay. impossibile recuperare il token!");
SavedHttpRequest shr = (SavedHttpRequest)req.getSession().getAttribute("_shr");
shr = new SavedHttpRequest();
shr.setCompleteRequestedURI(req.getContextPath() + "/admin/ebay/EbayAccess.abl");
shr.setServletPath("/admin/ebay/EbayAccess.abl");
shr.setAllParametersNAttributes(req);
if (useAlwaysSendRedirect())
shr.setUseSendRedirect(true);
req.getSession().setAttribute("_shr", shr);
try {
res.sendRedirect(req.getContextPath() + "/admin/menu/index.jsp");
} catch (Exception e2) {
e2.printStackTrace();
}
}
protected void otherCommands(HttpServletRequest req, HttpServletResponse res) {
search(req, res);
}
protected void searchOLD(HttpServletRequest req, HttpServletResponse res) {
String error = getRequestParameter(req, "error");
sendMessage(req, error);
setJspPageRelative("ebayRes.jsp", req);
req.setAttribute("status", "ko");
try {
RequestDispatcher rd = getServletContext().getRequestDispatcher(getJspPage(req));
rd.forward((ServletRequest)req, (ServletResponse)res);
} catch (Exception e2) {
e2.printStackTrace();
}
}
protected boolean isSecureServlet(HttpServletRequest req) {
return false;
}
}

View file

@ -0,0 +1,114 @@
package it.acxent.api.ebay.servlet;
import it.acxent.api.ebay.EbayAbliaApi;
import it.acxent.api.ebay.EbayAuthNAuthToken;
import it.acxent.api.ebay.EbayResult;
import it.acxent.common.Parm;
import it.acxent.db.ApplParmFull;
import it.acxent.db.CRAdapter;
import it.acxent.db.DBAdapter;
import it.acxent.servlet.AblServletSvlt;
import it.acxent.servlet.SavedHttpRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class EbayAccessOkSvlt extends AblServletSvlt {
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 null;
}
protected CRAdapter getBeanCR(HttpServletRequest req) {
return null;
}
protected void prepareNewRecord(HttpServletRequest req, HttpServletResponse res) {}
protected boolean isSimpleServlet(HttpServletRequest req) {
return false;
}
protected void search(HttpServletRequest req, HttpServletResponse res) {
ApplParmFull apFull = getApFull(req);
String code = getRequestParameter(req, "code");
String expiresIn = getRequestParameter(req, "expires_in");
if (code.isEmpty()) {
autNAuthFetchToken(req, res);
} else {
oAuth2FetchToken(req, res);
}
SavedHttpRequest shr = (SavedHttpRequest)req.getSession().getAttribute("_shr");
shr = new SavedHttpRequest();
shr.setCompleteRequestedURI(req.getContextPath() + "/admin/ebay/EbayAccess.abl");
shr.setServletPath("/admin/ebay/EbayAccess.abl");
shr.setAllParametersNAttributes(req);
if (useAlwaysSendRedirect())
shr.setUseSendRedirect(true);
req.getSession().setAttribute("_shr", shr);
try {
res.sendRedirect(req.getContextPath() + "/admin/menu/index.jsp");
} catch (Exception e2) {
e2.printStackTrace();
}
}
protected void otherCommands(HttpServletRequest req, HttpServletResponse res) {
search(req, res);
}
public void autNAuthFetchToken(HttpServletRequest req, HttpServletResponse res) {
ApplParmFull apFull = getApFull(req);
String username = getRequestParameter(req, "username");
EbayAbliaApi eaa = new EbayAbliaApi(apFull);
String sessionId = (String)req.getSession().getAttribute("_EBAY_SESSION_ID");
System.out.println("Ebay access OK: session id precedente...: " + sessionId);
EbayAuthNAuthToken fetchToken = eaa.fetchTokenSdk(sessionId);
if (fetchToken.getToken().isEmpty()) {
System.out.println("Ebay access ERRORE: token: " + fetchToken.getToken());
req.setAttribute("status", "ko");
sendMessage(req, "Errore! impossibile recuperare il token!");
} else {
System.out.println("Ebay access OK: token: " + fetchToken.getToken());
System.out.println("Ebay access OK: exp date: " + String.valueOf(fetchToken.getExpirationDate()));
Parm parm = getParm("EBAY_USER_TOKEN_PRODUCTION");
parm.setTesto(fetchToken.getToken());
parm.save();
parm = getParm("EBAY_USER_TOKEN_NAME_PRODUCTION");
parm.setTesto(username);
parm.save();
parm = getParm("EBAY_EXPIRE_DATE_TOKEN_PRODUCTION");
parm.setDataParm(fetchToken.getExpirationDate());
parm.save();
getApFull().resetCurrentApParms();
req.setAttribute("status", "ok");
sendMessage(req, "Rinnovato il token authNAuth per " + username + " correttamente,");
}
}
public void oAuth2FetchToken(HttpServletRequest req, HttpServletResponse res) {
ApplParmFull apFull = getApFull(req);
String code = getRequestParameter(req, "code");
String expiresIn = getRequestParameter(req, "expires_in");
System.out.println("Ebay oAuth2 access OK: code: " + code + "\nexpire: " + expiresIn);
EbayAbliaApi bean = new EbayAbliaApi(apFull);
EbayResult eRes = bean.ebayGetUserAccesToken(code);
if (!eRes.isOk()) {
System.out.println("Ebay user access token: " + eRes.getMsg());
req.setAttribute("status", "ko");
sendMessage(req, "Errore! impossibile recuperare il token! " + DBAdapter.convertStringToHtml(eRes.getMsg()));
} else {
System.out.println("Ebay access OK:\n" + DBAdapter.convertStringToHtml(bean.getStatus()));
req.setAttribute("status", "ok");
sendMessage(req, "Rinnovato il token oAuth2 ");
}
}
protected boolean isSecureServlet(HttpServletRequest req) {
return false;
}
}

View file

@ -0,0 +1,80 @@
package it.acxent.api.ebay.servlet;
import it.acxent.api.ebay.EbayAbliaApi;
import it.acxent.db.ApplParmFull;
import it.acxent.db.CRAdapter;
import it.acxent.db.DBAdapter;
import it.acxent.servlet.AblServletSvlt;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class EbayAccessSvlt extends AblServletSvlt {
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 null;
}
protected CRAdapter getBeanCR(HttpServletRequest req) {
return null;
}
protected void prepareNewRecord(HttpServletRequest req, HttpServletResponse res) {}
protected boolean isSimpleServlet(HttpServletRequest req) {
return false;
}
protected void search(HttpServletRequest req, HttpServletResponse res) {
ApplParmFull apFull = getApFull(req);
EbayAbliaApi eaa = new EbayAbliaApi(apFull);
req.setAttribute("eaa", eaa);
setJspPageRelative("ebay.jsp", req);
try {
RequestDispatcher rd = getServletContext().getRequestDispatcher(getJspPage(req));
rd.forward((ServletRequest)req, (ServletResponse)res);
} catch (Exception e2) {
e2.printStackTrace();
}
}
public void _callEbayLogin(HttpServletRequest req, HttpServletResponse res) {
ApplParmFull apFull = getApFull(req);
EbayAbliaApi eaa = new EbayAbliaApi(apFull);
req.setAttribute("eaa", eaa);
String sessionId = eaa.getSdkEbaySessionId();
System.out.println("sessionid: " + sessionId);
if (sessionId.isEmpty()) {
sendMessage(req, "Errore! Impossibile trovare il sessionid...");
sendHtmlMsgResponse(req, res, "Errore! Impossibile trovare il sessionid...");
} else {
req.getSession().setAttribute("_EBAY_SESSION_ID", sessionId);
String requestPage = getParm("EBAY_SIGN_IN_AUTH_N_AUTH_PRODUCTION_LINK").getTesto() + getParm("EBAY_SIGN_IN_AUTH_N_AUTH_PRODUCTION_LINK").getTesto();
try {
res.sendRedirect(requestPage);
} catch (Exception e) {
handleDebug(e);
}
}
}
protected void otherCommands(HttpServletRequest req, HttpServletResponse res) {
search(req, res);
}
public void _callEbayLoginO(HttpServletRequest req, HttpServletResponse res) {
String requestPage = getParm("EBAY_SIGN_IN_OAUTH_PRODUCTION_LINK").getTesto();
try {
res.sendRedirect(requestPage);
} catch (Exception e) {
handleDebug(e);
}
}
}

View file

@ -0,0 +1,75 @@
package it.acxent.api.ebay.servlet;
import it.acxent.api.ebay.EbayAbliaApi;
import it.acxent.api.ebay.EbayOrder;
import it.acxent.api.ebay.EbayResult;
import it.acxent.db.ApplParmFull;
import it.acxent.db.CRAdapter;
import it.acxent.db.DBAdapter;
import it.acxent.servlet.AblServletSvlt;
import it.acxent.util.Vectumerator;
import java.util.Vector;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class EbayOrdersSvlt extends AblServletSvlt {
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 null;
}
protected CRAdapter getBeanCR(HttpServletRequest req) {
return null;
}
protected void prepareNewRecord(HttpServletRequest req, HttpServletResponse res) {}
protected boolean isSimpleServlet(HttpServletRequest req) {
return false;
}
protected void search(HttpServletRequest req, HttpServletResponse res) {
ApplParmFull apFull = getApFull(req);
EbayAbliaApi eaa = new EbayAbliaApi(apFull);
req.setAttribute("eaa", eaa);
if (getParm("EBAY_USE_SANDBOX").isTrue())
eaa.setUseSandbox(true);
EbayResult result = eaa.getSdkEbayOrders();
if (result.isOk()) {
Vector<EbayOrder> resV = (Vector<EbayOrder>)result.getResult();
if (resV != null)
req.setAttribute("list", new Vectumerator(resV.elements()));
sendMessage(req, "Lettura ordini avvenuta correttamente");
} else {
sendMessage(req, "Impossibile leggere gli ordini ebay! " + result.getMsg());
}
forceJspPage("/admin/ebay/ebayOrderCR.jsp", req);
try {
RequestDispatcher rd = getServletContext().getRequestDispatcher(getJspPage(req));
rd.forward((ServletRequest)req, (ServletResponse)res);
} catch (Exception e) {
StringBuilder msg = new StringBuilder();
if (e.getCause() != null) {
msg.append("Causa:\n");
msg.append(e.getCause().getMessage());
msg.append("\n");
}
msg.append(e.getMessage());
handleDebug(e, 2);
forceMessage(req, getJspPage(req));
req.setAttribute("errorMsg", msg.toString());
RequestDispatcher rd = getServletContext().getRequestDispatcher("/admin/config/error.jsp");
try {
rd.forward((ServletRequest)req, (ServletResponse)res);
} catch (Exception exception) {}
}
}
}

View file

@ -0,0 +1 @@
package it.acxent.api.ebay.servlet;

View file

@ -0,0 +1,127 @@
package it.acxent.api.wa;
import it.acxent.api.ApiClientResult;
import it.acxent.api._AblApiClient;
import it.acxent.cc.Attivita;
import it.acxent.db.ApplParm;
import it.acxent.db.ApplParmFull;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;
public class WhatsappApi extends _AblApiClient {
public static final String ENDPOINT_PRODUCTION = "https://graph.facebook.com/";
public static final String ENDPOINT_SANDBOX = "https://graph.facebook.com/";
public static final String API_VERSION = "v17.0/";
private String phoneNumberId;
private Attivita attivita;
private boolean debug = false;
private static final String URI_MESSAGES = "/messages";
public WhatsappApi(ApplParmFull apFull, String token, String phoneNumberId) {
super(apFull);
setToken(token);
setPhoneNumberId(phoneNumberId);
setUseSandbox(false);
}
public WhatsappApi() {}
public static void main(String[] args) {
String hostname = "localhost";
String db = "misericordia";
ApplParmFull ap = new ApplParmFull(new ApplParm(17, "//" + hostname + ":3308/" + db, db, "root", "root", 1, 10, 300));
String token = "EAA2Yp61AWZB8BOxl8nthvvLO0okR9BJXA1NNkHox9BbZCMjE0LHGXybachAz78mGCz0RvoSqox3AF7hquq71kt6JL30ETSLdFUZBmcIKxSPT9jwoGHBL6x8X7rCpGdIqVc5FFjXpaUXZALKpf8IrUIvqHgRwyH9eZC6IhmI5U0LPraLJwZA43D6ZCcUer2ZAZAZAzAIQfWNRwmIn0tBNmoElvcr5aadiwR";
String phoneNumberId = "119770104557287";
WhatsappApi api = new WhatsappApi(ap, token, phoneNumberId);
ApiClientResult res = api._postSendTextMsg("ciao testina di vitello");
System.out.println(res.getMsg());
}
public Attivita getAttivita() {
if (this.attivita == null)
this.attivita = Attivita.getDefaultInstance(getApFull());
return this.attivita;
}
public String getEndpointProduction() {
return "https://graph.facebook.com/";
}
public String getEndpointSandbox() {
return "https://graph.facebook.com/";
}
public ApiClientResult _postSendTextMsg(String l_msg) {
ApiClientResult resER = new ApiClientResult();
try {
if (this.debug)
System.out.println("WhatsappApi --> _postSendTextMsg");
CloseableHttpClient client = HttpClients.createDefault();
HttpPost request = new HttpPost(getEndpoint() + "v17.0//messages");
request.setHeader("Authorization", getTokenBearer());
request.setHeader("Accept", "application/json");
request.setHeader("Content-Type", "application/json");
request.setHeader("Content-Language", "it-IT");
JSONObject joDottori = null;
StringEntity stringEntity = new StringEntity(joDottori.toString(4), "UTF-8");
request.setEntity((HttpEntity)stringEntity);
CloseableHttpResponse closeableHttpResponse = client.execute((HttpUriRequest)request);
String content = EntityUtils.toString(closeableHttpResponse.getEntity());
int statusCode = closeableHttpResponse.getStatusLine().getStatusCode();
if (this.debug) {
System.out.println("Status Code: " + statusCode);
System.out.println("\ncontent = " + content);
}
if (statusCode >= 400) {
resER.setOk(false);
JSONObject jo = new JSONObject(content);
resER.setMsg(jo.toString(2));
resER.setResult(jo);
} else {
JSONObject jo = new JSONObject(content);
if (this.debug)
System.out.println(jo.toString(4));
if (jo.has("success")) {
if (jo.getBoolean("success") == true) {
resER.setMsg(jo.getString("msg"));
resER.setOk(true);
resER.setResult(Long.valueOf(jo.getLong("id_rigaBolla")));
} else {
resER.setMsg(jo.getString("msg"));
resER.setOk(false);
}
} else {
resER.setMsg("Errore! Risposta non corretta!");
resER.setOk(false);
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
resER.setOk(false);
resER.setMsg(e.getMessage());
}
return resER;
}
public String getPhoneNumberId() {
return this.phoneNumberId;
}
public void setPhoneNumberId(String phoneNumberId) {
this.phoneNumberId = phoneNumberId;
}
}

View file

@ -0,0 +1 @@
package it.acxent.api.wa;