Back to project page khandroid.
The source code is released under:
Apache License
If you think the Android project khandroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * Copyright (C) 2012-2014 Ognyan Bankov *//from w ww . jav a 2 s. c o m * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.github.khandroid.rest; import java.io.IOException; import java.net.UnknownHostException; import org.slf4j.LoggerFactory; import com.github.khandroid.http.functionality.HttpFunctionality; import com.github.khandroid.rest.RestExchangeFailedException; public class RestFunctionalityImpl implements RestFunctionality { private final HttpFunctionality mHttpFunc; private final org.slf4j.Logger mLogger = LoggerFactory.getLogger(RestFunctionalityImpl.class .getSimpleName()); public RestFunctionalityImpl(HttpFunctionality httpFunc) { if (httpFunc != null) { mHttpFunc = httpFunc; } else { throw new IllegalArgumentException("Passed parameter httpFunc is null"); } } @Override public <T> T execute(RestExchange<T> x) throws RestExchangeFailedException { T ret = null; try { try { ret = x.perform(mHttpFunc); } catch (InvalidJsonString e) { mLogger.error(e.getMessage()); throw new RestExchangeFailedException("Parsing response failed because of malformed json returned from server.", e); } } catch (khandroid.ext.apache.http.client.ClientProtocolException e) { mLogger.error(e.getMessage()); throw new RestExchangeFailedException("Executing request failed because of protocol violation.", e); } catch (UnknownHostException e) { mLogger.error(e.getMessage()); throw new RestExchangeFailedException("Executing request failed. Unknown host. Is there internet connection?", e); } catch (IOException e) { mLogger.error(e.getMessage()); throw new RestExchangeFailedException("Executing request failed.", e); } return ret; } }