OAuthProblemException{error='unsupported_response_type', description='Invalid re

OAuthProblemException{error='unsupported_response_type', description='Invalid response! Response body is not application/json encoded', uri='null', state='null', scope='null', redirectUri='null', responseStatus=0, parameters={}}


以前用了 藍緣系統的開源代碼 整合開濤兄的  OAuth2 shiro集成功能的時候 整合的時候發現 一直報上面這個錯誤 網上搜了很久都沒找到,最後發現

<!-- 採用SpringMVC自帶的JSON轉換工具,支持@ResponseBody註解 -->
	<!--<ref bean="mappingJackson2HttpMessageConverter" />   -->  <!-- JSON轉換器 -->
 
	<bean
		class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
		<property name="messageConverters">
			<list>
				<ref bean="mappingJackson2HttpMessageConverter" />    
		  	</list>
		</property>
	</bean>

若是不把上面的去掉那麼 oathu2response返回的json被上面的攔截後處理成了這樣


這樣的話 paeseJson方法裏 轉化json就會報錯

若是去掉上面的配置 獲得的
protected void setBody(String body) throws OAuthProblemException {

        try {
            this.body = body;
            parameters = JSONUtils.parseJSON(body);
        } catch (JSONException e) {
            throw OAuthProblemException.error(OAuthError.CodeResponse.UNSUPPORTED_RESPONSE_TYPE,
                "Invalid response! Response body is not " + OAuth.ContentType.JSON + " encoded");
        }
    }
這裏的 body就是

這樣就不會報上面那個錯誤了 能夠對比發現兩個上面那個數據被加了「//」轉義符這個應該就是致使 報錯的緣由 藍緣系統裏spring-mvc.xml裏有一段配置是這樣的 把這個去掉後 該錯誤就解決了,想了下應該是 該 配置攔截了 oathu2的json數據 更改了它的格式 致使 oathu2認爲是非法的返回類型 從而報錯 。 若是 有人遇到相似的錯誤能夠參考 個人這個解決案例的思路。
相關文章