You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by pavel <pa...@mail.ru> on 2016/02/21 23:41:08 UTC

putRequest outputStream

Hello

I am new with CloseableHttpClient and HttpPut and want to use them, because
with java core HttpUrlConnection class I have to fully populate OutputStream
with data, before it starts transfer to server. While my data to send size
is big, this is not fits my need, because takes too much RAM. Data
collection speed much less than upload speed to server, where I want to PUT
data, so I want to use HttpPut with output stream. I was able to swithch
from Java core class and make PUT request with CloseableHttpClient and
HttpPut but only with short String data by ByteArrayEntity. When I try to
PUT with OutputStream, I get no errors/exceptions, but data entity not
transferred. After run I see on target server updated file, with zero
length. My network Interface traffic very small and looks like no entity
data transferred. Here my custom AbstractHttpEntity:

		AbstractHttpEntity entity = new  AbstractHttpEntity() {
			
			@Override
			public void writeTo(OutputStream outstream) throws IOException {
				for (Integer i=0; i<5000000; i++){
					String dataString = i+" data string.";
					outstream.write(dataString.getBytes(Charset.forName("UTF-8")));
				}
			}
			
			@Override
			public boolean isStreaming() {
				return true;
			}
			
			@Override
			public boolean isRepeatable() {
				return true;
			}
			
			@Override
			public long getContentLength() {
				return -1;
			}
			
			@Override
			public InputStream getContent() throws IOException,
UnsupportedOperationException {
				throw new UnsupportedOperationException();
				//return null;
			}
		};		

	In debugger I see writeTo method call and in loop writes to outstream. I
also played a bit with expect continue, like:
	
		HttpPut putRequest = new HttpPut(url.toString());
		RequestConfig defaultRequestConfig =
RequestConfig.custom().setExpectContinueEnabled(true).build();
		putRequest.setConfig(defaultRequestConfig);

		or 
		
		putRequest.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
		
	But this not helps. Here also my dependencies:

		<dependency>
			<groupId>org.apache.httpcomponents</groupId>
			<artifactId>httpclient</artifactId>
			<version>4.5.1</version>
		</dependency>
		<dependency>
			<groupId>org.apache.httpcomponents</groupId>
			<artifactId>httpcore</artifactId>
			<version>4.4.4</version>
		</dependency>
	
	Please help how to figure this out. Everything looks like works, but
actually data not transfer.



--
View this message in context: http://httpcomponents.10934.n7.nabble.com/putRequest-outputStream-tp27956.html
Sent from the HttpClient-User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: putRequest outputStream

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Mon, 2016-02-22 at 08:23 -0700, pavel wrote:
> Hi, Oleg.
> 
> I find can upload data if return from:
>                         @Override
>                         public long getContentLength() {
>                                 return -1;
>                         } 
> some data length, instead of -1. Now I find walk around, though I think will
> use HttpClient further and logging option will be useful.
> 

Most likely the server can't handle chunk coded transfer encoding.

Oleg


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: putRequest outputStream

Posted by pavel <pa...@mail.ru>.
Hi, Oleg.

I find can upload data if return from:
                        @Override
                        public long getContentLength() {
                                return -1;
                        } 
some data length, instead of -1. Now I find walk around, though I think will
use HttpClient further and logging option will be useful.

Thanks.



--
View this message in context: http://httpcomponents.10934.n7.nabble.com/putRequest-outputStream-tp27956p27963.html
Sent from the HttpClient-User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: putRequest outputStream

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Sun, 2016-02-21 at 15:41 -0700, pavel wrote:
> Hello
> 
> I am new with CloseableHttpClient and HttpPut and want to use them, because
> with java core HttpUrlConnection class I have to fully populate OutputStream
> with data, before it starts transfer to server. While my data to send size
> is big, this is not fits my need, because takes too much RAM. Data
> collection speed much less than upload speed to server, where I want to PUT
> data, so I want to use HttpPut with output stream. I was able to swithch
> from Java core class and make PUT request with CloseableHttpClient and
> HttpPut but only with short String data by ByteArrayEntity. When I try to
> PUT with OutputStream, I get no errors/exceptions, but data entity not
> transferred. After run I see on target server updated file, with zero
> length. My network Interface traffic very small and looks like no entity
> data transferred. 

You can see what gets written to the underlying socket by turning on
wire logging as described here.

http://hc.apache.org/httpcomponents-client-4.5.x/logging.html

Oleg


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org