OpenSPCoop2Message_saaj_11_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.IOException;
  22. import java.io.InputStream;

  23. import javax.xml.soap.MimeHeaders;
  24. import javax.xml.soap.SOAPException;
  25. import javax.xml.soap.SOAPMessage;

  26. import org.apache.commons.io.input.CountingInputStream;
  27. import org.openspcoop2.message.OpenSPCoop2MessageFactory;
  28. import org.openspcoop2.message.exception.MessageException;
  29. import org.openspcoop2.utils.transport.http.ContentTypeUtilities;
  30. import org.openspcoop2.utils.transport.http.HttpConstants;

  31. import com.sun.xml.messaging.saaj.packaging.mime.internet.ContentType;

  32. /**
  33.  * Implementazione dell'OpenSPCoop2Message
  34.  *
  35.  * @author Lorenzo Nardi (nardi@link.it)
  36.  * @author $Author$
  37.  * @version $Rev$, $Date$
  38.  */

  39. public class OpenSPCoop2Message_saaj_11_impl extends AbstractOpenSPCoop2Message_saaj_impl
  40. {  
  41.    
  42.     /* Costruttori */
  43.                
  44.     public OpenSPCoop2Message_saaj_11_impl(OpenSPCoop2MessageFactory messageFactory) {  
  45.         super(messageFactory, new Message1_1_FIX_Impl());
  46.     }
  47.    
  48.     public OpenSPCoop2Message_saaj_11_impl(OpenSPCoop2MessageFactory messageFactory, MimeHeaders mhs, InputStream is) throws SOAPException, IOException{
  49.         super(messageFactory, new Message1_1_FIX_Impl(mhs, new CountingInputStream(is)));
  50.     }
  51.    
  52.     public OpenSPCoop2Message_saaj_11_impl(OpenSPCoop2MessageFactory messageFactory, SOAPMessage msg) {
  53.         //TODO questo costruttore non funziona con messaggi con attachment.
  54.         //C'e' un bug nell'implementazione della sun che non copia gli attachment
  55.         //In particolare il parametro super.mimePart (protetto non accessibile).
  56.         // Per questo motivo essite la classe 1_1 FIX che utilizza direttamente il messaggio fornito
  57.         super(messageFactory, new Message1_1_FIX_Impl(msg));
  58.     }
  59.    
  60.    
  61.     /* Initialize ed internal Message Impl */
  62.    
  63.     public void initialize(long overhead){
  64.         getMessage1_1_FIX_Impl().setLazyAttachments(false);
  65.         this.incomingsize = getMessage1_1_FIX_Impl().getCountingInputStream().getByteCount() - overhead;
  66.     }

  67.     private Message1_1_FIX_Impl getMessage1_1_FIX_Impl(){
  68.         return ((Message1_1_FIX_Impl)this._getSoapMessage());
  69.     }
  70.    
  71.    
  72.    
  73.     /* ContentType */
  74.    
  75.     @Override
  76.     protected String _super_getContentType() {
  77.         try {
  78.             return _getContentType(false);
  79.         } catch (Throwable e) {
  80.             // Non dovrebbe avvenire errori
  81.         }   return getMessage1_1_FIX_Impl().getContentType();
  82.     }
  83.    
  84.     @Override
  85.     public void setContentType(String type) throws MessageException{
  86.         getMessage1_1_FIX_Impl().setContentType(type);
  87.     }
  88.    
  89.     @Override
  90.     public String getContentType() throws MessageException{
  91.         return _getContentType(true);
  92.     }
  93.     private String _getContentType(boolean includeContentTypeParameters) throws MessageException{
  94.        
  95.         try {
  96.             String ct = getMessage1_1_FIX_Impl().getContentType();
  97.             ContentType cType = new ContentType(ct);
  98.             if(cType.getBaseType().equalsIgnoreCase(HttpConstants.CONTENT_TYPE_MULTIPART_RELATED)) {
  99.                 if(getMessage1_1_FIX_Impl().getMimeMultipart() != null)
  100.                     cType.setParameter(HttpConstants.CONTENT_TYPE_MULTIPART_PARAMETER_BOUNDARY,
  101.                             getMessage1_1_FIX_Impl().getMimeMultipart().getContentType().getParameter(HttpConstants.CONTENT_TYPE_MULTIPART_PARAMETER_BOUNDARY));
  102.             }
  103.             if(includeContentTypeParameters) {
  104.                 return ContentTypeUtilities.buildContentType(cType.toString(),this.contentTypeParamaters);  
  105.             }
  106.             else {
  107.                 return cType.toString();
  108.             }
  109.         } catch (Exception e) {
  110.             e.printStackTrace(System.err);
  111.             try{
  112.                 String ct = getMessage1_1_FIX_Impl().getContentType();
  113.                 if(includeContentTypeParameters) {
  114.                     return ContentTypeUtilities.buildContentType(ct,this.contentTypeParamaters);
  115.                 }
  116.                 else {
  117.                     return ct;
  118.                 }
  119.             }catch(Exception eInternal){
  120.                 throw new RuntimeException(eInternal.getMessage(),eInternal);
  121.             }
  122.         }
  123.     }


  124. }