Fix DBCFX_SM_678 - Riadattata la chiamata ws EsitoVerificaCodiceSessione esposto da NOW in SOAP over HTTPS
This commit is contained in:
@@ -0,0 +1,226 @@
|
||||
package it.valueteam.gnp.ws.now.esitoverificacodicesessionefase2;
|
||||
|
||||
import com.tim.now.xsd.now_esitoverificacodicesessione.Enum_Response_ESITO;
|
||||
import com.tim.now.xsd.now_esitoverificacodicesessione.Request;
|
||||
import com.tim.now.xsd.now_esitoverificacodicesessione.Response;
|
||||
|
||||
import it.telecomitalia.soa.soap.soapheader.HeaderType;
|
||||
import it.valueteam.gnp.log.Loggable;
|
||||
import it.valueteam.gnp.log.ProcessLogger;
|
||||
import it.valueteam.gnp.obj.LogInfo;
|
||||
import it.valueteam.gnp.obj.LogProcess;
|
||||
import it.valueteam.gnp.utility.Func;
|
||||
import it.valueteam.gnp.utility.Resources;
|
||||
import it.valueteam.gnp.ws.utlities.WSUtils;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
|
||||
import javax.ejb.CreateException;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.xml.soap.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class EsitoVerificaCodiceSessioneFase2NowClient implements Loggable {
|
||||
|
||||
private String url;
|
||||
private int timeOut;
|
||||
private static final int defaultTimeOut = 30000;
|
||||
|
||||
protected ProcessLogger log;
|
||||
|
||||
protected String codiceProcesso = "SH"; // come da GNP_ANAGRAFICA_PROCESSO
|
||||
|
||||
protected String versione = "1.0.0.0";
|
||||
|
||||
public EsitoVerificaCodiceSessioneFase2NowClient() throws Exception {
|
||||
try {
|
||||
LogProcess logProcess = new LogProcess();
|
||||
logProcess.setCodice(codiceProcesso);
|
||||
logProcess.setProcess(this);
|
||||
log = new ProcessLogger(logProcess);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
System.out.println("Errore nella creazione del ProcessLogger, classe:" + EsitoVerificaCodiceSessioneFase2NowClient.class + " - " + ex.toString());
|
||||
throw new CreateException();
|
||||
}
|
||||
log.write("0001", " versione " + versione);
|
||||
|
||||
url = Resources.getURL_WS_NOW_ESITO_VERIFICA_CS();
|
||||
|
||||
if ("".equals(url)) {
|
||||
log.write("0003", "");
|
||||
throw new Exception("Errore in creazione client - impossibile recuperare url del ws da properties");
|
||||
}
|
||||
|
||||
String timeOutStr = Resources.getTIMEOUT_WS_NOW_ESITO_VERIFICA_CS();
|
||||
log.write("9999", " now client - url: " + url + " - timeOut: " + timeOutStr);
|
||||
|
||||
try {
|
||||
timeOut = Integer.parseInt(timeOutStr);
|
||||
} catch (NumberFormatException nfe) {
|
||||
log.write("9999", " impossibile recuperare property timeout - impostato valore di default: " + defaultTimeOut);
|
||||
timeOut = defaultTimeOut;
|
||||
}
|
||||
}
|
||||
|
||||
public Response invoke(Request request, HeaderType header) throws Exception{
|
||||
log.write("9999", "EsitoVerificaCodiceSessione - soapAction='Invoke' start");
|
||||
|
||||
CloseableHttpClient client = null;
|
||||
CloseableHttpResponse response = null;
|
||||
StringBuilder req = new StringBuilder();
|
||||
StringBuilder resp = new StringBuilder();
|
||||
String bid = header.getBusinessID();
|
||||
|
||||
try {
|
||||
SSLContext sslContext = WSUtils.createSSLContext("SSL");
|
||||
if(sslContext != null) {
|
||||
SSLConnectionSocketFactory scf = WSUtils.createSSLConnectionSocketFactory(sslContext,
|
||||
Resources.NOW_SUPPORTED_PROTOCOLS(), Resources.NOW_SUPPORTED_CIPHER_SUITES());
|
||||
client = HttpClients.custom().useSystemProperties().setSSLSocketFactory(scf).setConnectionTimeToLive(timeOut,
|
||||
TimeUnit.MILLISECONDS).build();
|
||||
} else {
|
||||
client = HttpClients.custom().useSystemProperties().setConnectionTimeToLive(timeOut, TimeUnit.MILLISECONDS).build();
|
||||
}
|
||||
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
|
||||
// Set Header HTTP Post
|
||||
Header[] headers = new BasicHeader[2];
|
||||
headers[0] = new BasicHeader("Content-Type", "text/xml; charset=UTF-8");
|
||||
headers[1] = new BasicHeader("SOAPAction", "Invoke");
|
||||
httpPost.setHeaders(headers);
|
||||
|
||||
// Set SOAPBody HTTP Post
|
||||
StringEntity lEntity = new StringEntity(createHttpRequest(header, request));
|
||||
httpPost.setEntity(lEntity);
|
||||
|
||||
// Loggata request EsitoVerificaCodiceSessione inviata a Now
|
||||
log.write("9999", "businessId: " + bid + " - [EsitoVerificaCodiceSessione] - Inizio Log Request");
|
||||
BufferedReader requestReader = new BufferedReader(new InputStreamReader(lEntity.getContent()));
|
||||
String lineReq;
|
||||
while ((lineReq = requestReader.readLine()) != null) {
|
||||
req.append(lineReq).append('\n');
|
||||
}
|
||||
log.write("9999", "businessId: " + bid + " - " + req.toString());
|
||||
log.write("9999", "businessId: " + bid + " - [EsitoVerificaCodiceSessione] - Fine Log Request");
|
||||
|
||||
response = client.execute(httpPost);
|
||||
|
||||
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
||||
String line;
|
||||
while ((line = rd.readLine()) != null) {
|
||||
resp.append(line).append('\n');
|
||||
}
|
||||
|
||||
if (response.getStatusLine().getStatusCode() != 200) {
|
||||
log.write("9999", "businessId: " + bid + " - [EsitoVerificaCodiceSessione] - Inizio Log Error");
|
||||
log.write("9999", "businessId: " + bid + " - " + resp.toString());
|
||||
log.write("9999", "businessId: " + bid + " - [EsitoVerificaCodiceSessione] - Fine Log Error");
|
||||
throw new Exception(header.getTransactionID() + " - Soap fault exception");
|
||||
}
|
||||
|
||||
// Loggata response EsitoVerificaCodiceSessione ricevuta da Now
|
||||
log.write("9999", "businessId: " + bid + " - [EsitoVerificaCodiceSessione] - Inizio Log Response");
|
||||
log.write("9999", "businessId: " + bid + " - " + resp.toString());
|
||||
log.write("9999", "businessId: " + bid + " - [EsitoVerificaCodiceSessione] - Fine Log Response");
|
||||
Response ack = getRispostaFromHttp(resp.toString());
|
||||
log.write("9999", "EsitoVerificaCodiceSessione - soapAction='Invoke' end");
|
||||
return ack;
|
||||
} catch (Exception e) {
|
||||
log.write("0003", "businessId: " + bid + " - Eccezione durante l'invocazione del ws [EsitoVerificaCodiceSessione.Invoke]: " + e);
|
||||
throw e;
|
||||
} finally {
|
||||
try {
|
||||
if (client != null) {
|
||||
client.close();
|
||||
}
|
||||
if (response != null) {
|
||||
response.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String createHttpRequest(HeaderType header, Request request) throws Exception {
|
||||
MessageFactory messageFactory = MessageFactory.newInstance();
|
||||
SOAPMessage soapMessage = messageFactory.createMessage();
|
||||
SOAPPart soapPart = soapMessage.getSOAPPart();
|
||||
String serverURI = "http://telecomitalia.it/SOA/SOAP/SOAPHeader";
|
||||
String serverURI2 = "http://www.tim.com/NOW/xsd/NOW_EsitoVerificaCodiceSessione/";
|
||||
SOAPEnvelope envelope = soapPart.getEnvelope();
|
||||
// SOAPHeader soapHeader = envelope.getHeader();
|
||||
|
||||
SOAPBody soapBody = envelope.getBody();
|
||||
|
||||
SOAPBodyElement hElement = soapBody.addBodyElement(envelope.createName("Header", "soap", serverURI));
|
||||
hElement.addChildElement("sourceSystem", "soap").addTextNode(header.getSourceSystem());
|
||||
SOAPElement interactionDate = hElement.addChildElement("interactionDate", "soap");
|
||||
interactionDate.addChildElement("Date", "soap").addTextNode(header.getInteractionDate().getDate());
|
||||
interactionDate.addChildElement("Time", "soap").addTextNode(header.getInteractionDate().getTime());
|
||||
hElement.addChildElement("businessID", "soap").addTextNode(header.getBusinessID());
|
||||
hElement.addChildElement("messageID", "soap").addTextNode(header.getMessageID());
|
||||
hElement.addChildElement("transactionID", "soap").addTextNode(header.getTransactionID());
|
||||
|
||||
SOAPBodyElement element = soapBody.addBodyElement(envelope.createName("Request", "now", serverURI2));
|
||||
SOAPElement elementEsito = element.addChildElement("EsitoVerificaCodiceSessione", "now");
|
||||
elementEsito.addChildElement("CODICE_ORDINE_WHS", "now").addTextNode(request.getEsitoVerificaCodiceSessione().getCODICE_ORDINE_WHS());
|
||||
elementEsito.addChildElement("ID_NOTIFICA", "now").addTextNode(request.getEsitoVerificaCodiceSessione().getID_NOTIFICA());
|
||||
if(!Func.isNull(request.getEsitoVerificaCodiceSessione().getDATA_NOTIFICA()))
|
||||
elementEsito.addChildElement("DATA_NOTIFICA", "now").addTextNode(request.getEsitoVerificaCodiceSessione().getDATA_NOTIFICA());
|
||||
elementEsito.addChildElement("ESITO", "now").addTextNode(String.valueOf(request.getEsitoVerificaCodiceSessione().getESITO()));
|
||||
elementEsito.addChildElement("CODICE_MOTIVAZIONE", "now").addTextNode(request.getEsitoVerificaCodiceSessione().getCODICE_MOTIVAZIONE());
|
||||
elementEsito.addChildElement("MOTIVAZIONE", "now").addTextNode(request.getEsitoVerificaCodiceSessione().getMOTIVAZIONE());
|
||||
if(!Func.isNull(request.getEsitoVerificaCodiceSessione().getNOTE()))
|
||||
elementEsito.addChildElement("NOTE", "now").addTextNode(request.getEsitoVerificaCodiceSessione().getNOTE());
|
||||
|
||||
soapMessage.saveChanges();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
soapMessage.writeTo(baos);
|
||||
return baos.toString();
|
||||
}
|
||||
|
||||
private Response getRispostaFromHttp(String risposta) throws Exception {
|
||||
SOAPBody soapBody = WSUtils.getSOAPBody(risposta);
|
||||
Response ack = new Response();
|
||||
org.w3c.dom.Node nMaster = soapBody.getChildNodes().item(0);
|
||||
if(nMaster != null) {
|
||||
org.w3c.dom.Node n = WSUtils.getChildByName(nMaster, "ID_NOTIFICA");
|
||||
if (n != null) {
|
||||
ack.setID_NOTIFICA(n.getFirstChild().getNodeValue());
|
||||
}
|
||||
n = WSUtils.getChildByName(nMaster, "ESITO");
|
||||
if (n != null) {
|
||||
ack.setESITO(Enum_Response_ESITO.fromValue(n.getFirstChild().getNodeValue()));
|
||||
}
|
||||
}
|
||||
return ack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements method in Loggable public Interface
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public LogInfo getLogInfo() throws Exception {
|
||||
LogInfo logInfo = new LogInfo();
|
||||
logInfo.setProcess(getClass().getName());
|
||||
logInfo.setLogPath(Resources.getLogPath());
|
||||
logInfo.setTypeInfo(Resources.getTypeInfo());
|
||||
logInfo.setTypeDebug(Resources.getTypeDebug());
|
||||
logInfo.setTypeError(Resources.getTypeError());
|
||||
return logInfo;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package it.valueteam.gnp.ws.now.esitoverificacodicesessionefase2;
|
||||
|
||||
import it.valueteam.gnp.log.Loggable;
|
||||
import it.valueteam.gnp.log.ProcessLogger;
|
||||
import it.valueteam.gnp.obj.LogProcess;
|
||||
import it.valueteam.gnp.systemcontroller.formatcontroller.crm.WSSOAPHandler;
|
||||
|
||||
import javax.xml.rpc.handler.MessageContext;
|
||||
import javax.xml.rpc.handler.soap.SOAPMessageContext;
|
||||
import javax.xml.soap.SOAPHeader;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
public class EsitoVerificaCodiceSessioneSOAPHandler extends WSSOAPHandler implements Loggable {
|
||||
|
||||
protected ProcessLogger log;
|
||||
|
||||
public EsitoVerificaCodiceSessioneSOAPHandler() throws Exception {
|
||||
LogProcess logProcess = new LogProcess();
|
||||
logProcess.setCodice(codiceProcesso);
|
||||
logProcess.setProcess(this);
|
||||
log = new ProcessLogger(logProcess);
|
||||
}
|
||||
|
||||
public boolean handleRequest(MessageContext context) {
|
||||
SOAPMessageContext soapMsgCtx = (SOAPMessageContext) context;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
try {
|
||||
SOAPMessage message = soapMsgCtx.getMessage();
|
||||
SOAPHeader header = message.getSOAPHeader();
|
||||
String bid = getBid(header);
|
||||
log.write("9999",bid + " - [EsitoVerificaCodiceSessioneSOAPHandler] - Inizio Log Request");
|
||||
soapMsgCtx.getMessage().writeTo(baos);
|
||||
log.write("9999",baos.toString());
|
||||
log.write("9999",bid + " - [EsitoVerificaCodiceSessioneSOAPHandler] - Fine Log Request");
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean handleResponse(MessageContext context) {
|
||||
SOAPMessageContext soapMsgCtx = (SOAPMessageContext) context;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
try {
|
||||
SOAPHeader header = ((SOAPMessageContext) context).getMessage().getSOAPHeader();
|
||||
String bid = getBid(header);
|
||||
log.write("9999",bid + " - [EsitoVerificaCodiceSessioneSOAPHandler] - Inizio Log Response");
|
||||
soapMsgCtx.getMessage().writeTo(baos);
|
||||
log.write("9999",bid + " - "+baos.toString());
|
||||
log.write("9999",bid + " - [EsitoVerificaCodiceSessioneSOAPHandler] - Fine Log Response");
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean handleFault(MessageContext context) {
|
||||
SOAPMessageContext soapMsgCtx = (SOAPMessageContext) context;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
try {
|
||||
SOAPMessage message = soapMsgCtx.getMessage();
|
||||
SOAPHeader header = message.getSOAPHeader();
|
||||
String bid = getBid(header);
|
||||
log.write("9999",bid + " - [EsitoVerificaCodiceSessioneSOAPHandler] - Inizio Log Error");
|
||||
soapMsgCtx.getMessage().writeTo(baos);
|
||||
log.write("9999",bid + " - "+baos.toString());
|
||||
log.write("9999",bid + " - [EsitoVerificaCodiceSessioneSOAPHandler] - Fine Log Error");
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user