Error sending MultipartFile to REST API using Spring Boot and Open feign
I'm trying to attach a file to send to and endpoint as a MultipartFile
but I'm getting this exception:
Expected no exception to be thrown, but got 'feign.codec.EncodeException'
//...
Caused by: feign.codec.EncodeException: Could not write request:
no suitable HttpMessageConverter found for request type [java.util.LinkedHashMap]
and content type [multipart/form-data]
My method is:
//...
final User user
//...
@Override
DocumentResponse attachDocument(File file, String userId, String documentId)
String timestamp = String.valueOf(System.currentTimeMillis())
String url = "$myProperties.apiUrl/documents/attach?ts=$timestamp"
String digest = myJWT.sign(HttpMethod.POST, url)
MultipartFile multiFile = new MockMultipartFile("test.xml",
new FileInputStream(file))
DocumentResponse documentResponse = user.attachDocument(multiFile,
userId, documentId, timestamp, digest)
return documentResponse
My interface is:
@FeignClient(name = 'myUser', url = '$apiUrl', configuration = myConfiguration)
interface User
//...
@PostMapping(value = '/documents/attach', consumes = 'multipart/form-data')
DocumentResponse attachDocument(@PathVariable('file') MultipartFile multiFile,
@PathVariable('clientId') String userId,
@PathVariable('documentId') String documentId,
@RequestParam('ts') String timestamp,
@RequestParam('digest') String digest)
And my configuration file is:
@Slf4j
@Configuration
class myConfiguration
@Bean
Retryer feignRetryer(@Value('$feign.client.config.myUser.period') Long period,
@Value('$feign.client.config.myUser.maxInterval') Long maxInterval,
@Value('$feign.client.config.myUser.maxAttempts') Integer maxAttempts)
return new Retryer.Default(period, maxInterval, maxAttempts)
@Bean
ErrorDecoder errorDecoder()
return new ErrorDecoder()
@Override
Exception decode(String methodKey, Response response)
if (HttpStatus.OK.value() != response.status())
FeignException ex = FeignException.errorStatus(methodKey, response)
if (response.status() != HttpStatus.BAD_REQUEST.value())
return new RetryableException('getting conflict and retry', new Date(System.currentTimeMillis() + TimeUnit.SECONDS
.toMillis(1)))
return new MyDocumentException()
Also, I have tried to add this code to myConfiguration file:
@Bean
Encoder encoder()
return new FormEncoder()
But I have another exception:
Cannot cast object 'feign.form.FormEncoder@5fa78e0a'
with class 'feign.form.FormEncoder' to class 'java.beans.Encoder'
I'm using Spring boot '2.0.2.RELEASE'
with:
"io.github.openfeign.form:feign-form:3.4.1",
"io.github.openfeign.form:feign-form-spring:3.4.1",
I checked these posts:
How to send POST request by Spring cloud Feign
no suitable HttpMessageConverter found for response type
Could not write request: no suitable HttpMessageConverter found for request type and content type
Converting file to multipartfile
Any suggestion?
java spring spring-boot groovy openfeint
add a comment |
I'm trying to attach a file to send to and endpoint as a MultipartFile
but I'm getting this exception:
Expected no exception to be thrown, but got 'feign.codec.EncodeException'
//...
Caused by: feign.codec.EncodeException: Could not write request:
no suitable HttpMessageConverter found for request type [java.util.LinkedHashMap]
and content type [multipart/form-data]
My method is:
//...
final User user
//...
@Override
DocumentResponse attachDocument(File file, String userId, String documentId)
String timestamp = String.valueOf(System.currentTimeMillis())
String url = "$myProperties.apiUrl/documents/attach?ts=$timestamp"
String digest = myJWT.sign(HttpMethod.POST, url)
MultipartFile multiFile = new MockMultipartFile("test.xml",
new FileInputStream(file))
DocumentResponse documentResponse = user.attachDocument(multiFile,
userId, documentId, timestamp, digest)
return documentResponse
My interface is:
@FeignClient(name = 'myUser', url = '$apiUrl', configuration = myConfiguration)
interface User
//...
@PostMapping(value = '/documents/attach', consumes = 'multipart/form-data')
DocumentResponse attachDocument(@PathVariable('file') MultipartFile multiFile,
@PathVariable('clientId') String userId,
@PathVariable('documentId') String documentId,
@RequestParam('ts') String timestamp,
@RequestParam('digest') String digest)
And my configuration file is:
@Slf4j
@Configuration
class myConfiguration
@Bean
Retryer feignRetryer(@Value('$feign.client.config.myUser.period') Long period,
@Value('$feign.client.config.myUser.maxInterval') Long maxInterval,
@Value('$feign.client.config.myUser.maxAttempts') Integer maxAttempts)
return new Retryer.Default(period, maxInterval, maxAttempts)
@Bean
ErrorDecoder errorDecoder()
return new ErrorDecoder()
@Override
Exception decode(String methodKey, Response response)
if (HttpStatus.OK.value() != response.status())
FeignException ex = FeignException.errorStatus(methodKey, response)
if (response.status() != HttpStatus.BAD_REQUEST.value())
return new RetryableException('getting conflict and retry', new Date(System.currentTimeMillis() + TimeUnit.SECONDS
.toMillis(1)))
return new MyDocumentException()
Also, I have tried to add this code to myConfiguration file:
@Bean
Encoder encoder()
return new FormEncoder()
But I have another exception:
Cannot cast object 'feign.form.FormEncoder@5fa78e0a'
with class 'feign.form.FormEncoder' to class 'java.beans.Encoder'
I'm using Spring boot '2.0.2.RELEASE'
with:
"io.github.openfeign.form:feign-form:3.4.1",
"io.github.openfeign.form:feign-form-spring:3.4.1",
I checked these posts:
How to send POST request by Spring cloud Feign
no suitable HttpMessageConverter found for response type
Could not write request: no suitable HttpMessageConverter found for request type and content type
Converting file to multipartfile
Any suggestion?
java spring spring-boot groovy openfeint
add a comment |
I'm trying to attach a file to send to and endpoint as a MultipartFile
but I'm getting this exception:
Expected no exception to be thrown, but got 'feign.codec.EncodeException'
//...
Caused by: feign.codec.EncodeException: Could not write request:
no suitable HttpMessageConverter found for request type [java.util.LinkedHashMap]
and content type [multipart/form-data]
My method is:
//...
final User user
//...
@Override
DocumentResponse attachDocument(File file, String userId, String documentId)
String timestamp = String.valueOf(System.currentTimeMillis())
String url = "$myProperties.apiUrl/documents/attach?ts=$timestamp"
String digest = myJWT.sign(HttpMethod.POST, url)
MultipartFile multiFile = new MockMultipartFile("test.xml",
new FileInputStream(file))
DocumentResponse documentResponse = user.attachDocument(multiFile,
userId, documentId, timestamp, digest)
return documentResponse
My interface is:
@FeignClient(name = 'myUser', url = '$apiUrl', configuration = myConfiguration)
interface User
//...
@PostMapping(value = '/documents/attach', consumes = 'multipart/form-data')
DocumentResponse attachDocument(@PathVariable('file') MultipartFile multiFile,
@PathVariable('clientId') String userId,
@PathVariable('documentId') String documentId,
@RequestParam('ts') String timestamp,
@RequestParam('digest') String digest)
And my configuration file is:
@Slf4j
@Configuration
class myConfiguration
@Bean
Retryer feignRetryer(@Value('$feign.client.config.myUser.period') Long period,
@Value('$feign.client.config.myUser.maxInterval') Long maxInterval,
@Value('$feign.client.config.myUser.maxAttempts') Integer maxAttempts)
return new Retryer.Default(period, maxInterval, maxAttempts)
@Bean
ErrorDecoder errorDecoder()
return new ErrorDecoder()
@Override
Exception decode(String methodKey, Response response)
if (HttpStatus.OK.value() != response.status())
FeignException ex = FeignException.errorStatus(methodKey, response)
if (response.status() != HttpStatus.BAD_REQUEST.value())
return new RetryableException('getting conflict and retry', new Date(System.currentTimeMillis() + TimeUnit.SECONDS
.toMillis(1)))
return new MyDocumentException()
Also, I have tried to add this code to myConfiguration file:
@Bean
Encoder encoder()
return new FormEncoder()
But I have another exception:
Cannot cast object 'feign.form.FormEncoder@5fa78e0a'
with class 'feign.form.FormEncoder' to class 'java.beans.Encoder'
I'm using Spring boot '2.0.2.RELEASE'
with:
"io.github.openfeign.form:feign-form:3.4.1",
"io.github.openfeign.form:feign-form-spring:3.4.1",
I checked these posts:
How to send POST request by Spring cloud Feign
no suitable HttpMessageConverter found for response type
Could not write request: no suitable HttpMessageConverter found for request type and content type
Converting file to multipartfile
Any suggestion?
java spring spring-boot groovy openfeint
I'm trying to attach a file to send to and endpoint as a MultipartFile
but I'm getting this exception:
Expected no exception to be thrown, but got 'feign.codec.EncodeException'
//...
Caused by: feign.codec.EncodeException: Could not write request:
no suitable HttpMessageConverter found for request type [java.util.LinkedHashMap]
and content type [multipart/form-data]
My method is:
//...
final User user
//...
@Override
DocumentResponse attachDocument(File file, String userId, String documentId)
String timestamp = String.valueOf(System.currentTimeMillis())
String url = "$myProperties.apiUrl/documents/attach?ts=$timestamp"
String digest = myJWT.sign(HttpMethod.POST, url)
MultipartFile multiFile = new MockMultipartFile("test.xml",
new FileInputStream(file))
DocumentResponse documentResponse = user.attachDocument(multiFile,
userId, documentId, timestamp, digest)
return documentResponse
My interface is:
@FeignClient(name = 'myUser', url = '$apiUrl', configuration = myConfiguration)
interface User
//...
@PostMapping(value = '/documents/attach', consumes = 'multipart/form-data')
DocumentResponse attachDocument(@PathVariable('file') MultipartFile multiFile,
@PathVariable('clientId') String userId,
@PathVariable('documentId') String documentId,
@RequestParam('ts') String timestamp,
@RequestParam('digest') String digest)
And my configuration file is:
@Slf4j
@Configuration
class myConfiguration
@Bean
Retryer feignRetryer(@Value('$feign.client.config.myUser.period') Long period,
@Value('$feign.client.config.myUser.maxInterval') Long maxInterval,
@Value('$feign.client.config.myUser.maxAttempts') Integer maxAttempts)
return new Retryer.Default(period, maxInterval, maxAttempts)
@Bean
ErrorDecoder errorDecoder()
return new ErrorDecoder()
@Override
Exception decode(String methodKey, Response response)
if (HttpStatus.OK.value() != response.status())
FeignException ex = FeignException.errorStatus(methodKey, response)
if (response.status() != HttpStatus.BAD_REQUEST.value())
return new RetryableException('getting conflict and retry', new Date(System.currentTimeMillis() + TimeUnit.SECONDS
.toMillis(1)))
return new MyDocumentException()
Also, I have tried to add this code to myConfiguration file:
@Bean
Encoder encoder()
return new FormEncoder()
But I have another exception:
Cannot cast object 'feign.form.FormEncoder@5fa78e0a'
with class 'feign.form.FormEncoder' to class 'java.beans.Encoder'
I'm using Spring boot '2.0.2.RELEASE'
with:
"io.github.openfeign.form:feign-form:3.4.1",
"io.github.openfeign.form:feign-form-spring:3.4.1",
I checked these posts:
How to send POST request by Spring cloud Feign
no suitable HttpMessageConverter found for response type
Could not write request: no suitable HttpMessageConverter found for request type and content type
Converting file to multipartfile
Any suggestion?
java spring spring-boot groovy openfeint
java spring spring-boot groovy openfeint
asked Nov 14 '18 at 12:00
Javier C.Javier C.
2,00221328
2,00221328
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
feign.codec.EncodeException
raised when a problem occurs encoding a message.
I think the @PathVariable('file') MultipartFile multiFile
, can be converted to a base64 sting and pass it to REST API or add an Encoder to MultipartFile
The API only accept Content-Type: multipart/form-data; boundary="the boundary here" so I think that the problem is how to correct use an Encoder.
– Javier C.
Nov 14 '18 at 14:57
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53299771%2ferror-sending-multipartfile-to-rest-api-using-spring-boot-and-open-feign%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
feign.codec.EncodeException
raised when a problem occurs encoding a message.
I think the @PathVariable('file') MultipartFile multiFile
, can be converted to a base64 sting and pass it to REST API or add an Encoder to MultipartFile
The API only accept Content-Type: multipart/form-data; boundary="the boundary here" so I think that the problem is how to correct use an Encoder.
– Javier C.
Nov 14 '18 at 14:57
add a comment |
feign.codec.EncodeException
raised when a problem occurs encoding a message.
I think the @PathVariable('file') MultipartFile multiFile
, can be converted to a base64 sting and pass it to REST API or add an Encoder to MultipartFile
The API only accept Content-Type: multipart/form-data; boundary="the boundary here" so I think that the problem is how to correct use an Encoder.
– Javier C.
Nov 14 '18 at 14:57
add a comment |
feign.codec.EncodeException
raised when a problem occurs encoding a message.
I think the @PathVariable('file') MultipartFile multiFile
, can be converted to a base64 sting and pass it to REST API or add an Encoder to MultipartFile
feign.codec.EncodeException
raised when a problem occurs encoding a message.
I think the @PathVariable('file') MultipartFile multiFile
, can be converted to a base64 sting and pass it to REST API or add an Encoder to MultipartFile
answered Nov 14 '18 at 13:10
Samuel J MathewSamuel J Mathew
3,61212229
3,61212229
The API only accept Content-Type: multipart/form-data; boundary="the boundary here" so I think that the problem is how to correct use an Encoder.
– Javier C.
Nov 14 '18 at 14:57
add a comment |
The API only accept Content-Type: multipart/form-data; boundary="the boundary here" so I think that the problem is how to correct use an Encoder.
– Javier C.
Nov 14 '18 at 14:57
The API only accept Content-Type: multipart/form-data; boundary="the boundary here" so I think that the problem is how to correct use an Encoder.
– Javier C.
Nov 14 '18 at 14:57
The API only accept Content-Type: multipart/form-data; boundary="the boundary here" so I think that the problem is how to correct use an Encoder.
– Javier C.
Nov 14 '18 at 14:57
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53299771%2ferror-sending-multipartfile-to-rest-api-using-spring-boot-and-open-feign%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown