Tag: spring rest

无法从salesforce站点重定向回Spring Boot JSP

我正在开发Spring Boot + Apache Oltu + Salesforce Integration示例。 在这个例子中,我试图调用Salesforce URL,但它应该通过Controller进行,但不会被调用。 问题是什么? 在后端,以下是执行,但不知道为什么它不重定向? 有什么快速帮助? @RequestMapping(value = “/redirect”, method = RequestMethod.GET) public HttpEntity redirect( @RequestParam(value = “code”, required = false) String code) throws OAuthSystemException, OAuthProblemException { String value = “UNKNOWN”; if (code != null && code.length() > 0) { System.out.println(“Received CODE: “+code); String details = getAccessToken(code); value […]

SpingREST:无法打开JPA EntityManager进行事务处理; 嵌套exception是org.hiberna

当我启动Postman看到我的SpringREST服务运行时,我收到以下错误: { “timestamp”: 1506965117328, “status”: 500, “error”: “Internal Server Error”, “exception”: “org.springframework.transaction.CannotCreateTransactionException”, “message”: “Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection”, “path”: “/api/matchs” } 我不知道错误在哪里,这里是项目的类: 的pom.xml 4.0.0 com.kaluzny spring-boot-rest-api-postgresql 0.0.1-SNAPSHOT jar org.springframework.boot spring-boot-starter-parent 1.5.3.RELEASE UTF-8 UTF-8 1.8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-data-rest org.springframework.boot spring-boot-starter-data-jpa org.springframework.boot spring-boot-starter-test test org.springframework.boot […]

restTemplate用body删除

我正在尝试使用请求正文进行DELETE,但我一直收到400(错误的请求)错误。 当我在招摇/邮递员中这样做时,它成功删除了记录。 但是从Java代码我不能这样做 外部API的设计方式需要正文和URL。 它无法改变。 请告诉我如何删除请求正文的条目 public Person delete(Person person, String url, Map uriVariables) throws JsonProcessingException { RestTemplate restTemplate = new RestTemplate(); CustomObjectMapper mapper = new CustomObjectMapper(); HttpEntity requestEntity = new HttpEntity(person); try { ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.DELETE, requestEntity, Person.class, uriVariables); return responseEntity.getBody(); } catch (RestClientException e) { System.out.println(mapper.writeValueAsString(person)); throw e; } } 当它转到exception时,我将以JSON格式获得JSON请求,并且在Swagger […]

如何将RestTemplate与多种响应类型一起使用?

我正在使用spring RestTemplate与xml webservice后端进行通信,如下所示: ResponseEntity dto = restTemplate.postForObject(url, postData, MainDTO.class); 问题:后端可以使用MainDTO响应正常数据,也可以使用MainDTO响应失败。 但是两者都使用HTTP 200 。 但我不知道之前会有哪些物体回来! 无论如何restTemplate要求我之前传递class类型。 那么,我怎么能将xml解析为普通或错误bean? 旁注:我对webservice后端没有任何控制权。

测试使用PersistentEntityResourceAssembler的自定义RepositoryRestController

我有一个RepositoryRestController ,它为一些持久性实体公开资源。 我的控制器上有一个方法,它使用PersistentEntityResourceAssembler来帮助我自动生成资源。 @RepositoryRestController @ExposesResourceFor(Customer.class) @RequestMapping(“/api/customers”) public class CustomerController { @Autowired private CustomerService service; @RequestMapping(method = GET, value=”current”) public ResponseEntity getCurrent(Principal principal Long id, PersistentEntityResourceAssembler assembler) { return ResponseEntity.ok(assembler.toResource(service.getForPrincipal(principal))); } } (举例说明,但它可以节省关于我的用例的无关细节的太多细节) 我想为我的控制器编写测试(我的实际用例实际上值得测试),并且我正在计划使用@WebMvcTest。 所以我有以下测试类: @RunWith(SpringRunner.class) @WebMvcTest(CustomerController.class) @AutoConfigureMockMvc(secure=false) public class CustomerControllerTest { @Autowired private MockMvc client; @MockBean private CustomerService service; @Test public void testSomething() { // […]

在Spring REST控制器中读取HTTP标头

我试图在基于Spring的REST API中读取HTTP头。 我跟着这个 。 但是我收到了这个错误: 没有为类java.lang.String找到消息正文阅读器, ContentType:application / octet-stream 我是Java和Spring的新手,所以无法弄清楚这一点。 这就是我的通话方式: @WebService(serviceName = “common”) @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public interface CommonApiService { @GET @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.APPLICATION_JSON) @Path(“/data”) public ResponseEntity getData(@RequestHeader(value=”User-Agent”) String userAgent, @DefaultValue (“”) @QueryParam(“ID”) String id); } 我试过@Context :在这种情况下,HTTPHeader为null 。 如何从HTTP标头中获取值?

使用REST和Javaconfig在Spring Security中消化Auth

我在使用spring security设置摘要式身份validation时遇到问题: 我的安全配置: @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private UserService userService; @Override @Bean public UserDetailsService userDetailsServiceBean() { return userService; } @Override protected void configure(AuthenticationManagerBuilder registry) throws Exception { registry.userDetailsService(userDetailsServiceBean()); } @Override public void configure(WebSecurity web) throws Exception { web.ignoring().antMatchers(“/resources/**”); } @Override protected void configure(HttpSecurity http) throws Exception { […]