55 */
66package com .gooddata .gdc ;
77
8- import com .github .sardine .Sardine ;
98import com .github .sardine .impl .SardineException ;
9+ import com .gooddata .GoodDataRestException ;
1010import com .gooddata .UriPrefixer ;
1111import org .apache .http .Header ;
1212import org .apache .http .HeaderIterator ;
2424import org .apache .http .client .methods .CloseableHttpResponse ;
2525import org .apache .http .client .methods .HttpUriRequest ;
2626import org .apache .http .conn .ClientConnectionManager ;
27+ import org .apache .http .entity .InputStreamEntity ;
2728import org .apache .http .impl .client .CloseableHttpClient ;
2829import org .apache .http .impl .client .HttpClientBuilder ;
30+ import org .apache .http .message .BasicHeader ;
2931import org .apache .http .params .HttpParams ;
32+ import org .apache .http .protocol .HTTP ;
3033import org .apache .http .protocol .HttpContext ;
3134import org .springframework .http .HttpMethod ;
3235import org .springframework .http .HttpStatus ;
3336import org .springframework .http .ResponseEntity ;
34- import org .springframework .web .client .RestClientException ;
3537import org .springframework .web .client .RestTemplate ;
3638
3739import java .io .IOException ;
3840import java .io .InputStream ;
3941import java .net .URI ;
42+ import java .util .Collections ;
43+ import java .util .List ;
4044import java .util .Locale ;
4145
4246import static com .gooddata .util .Validate .notEmpty ;
4751 */
4852public class DataStoreService {
4953
50- private final Sardine sardine ;
54+ private final GdcSardine sardine ;
5155 private final GdcService gdcService ;
5256 private final URI gdcUri ;
5357 private final RestTemplate restTemplate ;
@@ -102,7 +106,10 @@ public void upload(String path, InputStream stream) {
102106
103107 private void upload (URI url , InputStream stream ) {
104108 try {
105- sardine .put (url .toString (), stream );
109+ // We need to use it this way, if we want to track request_id in the stacktrace.
110+ InputStreamEntity entity = new InputStreamEntity (stream );
111+ List <Header > headers = Collections .singletonList (new BasicHeader (HTTP .EXPECT_DIRECTIVE , HTTP .EXPECT_CONTINUE ));
112+ sardine .put (url .toString (), entity , headers , new GdcSardineResponseHandler ());
106113 } catch (SardineException e ) {
107114 if (HttpStatus .INTERNAL_SERVER_ERROR .value () == e .getStatusCode ()) {
108115 // this error may occur when user issues request to WebDAV before SST and TT were obtained
@@ -144,7 +151,7 @@ public InputStream download(String path) {
144151 notEmpty (path , "path" );
145152 final URI uri = getUri (path );
146153 try {
147- return sardine .get (uri .toString ());
154+ return sardine .get (uri .toString (), Collections . emptyList (), new GdcSardineResponseHandler () );
148155 } catch (IOException e ) {
149156 throw new DataStoreException ("Unable to download from " + uri , e );
150157 }
@@ -165,7 +172,7 @@ public void delete(String path) {
165172 if (HttpStatus .MOVED_PERMANENTLY .equals (result .getStatusCode ())) {
166173 restTemplate .exchange (result .getHeaders ().getLocation (), HttpMethod .DELETE , org .springframework .http .HttpEntity .EMPTY , Void .class );
167174 }
168- } catch (RestClientException e ) {
175+ } catch (GoodDataRestException e ) {
169176 throw new DataStoreException ("Unable to delete " + uri , e );
170177 }
171178 }
0 commit comments