OpenSPCoop2Servlet.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */

  20. package org.openspcoop2.pdd.services.connector;

  21. import java.io.IOException;
  22. import java.util.Enumeration;

  23. import javax.servlet.RequestDispatcher;
  24. import javax.servlet.ServletException;
  25. import javax.servlet.http.HttpServlet;
  26. import javax.servlet.http.HttpServletRequest;
  27. import javax.servlet.http.HttpServletResponse;

  28. import org.openspcoop2.pdd.config.OpenSPCoop2Properties;
  29. import org.openspcoop2.pdd.core.CostantiPdD;
  30. import org.openspcoop2.pdd.core.byok.BYOKMapProperties;
  31. import org.openspcoop2.pdd.logger.OpenSPCoop2Logger;
  32. import org.openspcoop2.pdd.services.OpenSPCoop2Startup;
  33. import org.openspcoop2.protocol.engine.ProtocolFactoryManager;
  34. import org.openspcoop2.protocol.engine.URLProtocolContextImpl;
  35. import org.openspcoop2.protocol.manifest.constants.Costanti;
  36. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  37. import org.openspcoop2.protocol.sdk.constants.IDService;
  38. import org.openspcoop2.protocol.sdk.state.FunctionContextsCustom;
  39. import org.openspcoop2.protocol.sdk.state.URLProtocolContext;
  40. import org.openspcoop2.utils.LoggerWrapperFactory;
  41. import org.openspcoop2.utils.Semaphore;
  42. import org.openspcoop2.utils.SemaphoreLock;
  43. import org.openspcoop2.utils.Utilities;
  44. import org.openspcoop2.utils.transport.http.HttpRequestMethod;
  45. import org.slf4j.Logger;

  46. /**
  47.  * OpenSPCoop2Servlet
  48.  *
  49.  * @author Poli Andrea (apoli@link.it)
  50.  * @author $Author$
  51.  * @version $Rev$, $Date$
  52.  */
  53. @SuppressWarnings("serial")
  54. public class OpenSPCoop2Servlet extends HttpServlet {
  55.     private static Logger logger = null;

  56.     private static synchronized Logger _getLogger() {
  57.         if ( logger == null ) {
  58.             logger = LoggerWrapperFactory.getLogger("govway.startup");
  59.         }
  60.         return logger;
  61.     }
  62.     private static Logger getLogger() {
  63.         if ( logger == null )
  64.             _getLogger();
  65.         return logger;
  66.     }

  67.     private static boolean checkSecrets = false;
  68.     private static final Semaphore semaphoreCheckSecrets = new Semaphore("GovWaySecrets");
  69.     private static void checkSecrets() {
  70.         if(!checkSecrets) {
  71.             initSecrets();
  72.         }
  73.     }
  74.     private static void initSecrets() {
  75.         SemaphoreLock lock = semaphoreCheckSecrets.acquireThrowRuntime("initSecrets");
  76.         try {
  77.             if(!checkSecrets) {
  78.                 BYOKMapProperties secretsProperties = BYOKMapProperties.getInstance();
  79.                 if(secretsProperties!=null && secretsProperties.isExistsUnwrapPropertiesAfterGovWayStartup()) {
  80.                     secretsProperties.setGovWayStarted(true);
  81.                     try {
  82.                         secretsProperties.initEnvironment();
  83.                         String secretsConfig = OpenSPCoop2Properties.getInstance().getBYOKEnvSecretsConfig();
  84.                         String msgInit = "Environment inizializzato con i secrets definiti nel file '"+secretsConfig+"' dopo il completamento dell'avvio di GovWay"+
  85.                                 "\n\tJavaProperties: "+secretsProperties.getJavaMap().keys()+
  86.                                 "\n\tEnvProperties: "+secretsProperties.getEnvMap().keys()+
  87.                                 "\n\tObfuscateMode: "+secretsProperties.getObfuscateModeDescription();
  88.                         OpenSPCoop2Startup.logStartupInfo(msgInit);
  89.                     } catch (Exception e) {
  90.                         OpenSPCoop2Startup.logStartupError("Inizializzazione ambiente (secrets) non riuscita: "+e.getMessage(),e);
  91.                     }
  92.                 }
  93.                 checkSecrets = true;
  94.             }
  95.         }finally {
  96.             semaphoreCheckSecrets.release(lock, "initSecrets");
  97.         }
  98.     }
  99.    
  100.     @Override
  101.     protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  102.                
  103.         HttpRequestMethod m = null;
  104.         try {
  105.             m = HttpRequestMethod.valueOf(req.getMethod().toUpperCase());
  106.         }catch(Exception e) {
  107.             super.service(req, resp); // richiamo implementazione originale che genera errore: Method XXX is not defined in RFC 2068 and is not supported by the Servlet API
  108.             return;
  109.         }
  110.         switch (m) {
  111.        
  112.         // Standard
  113.        
  114.         case DELETE:
  115.             this.doDelete(req, resp);
  116.             break;
  117.         case GET:
  118.             this.doGet(req, resp);
  119.             break;
  120.         case HEAD:
  121.             this.doHead(req, resp);
  122.             break;
  123.         case OPTIONS:
  124.             this.doOptions(req, resp);
  125.             break;
  126.         case POST:
  127.             this.doPost(req, resp);
  128.             break;
  129.         case PUT:
  130.             this.doPut(req, resp);
  131.             break;
  132.         case TRACE:
  133.             this.doTrace(req, resp);
  134.             break;
  135.            
  136.         // Additionals
  137.         case PATCH:
  138.         case LINK:
  139.         case UNLINK:
  140.             boolean enabled = true;
  141.             OpenSPCoop2Properties op2Properties = null;
  142.             try {
  143.                 op2Properties = OpenSPCoop2Properties.getInstance();
  144.             }catch(Throwable t) {
  145.                 //come default si lasciano abilitati
  146.             }
  147.             if(op2Properties!=null) {
  148.                 if(HttpRequestMethod.PATCH.equals(m)) {
  149.                     enabled = op2Properties.isServiceRequestHttpMethodPatchEnabled();
  150.                 }
  151.                 else if(HttpRequestMethod.LINK.equals(m)) {
  152.                     enabled = op2Properties.isServiceRequestHttpMethodLinkEnabled();
  153.                 }
  154.                 else if(HttpRequestMethod.UNLINK.equals(m)) {
  155.                     enabled = op2Properties.isServiceRequestHttpMethodUnlinkEnabled();
  156.                 }
  157.             }
  158.             if(enabled) {
  159.                 dispatch(req, resp, m);
  160.             }
  161.             else {
  162.                 super.service(req, resp); // richiamo implementazione originale che genera errore: Method XXX is not defined in RFC 2068 and is not supported by the Servlet API
  163.             }
  164.             break;
  165.            
  166.         default:
  167.             super.service(req, resp); // richiamo implementazione originale che genera errore: Method XXX is not defined in RFC 2068 and is not supported by the Servlet API
  168.             break;
  169.         }
  170.     }

  171.     @Override
  172.     protected void doDelete(HttpServletRequest req, HttpServletResponse resp)
  173.             throws ServletException, IOException {
  174.         dispatch(req, resp, HttpRequestMethod.DELETE);
  175.     }

  176.     @Override
  177.     protected void doGet(HttpServletRequest req, HttpServletResponse resp)
  178.             throws ServletException, IOException {
  179.         dispatch(req, resp, HttpRequestMethod.GET);
  180.     }

  181.     @Override
  182.     protected void doHead(HttpServletRequest req, HttpServletResponse resp)
  183.             throws ServletException, IOException {
  184.         dispatch(req, resp, HttpRequestMethod.HEAD);
  185.     }

  186.     @Override
  187.     protected void doOptions(HttpServletRequest req, HttpServletResponse resp)
  188.             throws ServletException, IOException {
  189.         dispatch(req, resp, HttpRequestMethod.OPTIONS);
  190.     }

  191.     @Override
  192.     protected void doPost(HttpServletRequest req, HttpServletResponse resp)
  193.             throws ServletException, IOException {
  194.         dispatch(req, resp, HttpRequestMethod.POST);
  195.     }

  196.     @Override
  197.     protected void doPut(HttpServletRequest req, HttpServletResponse resp)
  198.             throws ServletException, IOException {
  199.         dispatch(req, resp, HttpRequestMethod.PUT);
  200.     }

  201.     @Override
  202.     protected void doTrace(HttpServletRequest req, HttpServletResponse resp)
  203.             throws ServletException, IOException {
  204.         dispatch(req, resp, HttpRequestMethod.TRACE);
  205.     }

  206.    
  207.     private void dispatch(HttpServletRequest req, HttpServletResponse res,HttpRequestMethod method) {
  208.        
  209.         Logger logCore = OpenSPCoop2Logger.getLoggerOpenSPCoopCore();
  210.         Logger logOpenSPCoop2Servlet = getLogger();
  211.        
  212.         OpenSPCoop2Properties op2Properties = null;
  213.         try {
  214.            
  215.             if (!OpenSPCoop2Startup.initialize) {
  216.                
  217.                 // req.getContextPath()[/govway] req.getRequestURI()[/govway/check]
  218.                 String contextPath = req.getContextPath();
  219.                 String requestUri = req.getRequestURI();
  220.                 if(requestUri!=null && contextPath!=null && requestUri.startsWith(contextPath) && requestUri.length()>contextPath.length()) {
  221.                     String function = requestUri.substring(contextPath.length(), requestUri.length());
  222.                     if(function.startsWith("/") && function.length()>1) {
  223.                         function = function.substring(1);
  224.                     }
  225.                     if(function.equals(URLProtocolContext.Check_FUNCTION) || function.equals(URLProtocolContext.Proxy_FUNCTION)){
  226.                         CheckStatoPdD.serializeNotInitializedResponse(res, (logCore!=null) ? logCore : logOpenSPCoop2Servlet);
  227.                         return;
  228.                     }
  229.                 }
  230.                
  231.                 // Attendo inizializzazione
  232.                 int max = CostantiPdD.WAIT_STARTUP_TIMEOUT_SECONDS;
  233.                 int sleepCheck = CostantiPdD.WAIT_STARTUP_CHECK_INTERVAL_MS;
  234.                 for (int i = 0; i < 5; i++) { // attendo 5 secondi la presenza delle proprietà
  235.                     if(OpenSPCoop2Properties.getInstance()==null) {
  236.                         Utilities.sleep(1000);
  237.                     }
  238.                     if(OpenSPCoop2Properties.getInstance()!=null) {
  239.                         break;
  240.                     }
  241.                 }
  242.                 if(OpenSPCoop2Properties.getInstance()!=null) {
  243.                     max = OpenSPCoop2Properties.getInstance().getStartupRichiesteIngressoTimeoutSecondi();
  244.                     sleepCheck = OpenSPCoop2Properties.getInstance().getStartupRichiesteIngressoCheckMs();
  245.                 }
  246.                
  247.                 int maxMs = (max * 1000);
  248.                 int actualMs = 0;
  249.                 while(!OpenSPCoop2Startup.initialize && actualMs<maxMs) {
  250.                     Utilities.sleep(sleepCheck);
  251.                     actualMs = actualMs + sleepCheck;
  252.                 }
  253.                
  254.                 if (!OpenSPCoop2Startup.initialize) {
  255.                
  256.                     // log su file core
  257.                     StringBuilder bfLogError = new StringBuilder();
  258.                     ConnectorUtils.generateErrorMessage(IDService.OPENSPCOOP2_SERVLET,method,req,bfLogError, "GovWay non inizializzato", true, false);
  259.                     if(logCore!=null){
  260.                         logCore.error(bfLogError.toString());
  261.                     }
  262.                     else{
  263.                         logOpenSPCoop2Servlet.error(bfLogError.toString());
  264.                     }
  265.                     res.sendError(404,ConnectorUtils.generateError404Message(ConnectorUtils.getFullCodeGovWayNotInitialized(IDService.OPENSPCOOP2_SERVLET)));
  266.                     return;
  267.                    
  268.                 }
  269.             }
  270.             op2Properties = OpenSPCoop2Properties.getInstance();
  271.            
  272.             boolean printCertificate = false;
  273.             FunctionContextsCustom customContexts = null;
  274.             if(op2Properties!=null) {
  275.                 printCertificate = op2Properties.isPrintInfoCertificate();
  276.                 customContexts = op2Properties.getCustomContexts();
  277.             }
  278.            
  279.             URLProtocolContext protocolContext = new URLProtocolContextImpl(req, logCore, printCertificate, customContexts);
  280.             String function = protocolContext.getFunction();
  281.             IDService idServiceCustom = protocolContext.getIdServiceCustom();
  282.            
  283.             IProtocolFactory<?> pf = ProtocolFactoryManager.getInstance().getProtocolFactoryByServletContext(protocolContext.getProtocolWebContext());
  284.             if(pf==null){
  285.                 if(!Costanti.CONTEXT_EMPTY.equals(protocolContext.getProtocolWebContext()))
  286.                     throw new Exception("Non risulta registrato un protocollo con contesto ["+protocolContext.getProtocolWebContext()+"]");
  287.                 else
  288.                     throw new Exception("Non risulta registrato un protocollo con contesto speciale 'vuoto'");
  289.             }
  290.                        
  291.             if(
  292.                     (function.equals(URLProtocolContext.PD_FUNCTION) && op2Properties.isEnabledFunctionPD())
  293.                     ||
  294.                     (idServiceCustom!=null && IDService.PORTA_DELEGATA.equals(idServiceCustom))
  295.                 ){
  296.                
  297.                 checkSecrets();
  298.                
  299.                 RicezioneContenutiApplicativiConnector r = new RicezioneContenutiApplicativiConnector();
  300.                 r.doEngine(ConnectorUtils.getRequestInfo(pf, protocolContext), req, res, method);
  301.                
  302.             }
  303.             else if(
  304.                     (function.equals(URLProtocolContext.PDtoSOAP_FUNCTION) && op2Properties.isEnabledFunctionPDtoSOAP())
  305.                     ||
  306.                     (idServiceCustom!=null && IDService.PORTA_DELEGATA_XML_TO_SOAP.equals(idServiceCustom))
  307.                 ){
  308.                
  309.                 checkSecrets();
  310.                
  311.                 RicezioneContenutiApplicativiHTTPtoSOAPConnector r = new RicezioneContenutiApplicativiHTTPtoSOAPConnector();
  312.                 r.doEngine(ConnectorUtils.getRequestInfo(pf, protocolContext), req, res, method);
  313.                
  314.             }
  315.             else if(
  316.                     (function.equals(URLProtocolContext.PA_FUNCTION) && op2Properties.isEnabledFunctionPA())
  317.                     ||
  318.                     (idServiceCustom!=null && IDService.PORTA_APPLICATIVA.equals(idServiceCustom))
  319.                 ){
  320.                
  321.                 checkSecrets();
  322.                
  323.                 RicezioneBusteConnector r = new RicezioneBusteConnector();
  324.                 r.doEngine(ConnectorUtils.getRequestInfo(pf, protocolContext), req, res, method);
  325.             }
  326.            
  327.             else if(function.equals(URLProtocolContext.IntegrationManager_FUNCTION) || (idServiceCustom!=null && IDService.INTEGRATION_MANAGER_SOAP.equals(idServiceCustom))){
  328.                
  329.                 checkSecrets();
  330.                
  331.                 if(op2Properties!=null && op2Properties.isIntegrationManagerEnabled()==false) {
  332.                     throw new Exception("Service ["+function+"] not active");
  333.                 }
  334.                
  335.                 boolean wsdl = false;
  336.                 if(HttpRequestMethod.GET.equals(method)){
  337.                     Enumeration<?> parameters = req.getParameterNames();
  338.                     while(parameters.hasMoreElements()){
  339.                         String key = (String) parameters.nextElement();
  340.                         String value = req.getParameter(key);
  341.                         if("wsdl".equalsIgnoreCase(key) && (value==null || "".equals(value)) ){
  342.                             // richiesta del wsdl
  343.                             if(op2Properties!=null && op2Properties.isGenerazioneWsdlIntegrationManagerEnabled()==false){
  344.                                 res.sendError(404, ConnectorUtils.generateError404Message(ConnectorUtils.getFullCodeWsdlUnsupported(IDService.INTEGRATION_MANAGER_SOAP)));
  345.                                 return;
  346.                             }
  347.                             else{
  348.                                 wsdl = true;
  349.                                 break;
  350.                             }
  351.                         }
  352.                     }
  353.                 }
  354.                
  355.                 if(!HttpRequestMethod.POST.equals(method) && !wsdl){
  356.                     // messaggio di errore
  357.                     boolean errore404 = false;
  358.                     if(op2Properties!=null && !op2Properties.isGenerazioneErroreHttpMethodUnsupportedIntegrationManagerEnabled()){
  359.                         errore404 = true;
  360.                     }
  361.                    
  362.                     if(errore404){
  363.                         res.sendError(404,ConnectorUtils.generateError404Message(ConnectorUtils.getFullCodeHttpMethodNotSupported(IDService.INTEGRATION_MANAGER_SOAP, method)));
  364.                         return;
  365.                     }
  366.                     else{
  367.                    
  368.                         res.setStatus(500);
  369.                        
  370.                         ConnectorUtils.generateErrorMessage(IDService.INTEGRATION_MANAGER_SOAP, method, req, res, ConnectorUtils.getMessageHttpMethodNotSupported(method), false, true);
  371.                                
  372.                         try{
  373.                             res.getOutputStream().flush();
  374.                         }catch(Exception eClose){
  375.                             // ignore
  376.                         }
  377.                         try{
  378.                             res.getOutputStream().close();
  379.                         }catch(Exception eClose){
  380.                             // ignore
  381.                         }
  382.                        
  383.                         return;
  384.                     }
  385.                 }
  386.                                
  387.                 // Dispatching al servizio di IntegrationManager implementato tramite CXF
  388.                 String serviceIM = protocolContext.getFunctionParameters();
  389.                 if(URLProtocolContext.IntegrationManager_SERVICE_PD_GOVWAY.equals(serviceIM) ||
  390.                         (URLProtocolContext.IntegrationManager_SERVICE_PD_GOVWAY+"/").equals(serviceIM)) {
  391.                     serviceIM = URLProtocolContext.IntegrationManager_SERVICE_PD;
  392.                 }
  393.                 String forwardUrl = "/"+URLProtocolContext.IntegrationManager_ENGINE+"/"+serviceIM;
  394.                 req.setAttribute(org.openspcoop2.core.constants.Costanti.PROTOCOL_NAME.getValue(), protocolContext.getProtocolName());
  395.                 req.setAttribute(org.openspcoop2.core.constants.Costanti.PROTOCOL_WEB_CONTEXT.getValue(), protocolContext.getProtocolWebContext());
  396.                 req.setAttribute(org.openspcoop2.core.constants.Costanti.INTEGRATION_MANAGER_ENGINE_AUTHORIZED.getValue(), true);
  397.                 RequestDispatcher dispatcher = req.getRequestDispatcher(forwardUrl);
  398.                 dispatcher.forward(req, res);
  399.                
  400.             }
  401.             else if(function.equals(URLProtocolContext.Check_FUNCTION)){
  402.                
  403.                 if(HttpRequestMethod.GET.equals(method)==false){
  404.                     // messaggio di errore
  405.                     boolean errore404 = false;
  406.                     if(op2Properties!=null && !op2Properties.isGenerazioneErroreHttpMethodUnsupportedCheckEnabled()){
  407.                         errore404 = true;
  408.                     }
  409.                    
  410.                     if(errore404){
  411.                         res.sendError(404,ConnectorUtils.generateError404Message(ConnectorUtils.getFullCodeHttpMethodNotSupported(IDService.CHECK_PDD, method)));
  412.                         return;
  413.                     }
  414.                     else{
  415.                        
  416.                         res.setStatus(500);
  417.                        
  418.                         ConnectorUtils.generateErrorMessage(IDService.CHECK_PDD,method,req,res, ConnectorUtils.getMessageHttpMethodNotSupported(method), false, true);
  419.                                
  420.                         try{
  421.                             res.getOutputStream().flush();
  422.                         }catch(Exception eClose){
  423.                             // ignore
  424.                         }
  425.                         try{
  426.                             res.getOutputStream().close();
  427.                         }catch(Exception eClose){
  428.                             // ignore
  429.                         }
  430.                        
  431.                         return;
  432.                     }
  433.                 }
  434.                
  435.                 // Dispatching al servizio
  436.                 CheckStatoPdD checkStatoPdD = new CheckStatoPdD();
  437.                 req.setAttribute(org.openspcoop2.core.constants.Costanti.PROTOCOL_NAME.getValue(), protocolContext.getProtocolName());
  438.                 checkStatoPdD.doGet(req, res);
  439.                
  440.             }
  441.             else if(function.equals(URLProtocolContext.Proxy_FUNCTION)){
  442.                
  443.                 if(op2Properties!=null && !op2Properties.isProxyReadJMXResourcesEnabled()) {
  444.                     throw new Exception("Service ["+function+"] not supported");
  445.                 }
  446.                
  447.                 if(HttpRequestMethod.GET.equals(method)==false){
  448.                     // messaggio di errore
  449.                     boolean errore404 = false;
  450.                     if(op2Properties!=null && !op2Properties.isGenerazioneErroreHttpMethodUnsupportedProxyEnabled()){
  451.                         errore404 = true;
  452.                     }
  453.                    
  454.                     if(errore404){
  455.                         res.sendError(404,ConnectorUtils.generateError404Message(ConnectorUtils.getFullCodeHttpMethodNotSupported(IDService.PROXY, method)));
  456.                         return;
  457.                     }
  458.                     else{
  459.                        
  460.                         res.setStatus(500);
  461.                        
  462.                         ConnectorUtils.generateErrorMessage(IDService.PROXY,method,req,res, ConnectorUtils.getMessageHttpMethodNotSupported(method), false, true);
  463.                                
  464.                         try{
  465.                             res.getOutputStream().flush();
  466.                         }catch(Exception eClose){
  467.                             // ignore
  468.                         }
  469.                         try{
  470.                             res.getOutputStream().close();
  471.                         }catch(Exception eClose){
  472.                             // ignore
  473.                         }
  474.                        
  475.                         return;
  476.                     }
  477.                 }
  478.                
  479.                 // Dispatching al servizio
  480.                 Proxy proxy = new Proxy();
  481.                 req.setAttribute(org.openspcoop2.core.constants.Costanti.PROTOCOL_NAME.getValue(), protocolContext.getProtocolName());
  482.                 proxy.doGet(req, res);
  483.                
  484.             }
  485.             else{
  486.                 throw new Exception("Service ["+function+"] not supported");
  487.             }
  488.            
  489.         } catch (Exception e) {
  490.            
  491.             StringBuilder bf = new StringBuilder();
  492.             bf.append("RemoteAddr["+req.getRemoteAddr()+"] ");
  493.             bf.append("RemoteHost["+req.getRemoteHost()+"] ");
  494.             bf.append("RemotePort["+req.getRemotePort()+"] ");
  495.             bf.append("RemoteUser["+req.getRemoteUser()+"] ");
  496.             bf.append("LocalAddr["+req.getLocalAddr()+"] ");
  497.             bf.append("LocalHost["+req.getLocalName()+"] ");
  498.             bf.append("LocalPort["+req.getLocalPort()+"] ");
  499.             bf.append("ServerName["+req.getServerName()+"] ");
  500.             bf.append("ServerPort["+req.getServerPort()+"] ");
  501.                        
  502.             if(logCore!=null){
  503.                 logCore.error(e.getMessage(),e);
  504.                 logCore.error("Detail: "+bf.toString());
  505.             }
  506.             else{
  507.                 logOpenSPCoop2Servlet.error(e.getMessage(),e);
  508.                 logOpenSPCoop2Servlet.error("Detail: "+bf.toString());
  509.             }
  510.            
  511.             // log su file core
  512.             StringBuilder bfLogError = new StringBuilder();
  513.             try {
  514.                 ConnectorUtils.generateErrorMessage(IDService.OPENSPCOOP2_SERVLET,method,req,bfLogError, e.getMessage(), true, false);
  515.                 if(logCore!=null){
  516.                     logCore.error(bfLogError.toString());
  517.                 }
  518.                 else{
  519.                     logOpenSPCoop2Servlet.error(bfLogError.toString());
  520.                 }
  521.             }catch(Throwable t) {
  522.                 if(logCore!=null){
  523.                     logCore.error("generateErrorMessage log failed: "+t.getMessage(),t);
  524.                 }
  525.                 else{
  526.                     logOpenSPCoop2Servlet.error("generateErrorMessage log failed: "+t.getMessage(),t);
  527.                 }
  528.             }
  529.            
  530.             // messaggio di errore
  531.             boolean errore404 = true;
  532.             if(op2Properties!=null && op2Properties.isGenerazioneErroreProtocolloNonSupportato()){
  533.                 errore404 = false;
  534.             }
  535.            
  536.             if(errore404){
  537.                 try {
  538.                     res.sendError(404,ConnectorUtils.generateError404Message(ConnectorUtils.getFullCodeProtocolUnsupported(IDService.OPENSPCOOP2_SERVLET)));
  539.                 }catch(Throwable t) {
  540.                     if(logCore!=null){
  541.                         logCore.error("sendError404 failed: "+t.getMessage(),t);
  542.                     }
  543.                     else{
  544.                         logOpenSPCoop2Servlet.error("sendError404 failed: "+t.getMessage(),t);
  545.                     }
  546.                 }
  547.             }
  548.             else{
  549.                 res.setStatus(500);

  550.                 try {
  551.                     ConnectorUtils.generateErrorMessage(IDService.OPENSPCOOP2_SERVLET,method,req,res, e.getMessage(), true, true);
  552.                 }catch(Throwable t) {
  553.                     if(logCore!=null){
  554.                         logCore.error("generateErrorMessage failed: "+t.getMessage(),t);
  555.                     }
  556.                     else{
  557.                         logOpenSPCoop2Servlet.error("generateErrorMessage failed: "+t.getMessage(),t);
  558.                     }
  559.                 }
  560.                
  561.                 try{
  562.                     res.getOutputStream().flush();
  563.                 }catch(Throwable eClose){
  564.                     // ignore
  565.                 }
  566.                 try{
  567.                     res.getOutputStream().close();
  568.                 }catch(Throwable eClose){
  569.                     // ignore
  570.                 }
  571.                
  572.             }
  573.            
  574.         }
  575.        

  576.        
  577.     }
  578.    

  579.    

  580. }