ModISecuritySoapToken.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.protocol.modipa;

  21. import javax.xml.soap.SOAPEnvelope;

  22. import org.openspcoop2.message.OpenSPCoop2MessageFactory;
  23. import org.openspcoop2.protocol.basic.Utilities;
  24. import org.openspcoop2.protocol.sdk.ProtocolException;
  25. import org.openspcoop2.protocol.sdk.constants.TipoSerializzazione;

  26. /**
  27.  * ModISecuritySoapToken
  28.  *
  29.  * @author Poli Andrea (apoli@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. public class ModISecuritySoapToken extends AbstractModISecurityToken<SOAPEnvelope> {

  34.     public ModISecuritySoapToken(SOAPEnvelope token) {
  35.         super(token);
  36.     }

  37.     @Override
  38.     public String toString(TipoSerializzazione tipoSerializzazione) throws ProtocolException{
  39.         switch (tipoSerializzazione) {
  40.         case XML:
  41.         case DEFAULT:
  42.             StringBuilder sb = new StringBuilder();
  43.             sb.append( Utilities.toString(OpenSPCoop2MessageFactory.getDefaultMessageFactory(), this.getToken(),false) );
  44.             if(this.tokenAudit!=null) {
  45.                 sb.append("\n");
  46.                 sb.append(this.tokenAuditHeaderName).append(": ").append(this.tokenAudit);
  47.             }
  48.             return sb.toString();
  49.         default:
  50.             throw new ProtocolException("Tipo di serializzazione ["+tipoSerializzazione+"] non supportata");
  51.         }
  52.     }
  53.    
  54.     @Override
  55.     public byte[] toByteArray(TipoSerializzazione tipoSerializzazione) throws ProtocolException{
  56.         switch (tipoSerializzazione) {
  57.         case XML:
  58.         case DEFAULT:
  59.             /**return Utilities.toByteArray(OpenSPCoop2MessageFactory.getDefaultMessageFactory(), this.getToken(),false);*/
  60.             return this.toString(tipoSerializzazione).getBytes();
  61.         default:
  62.             throw new ProtocolException("Tipo di serializzazione ["+tipoSerializzazione+"] non supportata");
  63.         }
  64.     }
  65.    
  66. }