/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sendfax;

//import com.sun.org.apache.xml.internal.serialize.OutputFormat;
//import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
//import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpState;
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;


/**
 *
 * @author test
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws ParserConfigurationException, IOException {
        // TODO code application logic here

        //Create an httpclient.
        HttpClient client = new HttpClient();

        HttpState state = client.getState();

        //Set credential with username and password
        Credentials credential = new UsernamePasswordCredentials("admin",
                    new String("admin"));

        state.setCredentials(AuthScope.ANY, credential);

        //Create post method.
        PostMethod post = new PostMethod("http://216.133.69.247/ffws/v1/ofax");

        //Load the 'schedule.xml' from disk.
        File input = new File("schedule.xml");

        //Set content-type.
        post.setRequestHeader("content-type", "application/xml");

        //Set the RequestEntity that contains an InputStream
        RequestEntity re = new InputStreamRequestEntity(new FileInputStream(input));

        //Connect FileInputStream with post.
        //post.setRequestBody(new FileInputStream(input));
        post.setRequestEntity(re);


        client.executeMethod(post);
         //Get the response from the server.
        System.out.println(post.getResponseBodyAsString());
        post.releaseConnection();

    }

}
