Spring WebClient调用Rest-Service:来自Jaxb2XmlDecoder的异常

时间:2018-02-18 12:38:10

标签: spring spring-mvc reactive-programming

我目前正在与Springs反应UnsupportedOperationException争夺休息服务。我从Springs decodeToMono获得了Jaxb2XmlDecoder - public Mono<T> decodeToMono(Publisher<DataBuffer> inputStream, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { throw new UnsupportedOperationException(); } 函数。

ResponseEntity<MyAsyncResponse> result = webClient.post()
        .contentType(MediaType.APPLICATION_XML)
        .syncBody(payload)
        .exchange()
        .flatMap(res -> res.toEntity(MyAsyncResponse.class))
        .block();

我的WebClient电话:

@RestController
public class MyAsyncController {

  @PostMapping(path = "foo")
  private CompletableFuture<MyAsyncResponse> getFoo() {
    return getMyAsyncResponse();
  }

  ...

休息服务:

Decoder

我需要配置什么,使用合适的 <?php $sql = "select * from contact_master"; $query = mysqli_query($conn, $sql) ; while ($row = mysqli_fetch_array($query)){ ?> <tr class="odd gradeX" > <td><input type="checkbox" name="chk[]" class="chk-box"/></td> <td><?php echo $row['Contact_Name']; ?> <input type="checkbox" id="myCheck" name="chk[]" class="chk-box" onclick="myFunction()"/></td> <td ><?php echo $row['Contact_Phone']; ?><input type="checkbox" id="myCheck" name="chk[]" class="chk-box" onclick="myFunction()" /></td> <td><?php echo $row['Contact_Email']; ?><input type="checkbox" id="myCheck" name="chk[]" class="chk-box" onclick="myFunction()"/></td> <td ><?php echo $row['Contact_Facebook']; ?><input type="checkbox" id="myCheck" name="chk[]" class="chk-box" onclick="myFunction()"/></td> <td ><?php echo $row['Contact_Wechat']; ?><input type="checkbox" id="myCheck" name="chk[]" class="chk-box" onclick="myFunction()"/></td> <td ><?php echo $row['Contact_Whatsapp']; ?><input type="checkbox" id="myCheck" name="chk[]" class="chk-box" onclick="myFunction()"/></td> <td ><?php echo $row['Contact_Linkin']; ?><input type="checkbox" id="myCheck" name="chk[]" class="chk-box" onclick="myFunction()"/></td> <td ><?php echo $row['Contact_Twitter']; ?><input type="checkbox" id="myCheck" name="chk[]" class="chk-box" onclick="myFunction()"/></td> <input type="submit" name="submit" value="Submit"/> //this is how i connect data from the database <?php $sql = "SELECT * FROM contact_master"; $result = mysqli_query( $conn, $sql ); if( $result ){ // success! check results while( $row = mysqli_fetch_assoc( $result )){ $i = 0 { $Contact_Name = $row['Contact_Name']; if(isset($_POST[$Contact_Name])!=NULL) { $i = 0; $i++; mysqli_query("select * from contact_master Where Contact_Name = $Contact_Name")or die(mysql_error()); }}}} $i = 0; echo "Selected Contact".$i['Contact_Name'] ?> </html> </tr> - 实现?这是一个普通的Spring-MVC(v5.0.3)应用程序,不是Spring-Boot

2 个答案:

答案 0 :(得分:1)

Take()未实施Jaxb2XmlDecoder,但现已通过SPR-16759修复。因此,只需升级到Spring Framework 5.0.6+ / Spring Boot 2.0.2+就可以避免报告的异常。

答案 1 :(得分:-1)

这是Spring 5.0.3中Jaxb2XmlDecoder的已知问题,它无法解码简单的单个消息(但是,它可以解码消息流)。

请参阅基类 - https://github.com/spring-projects/spring-framework/blob/master/spring-core/src/main/java/org/springframework/core/codec/AbstractDecoder.java

Jaxb2XmlDecoder不会覆盖“decodeToMono”方法。

要解决此问题,请按照以下样式创建自己的解码器并更新配置:

在科特林:

@Bean
open fun webFluxConfigurer(myReader: MyReader,                               
                           myWriter: MyWriter): WebFluxConfigurer {
    return object : WebFluxConfigurer {
        override fun configureHttpMessageCodecs(configurer: ServerCodecConfigurer) {
            // disable default codecs, because of problematic XML serialization in Jaxb2XmlDecoder
            configurer.registerDefaults(false)

            configurer.customCodecs().decoder(myReader)

            configurer.customCodecs().encoder(myWriter)
        }
    }

}

或者在Java上:

@Bean
WebFluxConfigurer webFluxConfigurer(MyReader myReader, MyWriter myWriter){ 
    return new WebFluxConfigurer() {
        @Override
        public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
            // disable default codecs, because of problematic XML serialization in Jaxb2XmlDecoder
            configurer.registerDefaults(false);

            configurer.customCodecs().decoder(myReader);

            configurer.customCodecs().encoder(myWriter);
        }
    };

}