// Path: src/main/java/org/kopi/ebics/interfaces/ContentFactory.java
// public interface ContentFactory extends Serializable {
// 
//   /**
//    * Returns a new data source of the data to be sent.
//    * The instance must ensure that the returned stream will
//    * deliver the identical data during the lifetime of this instance.
//    * Nevertheless how often the method will be called.
//    * @return a new data source of the data to be sent.
//    * @throws IOException
//    */
//   public InputStream getContent() throws IOException;
// }
// 
// Path: src/main/java/org/kopi/ebics/session/EbicsSession.java
// public class EbicsSession {
// 
//   /**
//    * Constructs a new ebics session
//    * @param user the ebics user
//    * @param the ebics client configuration
//    */
//   public EbicsSession(EbicsUser user, Configuration configuration) {
//     this.user = user;
//     this.configuration = configuration;
//     parameters = new HashMap<String, String>();
//   }
// 
//   /**
//    * Returns the banks encryption key.
//    * The key will be fetched automatically form the bank if needed.
//    * @return the banks encryption key.
//    * @throws IOException Communication error during key retrieval.
//    * @throws EbicsException Server error message generated during key retrieval.
//    */
//   public RSAPublicKey getBankE002Key() throws IOException, EbicsException {
//     return user.getPartner().getBank().getE002Key();
//   }
// 
//   /**
//    * Returns the banks authentication key.
//    * The key will be fetched automatically form the bank if needed.
//    * @return the banks authentication key.
//    * @throws IOException Communication error during key retrieval.
//    * @throws EbicsException Server error message generated during key retrieval.
//    */
//   public RSAPublicKey getBankX002Key() throws IOException, EbicsException {
//     return user.getPartner().getBank().getX002Key();
//   }
// 
//   /**
//    * Returns the bank id.
//    * @return the bank id.
//    * @throws EbicsException
//    */
//   public String getBankID() throws EbicsException {
//     return user.getPartner().getBank().getHostId();
//   }
// 
//   /**
//    * Return the session user.
//    * @return the session user.
//    */
//   public EbicsUser getUser() {
//     return user;
//   }
// 
//   /**
//    * Returns the client application configuration.
//    * @return the client application configuration.
//    */
//   public Configuration getConfiguration() {
//     return configuration;
//   }
// 
//   /**
//    * Sets the optional product identification that will be sent to the bank during each request.
//    * @param product Product description
//    */
//   public void setProduct(Product product) {
//     this.product = product;
//   }
// 
//   /**
//    * @return the product
//    */
//   public Product getProduct() {
//     return product;
//   }
// 
//   /**
//    * Adds a session parameter to use it in the transfer process.
//    * @param key the parameter key
//    * @param value the parameter value
//    */
//   public void addSessionParam(String key, String value) {
//     parameters.put(key, value);
//   }
// 
//   /**
//    * Retrieves a session parameter using its key.
//    * @param key the parameter key
//    * @return the session parameter
//    */
//   public String getSessionParam(String key) {
//     if (key == null) {
//       return null;
//     }
// 
//     return parameters.get(key);
//   }
// 
//   // --------------------------------------------------------------------
//   // DATA MEMBERS
//   // --------------------------------------------------------------------
// 
//   private EbicsUser				user;
//   private Configuration 			configuration;
//   private Product				product;
//   private Map<String, String>			parameters;
// }


import org.kopi.ebics.io.InputStreamContentFactory;
import org.kopi.ebics.session.EbicsSession;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.kopi.ebics.interfaces.ContentFactory;
/*
 * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * $Id$
 */

package org.kopi.ebics.client;




/**
 * A simple HTTP request sender and receiver.
 * The send returns a HTTP code that should be analyzed
 * before proceeding ebics request response parse.
 *
 * @author hachani
 *
 */
public class HttpRequestSender {

  /**
   * Constructs a new <code>HttpRequestSender</code> with a
   * given ebics session.
   * @param session the ebics session
   */
  public HttpRequestSender(EbicsSession session) {
    this.session = session;
  }

  /**
   * Sends the request contained in the <code>ContentFactory</code>.
   * The <code>ContentFactory</code> will deliver the request as
   * an <code>InputStream</code>.
   *
   * @param request the ebics request
   * @return the HTTP return code
   */
// Path: src/main/java/org/kopi/ebics/interfaces/ContentFactory.java
// public interface ContentFactory extends Serializable {
// 
//   /**
//    * Returns a new data source of the data to be sent.
//    * The instance must ensure that the returned stream will
//    * deliver the identical data during the lifetime of this instance.
//    * Nevertheless how often the method will be called.
//    * @return a new data source of the data to be sent.
//    * @throws IOException
//    */
//   public InputStream getContent() throws IOException;
// }
// 
// Path: src/main/java/org/kopi/ebics/session/EbicsSession.java
// public class EbicsSession {
// 
//   /**
//    * Constructs a new ebics session
//    * @param user the ebics user
//    * @param the ebics client configuration
//    */
//   public EbicsSession(EbicsUser user, Configuration configuration) {
//     this.user = user;
//     this.configuration = configuration;
//     parameters = new HashMap<String, String>();
//   }
// 
//   /**
//    * Returns the banks encryption key.
//    * The key will be fetched automatically form the bank if needed.
//    * @return the banks encryption key.
//    * @throws IOException Communication error during key retrieval.
//    * @throws EbicsException Server error message generated during key retrieval.
//    */
//   public RSAPublicKey getBankE002Key() throws IOException, EbicsException {
//     return user.getPartner().getBank().getE002Key();
//   }
// 
//   /**
//    * Returns the banks authentication key.
//    * The key will be fetched automatically form the bank if needed.
//    * @return the banks authentication key.
//    * @throws IOException Communication error during key retrieval.
//    * @throws EbicsException Server error message generated during key retrieval.
//    */
//   public RSAPublicKey getBankX002Key() throws IOException, EbicsException {
//     return user.getPartner().getBank().getX002Key();
//   }
// 
//   /**
//    * Returns the bank id.
//    * @return the bank id.
//    * @throws EbicsException
//    */
//   public String getBankID() throws EbicsException {
//     return user.getPartner().getBank().getHostId();
//   }
// 
//   /**
//    * Return the session user.
//    * @return the session user.
//    */
//   public EbicsUser getUser() {
//     return user;
//   }
// 
//   /**
//    * Returns the client application configuration.
//    * @return the client application configuration.
//    */
//   public Configuration getConfiguration() {
//     return configuration;
//   }
// 
//   /**
//    * Sets the optional product identification that will be sent to the bank during each request.
//    * @param product Product description
//    */
//   public void setProduct(Product product) {
//     this.product = product;
//   }
// 
//   /**
//    * @return the product
//    */
//   public Product getProduct() {
//     return product;
//   }
// 
//   /**
//    * Adds a session parameter to use it in the transfer process.
//    * @param key the parameter key
//    * @param value the parameter value
//    */
//   public void addSessionParam(String key, String value) {
//     parameters.put(key, value);
//   }
// 
//   /**
//    * Retrieves a session parameter using its key.
//    * @param key the parameter key
//    * @return the session parameter
//    */
//   public String getSessionParam(String key) {
//     if (key == null) {
//       return null;
//     }
// 
//     return parameters.get(key);
//   }
// 
//   // --------------------------------------------------------------------
//   // DATA MEMBERS
//   // --------------------------------------------------------------------
// 
//   private EbicsUser				user;
//   private Configuration 			configuration;
//   private Product				product;
//   private Map<String, String>			parameters;
// }


// Path: src/main/java/org/kopi/ebics/client/HttpRequestSender.java
import org.kopi.ebics.io.InputStreamContentFactory;
import org.kopi.ebics.session.EbicsSession;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.kopi.ebics.interfaces.ContentFactory;

/*
 * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * $Id$
 */

package org.kopi.ebics.client;




/**
 * A simple HTTP request sender and receiver.
 * The send returns a HTTP code that should be analyzed
 * before proceeding ebics request response parse.
 *
 * @author hachani
 *
 */
public class HttpRequestSender {

  /**
   * Constructs a new <code>HttpRequestSender</code> with a
   * given ebics session.
   * @param session the ebics session
   */
  public HttpRequestSender(EbicsSession session) {
    this.session = session;
  }

  /**
   * Sends the request contained in the <code>ContentFactory</code>.
   * The <code>ContentFactory</code> will deliver the request as
   * an <code>InputStream</code>.
   *
   * @param request the ebics request
   * @return the HTTP return code
   */
  public final int send(ContentFactory request) throws IOException {