spring-rest

Invalid mime type in spring rest template?

蹲街弑〆低调 提交于 2019-12-24 09:17:52
问题 I am just trying to make a simple REST request like below String url = "some url"; MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); headers.add(HttpHeaders.AUTHORIZATION, "some authorization"); RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter()); Body body = new Body(); body.setRemarks("test"); org.springframework.http

Advice about Swagger API

孤者浪人 提交于 2019-12-24 02:18:09
问题 I'm building an API using SpringBoot and Spring REST services using Java 8. I've just discovered Swagger API and now I would like to make my API Swagger compliant. As far I read, Swagger is a tool to document your APIS, but also provides functionalities to generate the client and server code from an specification (swagger.json in v2), besides of a nice web interface to interact with your API. Now, I would like some recommendations about how to proceed, given that I already have an existing

Spring-Boot disable transfer-coding from response header

岁酱吖の 提交于 2019-12-24 00:46:17
问题 Problem statement - a simple RESTful service in Spring-Boot (2.0.1.RELEASE, and embedded Tomcat Server) returns response like, HTTP/1.1 200 Content-Type: application/json;charset=UTF-8 Transfer-Encoding: chunked Date: Tue, 01 May 2018 00:33:04 GMT 7d {the-json-response-anticipated} 0 After a search-and-find, I found that this is caused due to the header Transfer-Encoding: chunked . Tried setting the following in application.properties spring.http.encoding.force=false spring.http.encoding

Spring Data REST Neo4j create a relationship

天大地大妈咪最大 提交于 2019-12-24 00:20:05
问题 I'm building a little test app as a way to learn Angular and refresh myself on a lot of the Spring stack. I have some minor experience with Neo4J, but the app idea has ground with a graph db like Neo4j. The idea is pretty simple, a ui to create characters and stories, and relate the characters to the stories and each other, map their individual versions of a story and create some graphs that show the character interactions to help write the overall narrative. I've got nodes for the characters

How to run @RestController on a different port?

僤鯓⒐⒋嵵緔 提交于 2019-12-23 20:15:00
问题 I'm using spring-rest to create some @RestController servlets. The application is not run on a webserver, but as a simple command line tool with embedded tomcat. Most of them should be running on a public port, which is specified using server.port=80 property. Question: how can I run different @RestController on different ports? So that some of them are only accessibly internally? @RestController @RequestMapping("test") public class TestServlet { @RequestMapping(value = "/", method =

How can I use Pageable in @RestController?

 ̄綄美尐妖づ 提交于 2019-12-23 12:19:06
问题 I know the Pageable comes from spring-data- domain. Is there any elegant way to directly use org.springframework.data.domain.Pageable in @RestController ? I tried following. @RequestMapping(method = RequestMethod.GET, path = "pageable", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Pageable> readPageable(@NotNull final Pageable pageable) { return ResponseEntity.ok(pageable); } The result is not what I expected. ...: ~ $ curl -X GET --header 'Accept: application/json'

restTemplate delete with body

对着背影说爱祢 提交于 2019-12-23 02:26:46
问题 I am trying to do DELETE with request body but I keep getting 400 (bad request) error. When I do it in the swagger/postman, it is successfully deleting the record. But from the Java code I can't do that The external API is designed in a way that it needs body along with URL. It can't be changed. please let me know how can I delete that entry with request body public Person delete(Person person, String url, Map<String, String> uriVariables) throws JsonProcessingException { RestTemplate

Generic Repository in Spring JPA

非 Y 不嫁゛ 提交于 2019-12-20 03:50:10
问题 We are working on a Restful project with lots of DB tables. Though the operations on the tables are almost same and mainly INSERT/UPDATE/DELETE/FETCH. my questions is: will we have to create a repository (extending JpaRepository) for every entity (Domain class) we create or, there is an option of creating a GenericRepository that can handle all the above-mentioned functionalities for all the entities? i.e a single GenericRepository for all. if so, could you share an example? 回答1: is [there]

Get XML in plain text

喜你入骨 提交于 2019-12-14 03:43:44
问题 I have this endpoint for Spring Rest API: @PostMapping(value = "/v1/", consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }) public PaymentResponse handleMessage(@RequestBody PaymentTransaction transaction, HttpServletRequest request) throws Exception { // get here plain XML } XML model. @XmlRootElement(name = "payment_transaction") @XmlAccessorType(XmlAccessType.FIELD) public class

JsonPath OR condition using MockMVC

久未见 提交于 2019-12-14 03:03:17
问题 I am practicing MockMVC for rest call unit testing. how can we test the Boolean values so that whether the result is true or false I need to pass the test, I tried as follows, mockMvc.perform(get("/student/{Id}", 1L)). .andExpect(status().isOk()) .andExpect(jsonPath("$.isPass", is(true || false))); Also I have list with 6 values, how can use list contains all kind of method, .andExpect(jsonPath("$.subjectList", hasSize(5))) .andExpect(jsonPath("$.subjectList.name", Matchers.contains("English"