Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File is required exception on uploading files using SDK #56

Open
avietrov opened this issue May 7, 2021 · 3 comments
Open

File is required exception on uploading files using SDK #56

avietrov opened this issue May 7, 2021 · 3 comments

Comments

@avietrov
Copy link

avietrov commented May 7, 2021

We are using smartling java sdk 0.18 to upload dynamically generated json files to smartling.
We use FilesAPI for that like this:

final InputStream stream = new ByteArrayInputStream(JACKSON_OBJECT_MAPPER.writeValueAsString(myDTOWithStrings));
final ImportTranslationsPTO pto =
    ImportTranslationsPTO.builder()
              .file(stream)
              .fileUri(fileUri)
              .fileType(JSON.name())
              .translationState(TranslationState.PUBLISHED)
              .overwrite(false)
              .build();
...
final ImportTranslationsResponse response =
                filesApi.importTranslations(projectId, locale, pto);

Quite often we get the exception:

com.smartling.api.v2.client.exception.client.ValidationErrorException: http_status=400, requestId=daedf180-7ea3-4651-92ba-847c777f4d58, top errors: 'File is required'
	at com.smartling.api.v2.client.exception.DefaultRestApiExceptionMapper.toExceptionByStatus(DefaultRestApiExceptionMapper.java:89)
	at com.smartling.api.v2.client.exception.DefaultRestApiExceptionMapper.toException(DefaultRestApiExceptionMapper.java:44)
	at com.smartling.api.files.v2.exceptions.FilesApiExceptionMapper.toException(FilesApiExceptionMapper.java:44)
	at com.smartling.api.v2.client.exception.RestApiExceptionHandler.createRestApiException(RestApiExceptionHandler.java:31)
	at com.smartling.api.v2.client.ExceptionDecoratorInvocationHandler.invoke(ExceptionDecoratorInvocationHandler.java:34)
	at com.sun.proxy.$Proxy101.importTranslations(Unknown Source)
	[my service stack trace]
	
Caused by: javax.ws.rs.BadRequestException: HTTP 400 Bad Request
	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.handleErrorStatus(ClientInvocation.java:220)
	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:196)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.BodyEntityExtractor.extractEntity(BodyEntityExtractor.java:62)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:151)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:112)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)
	at com.sun.proxy.$Proxy100.importTranslations(Unknown Source)
	at jdk.internal.reflect.GeneratedMethodAccessor349.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at com.smartling.api.v2.client.ExceptionDecoratorInvocationHandler.invoke(ExceptionDecoratorInvocationHandler.java:30)
	... 32 common frames omitted

Executing the code again usually helps, but I'd like to avoid that error in the first place. What does this error actually mean and how can we avoid getting it?

@dkBrazz
Copy link
Contributor

dkBrazz commented May 13, 2021

'File is required' is returned by the Files API when the file parameter is not provided or doesn't have content

Please ensure that JACKSON_OBJECT_MAPPER.writeValueAsString(myDTOWithStrings) returns any content and stream variable is not read between instantiation and calling filesApi.importTranslations()

@dkBrazz
Copy link
Contributor

dkBrazz commented May 13, 2021

It might be helpful to log serialized requests made by SDK using logging filter, so we could know if SDK sends an empty file or an API interpret non-empty file as empty

@avietrov
Copy link
Author

Thanks for your response, I'll add some logging and get back to you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants