android


android basic auth okhttpclient


I am connecting to my rest api using retrofit and okHttp client. When I disable Basic authentication on Tomcat everything works flawlessly.
When Basic Auth is enabled on Tomcat I get 404 Page not found.
Here is my authentication and error output.
okHttpClient.setAuthenticator(new Authenticator() {
#Override
public Request authenticate(Proxy proxy, Response response) throws IOException {
String credential = Credentials.basic(rest_user, rest_pw);
return response.request().newBuilder().header("Authorization", credential).build();
}
#Override
public Request authenticateProxy(Proxy proxy, Response response) throws IOException {
return null;
}
});
Error log
D/YOUR_LOG_TAG: <--- HTTP 404 https://myserver:8443/RestWS/objects/barcodes (4462ms)
D/YOUR_LOG_TAG: Server: Apache-Coyote/1.1
D/YOUR_LOG_TAG: Cache-Control: private
D/YOUR_LOG_TAG: Expires: Thu, 01 Jan 1970 01:00:00 CET
D/YOUR_LOG_TAG: Set-Cookie: JSESSIONID=*********************; Path=/; Secure; HttpOnly
D/YOUR_LOG_TAG: Content-Type: text/html;charset=ISO-8859-1
D/YOUR_LOG_TAG: Content-Length: 127
D/YOUR_LOG_TAG: Date: Tue, 26 Apr 2016 09:31:22 GMT
D/YOUR_LOG_TAG: OkHttp-Selected-Protocol: http/1.1
D/YOUR_LOG_TAG: OkHttp-Sent-Millis: 1461663081883
D/YOUR_LOG_TAG: OkHttp-Received-Millis: 1461663081973
D/YOUR_LOG_TAG: <html>
D/YOUR_LOG_TAG: <head>
D/YOUR_LOG_TAG: <title>404-Page Not Found</title>
D/YOUR_LOG_TAG: </head>
D/YOUR_LOG_TAG: <body> The requested URL was not found on this server. </body>
D/YOUR_LOG_TAG: </html>
D/YOUR_LOG_TAG: <--- END HTTP (127-byte body)
Problem solved using RequestInterceptor.
restAdapter = new RestAdapter.Builder()
.setConverter(new GsonConverter(gson))
.setRequestInterceptor(new RequestInterceptor() {
#Override
public void intercept(RequestFacade request) {
String credentials = DownloadService.rest_user + ":" + DownloadService.rest_pw;
String base64EncodedCredentials = Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
request.addHeader("Authorization", "Basic " + base64EncodedCredentials);
}
})
.setEndpoint(DownloadService.URL)
.setClient(new OkClient(okHttpClient))
.build();

Related Links

How create and show listview in onDraw method?
Android, How to access a common method through two different threads?
Formatting System.currentTimeMillis()
issues in phonegap android version(1.7)
Android - Two Maps in one App
android holo theme backgroud
i cannot be a message whether it is succesfully logged in or not
Increment android database version via onclick. (SQLiteOpenHelper)
Problems using ViewPager Example
Customize the android maps places?
Android Security Exception while accessing contacts
AsyncTask issue
How to create a custom page in ViewPager in which each page has 3 ImageViews( it could vary)?
How to set and then check day of week to make an Alarm go off - Android
get current location in android
want to start installed third party navigation app through my application

Categories

HOME
django
cygwin
grok
turing-machines
nvd3.js
github-for-windows
gpu
jmx
yandex
tivoli
switch-statement
jquery-ui
iis-6
recordrtc
accessibility
reactive-programming
ibeacon-android
plist
mod-security
selenium-ide
http-post
forgot-password
template-engine
bourbon
libigl
parcelable
pchart
displaytag
intersystems-cache
spotipy
python-2.6
record
mailkit
login-script
installshield-le
reactjs.net
modalviewcontroller
sql-delete
imx6
git-rewrite-history
projects-and-solutions
demo
google-data-api
plaintext
watchface
skylink
phpdbg
jide
textsum
er-diagram
pure-css
burrows-wheeler-transform
nikeplus-api
wso2developerstudio
appscale
shopping
deep
redis-cluster
createprocess
libav
concept-insights
oracle-spatial
dronekit-android
ansi
public-html
teaspoon
cbind
mintty
windows-embedded-standard
mt4j
bin
mbunit
ebay-lms
scringo
process-explorer
chart-director
tree-balancing
qi4j
nokia-s40
jquery-blockui
uimanageddocument
veracity
dajaxice
paginator
mapping-by-code
predicatebuilder
infobright
urlrewriter
pinch
role
entitydatasource
multiplatform
cac
easyb
drupal-fivestar
ajax-polling
strtod
xpsdocument
fail-fast-fail-early
contentpresenter

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App