我有一個使用CXF的REST服務,我還放置了一個攔截器來檢查基本身份驗證。當我試圖從瀏覽器訪問REST服務URL時,我確實收到了Interceptor引發的消息。但我期待一個正常的登錄彈出窗口。REST登錄無法按預期方式與攔截器一起工作
<ns1:XMLFault xmlns:ns1="http://cxf.apache.org/bindings/xformat">
<ns1:faultstring xmlns:ns1="http://cxf.apache.org/bindings/xformat">java.lang.RuntimeException: 401 UNAUTHORIZED</ns1:faultstring>
</ns1:XMLFault>
CXF servlet.xml中
<jaxrs:server id="bookService" address="/bookservice">
<jaxrs:serviceBeans>
<ref bean="bs"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean='jsonProvider' />
</jaxrs:providers>
<jaxrs:inInterceptors>
<ref bean="logininterceptor" />
</jaxrs:inInterceptors>
</jaxrs:server>
<bean id="logininterceptor" class="org.gsdev.ws.bookservice.interceptor.AuthenticatorInterceptor"/>
AuthenticatorInterceptor類
:REST服務URL
http://localhost:8080/SpringRestBasicAuth/api/bookservice/books/1234
有關訪問REST服務URL的錯誤消息
有人可以指導我,以便當任何人試圖訪問服務的URL然後應該得到一個正常的登錄彈出窗口,而不是直接的異常消息?
也許你應該向你提出要求你發送給你的服務。不過,我很好奇爲什麼在訪問REST-API時需要彈出窗口? – questionare
@questionare ....我更新了問題,以添加我發送1234作爲ID /請求的服務URL。我需要用戶登錄/認證到服務(如獨立),而無需登錄到應用程序。 – Garry
我仍然不明白爲什麼應該有一個登錄彈出?該行爲正是你在服務中定義的那樣拋出新的RuntimeException(HttpURLConnection.HTTP_UNAUTHORIZED +「UNAUTHORIZED」);''另外我沒有看到任何登錄頁面的定義? – questionare