com.sun.jersey.multipart.impl.MultiPartWriter Java Examples

The following examples show how to use com.sun.jersey.multipart.impl.MultiPartWriter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RestRequestSender.java    From osiris with Apache License 2.0 9 votes vote down vote up
public ClientResponse<File> upload(String url, File f, Headers... headers) {
	@SuppressWarnings("resource")
	FormDataMultiPart form = new FormDataMultiPart();
	form.bodyPart(new FileDataBodyPart("file", f, MediaType.APPLICATION_OCTET_STREAM_TYPE));

	String urlCreated = createURI(url);
	ClientConfig cc = new DefaultClientConfig();
	cc.getClasses().add(MultiPartWriter.class);
	WebResource webResource = Client.create(cc).resource(urlCreated);
	Builder builder = webResource.type(MULTIPART_MEDIA).accept(MEDIA).accept("text/plain");
	for (Headers h : headers) {
		builder.header(h.getKey(), h.getValue());
	}

	com.sun.jersey.api.client.ClientResponse clienteResponse = null;

	clienteResponse = builder.post(com.sun.jersey.api.client.ClientResponse.class, form);

	return new ClientResponse<File>(clienteResponse, File.class);
}
 
Example #2
Source File: RestRequestSender.java    From osiris with Apache License 2.0 6 votes vote down vote up
public void uploadVoid(String url, File f, String formName, Headers... headers) {

		FormDataMultiPart form = new FormDataMultiPart().field(formName, f, MediaType.MULTIPART_FORM_DATA_TYPE);
		String urlCreated = createURI(url);
		ClientConfig cc = new DefaultClientConfig();
		cc.getClasses().add(MultiPartWriter.class);
		WebResource webResource = Client.create(cc).resource(urlCreated);

		Builder builder = webResource.type(MULTIPART_MEDIA).accept(MEDIA);

		for (Headers h : headers) {
			builder.header(h.getKey(), h.getValue());
		}

		builder.post(form);
	}
 
Example #3
Source File: RestRequestSender.java    From osiris with Apache License 2.0 6 votes vote down vote up
public <T> ClientResponse<T> upload(String url, File f, Class<T> expectedResponse, Headers... headers) {
	
	@SuppressWarnings("resource")
	FormDataMultiPart form = new FormDataMultiPart();
	form.bodyPart(new FileDataBodyPart("file", f, MediaType.APPLICATION_OCTET_STREAM_TYPE));

	String urlCreated = createURI(url);
	ClientConfig cc = new DefaultClientConfig();
	cc.getClasses().add(MultiPartWriter.class);
	WebResource webResource = Client.create(cc).resource(urlCreated);
	Builder builder = webResource.type(MULTIPART_MEDIA).accept(MEDIA).accept("text/plain");
	for (Headers h : headers) {
		builder.header(h.getKey(), h.getValue());
	}

	com.sun.jersey.api.client.ClientResponse clienteResponse = null;

	clienteResponse = builder.post(com.sun.jersey.api.client.ClientResponse.class, form);

	return new ClientResponse<T>(clienteResponse, expectedResponse);
}
 
Example #4
Source File: RestRequestSender.java    From osiris with Apache License 2.0 6 votes vote down vote up
public ClientResponse<File> uploadNoMultipart(String url, File f, Headers... headers) throws FileNotFoundException {

		InputStream is = new FileInputStream(f);

		String urlCreated = createURI(url);
		ClientConfig cc = new DefaultClientConfig();
		cc.getClasses().add(MultiPartWriter.class);
		WebResource webResource = Client.create(cc).resource(urlCreated);
		Builder builder = webResource.type(MediaType.APPLICATION_OCTET_STREAM).accept(MEDIA).accept("text/plain");

		String sContentDisposition = "attachment; filename=\"" + f.getName() + "\"";
		builder.header("Content-Disposition", sContentDisposition);

		for (Headers h : headers) {
			builder.header(h.getKey(), h.getValue());
		}

		com.sun.jersey.api.client.ClientResponse clienteResponse = null;

		clienteResponse = builder.post(com.sun.jersey.api.client.ClientResponse.class, is);

		return new ClientResponse<File>(clienteResponse, File.class);
	}
 
Example #5
Source File: OlogClient.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private OlogClient(URI ologURI, ClientConfig config, boolean withHTTPBasicAuthFilter, String username, String password) {
    config.getClasses().add(MultiPartWriter.class);
    Client client = Client.create(config);
    if (withHTTPBasicAuthFilter) {
        client.addFilter(new HTTPBasicAuthFilter(username, password));
    }
    if (Logger.getLogger(OlogClient.class.getName()).isLoggable(Level.ALL)) {
        client.addFilter(new RawLoggingFilter(Logger.getLogger(OlogClient.class.getName())));
    }
    client.setFollowRedirects(true);
    client.setConnectTimeout(3000);
    this.service = client.resource(UriBuilder.fromUri(ologURI).build());
}
 
Example #6
Source File: OlogClient.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private OlogClient(URI ologURI, ClientConfig config, boolean withHTTPBasicAuthFilter, String username,
        String password, ExecutorService executor, boolean withRawFilter) {
    this.executor = executor;
    config.getClasses().add(MultiPartWriter.class);
    Client client = Client.create(config);
    if (withHTTPBasicAuthFilter) {
        client.addFilter(new HTTPBasicAuthFilter(username, password));
    }
    if (withRawFilter) {
        client.addFilter(new RawLoggingFilter(Logger.getLogger(OlogClient.class.getName())));
    }
    client.setFollowRedirects(true);
    service = client.resource(UriBuilder.fromUri(ologURI).build());
}
 
Example #7
Source File: RestRequestSender.java    From osiris with Apache License 2.0 5 votes vote down vote up
public void uploadVoid(String url, File f, String formName) {

		FormDataMultiPart form = new FormDataMultiPart().field(formName, f, MediaType.MULTIPART_FORM_DATA_TYPE);
		String urlCreated = createURI(url);
		ClientConfig cc = new DefaultClientConfig();
		cc.getClasses().add(MultiPartWriter.class);
		WebResource webResource = Client.create(cc).resource(urlCreated);
		webResource.type(MULTIPART_MEDIA).accept(MEDIA).post(form);
	}
 
Example #8
Source File: RestRequestSender.java    From osiris with Apache License 2.0 5 votes vote down vote up
public SimpleClientResponse upload(String url, File f, String formName) {
	@SuppressWarnings("resource")
	FormDataMultiPart form = new FormDataMultiPart().field(formName, f, MediaType.MULTIPART_FORM_DATA_TYPE);
	String urlCreated = createURI(url);
	ClientConfig cc = new DefaultClientConfig();
	cc.getClasses().add(MultiPartWriter.class);
	WebResource webResource = Client.create(cc).resource(urlCreated);
	webResource.type(MULTIPART_MEDIA).accept(MEDIA).post(form);
	return new SimpleClientResponse(com.sun.jersey.api.client.ClientResponse.Status.NO_CONTENT);
}
 
Example #9
Source File: PublishRestUtil.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Used for REST Jersey calls
 */
private void initRestService() {
  ClientConfig clientConfig = new DefaultClientConfig();
  clientConfig.getClasses().add( MultiPartWriter.class );
  clientConfig.getFeatures().put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE );
  client = Client.create( clientConfig );
  client.addFilter( new HTTPBasicAuthFilter( username, password ) );
}
 
Example #10
Source File: PublishRestUtilTestIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected AppDescriptor configure() {
  ClientConfig config = new DefaultClientConfig();
  config.getClasses().add( MultiPartWriter.class );
  config.getClasses().add( TestRepositoryPublishResource.class );
  config.getFeatures().put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE );

  return new WebAppDescriptor.Builder( "org.pentaho.reporting.libraries.pensol.resources" )
    .contextPath( "api" )
    .clientConfig( config )
    .build();
}
 
Example #11
Source File: DefaultRestClient.java    From qaf with MIT License 4 votes vote down vote up
public DefaultRestClient() {
	ClientConfig config = new DefaultClientConfig();
	config.getClasses().add(MultiPartWriter.class);
	client = Client.create(config);
}