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被上面的攔截後處理成了這樣

891f75d4-0c7a-3ffd-b87f-534e016cc093.png
這樣的話 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就是

33777087-b73f-3192-851b-e57776cfdec3.png
這樣就不會報上面那個錯誤了
可以對比發現兩個上面那個數據被加了“//”轉義符這個應該就是導致 報錯的原因

藍緣系統裏spring-mvc.xml裏有一段配置是這樣的 把這個去掉後 該錯誤就解決了,想了下應該是 該 配置攔截了 oathu2的json數據 更改了它的格式 導致 oathu2認爲是非法的返回類型 從而報錯 。

如果 有人遇到類似的錯誤可以參考 我的這個解決案例的思路。
  • 891f75d4-0c7a-3ffd-b87f-534e016cc093-thumb.png
  • 大小: 11.5 KB
  • 33777087-b73f-3192-851b-e57776cfdec3-thumb.png
  • 大小: 14.5 KB
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章