// Path: src/main/java/com/cisco/cta/taxii/adapter/httpclient/HttpBodyWriter.java
// public class HttpBodyWriter {
// 
//     private static final String UTF_8 = "UTF-8";
// 
//     private final Configuration cfg;
//     private final Template template;
//     private final Template templateFulfillment;
// 
//     public HttpBodyWriter() throws IOException {
//         cfg = new Configuration(new Version(2, 3, 21));
//         cfg.setDefaultEncoding(UTF_8);
//         cfg.setTemplateLoader(new ClassTemplateLoader(HttpBodyWriter.class, "templates"));
//         template = cfg.getTemplate("poll-request.ftl");
//         templateFulfillment = cfg.getTemplate("poll-fulfillment-request.ftl");
//     }
// 
//     /**
//      * Write the TAXII poll request to an {@link OutputStream}.
//      *
//      * @param messageId TAXII message id.
//      * @param feed The TAXII feed.
//      * @param body The {@link OutputStream} to write the body to.
//      * @throws Exception When any error occurs.
//      */
//     public void write(String messageId, TaxiiStatus.Feed feed, OutputStream body) throws Exception {
//         try (OutputStreamWriter out = new OutputStreamWriter(body, UTF_8)) {
//             Map<String, Object> data = new HashMap<>();
//             data.put("messageId", messageId);
//             data.put("collection", feed.getName());
//             XMLGregorianCalendar lastUpdate = getLastUpdate(feed);
//             if (lastUpdate != null) {
//                 data.put("begin", lastUpdate.toXMLFormat());
//             }
//             template.process(data, out);
//         }
//     }
// 
//     /**
//      * Write the TAXII poll fulfillment request to an {@link OutputStream}.
//      *
//      * @param messageId        TAXII message id.
//      * @param feed             The TAXII feed.
//      * @param resultId         result id.
//      * @param resultPartNumber result part number.
//      * @param body             The {@link OutputStream} to write the body to.
//      * @throws Exception When any error occurs.
//      */
//     public void write(String messageId, TaxiiStatus.Feed feed, String resultId, Integer resultPartNumber, OutputStream body) throws Exception {
//         try (OutputStreamWriter out = new OutputStreamWriter(body, UTF_8)) {
//             Map<String, Object> data = new HashMap<>();
//             data.put("messageId", messageId);
//             data.put("collection", feed.getName());
//             data.put("resultId", resultId);
//             data.put("resultPartNumber", resultPartNumber);
//             templateFulfillment.process(data, out);
//         }
//     }
// 
//     private XMLGregorianCalendar getLastUpdate(TaxiiStatus.Feed feed) {
//         if (feed != null && feed.getLastUpdate() != null) {
//             return feed.getLastUpdate();
//         } else {
//             return null;
//         }
//     }
// 
// }
// 
// Path: src/main/java/com/cisco/cta/taxii/adapter/httpclient/HttpHeadersAppender.java
// public class HttpHeadersAppender {
// 
//     public void appendTo(HttpHeaders headers) {
//         headers.setContentType(MediaType.APPLICATION_XML);
//         headers.setAccept(ImmutableList.of(MediaType.APPLICATION_XML));
//         headers.set("X-Taxii-Accept", "urn:taxii.mitre.org:message:xml:1.1");
//         headers.set("X-TAXII-Content-Type", "urn:taxii.mitre.org:message:xml:1.1");
//         headers.set("X-Taxii-Protocol", "urn:taxii.mitre.org:protocol:https:1.0");
//         headers.set("X-TAXII-Services", "urn:taxii.mitre.org:services:1.1");
//         headers.set("User-Agent", "taxii-log-adapter-" + Version.getImplVersion());
//     }
// 
// }
// 
// Path: src/main/java/com/cisco/cta/taxii/adapter/persistence/TaxiiStatus.java
// @Data
// @XmlRootElement(name="taxii-status")
// @XmlAccessorType(XmlAccessType.NONE)
// public class TaxiiStatus {
// 
//     @XmlElement
//     private final List<Feed> feed = new ArrayList<>();
//     
//     
//     /**
//      * JAXB annotated class holding consumption status of a single TAXII feed.
//      * @see TaxiiStatusDao
//      */
//     @Data
//     @XmlAccessorType(XmlAccessType.NONE)
//     public static class Feed {
//         
//         @XmlAttribute
//         private String name;
// 
//         @XmlAttribute
//         private XMLGregorianCalendar lastUpdate;
// 
//         @XmlAttribute
//         private Boolean more;
// 
//         @XmlAttribute
//         private String resultId;
// 
//         @XmlAttribute
//         private Integer resultPartNumber;
// 
//         @XmlAttribute
//         private Integer ioErrorCount;
// 
//     }
// }


import com.cisco.cta.taxii.adapter.httpclient.HttpBodyWriter;
import com.cisco.cta.taxii.adapter.httpclient.HttpHeadersAppender;
import com.cisco.cta.taxii.adapter.persistence.TaxiiStatus;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpRequestFactory;
import java.net.URL;
/*
   Copyright 2015 Cisco Systems

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

package com.cisco.cta.taxii.adapter;



/**
 * Factory to create complete TAXII requests.
 */
@AllArgsConstructor
public class RequestFactory {

    private final URL pollEndpoint;
    private final ClientHttpRequestFactory httpRequestFactory;
// Path: src/main/java/com/cisco/cta/taxii/adapter/httpclient/HttpBodyWriter.java
// public class HttpBodyWriter {
// 
//     private static final String UTF_8 = "UTF-8";
// 
//     private final Configuration cfg;
//     private final Template template;
//     private final Template templateFulfillment;
// 
//     public HttpBodyWriter() throws IOException {
//         cfg = new Configuration(new Version(2, 3, 21));
//         cfg.setDefaultEncoding(UTF_8);
//         cfg.setTemplateLoader(new ClassTemplateLoader(HttpBodyWriter.class, "templates"));
//         template = cfg.getTemplate("poll-request.ftl");
//         templateFulfillment = cfg.getTemplate("poll-fulfillment-request.ftl");
//     }
// 
//     /**
//      * Write the TAXII poll request to an {@link OutputStream}.
//      *
//      * @param messageId TAXII message id.
//      * @param feed The TAXII feed.
//      * @param body The {@link OutputStream} to write the body to.
//      * @throws Exception When any error occurs.
//      */
//     public void write(String messageId, TaxiiStatus.Feed feed, OutputStream body) throws Exception {
//         try (OutputStreamWriter out = new OutputStreamWriter(body, UTF_8)) {
//             Map<String, Object> data = new HashMap<>();
//             data.put("messageId", messageId);
//             data.put("collection", feed.getName());
//             XMLGregorianCalendar lastUpdate = getLastUpdate(feed);
//             if (lastUpdate != null) {
//                 data.put("begin", lastUpdate.toXMLFormat());
//             }
//             template.process(data, out);
//         }
//     }
// 
//     /**
//      * Write the TAXII poll fulfillment request to an {@link OutputStream}.
//      *
//      * @param messageId        TAXII message id.
//      * @param feed             The TAXII feed.
//      * @param resultId         result id.
//      * @param resultPartNumber result part number.
//      * @param body             The {@link OutputStream} to write the body to.
//      * @throws Exception When any error occurs.
//      */
//     public void write(String messageId, TaxiiStatus.Feed feed, String resultId, Integer resultPartNumber, OutputStream body) throws Exception {
//         try (OutputStreamWriter out = new OutputStreamWriter(body, UTF_8)) {
//             Map<String, Object> data = new HashMap<>();
//             data.put("messageId", messageId);
//             data.put("collection", feed.getName());
//             data.put("resultId", resultId);
//             data.put("resultPartNumber", resultPartNumber);
//             templateFulfillment.process(data, out);
//         }
//     }
// 
//     private XMLGregorianCalendar getLastUpdate(TaxiiStatus.Feed feed) {
//         if (feed != null && feed.getLastUpdate() != null) {
//             return feed.getLastUpdate();
//         } else {
//             return null;
//         }
//     }
// 
// }
// 
// Path: src/main/java/com/cisco/cta/taxii/adapter/httpclient/HttpHeadersAppender.java
// public class HttpHeadersAppender {
// 
//     public void appendTo(HttpHeaders headers) {
//         headers.setContentType(MediaType.APPLICATION_XML);
//         headers.setAccept(ImmutableList.of(MediaType.APPLICATION_XML));
//         headers.set("X-Taxii-Accept", "urn:taxii.mitre.org:message:xml:1.1");
//         headers.set("X-TAXII-Content-Type", "urn:taxii.mitre.org:message:xml:1.1");
//         headers.set("X-Taxii-Protocol", "urn:taxii.mitre.org:protocol:https:1.0");
//         headers.set("X-TAXII-Services", "urn:taxii.mitre.org:services:1.1");
//         headers.set("User-Agent", "taxii-log-adapter-" + Version.getImplVersion());
//     }
// 
// }
// 
// Path: src/main/java/com/cisco/cta/taxii/adapter/persistence/TaxiiStatus.java
// @Data
// @XmlRootElement(name="taxii-status")
// @XmlAccessorType(XmlAccessType.NONE)
// public class TaxiiStatus {
// 
//     @XmlElement
//     private final List<Feed> feed = new ArrayList<>();
//     
//     
//     /**
//      * JAXB annotated class holding consumption status of a single TAXII feed.
//      * @see TaxiiStatusDao
//      */
//     @Data
//     @XmlAccessorType(XmlAccessType.NONE)
//     public static class Feed {
//         
//         @XmlAttribute
//         private String name;
// 
//         @XmlAttribute
//         private XMLGregorianCalendar lastUpdate;
// 
//         @XmlAttribute
//         private Boolean more;
// 
//         @XmlAttribute
//         private String resultId;
// 
//         @XmlAttribute
//         private Integer resultPartNumber;
// 
//         @XmlAttribute
//         private Integer ioErrorCount;
// 
//     }
// }


// Path: src/main/java/com/cisco/cta/taxii/adapter/RequestFactory.java
import com.cisco.cta.taxii.adapter.httpclient.HttpBodyWriter;
import com.cisco.cta.taxii.adapter.httpclient.HttpHeadersAppender;
import com.cisco.cta.taxii.adapter.persistence.TaxiiStatus;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpRequestFactory;
import java.net.URL;

/*
   Copyright 2015 Cisco Systems

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

package com.cisco.cta.taxii.adapter;



/**
 * Factory to create complete TAXII requests.
 */
@AllArgsConstructor
public class RequestFactory {

    private final URL pollEndpoint;
    private final ClientHttpRequestFactory httpRequestFactory;
    private final HttpHeadersAppender httpHeadersAppender;