Example usage for org.apache.http.nio.entity FileNIOEntity FileNIOEntity

List of usage examples for org.apache.http.nio.entity FileNIOEntity FileNIOEntity

Introduction

In this page you can find the example usage for org.apache.http.nio.entity FileNIOEntity FileNIOEntity.

Prototype

public FileNIOEntity(final File file, final String contentType) 

Source Link

Usage

From source file:io.fabric8.itests.basic.FabricMavenProxyTest.java

@Test
public void testUpload() throws Exception {
    String featureLocation = System.getProperty("feature.location");
    System.out.println("Testing with feature from:" + featureLocation);
    System.err.println(executeCommand("fabric:create -n"));
    Set<Container> containers = ContainerBuilder.create(2).withName("maven").withProfiles("fabric")
            .assertProvisioningResult().build();
    try {/*from w  ww. j a  v a 2 s  . c  o m*/
        List<String> uploadUrls = new ArrayList<String>();
        ServiceProxy<CuratorFramework> curatorProxy = ServiceProxy.createServiceProxy(bundleContext,
                CuratorFramework.class);
        try {
            CuratorFramework curator = curatorProxy.getService();
            List<String> children = ZooKeeperUtils.getChildren(curator, ZkPath.MAVEN_PROXY.getPath("upload"));
            for (String child : children) {
                String uploadeUrl = ZooKeeperUtils.getSubstitutedPath(curator,
                        ZkPath.MAVEN_PROXY.getPath("upload") + "/" + child);
                uploadUrls.add(uploadeUrl);
            }
        } finally {
            curatorProxy.close();
        }
        //Pick a random maven proxy from the list.
        Random random = new Random();
        int index = random.nextInt(uploadUrls.size());
        String targetUrl = uploadUrls.get(index);

        String uploadUrl = targetUrl + "itest/itest/1.0/itest-1.0-features.xml";
        System.out.println("Using URI: " + uploadUrl);
        DefaultHttpClient client = new DefaultHttpClient();
        HttpPut put = new HttpPut(uploadUrl);
        client.getCredentialsProvider().setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials("admin", "admin"));

        FileNIOEntity entity = new FileNIOEntity(new File(featureLocation), "text/xml");
        put.setEntity(entity);
        HttpResponse response = client.execute(put);
        System.err.println("Response:" + response.getStatusLine());
        Assert.assertTrue(response.getStatusLine().getStatusCode() == 200
                || response.getStatusLine().getStatusCode() == 202);

        System.err.println(
                executeCommand("fabric:profile-edit --repositories mvn:itest/itest/1.0/xml/features default"));
        System.err.println(executeCommand("fabric:profile-edit --features example-cbr default"));
        Provision.containerStatus(containers, PROVISION_TIMEOUT);
    } finally {
        ContainerBuilder.destroy(containers);
    }
}

From source file:org.fusesource.fabric.itests.paxexam.FabricMavenProxyTest.java

@Test
public void testUpload() throws Exception {
    String featureLocation = System.getProperty("feature.location");
    System.out.println("Testing with feature from:" + featureLocation);
    System.err.println(executeCommand("fabric:create -n"));
    Set<Container> containers = ContainerBuilder.create(2).withName("maven").withProfiles("fabric")
            .assertProvisioningResult().build();

    FabricService fabricService = getFabricService();
    CuratorFramework curator = getCurator();
    List<String> children = getChildren(curator, ZkPath.MAVEN_PROXY.getPath("upload"));
    List<String> uploadUrls = new ArrayList<String>();
    for (String child : children) {
        String uploadeUrl = getSubstitutedPath(curator, ZkPath.MAVEN_PROXY.getPath("upload") + "/" + child);
        uploadUrls.add(uploadeUrl);//  w w w. j  a v  a 2  s .  co  m
    }
    //Pick a random maven proxy from the list.
    Random random = new Random();
    int index = random.nextInt(uploadUrls.size());
    String targetUrl = uploadUrls.get(index);

    String uploadUrl = targetUrl + "itest/itest/1.0/itest-1.0-features.xml";
    System.out.println("Using URI: " + uploadUrl);
    DefaultHttpClient client = new DefaultHttpClient();
    HttpPut put = new HttpPut(uploadUrl);
    client.getCredentialsProvider().setCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials("admin", "admin"));

    FileNIOEntity entity = new FileNIOEntity(new File(featureLocation), "text/xml");
    put.setEntity(entity);
    HttpResponse response = client.execute(put);
    System.err.println("Response:" + response.getStatusLine());
    Assert.assertTrue(
            response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 202);

    System.err.println(
            executeCommand("fabric:profile-edit --repositories mvn:itest/itest/1.0/xml/features default"));
    System.err.println(executeCommand("fabric:profile-edit --features example-cbr default"));
    Provision.waitForContainerStatus(containers, PROVISION_TIMEOUT);
}

From source file:org.fusesource.fabric.itests.smoke.FabricMavenProxyTest.java

@Test
public void testUpload() throws Exception {
    String featureLocation = System.getProperty("feature.location");
    System.out.println("Testing with feature from:" + featureLocation);
    System.err.println(executeCommand("fabric:create -n"));
    Set<Container> containers = ContainerBuilder.create(2).withName("maven").withProfiles("fabric")
            .assertProvisioningResult().build();

    FabricService fabricService = getFabricService();
    CuratorFramework curator = getCurator();
    List<String> children = getChildren(curator, ZkPath.MAVEN_PROXY.getPath("upload"));
    List<String> uploadUrls = new ArrayList<String>();
    for (String child : children) {
        String uploadeUrl = getSubstitutedPath(curator, ZkPath.MAVEN_PROXY.getPath("upload") + "/" + child);
        uploadUrls.add(uploadeUrl);//from   w w w  .j a va 2s . co m
    }
    //Pick a random maven proxy from the list.
    Random random = new Random();
    int index = random.nextInt(uploadUrls.size());
    String targetUrl = uploadUrls.get(index);

    String uploadUrl = targetUrl + "itest/itest/1.0/itest-1.0-features.xml";
    System.out.println("Using URI: " + uploadUrl);
    DefaultHttpClient client = new DefaultHttpClient();
    HttpPut put = new HttpPut(uploadUrl);
    client.getCredentialsProvider().setCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials("admin", "admin"));

    FileNIOEntity entity = new FileNIOEntity(new File(featureLocation), "text/xml");
    put.setEntity(entity);
    HttpResponse response = client.execute(put);
    System.err.println("Response:" + response.getStatusLine());
    Assert.assertTrue(
            response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 202);

    System.err.println(
            executeCommand("fabric:profile-edit --repositories mvn:itest/itest/1.0/xml/features default"));
    System.err.println(executeCommand("fabric:profile-edit --features example-cbr default"));
    Provision.containerStatus(containers, PROVISION_TIMEOUT);
}

From source file:io.fabric8.itests.paxexam.basic.FabricMavenProxyTest.java

@Test
public void testUpload() throws Exception {
    String featureLocation = System.getProperty("feature.location");
    System.out.println("Testing with feature from:" + featureLocation);
    System.out.println(executeCommand("fabric:create -n --wait-for-provisioning"));
    //System.out.println(executeCommand("shell:info"));
    //System.out.println(executeCommand("fabric:info"));
    //System.out.println(executeCommand("fabric:profile-list"));

    ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(bundleContext,
            FabricService.class);
    try {//from   w ww  .ja va 2s  .  c  o m
        Set<ContainerProxy> containers = ContainerBuilder.create(fabricProxy, 2).withName("maven")
                .withProfiles("fabric").assertProvisioningResult().build();
        try {
            List<String> uploadUrls = new ArrayList<String>();
            ServiceProxy<CuratorFramework> curatorProxy = ServiceProxy.createServiceProxy(bundleContext,
                    CuratorFramework.class);
            try {
                CuratorFramework curator = curatorProxy.getService();
                List<String> children = ZooKeeperUtils.getChildren(curator,
                        ZkPath.MAVEN_PROXY.getPath("upload"));
                for (String child : children) {
                    String uploadeUrl = ZooKeeperUtils.getSubstitutedPath(curator,
                            ZkPath.MAVEN_PROXY.getPath("upload") + "/" + child);
                    uploadUrls.add(uploadeUrl);
                }
            } finally {
                curatorProxy.close();
            }
            //Pick a random maven proxy from the list.
            Random random = new Random();
            int index = random.nextInt(uploadUrls.size());
            String targetUrl = uploadUrls.get(index);

            String uploadUrl = targetUrl + "itest/itest/1.0/itest-1.0-features.xml";
            System.out.println("Using URI: " + uploadUrl);
            DefaultHttpClient client = new DefaultHttpClient();
            HttpPut put = new HttpPut(uploadUrl);
            client.getCredentialsProvider().setCredentials(AuthScope.ANY,
                    new UsernamePasswordCredentials("admin", "admin"));

            FileNIOEntity entity = new FileNIOEntity(new File(featureLocation), "text/xml");
            put.setEntity(entity);
            HttpResponse response = client.execute(put);
            System.out.println("Response:" + response.getStatusLine());
            Assert.assertTrue(response.getStatusLine().getStatusCode() == 200
                    || response.getStatusLine().getStatusCode() == 202);

            System.out.println(executeCommand(
                    "fabric:profile-edit --repositories mvn:itest/itest/1.0/xml/features default"));
            System.out.println(executeCommand("fabric:profile-edit --features example-cbr default"));
            Provision.containerStatus(containers, PROVISION_TIMEOUT);
        } finally {
            ContainerBuilder.destroy(containers);
        }
    } finally {
        fabricProxy.close();
    }
}