【问题标题】:Android rest template - GET request - Too many redirectsAndroid 休息模板 - GET 请求 - 重定向过多
【发布时间】:2013-12-05 10:11:28
【问题描述】:

我有一个触发重定向的 REST GET 请求,或者看起来……

这是日志输出:

D/AndroidRuntime(1353): 关闭虚拟机 W/dalvikvm(1353):threadid=1:线程退出但未捕获异常(组=0xb2ab3b90) E/AndroidRuntime(1353):致命异常:主要 E/AndroidRuntime(1353):进程:com.thalasoft.learnintouch.android,PID:1353 E/AndroidRuntime(1353):java.lang.RuntimeException:无法启动活动 ComponentInfo{com.thalasoft.learnintouch.android/com.thalasoft.learnintouch.android.AdminActivity}:org.springframework.web.client.ResourceAccessException:I/ O 错误:重定向过多:21;嵌套异常是 java.net.ProtocolException: Too many redirects: 21

REST 客户端代码:

public class AdminActivity extends Activity {

    private static final String REST_HOST = "10.0.2.2";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.admin_layout);
    }

    @Override
    public void onStart() {
        super.onStart();

        RestTemplate restTemplate = new RestTemplate();
        restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
        HttpHeaders httpHeaders = Common.createAuthenticationHeaders("joethebouncer" + ":" + "mypassword");
        Admin admin = null;
        try {
            ResponseEntity<Admin> responseEntity = restTemplate.exchange("http://" + REST_HOST + ":8080/learnintouch-rest/admin/" + 623L, HttpMethod.GET, new HttpEntity<Object>(httpHeaders), Admin.class);

            if (responseEntity != null) {
                admin = responseEntity.getBody();
                if (admin != null) {
                    TextView textView = (TextView) this.findViewById(R.id.id);
                    textView.setText(Long.toString(admin.getId()));

                    textView = (TextView) this.findViewById(R.id.email);
                    textView.setText(admin.getEmail());

                    textView = (TextView) this.findViewById(R.id.firstname);
                    textView.setText(admin.getFirstname());

                    textView = (TextView) this.findViewById(R.id.lastname);
                    textView.setText(admin.getLastname());

                    textView = (TextView) this.findViewById(R.id.login);
                    textView.setText(admin.getLogin());

                    textView = (TextView) this.findViewById(R.id.password);
                    textView.setText(admin.getPassword());

                    textView = (TextView) this.findViewById(R.id.passwordSalt);
                    textView.setText(admin.getPasswordSalt());
                }
            }
        } catch (HttpClientErrorException e) {
            Log.e("Msg", ">>>>>>>>>>>>>>>> Could not request the rest service " + e.getLocalizedMessage());
        }
    }

}

这是 Spring REST 控制器:

@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
@ResponseBody
public ResponseEntity<Admin> findOne(@PathVariable Long id, UriComponentsBuilder builder) {
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.add("Content-Type", "application/json; charset=utf-8");
    OneAdminEvent oneAdminEvent;
    try {
        oneAdminEvent = adminService.findById(new GetOneAdminEvent(id));
    } catch (NotFoundException e) {
        return new ResponseEntity<Admin>(responseHeaders, HttpStatus.NOT_FOUND);
    }
    responseHeaders.setLocation(builder.path("/admin/{id}").buildAndExpand(oneAdminEvent.getEventAdmin().getId()).toUri());
    Admin admin = adminResourceAssembler.toResource(oneAdminEvent.getEventAdmin());
    ResponseEntity<Admin> responseEntity = new ResponseEntity<Admin>(admin, responseHeaders, HttpStatus.FOUND);
    return responseEntity;
}

我可以使用 curl 请求手动测试我的服务器端 REST 服务:

curl --user joethebouncer:mypassword http://localhost:8080/learnintouch-rest/admin/623
{"links":[{"rel":"self","href":"http://localhost:8080/learnintouch-rest/admin/623"}],"id2":null,"firstname":"Stephane","lastname":"Eybert","email":"joethebouncer@thalasoft.com","login":"joethebouncer","password":"e41de4c55873f9c000f4cdaac6efd3aa","passwordSalt":"7bc7bf5f94fef7c7106afe5c3a40a2"}

而且它不做任何重定向。

这是运行 Andoid 应用 REST GET 请求时的服务器端控制台输出:

2013-12-05 11:12:13,446 DEBUG  [DispatcherServlet] Successfully completed request 
2013-12-05 11:12:13,446 DEBUG  [ExceptionTranslationFilter] Chain processed normally 
2013-12-05 11:12:13,446 DEBUG  [SecurityContextPersistenceFilter] SecurityContextHolder now cleared, as request processing completed 
2013-12-05 11:12:13,471 DEBUG  [AntPathRequestMatcher] Checking match of request : '/admin/623'; against '/admin/**' 
2013-12-05 11:12:13,471 DEBUG  [FilterChainProxy] /admin/623 at position 1 of 9 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter' 
2013-12-05 11:12:13,471 DEBUG  [HttpSessionSecurityContextRepository] No HttpSession currently exists 
2013-12-05 11:12:13,471 DEBUG  [HttpSessionSecurityContextRepository] No SecurityContext was available from the HttpSession: null. A new one will be created. 
2013-12-05 11:12:13,471 DEBUG  [FilterChainProxy] /admin/623 at position 2 of 9 in additional filter chain; firing Filter: 'LogoutFilter' 
2013-12-05 11:12:13,471 DEBUG  [FilterChainProxy] /admin/623 at position 3 of 9 in additional filter chain; firing Filter: 'BasicAuthenticationFilter' 
2013-12-05 11:12:13,471 DEBUG  [BasicAuthenticationFilter] Basic Authentication Authorization header found for user 'joethebouncer' 
2013-12-05 11:12:13,471 DEBUG  [ProviderManager] Authentication attempt using com.thalasoft.learnintouch.rest.security.CustomAuthenticationProvider 
2013-12-05 11:12:13,471 DEBUG  [DefaultListableBeanFactory] Returning cached instance of singleton bean 'transactionManager' 
2013-12-05 11:12:13,471 DEBUG  [JpaTransactionManager] Creating new transaction with name [com.thalasoft.learnintouch.data.service.jpa.AdminServiceImpl.findByLogin]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; '' 
2013-12-05 11:12:13,471 DEBUG  [JpaTransactionManager] Opened new EntityManager [org.hibernate.ejb.EntityManagerImpl@1812c48] for JPA transaction 
2013-12-05 11:12:13,471 DEBUG  [DriverManagerDataSource] Creating new JDBC DriverManager Connection to [jdbc:log4jdbc:mysql://127.0.0.1:3306/db_integration] 
2013-12-05 11:12:13,478 DEBUG  [JpaTransactionManager] Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@e9ac75] 
Hibernate: 
    select
        admin0_.id as id14_,
        admin0_.version as version14_,
        admin0_.address as address14_,
        admin0_.city as city14_,
        admin0_.country as country14_,
        admin0_.email as email14_,
        admin0_.firstname as firstname14_,
        admin0_.lastname as lastname14_,
        admin0_.login as login14_,
        admin0_.password as password14_,
        admin0_.password_salt as password11_14_,
        admin0_.post_login_url as post12_14_,
        admin0_.preference_admin as preference13_14_,
        admin0_.profile as profile14_,
        admin0_.super_admin as super15_14_,
        admin0_.zip_code as zip16_14_ 
    from
        admin admin0_ 
    where
        admin0_.login=? limit ?
2013-12-05 11:12:13,480 TRACE  [BasicBinder] binding parameter [1] as [VARCHAR] - joethebouncer 
2013-12-05 11:12:13,481 DEBUG  [sqlonly]  org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
282. select admin0_.id as id14_, admin0_.version as version14_, admin0_.address as address14_, admin0_.city 
as city14_, admin0_.country as country14_, admin0_.email as email14_, admin0_.firstname as 
firstname14_, admin0_.lastname as lastname14_, admin0_.login as login14_, admin0_.password 
as password14_, admin0_.password_salt as password11_14_, admin0_.post_login_url as post12_14_, 
admin0_.preference_admin as preference13_14_, admin0_.profile as profile14_, admin0_.super_admin 
as super15_14_, admin0_.zip_code as zip16_14_ from admin admin0_ where admin0_.login='joethebouncer' 
limit 2  
2013-12-05 11:12:13,484 TRACE  [BasicExtractor] found [623] as column [id14_] 
2013-12-05 11:12:13,485 TRACE  [BasicExtractor] found [0] as column [version14_] 
2013-12-05 11:12:13,486 TRACE  [BasicExtractor] found [] as column [address14_] 
2013-12-05 11:12:13,486 TRACE  [BasicExtractor] found [] as column [city14_] 
2013-12-05 11:12:13,487 TRACE  [BasicExtractor] found [] as column [country14_] 
2013-12-05 11:12:13,488 TRACE  [BasicExtractor] found [joethebouncer@thalasoft.com] as column [email14_] 
2013-12-05 11:12:13,488 TRACE  [BasicExtractor] found [Stephane] as column [firstname14_] 
2013-12-05 11:12:13,489 TRACE  [BasicExtractor] found [Eybert] as column [lastname14_] 
2013-12-05 11:12:13,489 TRACE  [BasicExtractor] found [joethebouncer] as column [login14_] 
2013-12-05 11:12:13,490 TRACE  [BasicExtractor] found [e41de4c55873f9c000f4cdaac6efd3aa] as column [password14_] 
2013-12-05 11:12:13,491 TRACE  [BasicExtractor] found [7bc7bf5f94fef7c7106afe5c3a40a2] as column [password11_14_] 
2013-12-05 11:12:13,491 TRACE  [BasicExtractor] found [null] as column [post12_14_] 
2013-12-05 11:12:13,492 TRACE  [BasicExtractor] found [false] as column [preference13_14_] 
2013-12-05 11:12:13,492 TRACE  [BasicExtractor] found [] as column [profile14_] 
2013-12-05 11:12:13,493 TRACE  [BasicExtractor] found [true] as column [super15_14_] 
2013-12-05 11:12:13,493 TRACE  [BasicExtractor] found [] as column [zip16_14_] 
2013-12-05 11:12:13,496 DEBUG  [JpaTransactionManager] Initiating transaction commit 
2013-12-05 11:12:13,496 DEBUG  [JpaTransactionManager] Committing JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl@1812c48] 
2013-12-05 11:12:13,499 DEBUG  [JpaTransactionManager] Closing JPA EntityManager [org.hibernate.ejb.EntityManagerImpl@1812c48] after transaction 
2013-12-05 11:12:13,499 DEBUG  [EntityManagerFactoryUtils] Closing JPA EntityManager 
2013-12-05 11:12:13,499 DEBUG  [DefaultListableBeanFactory] Returning cached instance of singleton bean 'transactionManager' 
2013-12-05 11:12:13,499 DEBUG  [JpaTransactionManager] Creating new transaction with name [com.thalasoft.learnintouch.data.service.jpa.AdminServiceImpl.checkPassword]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; '' 
2013-12-05 11:12:13,499 DEBUG  [JpaTransactionManager] Opened new EntityManager [org.hibernate.ejb.EntityManagerImpl@97f1ff] for JPA transaction 
2013-12-05 11:12:13,499 DEBUG  [DriverManagerDataSource] Creating new JDBC DriverManager Connection to [jdbc:log4jdbc:mysql://127.0.0.1:3306/db_integration] 
2013-12-05 11:12:13,507 DEBUG  [JpaTransactionManager] Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@16354d0] 
2013-12-05 11:12:13,507 DEBUG  [JpaTransactionManager] Initiating transaction commit 
2013-12-05 11:12:13,507 DEBUG  [JpaTransactionManager] Committing JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl@97f1ff] 
2013-12-05 11:12:13,509 DEBUG  [JpaTransactionManager] Closing JPA EntityManager [org.hibernate.ejb.EntityManagerImpl@97f1ff] after transaction 
2013-12-05 11:12:13,509 DEBUG  [EntityManagerFactoryUtils] Closing JPA EntityManager 
2013-12-05 11:12:13,509 DEBUG  [BasicAuthenticationFilter] Authentication success: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@833e8985: Principal: joethebouncer; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null; Granted Authorities: ROLE_ADMIN 
2013-12-05 11:12:13,509 DEBUG  [FilterChainProxy] /admin/623 at position 4 of 9 in additional filter chain; firing Filter: 'RequestCacheAwareFilter' 
2013-12-05 11:12:13,509 DEBUG  [FilterChainProxy] /admin/623 at position 5 of 9 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter' 
2013-12-05 11:12:13,509 DEBUG  [FilterChainProxy] /admin/623 at position 6 of 9 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter' 
2013-12-05 11:12:13,509 DEBUG  [AnonymousAuthenticationFilter] SecurityContextHolder not populated with anonymous token, as it already contained: 'org.springframework.security.authentication.UsernamePasswordAuthenticationToken@833e8985: Principal: joethebouncer; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null; Granted Authorities: ROLE_ADMIN' 
2013-12-05 11:12:13,509 DEBUG  [FilterChainProxy] /admin/623 at position 7 of 9 in additional filter chain; firing Filter: 'SessionManagementFilter' 
2013-12-05 11:12:13,509 DEBUG  [HttpSessionSecurityContextRepository] HttpSession being created as SecurityContext is non-default 
2013-12-05 11:12:13,509 DEBUG  [HttpSessionSecurityContextRepository] SecurityContext stored to HttpSession: 'org.springframework.security.core.context.SecurityContextImpl@833e8985: Authentication: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@833e8985: Principal: joethebouncer; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null; Granted Authorities: ROLE_ADMIN' 
2013-12-05 11:12:13,510 DEBUG  [FilterChainProxy] /admin/623 at position 8 of 9 in additional filter chain; firing Filter: 'ExceptionTranslationFilter' 
2013-12-05 11:12:13,510 DEBUG  [FilterChainProxy] /admin/623 at position 9 of 9 in additional filter chain; firing Filter: 'FilterSecurityInterceptor' 
2013-12-05 11:12:13,510 DEBUG  [FilterSecurityInterceptor] Secure object: FilterInvocation: URL: /admin/623; Attributes: [hasRole('ROLE_ADMIN')] 
2013-12-05 11:12:13,510 DEBUG  [FilterSecurityInterceptor] Previously Authenticated: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@833e8985: Principal: joethebouncer; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null; Granted Authorities: ROLE_ADMIN 
2013-12-05 11:12:13,510 DEBUG  [AffirmativeBased] Voter: org.springframework.security.web.access.expression.WebExpressionVoter@115654d, returned: 1 
2013-12-05 11:12:13,510 DEBUG  [FilterSecurityInterceptor] Authorization successful 
2013-12-05 11:12:13,510 DEBUG  [FilterSecurityInterceptor] RunAsManager did not change Authentication object 
2013-12-05 11:12:13,510 DEBUG  [FilterChainProxy] /admin/623 reached end of additional filter chain; proceeding with original chain 
2013-12-05 11:12:13,510 DEBUG  [DispatcherServlet] DispatcherServlet with name 'dispatcher' processing GET request for [/learnintouch-rest/admin/623] 
2013-12-05 11:12:13,510 DEBUG  [RequestMappingHandlerMapping] Looking up handler method for path /admin/623 
2013-12-05 11:12:13,511 DEBUG  [RequestMappingHandlerMapping] Returning handler method [public org.springframework.http.ResponseEntity<com.thalasoft.learnintouch.rest.domain.Admin> com.thalasoft.learnintouch.rest.controller.AdminController.findOne(java.lang.Long,org.springframework.web.util.UriComponentsBuilder)] 
2013-12-05 11:12:13,511 DEBUG  [DefaultListableBeanFactory] Returning cached instance of singleton bean 'adminController' 
2013-12-05 11:12:13,511 DEBUG  [DispatcherServlet] Last-Modified value for [/learnintouch-rest/admin/623] is: -1 
2013-12-05 11:12:13,511 DEBUG  [DefaultListableBeanFactory] Returning cached instance of singleton bean 'transactionManager' 
2013-12-05 11:12:13,511 DEBUG  [JpaTransactionManager] Creating new transaction with name [com.thalasoft.learnintouch.data.service.jpa.AdminServiceImpl.findById]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; '' 
2013-12-05 11:12:13,511 DEBUG  [JpaTransactionManager] Opened new EntityManager [org.hibernate.ejb.EntityManagerImpl@b410a] for JPA transaction 
2013-12-05 11:12:13,512 DEBUG  [DriverManagerDataSource] Creating new JDBC DriverManager Connection to [jdbc:log4jdbc:mysql://127.0.0.1:3306/db_integration] 
2013-12-05 11:12:13,520 DEBUG  [JpaTransactionManager] Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@a709f3] 
2013-12-05 11:12:13,520 DEBUG  [DefaultListableBeanFactory] Returning cached instance of singleton bean 'transactionManager' 
2013-12-05 11:12:13,520 DEBUG  [JpaTransactionManager] Found thread-bound EntityManager [org.hibernate.ejb.EntityManagerImpl@b410a] for JPA transaction 
2013-12-05 11:12:13,520 DEBUG  [JpaTransactionManager] Participating in existing transaction 
Hibernate: 
    select
        admin0_.id as id14_0_,
        admin0_.version as version14_0_,
        admin0_.address as address14_0_,
        admin0_.city as city14_0_,
        admin0_.country as country14_0_,
        admin0_.email as email14_0_,
        admin0_.firstname as firstname14_0_,
        admin0_.lastname as lastname14_0_,
        admin0_.login as login14_0_,
        admin0_.password as password14_0_,
        admin0_.password_salt as password11_14_0_,
        admin0_.post_login_url as post12_14_0_,
        admin0_.preference_admin as preference13_14_0_,
        admin0_.profile as profile14_0_,
        admin0_.super_admin as super15_14_0_,
        admin0_.zip_code as zip16_14_0_ 
    from
        admin admin0_ 
    where
        admin0_.id=?
2013-12-05 11:12:13,522 TRACE  [BasicBinder] binding parameter [1] as [BIGINT] - 623 
2013-12-05 11:12:13,523 DEBUG  [sqlonly]  org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
284. select admin0_.id as id14_0_, admin0_.version as version14_0_, admin0_.address as address14_0_, 
admin0_.city as city14_0_, admin0_.country as country14_0_, admin0_.email as email14_0_, admin0_.firstname 
as firstname14_0_, admin0_.lastname as lastname14_0_, admin0_.login as login14_0_, admin0_.password 
as password14_0_, admin0_.password_salt as password11_14_0_, admin0_.post_login_url as post12_14_0_, 
admin0_.preference_admin as preference13_14_0_, admin0_.profile as profile14_0_, admin0_.super_admin 
as super15_14_0_, admin0_.zip_code as zip16_14_0_ from admin admin0_ where admin0_.id=623  
2013-12-05 11:12:13,527 TRACE  [BasicExtractor] found [0] as column [version14_0_] 
2013-12-05 11:12:13,528 TRACE  [BasicExtractor] found [] as column [address14_0_] 
2013-12-05 11:12:13,529 TRACE  [BasicExtractor] found [] as column [city14_0_] 
2013-12-05 11:12:13,529 TRACE  [BasicExtractor] found [] as column [country14_0_] 
2013-12-05 11:12:13,531 TRACE  [BasicExtractor] found [joethebouncer@thalasoft.com] as column [email14_0_] 
2013-12-05 11:12:13,532 TRACE  [BasicExtractor] found [Stephane] as column [firstname14_0_] 
2013-12-05 11:12:13,532 TRACE  [BasicExtractor] found [Eybert] as column [lastname14_0_] 
2013-12-05 11:12:13,533 TRACE  [BasicExtractor] found [joethebouncer] as column [login14_0_] 
2013-12-05 11:12:13,534 TRACE  [BasicExtractor] found [e41de4c55873f9c000f4cdaac6efd3aa] as column [password14_0_] 
2013-12-05 11:12:13,535 TRACE  [BasicExtractor] found [7bc7bf5f94fef7c7106afe5c3a40a2] as column [password11_14_0_] 
2013-12-05 11:12:13,536 TRACE  [BasicExtractor] found [null] as column [post12_14_0_] 
2013-12-05 11:12:13,537 TRACE  [BasicExtractor] found [false] as column [preference13_14_0_] 
2013-12-05 11:12:13,537 TRACE  [BasicExtractor] found [] as column [profile14_0_] 
2013-12-05 11:12:13,538 TRACE  [BasicExtractor] found [true] as column [super15_14_0_] 
2013-12-05 11:12:13,539 TRACE  [BasicExtractor] found [] as column [zip16_14_0_] 
2013-12-05 11:12:13,543 DEBUG  [JpaTransactionManager] Initiating transaction commit 
2013-12-05 11:12:13,543 DEBUG  [JpaTransactionManager] Committing JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl@b410a] 
2013-12-05 11:12:13,546 DEBUG  [JpaTransactionManager] Closing JPA EntityManager [org.hibernate.ejb.EntityManagerImpl@b410a] after transaction 
2013-12-05 11:12:13,546 DEBUG  [EntityManagerFactoryUtils] Closing JPA EntityManager 
2013-12-05 11:12:13,555 DEBUG  [HttpSessionSecurityContextRepository] SecurityContext stored to HttpSession: 'org.springframework.security.core.context.SecurityContextImpl@833e8985: Authentication: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@833e8985: Principal: joethebouncer; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null; Granted Authorities: ROLE_ADMIN' 
2013-12-05 11:12:13,556 DEBUG  [HttpSessionSecurityContextRepository] SecurityContext stored to HttpSession: 'org.springframework.security.core.context.SecurityContextImpl@833e8985: Authentication: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@833e8985: Principal: joethebouncer; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null; Granted Authorities: ROLE_ADMIN' 
2013-12-05 11:12:13,556 DEBUG  [HttpEntityMethodProcessor] Written [links: [<http://10.0.2.2:8080/learnintouch-rest/admin/623>;rel="self"]] as "application/json;charset=utf-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@b72a5e] 
2013-12-05 11:12:13,556 DEBUG  [DispatcherServlet] Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling 
2013-12-05 11:12:13,556 DEBUG  [DispatcherServlet] Successfully completed request 
2013-12-05 11:12:13,556 DEBUG  [ExceptionTranslationFilter] Chain processed normally 
2013-12-05 11:12:13,556 DEBUG  [SecurityContextPersistenceFilter] SecurityContextHolder now cleared, as request processing completed

另外,wireshark 只重复显示这两个帧:

No.     Time           Source                Destination           Protocol Length Info
    320 20.659878000   127.0.0.1             127.0.0.1             HTTP     375    GET /learnintouch-rest/admin/623 HTTP/1.1 

Frame 320: 375 bytes on wire (3000 bits), 375 bytes captured (3000 bits) on interface 0
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol Version 4, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 (127.0.0.1)
Transmission Control Protocol, Src Port: 57253 (57253), Dst Port: http-alt (8080), Seq: 1, Ack: 1, Len: 309
Hypertext Transfer Protocol

No.     Time           Source                Destination           Protocol Length Info
    427 20.741684000   127.0.0.1             127.0.0.1             HTTP     71     HTTP/1.1 302 Found  (application/json)

Frame 427: 71 bytes on wire (568 bits), 71 bytes captured (568 bits) on interface 0
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol Version 4, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 (127.0.0.1)
Transmission Control Protocol, Src Port: http-alt (8080), Dst Port: 57253 (57253), Seq: 615, Ack: 310, Len: 5
[2 Reassembled TCP Segments (619 bytes): #425(614), #427(5)]
Hypertext Transfer Protocol
JavaScript Object Notation: application/json

No.     Time           Source                Destination           Protocol Length Info
    429 20.794399000   127.0.0.1             127.0.0.1             HTTP     375    GET /learnintouch-rest/admin/623 HTTP/1.1 

Frame 429: 375 bytes on wire (3000 bits), 375 bytes captured (3000 bits) on interface 0
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol Version 4, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 (127.0.0.1)
Transmission Control Protocol, Src Port: 57253 (57253), Dst Port: http-alt (8080), Seq: 310, Ack: 620, Len: 309
Hypertext Transfer Protocol

No.     Time           Source                Destination           Protocol Length Info
    517 20.872213000   127.0.0.1             127.0.0.1             HTTP     71     HTTP/1.1 302 Found  (application/json)

Frame 517: 71 bytes on wire (568 bits), 71 bytes captured (568 bits) on interface 0
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol Version 4, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 (127.0.0.1)
Transmission Control Protocol, Src Port: http-alt (8080), Dst Port: 57253 (57253), Seq: 1234, Ack: 619, Len: 5
[2 Reassembled TCP Segments (619 bytes): #515(614), #517(5)]
Hypertext Transfer Protocol
JavaScript Object Notation: application/json

有什么线索吗?

亲切的问候,

【问题讨论】:

  • 我现在看到状态码 302 正在触发重定向到我提供的 Location 标头,这是规范所要求的。我错过了那个。我现在必须看看我应该返回哪个状态码。
  • http 状态码 FOUND 302 用于触发对临时移动资源的重定向。不是我想要的。相反,我将使用 OK 200 状态码。
  • 您是如何解决这个问题的? @斯蒂芬

标签: android rest redirect


【解决方案1】:

http 状态码 FOUND 302 用于触发对移动的临时资源的重定向。不是我想要的。相反,我将使用 OK 200 状态码。

下面是 REST 控制器响应现在的样子:

ResponseEntity<Admin> responseEntity = new ResponseEntity<Admin>(admin, responseHeaders, HttpStatus.OK);

【讨论】:

    猜你喜欢
    • 2021-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-16
    • 2019-10-12
    • 2020-12-17
    • 2018-11-26
    相关资源
    最近更新 更多