Example usage for org.apache.http.entity FileEntity FileEntity

List of usage examples for org.apache.http.entity FileEntity FileEntity

Introduction

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

Prototype

public FileEntity(File file, ContentType contentType) 

Source Link

Usage

From source file:org.opencredo.cloud.storage.azure.rest.internal.XPathContainerListFactoryTest.java

@Test
public void testCreateContainersList() throws Exception {
    String fileName = getClass().getPackage().getName().replace('.', '/') + "/containerList.xml";
    URL resource = getClass().getClassLoader().getResource(fileName);

    assertNotNull("Unable to find file: " + fileName, resource);
    HttpEntity entity = new FileEntity(new File(resource.getFile()), null);
    List<String> containersList = factory.createContainerNamesList(entity);
    assertEquals("Incorrect amount of containers", 3, containersList.size());
    for (String containerName : containersList) {
        System.out.println("Container: " + containerName);
    }//from w  ww . j av  a  2s  .  c o m
}

From source file:com.yanzhenjie.andserver.sample.response.RequestFileHandler.java

@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context)
        throws HttpException, IOException {
    // You can according to the client param can also be downloaded.

    File file = new File(mFilePath);
    if (file.exists()) {
        response.setStatusCode(200);//w w w  . j  a v a  2s .  c  o  m

        long contentLength = file.length();
        response.setHeader("ContentLength", Long.toString(contentLength));
        response.setEntity(new FileEntity(file, HttpRequestParser.getMimeType(file.getName())));
    } else {
        response.setStatusCode(404);
        response.setEntity(new StringEntity(""));
    }
}

From source file:de.wdilab.coma.gui.extensions.RemoteRepo.java

public static boolean getRemoteConnection(String s, UUID uid) {

    UUID uuid;/* ww  w . ja  v  a  2s.  c o m*/
    String xslt_text;
    boolean is_stored = false;

    xslt_text = s.replaceAll("\"", "\\\"");
    xslt_text = xslt_text.replaceAll("\'", "\\\'");
    uuid = uid;

    try {
        File f = new File("helpingFile.csv");
        PrintWriter output = new PrintWriter(new FileWriter(f));
        output.println("uuid,data");
        xslt_text.trim();
        xslt_text = xslt_text.replace("\n", "").replace("\r", "");
        output.println(uuid + "," + xslt_text);
        output.close();

        HttpClient client = new DefaultHttpClient();
        FileEntity entity = new FileEntity(f, ContentType.create("text/plain", "UTF-8"));

        HttpPost httppost = new HttpPost(url);
        httppost.setEntity(entity);
        HttpResponse response = client.execute(httppost);
        //            System.out.println(response.getStatusLine().getStatusCode());
        if (response.getStatusLine().getStatusCode() == 200)
            is_stored = true;
        f.delete();
    } catch (IOException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }

    //        System.out.println("xslt stored   "+is_stored);

    return is_stored;

}

From source file:org.opencredo.cloud.storage.azure.rest.internal.XPathContainerObjectListFactoryTest.java

@Test
public void testCreateContainersList() throws Exception {
    String fileName = getClass().getPackage().getName().replace('.', '/') + "/containerObjectList.xml";
    URL resource = getClass().getClassLoader().getResource(fileName);

    assertNotNull("Unable to find file: " + fileName, resource);
    HttpEntity entity = new FileEntity(new File(resource.getFile()), null);
    List<BlobDetails> containersList = factory.createContainerObjectDetailsList("container1", entity);
    assertEquals("Incorrect amount of container objects", 2, containersList.size());
}

From source file:com.autonomy.nonaci.indexing.impl.PostDataImpl.java

public PostDataImpl(final File file, final String contentType) {
    this.httpEntity = new FileEntity(file, ContentType.create(contentType));
}

From source file:com.autonomy.nonaci.indexing.impl.PostDataImpl.java

public PostDataImpl(final File file, final ContentType contentType) {
    this.httpEntity = new FileEntity(file, contentType);
}

From source file:org.fedoraproject.copr.client.impl.HttpMock.java

@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context)
        throws HttpException, IOException {
    String uri = request.getRequestLine().getUri();
    String resourceName;//from  w ww .ja  v  a2s.  c  o  m

    try {
        String method = request.getRequestLine().getMethod();
        if (method.equals("GET")) {
            resourceName = test.getMock().get(uri);
        } else if (method.equals("POST")) {
            resourceName = test.getMock().post(uri);
        } else {
            fail("Unexpected method: " + method);
            throw new RuntimeException();
        }

        if (resourceName == null) {
            response.setStatusCode(SC_NOT_FOUND);
        } else {
            Path resourcePath = Paths.get("src/test/resources").resolve(resourceName + ".json");
            response.setStatusCode(SC_OK);
            response.setEntity(new FileEntity(resourcePath.toFile(), APPLICATION_JSON));
        }
    } catch (Exception e) {
        response.setStatusCode(SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:org.Cherry.Modules.Web.Engine.FileRequestHandler.java

@Override
public void handle(final RequestCommand command) throws HttpException, IOException {
    final File file = getFile(command.getUri());

    if (!file.exists())
        throw new IllegalArgumentException(
                "File [" + file.getAbsolutePath() + "] not found, is missing or bad named!");
    if (!file.canRead() || file.isDirectory())
        throw new IllegalArgumentException(
                "File [" + file.getAbsolutePath() + "] can't be read or it is a directory!");

    debug("Serving file [{}]", file.getPath());

    command.getResponse().setStatusCode(HttpStatus.SC_OK);
    command.getResponse().setEntity(new FileEntity(file, getFor(command.getUri())));
}

From source file:com.sonatype.nexus.perftest.maven.ArtifactDeployer.java

/**
 * Deploys provided file under specified groupId, artifactId and version with packaging=jar.
 *///from ww w.j  av a  2  s.  co  m
public void deployJar(String groupId, String artifactId, String version, File jar) throws IOException {
    HttpEntity jarEntity = new FileEntity(jar, ContentType.DEFAULT_BINARY);
    deploy(jarEntity, groupId, artifactId, version, ".jar");
}

From source file:cn.aofeng.demo.httpclient.HttpClientBasic.java

public void sendFile(String filePath) throws UnsupportedOperationException, IOException {
    CloseableHttpClient client = HttpClients.createDefault();
    HttpPost post = new HttpPost(_targetHost + "/file");
    File file = new File(filePath);
    FileEntity entity = new FileEntity(file,
            ContentType.create(ContentType.TEXT_PLAIN.getMimeType(), _charset));
    post.setEntity(entity);/*from   w w w  .j ava2s. co  m*/
    CloseableHttpResponse response = client.execute(post);
    processResponse(response);
}