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

import java.net.URI;
import java.net.URL;

import com.cisco.cta.taxii.adapter.persistence.TaxiiStatus;
import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpRequestFactory;

import com.cisco.cta.taxii.adapter.httpclient.HttpBodyWriter;
import com.cisco.cta.taxii.adapter.httpclient.HttpHeadersAppender;

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

    private final URI pollEndpoint;
    private final ClientHttpRequestFactory httpRequestFactory;
    private final HttpHeadersAppender httpHeadersAppender;
    private final HttpBodyWriter httpBodyWriter;

    public RequestFactory(
            URL pollEndpoint,
            ClientHttpRequestFactory httpRequestFactory,
            HttpHeadersAppender httpHeadersAppender,
            HttpBodyWriter httpBodyWriter
            ) throws Exception {
        this.pollEndpoint = pollEndpoint.toURI();
        this.httpRequestFactory = httpRequestFactory;
        this.httpHeadersAppender = httpHeadersAppender;
        this.httpBodyWriter = httpBodyWriter;
    }

    /**
     * Create the TAXII request.
     * 
     * @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, HttpMethod.POST);
        httpHeadersAppender.appendTo(req.getHeaders());
        httpBodyWriter.write(messageId, feed, req.getBody());
        return req;
    }

    /**
     * Create the TAXII request.
     *
     * @param feed The TAXII feed name.
     * @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, HttpMethod.POST);
        httpHeadersAppender.appendTo(req.getHeaders());
        httpBodyWriter.write(messageId, feed, resultId, resultPartNumber, req.getBody());
        return req;
    }

}

@@ -626,29 +626,8 @@
 r;%0A%0A
-import java.net.URI;%0A
 impo
@@ -643,16 +643,16 @@
 et.URL;%0A
+
 %0Aimport 
@@ -704,16 +704,52 @@
 Status;%0A
+%0Aimport lombok.AllArgsConstructor;%0A%0A
 import o
@@ -1092,16 +1092,36 @@
 ts.%0A */%0A
+@AllArgsConstructor%0A
 public c
@@ -1163,17 +1163,17 @@
 final UR
-I
+L
  pollEnd
@@ -1355,462 +1355,8 @@
 r;%0A%0A
-    public RequestFactory(%0A            URL pollEndpoint,%0A            ClientHttpRequestFactory httpRequestFactory,%0A            HttpHeadersAppender httpHeadersAppender,%0A            HttpBodyWriter httpBodyWriter%0A            ) throws Exception %7B%0A        this.pollEndpoint = pollEndpoint.toURI();%0A        this.httpRequestFactory = httpRequestFactory;%0A        this.httpHeadersAppender = httpHeadersAppender;%0A        this.httpBodyWriter = httpBodyWriter;%0A    %7D%0A
 %0A   
@@ -1703,32 +1703,40 @@
 est(pollEndpoint
+.toURI()
 , HttpMethod.POS
@@ -2212,32 +2212,32 @@
 ows Exception %7B%0A
-
         ClientHt
@@ -2297,16 +2297,24 @@
 Endpoint
+.toURI()
 , HttpMe

simplify class internals