// Path: src/main/java/com/cisco/cta/taxii/adapter/RequestFactory.java
// @AllArgsConstructor
// public class RequestFactory {
// 
//     private final URL pollEndpoint;
//     private final ClientHttpRequestFactory httpRequestFactory;
//     private final HttpHeadersAppender httpHeadersAppender;
//     private final HttpBodyWriter httpBodyWriter;
// 
// 
//     /**
//      * Create the TAXII request.
//      *
//      * @param messageId TAXII message id.
//      * @param feed The TAXII feed.
//      * @return TAXII poll request.
//      * @throws Exception When any error occurs.
//      */
//     public ClientHttpRequest createPollRequest(String messageId, TaxiiStatus.Feed feed) throws Exception {
//         ClientHttpRequest req = httpRequestFactory.createRequest(pollEndpoint.toURI(), HttpMethod.POST);
//         httpHeadersAppender.appendTo(req.getHeaders());
//         httpBodyWriter.write(messageId, feed, req.getBody());
//         return req;
//     }
// 
//     /**
//      * Create the TAXII request.
//      *
//      * @param messageId TAXII message id.
//      * @param feed The TAXII feed name.
//      * @param resultId TAXII result id.
//      * @param resultPartNumber TAXII result part number.
//      * @return TAXII poll request.
//      * @throws Exception When any error occurs.
//      */
//     public ClientHttpRequest createFulfillmentRequest(String messageId, TaxiiStatus.Feed feed, String resultId, Integer resultPartNumber) throws Exception {
//         ClientHttpRequest req = httpRequestFactory.createRequest(pollEndpoint.toURI(), HttpMethod.POST);
//         httpHeadersAppender.appendTo(req.getHeaders());
//         httpBodyWriter.write(messageId, feed, resultId, resultPartNumber, req.getBody());
//         return req;
//     }
// 
// }
// 
// Path: src/main/java/com/cisco/cta/taxii/adapter/persistence/TaxiiStatusDao.java
// public class TaxiiStatusDao {
// 
//     private static final Logger LOG = LoggerFactory.getLogger(TaxiiStatusDao.class);
//     
//     private final TaxiiStatusFileHandler fileHandler;
//     private TaxiiStatus dirtyStatus;
// 
//     public TaxiiStatusDao(TaxiiStatusFileHandler fileHandler) {
//         this.fileHandler = fileHandler;
//         dirtyStatus = fileHandler.load();
//         if (dirtyStatus == null) {
//             LOG.warn("TAXII status file not found, all feeds will be fully downloaded");
//             dirtyStatus = new TaxiiStatus();
//         } else {
//             LOG.debug("TAXII status file loaded: {}", dirtyStatus);
//         }
//     }
// 
//     public Feed find(String feedName) {
//         for (Feed feed : dirtyStatus.getFeed()) {
//             if (feed.getName().equals(feedName)) {
//                 return feed;
//             }
//         }
//         return null;
//     }
// 
//     public synchronized void updateOrAdd(Feed feed) {
//         Feed savedFeed = find(feed.getName());
//         if (savedFeed != null) {
//             savedFeed.setMore(feed.getMore());
//             savedFeed.setResultId(feed.getResultId());
//             savedFeed.setResultPartNumber(feed.getResultPartNumber());
//             savedFeed.setLastUpdate(feed.getLastUpdate());
//         } else {
//             dirtyStatus.getFeed().add(feed);
//         }
//         fileHandler.save(dirtyStatus);
//     }
// 
// }
// 
// Path: src/main/java/com/cisco/cta/taxii/adapter/settings/ProxySettings.java
// @ConfigurationProperties(prefix="proxy")
// @Data
// public class ProxySettings {
// 
//     private URL url;
// 
//     private ProxyAuthenticationType authenticationType;
// 
//     private String domain;
// 
//     private String username;
// 
//     private String password;
// 
//     private String workstation;
// 
// }
// 
// Path: src/main/java/com/cisco/cta/taxii/adapter/settings/TaxiiServiceSettings.java
// @ConfigurationProperties(prefix="taxii-service")
// @Data
// @Validated
// public class TaxiiServiceSettings {
// 
//     private static final Charset UTF8 = Charset.forName("UTF-8");
// 
//     @NotNull
//     private URL pollEndpoint;
// 
//     @NotNull
//     private String username;
// 
//     @NotNull
//     private String password;
// 
//     private List<String> feeds;
// 
//     private File feedNamesFile;
// 
//     private File statusFile = new File("taxii-status.xml");
// 
//     @PostConstruct
//     public void loadFeedNames() throws IOException {
//         Preconditions.checkState(
//             feeds != null ^ feedNamesFile != null,
//             "taxii-service.feeds or taxii-service.feedNamesFile must be set");
//         if (feedNamesFile != null) {
//             feeds = Files.readLines(feedNamesFile, UTF8);
//         }
//     }
// }


import com.cisco.cta.taxii.adapter.RequestFactory;
import com.cisco.cta.taxii.adapter.persistence.TaxiiStatusDao;
import com.cisco.cta.taxii.adapter.settings.ProxySettings;
import com.cisco.cta.taxii.adapter.settings.TaxiiServiceSettings;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
/*
   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.httpclient;


@Configuration
public class HttpClientConfiguration {

    @Autowired
    private TaxiiServiceSettings taxiiServiceSettings;

    @Autowired
    private TaxiiStatusDao taxiiStatusDao;

    @Autowired
// Path: src/main/java/com/cisco/cta/taxii/adapter/RequestFactory.java
// @AllArgsConstructor
// public class RequestFactory {
// 
//     private final URL pollEndpoint;
//     private final ClientHttpRequestFactory httpRequestFactory;
//     private final HttpHeadersAppender httpHeadersAppender;
//     private final HttpBodyWriter httpBodyWriter;
// 
// 
//     /**
//      * Create the TAXII request.
//      *
//      * @param messageId TAXII message id.
//      * @param feed The TAXII feed.
//      * @return TAXII poll request.
//      * @throws Exception When any error occurs.
//      */
//     public ClientHttpRequest createPollRequest(String messageId, TaxiiStatus.Feed feed) throws Exception {
//         ClientHttpRequest req = httpRequestFactory.createRequest(pollEndpoint.toURI(), HttpMethod.POST);
//         httpHeadersAppender.appendTo(req.getHeaders());
//         httpBodyWriter.write(messageId, feed, req.getBody());
//         return req;
//     }
// 
//     /**
//      * Create the TAXII request.
//      *
//      * @param messageId TAXII message id.
//      * @param feed The TAXII feed name.
//      * @param resultId TAXII result id.
//      * @param resultPartNumber TAXII result part number.
//      * @return TAXII poll request.
//      * @throws Exception When any error occurs.
//      */
//     public ClientHttpRequest createFulfillmentRequest(String messageId, TaxiiStatus.Feed feed, String resultId, Integer resultPartNumber) throws Exception {
//         ClientHttpRequest req = httpRequestFactory.createRequest(pollEndpoint.toURI(), HttpMethod.POST);
//         httpHeadersAppender.appendTo(req.getHeaders());
//         httpBodyWriter.write(messageId, feed, resultId, resultPartNumber, req.getBody());
//         return req;
//     }
// 
// }
// 
// Path: src/main/java/com/cisco/cta/taxii/adapter/persistence/TaxiiStatusDao.java
// public class TaxiiStatusDao {
// 
//     private static final Logger LOG = LoggerFactory.getLogger(TaxiiStatusDao.class);
//     
//     private final TaxiiStatusFileHandler fileHandler;
//     private TaxiiStatus dirtyStatus;
// 
//     public TaxiiStatusDao(TaxiiStatusFileHandler fileHandler) {
//         this.fileHandler = fileHandler;
//         dirtyStatus = fileHandler.load();
//         if (dirtyStatus == null) {
//             LOG.warn("TAXII status file not found, all feeds will be fully downloaded");
//             dirtyStatus = new TaxiiStatus();
//         } else {
//             LOG.debug("TAXII status file loaded: {}", dirtyStatus);
//         }
//     }
// 
//     public Feed find(String feedName) {
//         for (Feed feed : dirtyStatus.getFeed()) {
//             if (feed.getName().equals(feedName)) {
//                 return feed;
//             }
//         }
//         return null;
//     }
// 
//     public synchronized void updateOrAdd(Feed feed) {
//         Feed savedFeed = find(feed.getName());
//         if (savedFeed != null) {
//             savedFeed.setMore(feed.getMore());
//             savedFeed.setResultId(feed.getResultId());
//             savedFeed.setResultPartNumber(feed.getResultPartNumber());
//             savedFeed.setLastUpdate(feed.getLastUpdate());
//         } else {
//             dirtyStatus.getFeed().add(feed);
//         }
//         fileHandler.save(dirtyStatus);
//     }
// 
// }
// 
// Path: src/main/java/com/cisco/cta/taxii/adapter/settings/ProxySettings.java
// @ConfigurationProperties(prefix="proxy")
// @Data
// public class ProxySettings {
// 
//     private URL url;
// 
//     private ProxyAuthenticationType authenticationType;
// 
//     private String domain;
// 
//     private String username;
// 
//     private String password;
// 
//     private String workstation;
// 
// }
// 
// Path: src/main/java/com/cisco/cta/taxii/adapter/settings/TaxiiServiceSettings.java
// @ConfigurationProperties(prefix="taxii-service")
// @Data
// @Validated
// public class TaxiiServiceSettings {
// 
//     private static final Charset UTF8 = Charset.forName("UTF-8");
// 
//     @NotNull
//     private URL pollEndpoint;
// 
//     @NotNull
//     private String username;
// 
//     @NotNull
//     private String password;
// 
//     private List<String> feeds;
// 
//     private File feedNamesFile;
// 
//     private File statusFile = new File("taxii-status.xml");
// 
//     @PostConstruct
//     public void loadFeedNames() throws IOException {
//         Preconditions.checkState(
//             feeds != null ^ feedNamesFile != null,
//             "taxii-service.feeds or taxii-service.feedNamesFile must be set");
//         if (feedNamesFile != null) {
//             feeds = Files.readLines(feedNamesFile, UTF8);
//         }
//     }
// }


// Path: src/main/java/com/cisco/cta/taxii/adapter/httpclient/HttpClientConfiguration.java
import com.cisco.cta.taxii.adapter.RequestFactory;
import com.cisco.cta.taxii.adapter.persistence.TaxiiStatusDao;
import com.cisco.cta.taxii.adapter.settings.ProxySettings;
import com.cisco.cta.taxii.adapter.settings.TaxiiServiceSettings;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;

/*
   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.httpclient;


@Configuration
public class HttpClientConfiguration {

    @Autowired
    private TaxiiServiceSettings taxiiServiceSettings;

    @Autowired
    private TaxiiStatusDao taxiiStatusDao;

    @Autowired
    private ProxySettings proxySettings;