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

[Bug]: Error 400 when using update-metadata api #2346

Closed
1 task done
InfoMdle opened this issue Nov 27, 2024 · 1 comment · Fixed by #2382
Closed
1 task done

[Bug]: Error 400 when using update-metadata api #2346

InfoMdle opened this issue Nov 27, 2024 · 1 comment · Fixed by #2382

Comments

@InfoMdle
Copy link

InfoMdle commented Nov 27, 2024

Installation Method

Docker

The Problem

When trying to use update-metadata api with swagger and try to add Custom Parameters in allRequestParams i always get a 400 error message.

Request generated in swagger
curl -X 'POST' \ 'https://removed-for-security' \ -H 'accept: */*' \ -H 'Content-Type: multipart/form-data' \ -F 'trapped=' \ -F 'modificationDate=' \ -F 'keywords=' \ -F 'author=' \ -F 'creator=' \ -F 'subject=' \ -F 'creationDate=' \ -F 'fileInput=@image2024-11-27-103615_OCR (1).pdf;type=application/pdf' \ -F 'producer=' \ -F 'allRequestParams={ "additionalProp1": "string", "additionalProp2": "string", "additionalProp3": "string" }' \ -F 'deleteAll=false' \ -F 'title=''

Or
curl -X 'POST' \ 'https://pdf.manufacturedelephemere.fr/api/v1/misc/update-metadata' \ -H 'accept: */*' \ -H 'Content-Type: multipart/form-data' \ -F 'trapped=' \ -F 'modificationDate=' \ -F 'keywords=' \ -F 'author=' \ -F 'creator=' \ -F 'subject=' \ -F 'creationDate=' \ -F 'fileInput=@image2024-11-27-103615_OCR (1).pdf;type=application/pdf' \ -F 'producer=' \ -F 'allRequestParams={ "customKey1": "MyCustomMetadataKey1", "customValue1": "MyCustomMetadataValue1", "customKey2": "MyCustomMetadataKey2", "customValue2": "MyCustomMetadataValue2" }' \ -F 'deleteAll=false' \ -F 'title='

Version of Stirling-PDF

0.34.0

Last Working Version of Stirling-PDF

No response

Page Where the Problem Occurred

http://localhost/swagger-ui/index.html#/Misc/metadata

Docker Configuration

No response

Relevant Log Output

{
  "timestamp": "2024-11-27T16:09:12.880+00:00",
  "status": 400,
  "error": "Bad Request",
  "exception": "org.springframework.web.bind.MethodArgumentNotValidException",
  "trace": "org.springframework.web.bind.MethodArgumentNotValidException: Validation failed for argument [0] in public org.springframework.http.ResponseEntity<byte[]> stirling.software.SPDF.controller.api.misc.MetadataController.metadata(stirling.software.SPDF.model.api.misc.MetadataRequest) throws java.io.IOException: [Field error in object 'metadataRequest' on field 'allRequestParams': rejected value [{\r\n  \"additionalProp1\": \"string\",\r\n  \"additionalProp2\": \"string\",\r\n  \"additionalProp3\": \"string\"\r\n}]; codes [typeMismatch.metadataRequest.allRequestParams,typeMismatch.allRequestParams,typeMismatch.java.util.Map,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [metadataRequest.allRequestParams,allRequestParams]; arguments []; default message [allRequestParams]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Map' for property 'allRequestParams'; Cannot convert value of type 'java.lang.String' to required type 'java.util.Map' for property 'allRequestParams': no matching editors or conversion strategy found]] \n\tat org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:158)\n\tat org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:122)\n\tat org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:224)\n\tat org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:178)\n\tat org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:118)\n\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:986)\n\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:891)\n\tat org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)\n\tat org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1088)\n\tat org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:978)\n\tat org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014)\n\tat org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:914)\n\tat jakarta.servlet.http.HttpServlet.service(HttpServlet.java:547)\n\tat org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885)\n\tat jakarta.servlet.http.HttpServlet.service(HttpServlet.java:614)\n\tat org.eclipse.jetty.ee10.servlet.ServletHolder.handle(ServletHolder.java:736)\n\tat org.eclipse.jetty.ee10.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1614)\n\tat org.eclipse.jetty.ee10.websocket.servlet.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:195)\n\tat org.eclipse.jetty.ee10.servlet.FilterHolder.doFilter(FilterHolder.java:205)\n\tat org.eclipse.jetty.ee10.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1586)\n\tat stirling.software.SPDF.config.MetricsFilter.doFilterInternal(MetricsFilter.java:48)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)\n\tat org.eclipse.jetty.ee10.servlet.FilterHolder.doFilter(FilterHolder.java:205)\n\tat org.eclipse.jetty.ee10.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1586)\n\tat org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)\n\tat org.eclipse.jetty.ee10.servlet.FilterHolder.doFilter(FilterHolder.java:205)\n\tat org.eclipse.jetty.ee10.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1586)\n\tat org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)\n\tat org.eclipse.jetty.ee10.servlet.FilterHolder.doFilter(FilterHolder.java:205)\n\tat org.eclipse.jetty.ee10.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1586)\n\tat org.springframework.web.filter.ServerHttpObservationFilter.doFilterInternal(ServerHttpObservationFilter.java:114)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)\n\tat org.eclipse.jetty.ee10.servlet.FilterHolder.doFilter(FilterHolder.java:205)\n\tat org.eclipse.jetty.ee10.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1586)\n\tat org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)\n\tat org.eclipse.jetty.ee10.servlet.FilterHolder.doFilter(FilterHolder.java:205)\n\tat org.eclipse.jetty.ee10.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1586)\n\tat org.eclipse.jetty.ee10.servlet.ServletHandler$MappedServlet.handle(ServletHandler.java:1547)\n\tat org.eclipse.jetty.ee10.servlet.ServletChannel.dispatch(ServletChannel.java:819)\n\tat org.eclipse.jetty.ee10.servlet.ServletChannel.handle(ServletChannel.java:436)\n\tat org.eclipse.jetty.ee10.servlet.ServletHandler.handle(ServletHandler.java:464)\n\tat org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:575)\n\tat org.eclipse.jetty.ee10.servlet.SessionHandler.handle(SessionHandler.java:717)\n\tat org.eclipse.jetty.server.handler.ContextHandler.handle(ContextHandler.java:1060)\n\tat org.eclipse.jetty.server.Handler$Wrapper.handle(Handler.java:740)\n\tat org.eclipse.jetty.server.handler.EventsHandler.handle(EventsHandler.java:81)\n\tat org.eclipse.jetty.server.Server.handle(Server.java:182)\n\tat org.eclipse.jetty.server.internal.HttpChannelState$HandlerInvoker.run(HttpChannelState.java:662)\n\tat org.eclipse.jetty.server.internal.HttpConnection.onFillable(HttpConnection.java:418)\n\tat org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:322)\n\tat org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:99)\n\tat org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)\n\tat org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(AdaptiveExecutionStrategy.java:478)\n\tat org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:441)\n\tat org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:293)\n\tat org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.run(AdaptiveExecutionStrategy.java:201)\n\tat org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:311)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:979)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.doRunJob(QueuedThreadPool.java:1209)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1164)\n\tat java.base/java.lang.Thread.run(Thread.java:1583)\n",
  "message": "Validation failed for object='metadataRequest'. Error count: 1",
  "path": "/api/v1/misc/update-metadata"
}

Additional Information

No response

Browsers Affected

No response

No Duplicate of the Issue

  • I have verified that there are no existing issues raised related to my problem.
Copy link

dosubot bot commented Nov 27, 2024

Hello @InfoMdle 👋, I'm here to help you with any bugs, questions, or contributions. Let's tackle this together!

The error you're encountering is due to the incorrect format of the allRequestParams field in your request. The allRequestParams field should be a Map<String, String>, but it seems like it's being sent as a string instead of a map.

To fix this, you need to ensure that the allRequestParams is correctly formatted as a map in your request. Here's how you can adjust your curl command:

curl -X 'POST' \
  'https://removed-for-security' \
  -H 'accept: */*' \
  -H 'Content-Type: multipart/form-data' \
  -F 'trapped=' \
  -F 'modificationDate=' \
  -F 'keywords=' \
  -F 'author=' \
  -F 'creator=' \
  -F 'subject=' \
  -F 'creationDate=' \
  -F 'fileInput=@image2024-11-27-103615_OCR (1).pdf;type=application/pdf' \
  -F 'producer=' \
  -F 'allRequestParams[customKey1]=customValue1' \
  -F 'allRequestParams[customKey2]=customValue2' \
  -F 'allRequestParams[customKey3]=customValue3' \
  -F 'deleteAll=false' \
  -F 'title='

In this example, replace customKey1, customKey2, and customKey3 with your actual custom keys, and customValue1, customValue2, and customValue3 with the corresponding values. This format should correctly represent the map structure expected by the API [1].

To continue talking to Dosu, mention @dosu.

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

Successfully merging a pull request may close this issue.

1 participant