OpenSPCoop2Message_soap11_impl.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.message.soap;

  21. import java.io.ByteArrayInputStream;
  22. import java.io.FileInputStream;
  23. import java.io.InputStream;

  24. import javax.xml.soap.MimeHeaders;
  25. import javax.xml.soap.SOAPEnvelope;
  26. import javax.xml.soap.SOAPHeader;

  27. import org.openspcoop2.message.OpenSPCoop2MessageFactory;
  28. import org.openspcoop2.message.exception.MessageException;
  29. import org.openspcoop2.message.soap.reader.OpenSPCoop2MessageSoapStreamReader;
  30. import org.openspcoop2.utils.io.DumpByteArrayOutputStream;

  31. /**
  32.  * Implementazione dell'OpenSPCoop2Message utilizzabile per messaggi SOAP 11
  33.  *
  34.  * @author Andrea Poli (poli@link.it)
  35.  * @author $Author$
  36.  * @version $Rev$, $Date$
  37.  */
  38. public class OpenSPCoop2Message_soap11_impl extends AbstractOpenSPCoop2Message_soap_impl<OpenSPCoop2Message_saaj_11_impl> {
  39.    
  40.     public OpenSPCoop2Message_soap11_impl(OpenSPCoop2MessageFactory messageFactory, MimeHeaders mhs, InputStream is, long overhead,
  41.             OpenSPCoop2MessageSoapStreamReader soapStreamReader) throws MessageException {
  42.         super(messageFactory, mhs, is, overhead, soapStreamReader);
  43.     }
  44.    
  45.     @Override
  46.     protected OpenSPCoop2Message_saaj_11_impl buildContent() throws MessageException{
  47.         try{
  48.             return buildContent(this._getInputStream());
  49.         }finally{
  50.             try{
  51.                 this._getInputStream().close();
  52.             }catch(Exception eClose){
  53.                 // close
  54.             }
  55.         }
  56.     }
  57.     @Override
  58.     protected OpenSPCoop2Message_saaj_11_impl buildContent(DumpByteArrayOutputStream contentBuffer) throws MessageException{
  59.         try{
  60.             if(contentBuffer.isSerializedOnFileSystem()) {
  61.                 try(InputStream is = new FileInputStream(contentBuffer.getSerializedFile())){
  62.                     return buildContent(is);
  63.                 }
  64.             }
  65.             else {
  66.                 try(InputStream is = new ByteArrayInputStream(contentBuffer.toByteArray())){
  67.                     return buildContent(is);
  68.                 }
  69.             }
  70.         }
  71.         catch(MessageException me) {
  72.             throw me;
  73.         }
  74.         catch(Exception e){
  75.             throw new MessageException(e.getMessage(),e);
  76.         }
  77.     }

  78.     protected OpenSPCoop2Message_saaj_11_impl buildContent(InputStream is) throws MessageException{
  79.         try{
  80. //          System.out.println("BUILD 11");
  81.            
  82. //          byte[] b = org.openspcoop2.utils.Utilities.getAsByteArray(is);
  83. //          java.io.ByteArrayOutputStream bout = new java.io.ByteArrayOutputStream();
  84. //          bout.write(b);
  85. //          bout.flush();
  86. //          bout.close();
  87. //          System.out.println("AAAAAAA: '"+bout.toString()+"'");
  88. //          is = new java.io.ByteArrayInputStream(b);
  89.            
  90.             OpenSPCoop2Message_saaj_11_impl msg = new OpenSPCoop2Message_saaj_11_impl(this.messageFactory, this.mhs, is);
  91.             msg.initialize(this.overhead);
  92.             msg.copyResourceFrom(this.soapCore);
  93.             msg.setMessageRole(this.messageRole);
  94.             msg.setMessageType(this.messageType);
  95.            
  96.             // Verifica struttura (in AbstractBaseOpenSPCoop2MessageDynamicContent verrĂ  collezionato l'errore di parsing)
  97.             // Servono tutti e 3 i comandi per far leggere tutto lo stream
  98.             // Se si levano alcuni test falliscono
  99.             SOAPHeader hdr = msg.getSOAPHeader();
  100.             SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
  101.             msg.countAttachments();
  102.            
  103.             this.addSoapHeaderModifiedIntoSoapReader(hdr, envelope);
  104.            
  105.             return msg;
  106.         }catch(Throwable t){
  107.             throw SoapUtils.buildMessageException("Unable to create envelope from given source: ",t);
  108.         }
  109.     }
  110.    
  111. }