I am trying to make an PUT request with spring webclinet (org.springframework.web.reactive.function.client.WebClient) which looks like following in case its made with curl
curl -X PUT localhost:8080/bline/v1/anchor/anchor_id/handle/mac_id/43?response=false -H 'Content-Type: hex' -d '02'
I am buidling the request as follows:
WebClient.builder().build()
.put()
.uri(this.URL)
.header(HttpHeaders.CONTENT_TYPE, "hex")
.bodyValue(0x02)
.retrieve()
.bodyToMono(String.class);
But it fails to make a successful request and following exception is thrown org.springframework.util.InvalidMimeTypeException: Invalid mime type "hex": does not contain '/'
The stack trace looks like following:
Caused by: org.springframework.util.InvalidMimeTypeException: Invalid mime type "hex": does not contain '/'
at org.springframework.util.MimeTypeUtils.parseMimeTypeInternal(MimeTypeUtils.java:229) ~[spring-core-6.1.4.jar:6.1.4]
at org.springframework.util.ConcurrentLruCache.get(ConcurrentLruCache.java:103) ~[spring-core-6.1.4.jar:6.1.4]
at org.springframework.util.MimeTypeUtils.parseMimeType(MimeTypeUtils.java:213) ~[spring-core-6.1.4.jar:6.1.4]
at org.springframework.http.MediaType.parseMediaType(MediaType.java:739) ~[spring-web-6.1.4.jar:6.1.4]
at org.springframework.http.HttpHeaders.getContentType(HttpHeaders.java:1000) ~[spring-web-6.1.4.jar:6.1.4]
at org.springframework.web.reactive.function.BodyInserters.writeWithMessageWriters(BodyInserters.java:423) ~[spring-webflux-6.1.1.jar:6.1.1]
at org.springframework.web.reactive.function.BodyInserters.lambda$fromValue$1(BodyInserters.java:103) ~[spring-webflux-6.1.1.jar:6.1.1]
at org.springframework.web.reactive.function.client.DefaultClientRequestBuilder$BodyInserterRequest.writeTo(DefaultClientRequestBuilder.java:272) ~[spring-webflux-6.1.1.jar:6.1.1]
at org.springframework.web.reactive.function.client.ExchangeFunctions$DefaultExchangeFunction.lambda$exchange$1(ExchangeFunctions.java:102) ~[spring-webflux-6.1.1.jar:6.1.1]
at org.springframework.http.client.reactive.JdkClientHttpConnector.connect(JdkClientHttpConnector.java:101) ~[spring-web-6.1.4.jar:6.1.4]
at org.springframework.web.reactive.function.client.ExchangeFunctions$DefaultExchangeFunction.exchange(ExchangeFunctions.java:102) ~[spring-webflux-6.1.1.jar:6.1.1]
at org.springframework.web.reactive.function.client.DefaultWebClient$ObservationFilterFunction.filter(DefaultWebClient.java:746) ~[spring-webflux-6.1.1.jar:6.1.1]
at org.springframework.web.reactive.function.client.ExchangeFilterFunction.lambda$apply$2(ExchangeFilterFunction.java:73) ~[spring-webflux-6.1.1.jar:6.1.1]
at org.springframework.web.reactive.function.client.DefaultWebClient$DefaultRequestBodyUriSpec.lambda$exchange$11(DefaultWebClient.java:457) ~[spring-webflux-6.1.1.jar:6.1.1]
at reactor.core.publisher.MonoDeferContextual.subscribe(MonoDeferContextual.java:47) ~[reactor-core-3.6.3.jar:3.6.3]
at reactor.core.publisher.Mono.subscribe(Mono.java:4563) ~[reactor-core-3.6.3.jar:3.6.3]
at reactor.core.publisher.Mono.block(Mono.java:1778) ~[reactor-core-3.6.3.jar:3.6.3]
at com.scheidtbachmann.edgedevicemock.core.BeaconFlashingService.connectAndFlashLights(BeaconFlashingService.java:38) ~[classes/:na]
at com.scheidtbachmann.edgedevicemock.core.MqttMessageHandler.handleMessage(MqttMessageHandler.java:38) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:169) ~[spring-messaging-6.1.4.jar:6.1.4]
at org.springframework.integration.handler.support.IntegrationInvocableHandlerMethod.doInvoke(IntegrationInvocableHandlerMethod.java:45) ~[spring-integration-core-6.2.2.jar:6.2.2]
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:119) ~[spring-messaging-6.1.4.jar:6.1.4]
at org.springframework.integration.handler.support.MessagingMethodInvokerHelper$HandlerMethod.invoke(MessagingMethodInvokerHelper.java:1086) ~[spring-integration-core-6.2.2.jar:6.2.2]
at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.invokeHandlerMethod(MessagingMethodInvokerHelper.java:569) ~[spring-integration-core-6.2.2.jar:6.2.2]
at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.processInternal(MessagingMethodInvokerHelper.java:482) ~[spring-integration-core-6.2.2.jar:6.2.2]
at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.process(MessagingMethodInvokerHelper.java:360) ~[spring-integration-core-6.2.2.jar:6.2.2]
at org.springframework.integration.handler.MethodInvokingMessageProcessor.processMessage(MethodInvokingMessageProcessor.java:114) ~[spring-integration-core-6.2.2.jar:6.2.2]
at org.springframework.integration.handler.ServiceActivatingHandler.handleRequestMessage(ServiceActivatingHandler.java:95) ~[spring-integration-core-6.2.2.jar:6.2.2]
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:145) ~[spring-integration-core-6.2.2.jar:6.2.2]
at org.springframework.integration.handler.AbstractMessageHandler.doHandleMessage(AbstractMessageHandler.java:105) ~[spring-integration-core-6.2.2.jar:6.2.2]
at org.springframework.integration.handler.AbstractMessageHandler.handleWithMetrics(AbstractMessageHandler.java:90) ~[spring-integration-core-6.2.2.jar:6.2.2]
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:70) ~[spring-integration-core-6.2.2.jar:6.2.2]
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:132) ~[spring-integration-core-6.2.2.jar:6.2.2]
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:133) ~[spring-integration-core-6.2.2.jar:6.2.2]
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:106) ~[spring-integration-core-6.2.2.jar:6.2.2]
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:72) ~[spring-integration-core-6.2.2.jar:6.2.2]
at org.springframework.integration.channel.AbstractMessageChannel.sendInternal(AbstractMessageChannel.java:378) ~[spring-integration-core-6.2.2.jar:6.2.2]
at org.springframework.integration.channel.AbstractMessageChannel.sendWithMetrics(AbstractMessageChannel.java:349) ~[spring-integration-core-6.2.2.jar:6.2.2]
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:329) ~[spring-integration-core-6.2.2.jar:6.2.2]
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:302) ~[spring-integration-core-6.2.2.jar:6.2.2]
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:187) ~[spring-messaging-6.1.4.jar:6.1.4]
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:166) ~[spring-messaging-6.1.4.jar:6.1.4]
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:47) ~[spring-messaging-6.1.4.jar:6.1.4]
at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:109) ~[spring-messaging-6.1.4.jar:6.1.4]
at org.springframework.integration.endpoint.MessageProducerSupport.lambda$sendMessage$1(MessageProducerSupport.java:262) ~[spring-integration-core-6.2.2.jar:6.2.2]
at io.micrometer.observation.Observation.observe(Observation.java:499) ~[micrometer-observation-1.12.3.jar:1.12.3]
at org.springframework.integration.endpoint.MessageProducerSupport.sendMessage(MessageProducerSupport.java:262) ~[spring-integration-core-6.2.2.jar:6.2.2]
at org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter.messageArrived(MqttPahoMessageDrivenChannelAdapter.java:371) ~[spring-integration-mqtt-6.2.2.jar:6.2.2]
at org.eclipse.paho.client.mqttv3.internal.CommsCallback.deliverMessage(CommsCallback.java:511) ~[org.eclipse.paho.client.mqttv3-1.2.5.jar:na]
at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:417) ~[org.eclipse.paho.client.mqttv3-1.2.5.jar:na]
at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:214) ~[org.eclipse.paho.client.mqttv3-1.2.5.jar:na]
How to pass a body in case the content-type is hex? or is there another way to make this request?