I try to pass the protobuf parameter to the REST endpoint, but I get
org.springframework.web.client.HttpServerErrorException: 500 null
every time i try. Now I have something like this:
@RestController
public class TestTaskEndpoint {
@PostMapping(value = "/testTask", consumes = "application/x-protobuf", produces = "application/x-protobuf")
TestTaskComplete processTestTask(TestTask testTask) {
return generateResult(testTask);
}
}
@Configuration
public class AppConfiguration {
@Bean
ProtobufHttpMessageConverter protobufHttpMessageConverter() {
return new ProtobufHttpMessageConverter();
}
}
@SpringBootApplication
public class JavaConnectorApplication {
public static void main(String[] args) {
SpringApplication.run(JavaConnectorApplication.class, args);
}
}
and my test is as follows:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
@WebAppConfiguration
public class JavaConnectorApplicationTest {
@Configuration
public static class RestClientConfiguration {
@Bean
RestTemplate restTemplate(ProtobufHttpMessageConverter hmc) {
return new RestTemplate(Arrays.asList(hmc));
}
@Bean
ProtobufHttpMessageConverter protobufHttpMessageConverter() {
return new ProtobufHttpMessageConverter();
}
}
@Autowired
private RestTemplate restTemplate;
private int port = 8081;
@Test
public void contextLoaded() {
TestTask testTask = generateTestTask();
final String url = "http://127.0.0.1:" + port + "/testTask/";
ResponseEntity<TestTaskComplete> customer = restTemplate.postForEntity(url, testTask, TestTaskComplete.class);
}
}
I'm sure this is something with parameters, because if I create an option that does not accept the protobuf parameter, but returns it, it just works fine. I tried debugging the controller code, but the execution does not reach the method, so the problem is probably in a different place. How to properly parameterize this REST method?
source
share