use of de.geeksfactory.opacclient.networking.SSLSecurityException in project opacclient by opacapp.
the class AccountFragment method show_connectivity_error.
public void show_connectivity_error(Exception e) {
if (e != null) {
e.printStackTrace();
}
if (getActivity() == null) {
return;
}
if (e instanceof OpacErrorException) {
AccountDataSource adatasource = new AccountDataSource(getActivity());
adatasource.invalidateCachedAccountData(account);
dialog_wrong_credentials(e.getMessage());
return;
}
if (getView() != null) {
final FrameLayout errorView = (FrameLayout) getView().findViewById(R.id.error_view);
errorView.removeAllViews();
View connError = getActivity().getLayoutInflater().inflate(R.layout.error_connectivity, errorView);
TextView tvErrBody = (TextView) connError.findViewById(R.id.tvErrBody);
Button btnRetry = (Button) connError.findViewById(R.id.btRetry);
btnRetry.setVisibility(View.VISIBLE);
if (e != null && e instanceof SSLSecurityException) {
tvErrBody.setText(R.string.connection_error_detail_security);
} else if (e != null && e instanceof NotReachableException) {
tvErrBody.setText(R.string.connection_error_detail_nre);
} else if (e != null && e instanceof OpacClient.LibraryRemovedException) {
tvErrBody.setText(R.string.library_removed_error);
btnRetry.setVisibility(View.GONE);
}
btnRetry.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
refresh();
}
});
llLoading.setVisibility(View.GONE);
swipeRefreshLayout.setVisibility(View.GONE);
connError.setVisibility(View.VISIBLE);
}
}
use of de.geeksfactory.opacclient.networking.SSLSecurityException in project opacclient by opacapp.
the class OkHttpBaseApi method httpPost.
/**
* Perform a HTTP POST request to a given URL
*
* @param url URL to fetch
* @param data POST data to send
* @param encoding Expected encoding of the response body
* @param ignore_errors If true, status codes above 400 do not raise an exception
* @return Answer content
* @throws NotReachableException Thrown when server returns a HTTP status code greater or equal
* than 400.
*/
public String httpPost(String url, RequestBody data, String encoding, boolean ignore_errors) throws IOException {
Request.Builder requestbuilder = new Request.Builder().url(cleanUrl(url)).header("Accept", "*/*").header("User-Agent", getUserAgent());
if (data.contentType() != null) {
requestbuilder = requestbuilder.header("Content-Type", data.contentType().toString());
}
Request request = requestbuilder.post(data).build();
try {
Response response = http_client.newCall(request).execute();
if (!ignore_errors && response.code() >= 400) {
throw new NotReachableException(response.message());
}
return readBody(response, encoding);
} catch (javax.net.ssl.SSLPeerUnverifiedException e) {
logHttpError(e);
throw new SSLSecurityException(e.getMessage());
} catch (javax.net.ssl.SSLException e) {
// aborted/interrupted handshake/connection
if (e.getMessage().contains("timed out") || e.getMessage().contains("reset by")) {
logHttpError(e);
throw new NotReachableException(e.getMessage());
} else {
logHttpError(e);
throw new SSLSecurityException(e.getMessage());
}
} catch (InterruptedIOException e) {
logHttpError(e);
throw new NotReachableException(e.getMessage());
} catch (UnknownHostException e) {
throw new NotReachableException(e.getMessage());
} catch (IOException e) {
if (e.getMessage() != null && e.getMessage().contains("Request aborted")) {
logHttpError(e);
throw new NotReachableException(e.getMessage());
} else {
throw e;
}
}
}
use of de.geeksfactory.opacclient.networking.SSLSecurityException in project opacclient by opacapp.
the class SearchResultListFragment method setSearchResult.
public void setSearchResult(final SearchRequestResult searchresult) {
for (SearchResult result : searchresult.getResults()) {
result.setPage(searchresult.getPage_index());
}
if (searchresult.getTotal_result_count() >= 0) {
((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(getResources().getQuantityString(R.plurals.result_number, searchresult.getTotal_result_count(), searchresult.getTotal_result_count()));
}
if (searchresult.getResults().size() == 0 && searchresult.getTotal_result_count() <= 0) {
setEmptyText(getString(R.string.no_results));
}
this.searchresult = searchresult;
OpacApi api = null;
try {
api = app.getApi();
} catch (OpacClient.LibraryRemovedException ignored) {
}
adapter = new ResultsAdapterEndless(getActivity(), searchresult, new OnLoadMoreListener() {
@Override
public SearchRequestResult onLoadMore(int page) throws Exception {
SearchRequestResult res = app.getApi().searchGetPage(page);
setLastLoadedPage(page);
return res;
}
@Override
public void onError(Exception e) {
if (getActivity() != null) {
if (e instanceof OpacErrorException) {
showConnectivityError(e.getMessage());
} else if (e instanceof SSLSecurityException) {
showConnectivityError(getResources().getString(R.string.connection_error_detail_security));
} else if (e instanceof NotReachableException) {
showConnectivityError(getResources().getString(R.string.connection_error_detail_nre));
} else {
e.printStackTrace();
showConnectivityError();
}
}
}
@Override
public void updateResultCount(int resultCount) {
/*
* When IOpac finds more than 200 results, the real
* result count is not known until the second page is
* loaded
*/
if (resultCount >= 0 && getActivity() != null) {
((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(getResources().getQuantityString(R.plurals.result_number, resultCount, resultCount));
}
}
}, api);
setListAdapter(adapter);
getListView().setTextFilterEnabled(true);
setListShown(true);
}
use of de.geeksfactory.opacclient.networking.SSLSecurityException in project opacclient by opacapp.
the class ApacheBaseApi method httpPost.
/**
* Perform a HTTP POST request to a given URL
*
* @param url URL to fetch
* @param data POST data to send
* @param encoding Expected encoding of the response body
* @param ignore_errors If true, status codes above 400 do not raise an exception
* @param cookieStore If set, the given cookieStore is used instead of the built-in one.
* @return Answer content
* @throws NotReachableException Thrown when server returns a HTTP status code greater or equal
* than 400.
*/
public String httpPost(String url, HttpEntity data, String encoding, boolean ignore_errors, CookieStore cookieStore) throws IOException {
HttpPost httppost = new HttpPost(cleanUrl(url));
httppost.setEntity(data);
httppost.setHeader("Accept", "*/*");
HttpResponse response;
String html;
try {
if (cookieStore != null) {
// Create local HTTP context
HttpContext localContext = new BasicHttpContext();
// Bind custom cookie store to the local context
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
response = http_client.execute(httppost, localContext);
} else {
response = http_client.execute(httppost);
}
if (!ignore_errors && response.getStatusLine().getStatusCode() >= 400) {
throw new NotReachableException(response.getStatusLine().getReasonPhrase());
}
html = convertStreamToString(response.getEntity().getContent(), encoding);
HttpUtils.consume(response.getEntity());
} catch (javax.net.ssl.SSLPeerUnverifiedException e) {
logHttpError(e);
throw new SSLSecurityException(e.getMessage());
} catch (javax.net.ssl.SSLException e) {
// aborted/interrupted handshake/connection
if (e.getMessage().contains("timed out") || e.getMessage().contains("reset by")) {
logHttpError(e);
throw new NotReachableException(e.getMessage());
} else {
logHttpError(e);
throw new SSLSecurityException(e.getMessage());
}
} catch (InterruptedIOException e) {
logHttpError(e);
throw new NotReachableException(e.getMessage());
} catch (UnknownHostException e) {
throw new NotReachableException(e.getMessage());
} catch (IOException e) {
if (e.getMessage() != null && e.getMessage().contains("Request aborted")) {
logHttpError(e);
throw new NotReachableException(e.getMessage());
} else {
throw e;
}
}
return html;
}
use of de.geeksfactory.opacclient.networking.SSLSecurityException in project opacclient by opacapp.
the class ApacheBaseApi method httpGet.
/**
* Perform a HTTP GET request to a given URL
*
* @param url URL to fetch
* @param encoding Expected encoding of the response body
* @param ignore_errors If true, status codes above 400 do not raise an exception
* @param cookieStore If set, the given cookieStore is used instead of the built-in one.
* @return Answer content
* @throws NotReachableException Thrown when server returns a HTTP status code greater or equal
* than 400.
*/
public String httpGet(String url, String encoding, boolean ignore_errors, CookieStore cookieStore) throws IOException {
HttpGet httpget = new HttpGet(cleanUrl(url));
HttpResponse response;
String html;
httpget.setHeader("Accept", "*/*");
try {
if (cookieStore != null) {
// Create local HTTP context
HttpContext localContext = new BasicHttpContext();
// Bind custom cookie store to the local context
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
response = http_client.execute(httpget, localContext);
} else {
response = http_client.execute(httpget);
}
if (!ignore_errors && response.getStatusLine().getStatusCode() >= 400) {
HttpUtils.consume(response.getEntity());
throw new NotReachableException(response.getStatusLine().getReasonPhrase());
}
html = convertStreamToString(response.getEntity().getContent(), encoding);
HttpUtils.consume(response.getEntity());
} catch (javax.net.ssl.SSLPeerUnverifiedException e) {
logHttpError(e);
throw new SSLSecurityException(e.getMessage());
} catch (javax.net.ssl.SSLException e) {
// aborted/interrupted handshake/connection
if (e.getMessage().contains("timed out") || e.getMessage().contains("reset by")) {
logHttpError(e);
throw new NotReachableException(e.getMessage());
} else {
logHttpError(e);
throw new SSLSecurityException(e.getMessage());
}
} catch (InterruptedIOException e) {
logHttpError(e);
throw new NotReachableException(e.getMessage());
} catch (UnknownHostException e) {
throw new NotReachableException(e.getMessage());
} catch (IOException e) {
if (e.getMessage() != null && e.getMessage().contains("Request aborted")) {
logHttpError(e);
throw new NotReachableException(e.getMessage());
} else {
throw e;
}
}
return html;
}
Aggregations