77
88import com .github .sardine .Sardine ;
99import com .github .sardine .impl .SardineException ;
10+ import com .github .sardine .impl .SardineImpl ;
11+ import com .gooddata .GoodDataRestException ;
1012import com .gooddata .UriPrefixer ;
1113import org .apache .http .Header ;
1214import org .apache .http .HeaderIterator ;
2426import org .apache .http .client .methods .CloseableHttpResponse ;
2527import org .apache .http .client .methods .HttpUriRequest ;
2628import org .apache .http .conn .ClientConnectionManager ;
29+ import org .apache .http .entity .InputStreamEntity ;
2730import org .apache .http .impl .client .CloseableHttpClient ;
2831import org .apache .http .impl .client .HttpClientBuilder ;
32+ import org .apache .http .message .BasicHeader ;
2933import org .apache .http .params .HttpParams ;
34+ import org .apache .http .protocol .HTTP ;
3035import org .apache .http .protocol .HttpContext ;
3136import org .springframework .http .HttpMethod ;
3237import org .springframework .http .HttpStatus ;
3338import org .springframework .http .ResponseEntity ;
34- import org .springframework .web .client .RestClientException ;
3539import org .springframework .web .client .RestTemplate ;
3640
3741import java .io .IOException ;
3842import java .io .InputStream ;
3943import java .net .URI ;
44+ import java .util .Collections ;
45+ import java .util .List ;
4046import java .util .Locale ;
4147
4248import static com .gooddata .util .Validate .notEmpty ;
@@ -102,7 +108,13 @@ public void upload(String path, InputStream stream) {
102108
103109 private void upload (URI url , InputStream stream ) {
104110 try {
105- sardine .put (url .toString (), stream );
111+ // The variable name means that data size in bytes to set to Content-Length header.
112+ // Taken from {@link Sardine#put(String, InputStream, String, boolean, long)}
113+ final int contentLength = -1 ;
114+ // We need to use it this way, if we want to track request_id in the stacktrace.
115+ InputStreamEntity entity = new InputStreamEntity (stream , contentLength );
116+ List <Header > headers = Collections .singletonList (new BasicHeader (HTTP .EXPECT_DIRECTIVE , HTTP .EXPECT_CONTINUE ));
117+ ((SardineImpl ) sardine ).put (url .toString (), entity , headers , new GdcSardineResponseHandler ());
106118 } catch (SardineException e ) {
107119 if (HttpStatus .INTERNAL_SERVER_ERROR .value () == e .getStatusCode ()) {
108120 // this error may occur when user issues request to WebDAV before SST and TT were obtained
@@ -144,7 +156,7 @@ public InputStream download(String path) {
144156 notEmpty (path , "path" );
145157 final URI uri = getUri (path );
146158 try {
147- return sardine .get (uri .toString ());
159+ return (( GdcSardine ) sardine ) .get (uri .toString (), Collections . emptyList (), new GdcSardineResponseHandler ());
148160 } catch (IOException e ) {
149161 throw new DataStoreException ("Unable to download from " + uri , e );
150162 }
@@ -165,7 +177,7 @@ public void delete(String path) {
165177 if (HttpStatus .MOVED_PERMANENTLY .equals (result .getStatusCode ())) {
166178 restTemplate .exchange (result .getHeaders ().getLocation (), HttpMethod .DELETE , org .springframework .http .HttpEntity .EMPTY , Void .class );
167179 }
168- } catch (RestClientException e ) {
180+ } catch (GoodDataRestException e ) {
169181 throw new DataStoreException ("Unable to delete " + uri , e );
170182 }
171183 }
0 commit comments