// Path: client-transport/src/main/java/com/nortal/jroad/client/service/XRoadDatabaseService.java
// public abstract class XRoadDatabaseService extends BaseXRoadDatabaseService {
// 
//   @Resource
//   protected XRoadConsumer xRoadConsumer;
//   @Resource
//   protected XRoadServiceConfigurationProvider xRoadServiceConfigurationProvider;
// 
//   @Override
//   protected XRoadConsumer getXRoadConsumer() {
//     return xRoadConsumer;
//   }
// 
//   @Override
//   protected XRoadServiceConfigurationProvider getXRoadServiceConfigurationProvider() {
//     return xRoadServiceConfigurationProvider;
//   }
// }
// 
// Path: common/src/main/java/com/nortal/jroad/model/XRoadAttachment.java
// public class XRoadAttachment implements InputStreamSource {
//   private String cid;
//   private DataHandler dataHandler;
// 
//   public XRoadAttachment(String cid, String contentType, byte[] data) {
//     this.cid = cid;
//     this.dataHandler = new DataHandler(new ByteArrayDataSource(contentType, data));
//   }
// 
//   public XRoadAttachment(String cid, DataHandler dataHandler) {
//     this.cid = cid;
//     this.dataHandler = dataHandler;
//   }
// 
//   public InputStream getInputStream() throws IOException {
//     return dataHandler.getInputStream();
//   }
// 
//   @Override
//   public String toString() {
//     return "cid:" + cid;
//   }
// 
//   public String getCid() {
//     return cid;
//   }
// 
//   public byte[] getData() throws IOException {
//     return FileCopyUtils.copyToByteArray(dataHandler.getInputStream());
//   }
// 
//   public String getContentType() {
//     return dataHandler.getContentType();
//   }
// 
//   public DataHandler getDataHandler() {
//     return dataHandler;
//   }
// 
// }


import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFactory;
import javax.xml.soap.SOAPMessage;
import javax.xml.transform.TransformerException;
import org.apache.xmlbeans.impl.util.Base64;
import org.springframework.stereotype.Service;
import org.springframework.ws.WebServiceMessage;
import org.w3c.dom.Node;
import com.nortal.jroad.client.exception.XRoadServiceConsumptionException;
import com.nortal.jroad.client.service.XRoadDatabaseService;
import com.nortal.jroad.client.service.callback.CustomCallback;
import com.nortal.jroad.client.treasury.database.TreasuryXRoadDatabase;
import com.nortal.jroad.client.treasury.types.ee.riik.xtee.treasury.producers.producer.treasury.SendDocumentRequestType;
import com.nortal.jroad.client.treasury.types.ee.riik.xtee.treasury.producers.producer.treasury.SendDocumentResponseType;
import com.nortal.jroad.model.XRoadAttachment;
import com.nortal.jroad.model.XRoadMessage;
import com.nortal.jroad.model.XmlBeansXRoadMessage;
import com.nortal.jroad.util.SOAPUtil;
package com.nortal.jroad.client.treasury;





/**
 * At the time of writing the implementation of this service on the treasury side does NOT conform to their WSDL nor the
 * X-tee specification in general, thus the client-side implementation also does NOT conform to the WSDL. Hopefully this
 * will change in the future, but until then PLEASE DO NOT USE this service as an example. Due to the fact, that there
 * is an element present outside "keha". Some hacking is required to make this work...
 * 
 * @author Dmitri Danilkin
 * @author Lauri Lättemäe <lauri.lattemae@nortal.com>
 */
@Service("treasuryXTeeService")
public class TreasuryXTeeServiceImpl extends XRoadDatabaseService implements TreasuryXTeeService {
  private static final String SEND_DOCUMENT = "sendDocument";
  private static final String VERSION = "v1";

  @Resource
  private TreasuryXRoadDatabase treasuryXRoadDatabase;

  public SendDocumentResponseType sendDocument(String uniqueId, String type, byte[] manus)
      throws XRoadServiceConsumptionException {
    SendDocumentRequestType kassaReq = SendDocumentRequestType.Factory.newInstance();

    kassaReq.setUniqueId(uniqueId);
    kassaReq.setType(type);
    kassaReq.setManus("".getBytes());

// Path: client-transport/src/main/java/com/nortal/jroad/client/service/XRoadDatabaseService.java
// public abstract class XRoadDatabaseService extends BaseXRoadDatabaseService {
// 
//   @Resource
//   protected XRoadConsumer xRoadConsumer;
//   @Resource
//   protected XRoadServiceConfigurationProvider xRoadServiceConfigurationProvider;
// 
//   @Override
//   protected XRoadConsumer getXRoadConsumer() {
//     return xRoadConsumer;
//   }
// 
//   @Override
//   protected XRoadServiceConfigurationProvider getXRoadServiceConfigurationProvider() {
//     return xRoadServiceConfigurationProvider;
//   }
// }
// 
// Path: common/src/main/java/com/nortal/jroad/model/XRoadAttachment.java
// public class XRoadAttachment implements InputStreamSource {
//   private String cid;
//   private DataHandler dataHandler;
// 
//   public XRoadAttachment(String cid, String contentType, byte[] data) {
//     this.cid = cid;
//     this.dataHandler = new DataHandler(new ByteArrayDataSource(contentType, data));
//   }
// 
//   public XRoadAttachment(String cid, DataHandler dataHandler) {
//     this.cid = cid;
//     this.dataHandler = dataHandler;
//   }
// 
//   public InputStream getInputStream() throws IOException {
//     return dataHandler.getInputStream();
//   }
// 
//   @Override
//   public String toString() {
//     return "cid:" + cid;
//   }
// 
//   public String getCid() {
//     return cid;
//   }
// 
//   public byte[] getData() throws IOException {
//     return FileCopyUtils.copyToByteArray(dataHandler.getInputStream());
//   }
// 
//   public String getContentType() {
//     return dataHandler.getContentType();
//   }
// 
//   public DataHandler getDataHandler() {
//     return dataHandler;
//   }
// 
// }


// Path: client-service/treasury/src/main/java/com/nortal/jroad/client/treasury/TreasuryXTeeServiceImpl.java
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFactory;
import javax.xml.soap.SOAPMessage;
import javax.xml.transform.TransformerException;
import org.apache.xmlbeans.impl.util.Base64;
import org.springframework.stereotype.Service;
import org.springframework.ws.WebServiceMessage;
import org.w3c.dom.Node;
import com.nortal.jroad.client.exception.XRoadServiceConsumptionException;
import com.nortal.jroad.client.service.XRoadDatabaseService;
import com.nortal.jroad.client.service.callback.CustomCallback;
import com.nortal.jroad.client.treasury.database.TreasuryXRoadDatabase;
import com.nortal.jroad.client.treasury.types.ee.riik.xtee.treasury.producers.producer.treasury.SendDocumentRequestType;
import com.nortal.jroad.client.treasury.types.ee.riik.xtee.treasury.producers.producer.treasury.SendDocumentResponseType;
import com.nortal.jroad.model.XRoadAttachment;
import com.nortal.jroad.model.XRoadMessage;
import com.nortal.jroad.model.XmlBeansXRoadMessage;
import com.nortal.jroad.util.SOAPUtil;

package com.nortal.jroad.client.treasury;





/**
 * At the time of writing the implementation of this service on the treasury side does NOT conform to their WSDL nor the
 * X-tee specification in general, thus the client-side implementation also does NOT conform to the WSDL. Hopefully this
 * will change in the future, but until then PLEASE DO NOT USE this service as an example. Due to the fact, that there
 * is an element present outside "keha". Some hacking is required to make this work...
 * 
 * @author Dmitri Danilkin
 * @author Lauri Lättemäe <lauri.lattemae@nortal.com>
 */
@Service("treasuryXTeeService")
public class TreasuryXTeeServiceImpl extends XRoadDatabaseService implements TreasuryXTeeService {
  private static final String SEND_DOCUMENT = "sendDocument";
  private static final String VERSION = "v1";

  @Resource
  private TreasuryXRoadDatabase treasuryXRoadDatabase;

  public SendDocumentResponseType sendDocument(String uniqueId, String type, byte[] manus)
      throws XRoadServiceConsumptionException {
    SendDocumentRequestType kassaReq = SendDocumentRequestType.Factory.newInstance();

    kassaReq.setUniqueId(uniqueId);
    kassaReq.setType(type);
    kassaReq.setManus("".getBytes());

    List<XRoadAttachment> attachments = new ArrayList<XRoadAttachment>();