# SocketException on \_bulk request working in curl but not in restTemplate

**URL:** <https://discuss.elastic.co/t/socketexception-on-bulk-request-working-in-curl-but-not-in-resttemplate/326437>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-security\
**Created:** [February 24, 2023, 12:12pm UTC](https://discuss.elastic.co/t/socketexception-on-bulk-request-working-in-curl-but-not-in-resttemplate/326437 "2023-02-24T12:12:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![D1sturbance](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/d1sturbance/32/98965_2.png) [@D1sturbance](https://discuss.elastic.co/u/D1sturbance)\
**Post date:** [February 24, 2023, 12:12pm UTC](https://discuss.elastic.co/t/socketexception-on-bulk-request-working-in-curl-but-not-in-resttemplate/326437/1 "2023-02-24T12:12:49Z")

</div>

Hello,

I have problems with \_bulk request throwing Connection reset by peer: socket write error; nested exception is javax.net.ssl.SSLProtocolException.

I've read and know about bulk size and etc... So that's not an issue, because the same exact request works with curl or intelij http client:

```auto
PUT {{elastic-search-url}}/_bulk
Authorization: Basic {{username}} {{password}}
Accept: application/json
Content-Type: application/x-ndjson

< input.txt

```

However if I try using spring boot restTemplate I get the error Connection reset by peer:

```auto
HttpEntity<String> requestEntity = new HttpEntity<>(stringBuilder.toString(), getHeaderEntity());
restTemplate.put("ELKurl/_bulk", requestEntity, Object.class);

```

Header entity have all required authorization and accepts:

```auto
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN));
headers.setContentType(MediaType.APPLICATION_JSON);

```

SSL for restTemplate is disabled:

```auto
private CloseableHttpClient createHttpClient() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
        return HttpClients
                .custom()
                .setSSLHostnameVerifier(new NoopHostnameVerifier())
                .setSSLContext(createSSLContext())
                .build();
    }
private SSLContext createSSLContext() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
        return new SSLContextBuilder().loadTrustMaterial(null, (TrustStrategy) (arg0, arg1) -> true).build();
    }

```

I don't know what else can cause problems? I also checked logs on ELK server side, but nothing can be found there.  
How can curl work and spring boot not? 🙂

ELK version 7.17.5

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 24, 2023, 12:13pm UTC](https://discuss.elastic.co/t/socketexception-on-bulk-request-working-in-curl-but-not-in-resttemplate/326437/2 "2023-03-24T12:13:01Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
