DirectVMConnectorOutMessage.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.messages;

  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Map;

  24. import org.openspcoop2.message.OpenSPCoop2Message;
  25. import org.openspcoop2.pdd.services.DirectVMProtocolInfo;
  26. import org.openspcoop2.pdd.services.connector.ConnectorException;
  27. import org.openspcoop2.utils.io.DumpByteArrayOutputStream;
  28. import org.openspcoop2.utils.transport.TransportUtils;

  29. /**
  30.  * DirectVMConnectorOutMessage
  31.  *
  32.  * @author Andrea Poli (apoli@link.it)
  33.  * @author $Author$
  34.  * @version $Rev$, $Date$
  35.  */
  36. public class DirectVMConnectorOutMessage implements ConnectorOutMessage {

  37.     private DirectVMProtocolInfo directVMProtocolInfo;
  38.    
  39.     public DirectVMConnectorOutMessage() throws ConnectorException{
  40.         try{
  41.         }catch(Exception e){
  42.             throw new ConnectorException(e.getMessage(),e);
  43.         }
  44.     }

  45.     public DirectVMProtocolInfo getDirectVMProtocolInfo() {
  46.         return this.directVMProtocolInfo;
  47.     }
  48.     public void setDirectVMProtocolInfo(DirectVMProtocolInfo directVMProtocolInfo) {
  49.         this.directVMProtocolInfo = directVMProtocolInfo;
  50.     }
  51.    
  52.     private OpenSPCoop2Message message;
  53.     public OpenSPCoop2Message getMessage() {
  54.         return this.message;
  55.     }
  56.     @Override
  57.     public void sendResponse(OpenSPCoop2Message msg, boolean consume) throws ConnectorException {
  58.         this.message = msg;
  59.     }

  60.     private DumpByteArrayOutputStream messageAsBytes;
  61.     public DumpByteArrayOutputStream getMessageAsBytes() {
  62.         return this.messageAsBytes;
  63.     }
  64.     @Override
  65.     public void sendResponse(DumpByteArrayOutputStream message) throws ConnectorException{
  66.         this.messageAsBytes = message;
  67.     }
  68.    
  69.     private OpenSPCoop2Message responseHeaderMessage;
  70.     public OpenSPCoop2Message getResponseHeaderMessage() {
  71.         return this.responseHeaderMessage;
  72.     }
  73.     @Override
  74.     public void sendResponseHeaders(OpenSPCoop2Message message) throws ConnectorException{
  75.         this.responseHeaderMessage = message;
  76.     }
  77.    
  78.     private Map<String, List<String>> headers = new HashMap<>();
  79.     public List<String> getHeaderValues(String key) throws ConnectorException{
  80.         return TransportUtils.getRawObject(this.headers,key);
  81.     }
  82.     public Map<String,  List<String>> getHeaders(){
  83.         Map<String,  List<String>> pH = new HashMap<String,  List<String>>();
  84.         pH.putAll(this.headers);
  85.         return pH;
  86.     }
  87.     @Override
  88.     public void setHeader(String key,String value) throws ConnectorException{
  89.         try{
  90.             TransportUtils.setHeader(this.headers, key,value);
  91.         }catch(Exception e){
  92.             throw new ConnectorException(e.getMessage(),e);
  93.         }
  94.     }
  95.     @Override
  96.     public void addHeader(String key,String value) throws ConnectorException{
  97.         try{
  98.             TransportUtils.addHeader(this.headers, key,value);
  99.         }catch(Exception e){
  100.             throw new ConnectorException(e.getMessage(),e);
  101.         }
  102.     }
  103.    
  104.     private int length;
  105.     public int getContentLength() {
  106.         return this.length;
  107.     }
  108.     @Override
  109.     public void setContentLength(int length) throws ConnectorException{
  110.         this.length = length;
  111.     }
  112.    
  113.     String type;
  114.     public String getContentType() {
  115.         return this.type;
  116.     }
  117.     @Override
  118.     public void setContentType(String type) throws ConnectorException{
  119.         this.type = type;
  120.     }
  121.    
  122.     private int status = 200;
  123.     @Override
  124.     public void setStatus(int status) throws ConnectorException{
  125.         this.status = status;
  126.     }
  127.     @Override
  128.     public int getResponseStatus() throws ConnectorException{
  129.         return this.status;
  130.     }
  131.    
  132.     @Override
  133.     public void flush(boolean throwException) throws ConnectorException{
  134.         // nop
  135.     }
  136.    
  137.     @Override
  138.     public void close(boolean throwException) throws ConnectorException{
  139.         // nop
  140.     }
  141. }