List of usage examples for java.net HttpCookie HttpCookie
public HttpCookie(String name, String value)
From source file:de.fh_zwickau.informatik.sensor.ZWayApiHttp.java
@Override public void getDeviceHistories(final IZWayCallback<DeviceHistoryList> callback) { if (checkLogin()) { try {// w w w . j av a 2 s. c o m startHttpClient(); Request request = mHttpClient.newRequest(getZAutomationTopLevelUrl() + "/" + PATH_DEVICE_HISTORY) .method(HttpMethod.GET).header(HttpHeader.ACCEPT, "application/json") .header(HttpHeader.CONTENT_TYPE, "application/json") .cookie(new HttpCookie("ZWAYSession", mZWaySessionId)) .onRequestFailure(new ZWayFailureListener()); if (mUseRemoteService) { request.cookie(new HttpCookie("ZBW_SESSID", mZWayRemoteSessionId)); } request.send(new BufferingResponseListener() { @Override public void onComplete(Result result) { int statusCode = result.getResponse().getStatus(); if (statusCode != HttpStatus.OK_200) { if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { getDeviceHistories(callback); } } else { processResponseStatus(statusCode); } } else { callback.onSuccess(parseGetDeviceHistories(getContentAsString())); } } }); } catch (Exception e) { if (e.getCause() instanceof HttpResponseException) { int statusCode = ((HttpResponseException) e.getCause()).getResponse().getStatus(); // Authentication error - retry login and operation if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { getDeviceHistories(callback); } } } else { handleException(e, "get device histories"); } } finally { // do not stop http client for asynchronous call } } // no else ... checkLogin() method will invoke the appropriate callback method }
From source file:de.fh_zwickau.informatik.sensor.ZWayApiHttp.java
@Override public synchronized ArrayList<DeviceHistoryData> getDeviceHistory(String deviceId, Long since) { if (checkLogin()) { try {//from w w w. j a v a 2s . c o m startHttpClient(); Request request = mHttpClient .newRequest(getZAutomationTopLevelUrl() + "/" + PATH_DEVICE_HISTORY + "/" + deviceId + "?since=" + String.valueOf(since)) .method(HttpMethod.GET).header(HttpHeader.ACCEPT, "application/json") .header(HttpHeader.CONTENT_TYPE, "application/json") .cookie(new HttpCookie("ZWAYSession", mZWaySessionId)); if (mUseRemoteService) { request.cookie(new HttpCookie("ZBW_SESSID", mZWayRemoteSessionId)); } ContentResponse response = request.send(); // Check HTTP status code int statusCode = response.getStatus(); if (statusCode != HttpStatus.OK_200) { // Authentication error - retry login and operation if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { return getDeviceHistory(deviceId, since); } } else { processResponseStatus(statusCode); } } else { return parseGetDeviceHistory(response.getContentAsString()); } } catch (Exception e) { if (e.getCause() instanceof HttpResponseException) { int statusCode = ((HttpResponseException) e.getCause()).getResponse().getStatus(); // Authentication error - retry login and operation if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { return getDeviceHistory(deviceId, since); } } } else { handleException(e, "get device history"); } } finally { stopHttpClient(); } } // no else ... checkLogin() method will invoke the appropriate callback method return null; }
From source file:de.fh_zwickau.informatik.sensor.ZWayApiHttp.java
@Override public void getDeviceHistory(final String deviceId, final Long since, final IZWayCallback<ArrayList<DeviceHistoryData>> callback) { if (checkLogin()) { try {// w w w.ja v a 2 s .c om startHttpClient(); Request request = mHttpClient .newRequest(getZAutomationTopLevelUrl() + "/" + PATH_DEVICE_HISTORY + "/" + deviceId + "?since=" + String.valueOf(since)) .method(HttpMethod.GET).header(HttpHeader.ACCEPT, "application/json") .header(HttpHeader.CONTENT_TYPE, "application/json") .cookie(new HttpCookie("ZWAYSession", mZWaySessionId)) .onRequestFailure(new ZWayFailureListener()); if (mUseRemoteService) { request.cookie(new HttpCookie("ZBW_SESSID", mZWayRemoteSessionId)); } request.send(new BufferingResponseListener() { @Override public void onComplete(Result result) { int statusCode = result.getResponse().getStatus(); if (statusCode != HttpStatus.OK_200) { if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { getDeviceHistory(deviceId, since, callback); } } else { processResponseStatus(statusCode); } } else { callback.onSuccess(parseGetDeviceHistory(getContentAsString())); } } }); } catch (Exception e) { if (e.getCause() instanceof HttpResponseException) { int statusCode = ((HttpResponseException) e.getCause()).getResponse().getStatus(); // Authentication error - retry login and operation if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { getDeviceHistory(deviceId, since, callback); } } } else { handleException(e, "get device history"); } } finally { // do not stop http client for asynchronous call } } // no else ... checkLogin() method will invoke the appropriate callback method }
From source file:de.fh_zwickau.informatik.sensor.ZWayApiHttp.java
@Override public synchronized ProfileList getProfiles() { if (checkLogin()) { try {/*from w ww . jav a2s. co m*/ startHttpClient(); Request request = mHttpClient.newRequest(getZAutomationTopLevelUrl() + "/" + PATH_PROFILES) .method(HttpMethod.GET).header(HttpHeader.ACCEPT, "application/json") .header(HttpHeader.CONTENT_TYPE, "application/json") .cookie(new HttpCookie("ZWAYSession", mZWaySessionId)); if (mUseRemoteService) { request.cookie(new HttpCookie("ZBW_SESSID", mZWayRemoteSessionId)); } ContentResponse response = request.send(); // Check HTTP status code int statusCode = response.getStatus(); if (statusCode != HttpStatus.OK_200) { // Authentication error - retry login and operation if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { return getProfiles(); } } else { processResponseStatus(statusCode); } } else { return parseGetProfiles(response.getContentAsString()); } } catch (Exception e) { if (e.getCause() instanceof HttpResponseException) { int statusCode = ((HttpResponseException) e.getCause()).getResponse().getStatus(); // Authentication error - retry login and operation if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { return getProfiles(); } } } else { handleException(e, "get profiles"); } } finally { stopHttpClient(); } } // no else ... checkLogin() method will invoke the appropriate callback method return null; }
From source file:de.fh_zwickau.informatik.sensor.ZWayApiHttp.java
@Override public void getProfiles(final IZWayCallback<ProfileList> callback) { if (checkLogin()) { try {// w w w. ja va2s.c o m startHttpClient(); Request request = mHttpClient.newRequest(getZAutomationTopLevelUrl() + "/" + PATH_PROFILES) .method(HttpMethod.GET).header(HttpHeader.ACCEPT, "application/json") .header(HttpHeader.CONTENT_TYPE, "application/json") .cookie(new HttpCookie("ZWAYSession", mZWaySessionId)) .onRequestFailure(new ZWayFailureListener()); if (mUseRemoteService) { request.cookie(new HttpCookie("ZBW_SESSID", mZWayRemoteSessionId)); } request.send(new BufferingResponseListener() { @Override public void onComplete(Result result) { int statusCode = result.getResponse().getStatus(); if (statusCode != HttpStatus.OK_200) { if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { getProfiles(callback); } } else { processResponseStatus(statusCode); } } else { callback.onSuccess(parseGetProfiles(getContentAsString())); } } }); } catch (Exception e) { if (e.getCause() instanceof HttpResponseException) { int statusCode = ((HttpResponseException) e.getCause()).getResponse().getStatus(); // Authentication error - retry login and operation if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { getProfiles(callback); } } } else { handleException(e, "get profiles"); } } finally { // do not stop http client for asynchronous call } } // no else ... checkLogin() method will invoke the appropriate callback method }
From source file:de.fh_zwickau.informatik.sensor.ZWayApiHttp.java
@Override public synchronized NotificationList getNotifications(Long since) { if (checkLogin()) { try {//from w w w . j a va 2s.c om startHttpClient(); Request request = mHttpClient .newRequest(getZAutomationTopLevelUrl() + "/" + PATH_NOTIFICATIONS + "?since=" + since) .method(HttpMethod.GET).header(HttpHeader.ACCEPT, "application/json") .header(HttpHeader.CONTENT_TYPE, "application/json") .cookie(new HttpCookie("ZWAYSession", mZWaySessionId)); if (mUseRemoteService) { request.cookie(new HttpCookie("ZBW_SESSID", mZWayRemoteSessionId)); } ContentResponse response = request.send(); // Check HTTP status code int statusCode = response.getStatus(); if (statusCode != HttpStatus.OK_200) { // Authentication error - retry login and operation if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { return getNotifications(since); } } else { processResponseStatus(statusCode); } } else { return parseGetNotifications(response.getContentAsString()); } } catch (Exception e) { if (e.getCause() instanceof HttpResponseException) { int statusCode = ((HttpResponseException) e.getCause()).getResponse().getStatus(); // Authentication error - retry login and operation if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { return getNotifications(since); } } } else { handleException(e, "get notifications"); } } finally { stopHttpClient(); } } // no else ... checkLogin() method will invoke the appropriate callback method return null; }
From source file:de.fh_zwickau.informatik.sensor.ZWayApiHttp.java
@Override public void getNotifications(final IZWayCallback<NotificationList> callback, final Long since) { if (checkLogin()) { try {// w w w . j av a 2 s. com startHttpClient(); Request request = mHttpClient .newRequest(getZAutomationTopLevelUrl() + "/" + PATH_NOTIFICATIONS + "?since=" + since) .method(HttpMethod.GET).header(HttpHeader.ACCEPT, "application/json") .header(HttpHeader.CONTENT_TYPE, "application/json") .cookie(new HttpCookie("ZWAYSession", mZWaySessionId)) .onRequestFailure(new ZWayFailureListener()); if (mUseRemoteService) { request.cookie(new HttpCookie("ZBW_SESSID", mZWayRemoteSessionId)); } request.send(new BufferingResponseListener() { @Override public void onComplete(Result result) { int statusCode = result.getResponse().getStatus(); if (statusCode != HttpStatus.OK_200) { if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { getNotifications(callback, since); } } else { processResponseStatus(statusCode); } } else { callback.onSuccess(parseGetNotifications(getContentAsString())); } } }); } catch (Exception e) { if (e.getCause() instanceof HttpResponseException) { int statusCode = ((HttpResponseException) e.getCause()).getResponse().getStatus(); // Authentication error - retry login and operation if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { getNotifications(callback, since); } } } else { handleException(e, "get notifications"); } } finally { // do not stop http client for asynchronous call } } // no else ... checkLogin() method will invoke the appropriate callback method }
From source file:de.fh_zwickau.informatik.sensor.ZWayApiHttp.java
@Override public synchronized Instance getInstance(Integer id) { if (checkLogin()) { try {/* w w w. j a va 2s. c o m*/ startHttpClient(); Request request = mHttpClient .newRequest(getZAutomationTopLevelUrl() + "/" + PATH_INSTANCES + "/" + id) .method(HttpMethod.GET).header(HttpHeader.ACCEPT, "application/json") .header(HttpHeader.CONTENT_TYPE, "application/json") .cookie(new HttpCookie("ZWAYSession", mZWaySessionId)); if (mUseRemoteService) { request.cookie(new HttpCookie("ZBW_SESSID", mZWayRemoteSessionId)); } ContentResponse response = request.send(); // Check HTTP status code int statusCode = response.getStatus(); if (statusCode != HttpStatus.OK_200) { // Authentication error - retry login and operation if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { return getInstance(id); } } else { processResponseStatus(statusCode); } } else { return parseGetInstance(response.getContentAsString()); } } catch (Exception e) { if (e.getCause() instanceof HttpResponseException) { int statusCode = ((HttpResponseException) e.getCause()).getResponse().getStatus(); // Authentication error - retry login and operation if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { return getInstance(id); } } } else { handleException(e, "get instance"); } } finally { stopHttpClient(); } } // no else ... checkLogin() method will invoke the appropriate callback method return null; }
From source file:de.fh_zwickau.informatik.sensor.ZWayApiHttp.java
@Override public void getInstance(final Integer id, final IZWayCallback<Instance> callback) { if (checkLogin()) { try {//from w w w. j a va 2 s .co m startHttpClient(); Request request = mHttpClient .newRequest(getZAutomationTopLevelUrl() + "/" + PATH_INSTANCES + "/" + id) .method(HttpMethod.GET).header(HttpHeader.ACCEPT, "application/json") .header(HttpHeader.CONTENT_TYPE, "application/json") .cookie(new HttpCookie("ZWAYSession", mZWaySessionId)) .onRequestFailure(new ZWayFailureListener()); if (mUseRemoteService) { request.cookie(new HttpCookie("ZBW_SESSID", mZWayRemoteSessionId)); } request.send(new BufferingResponseListener() { @Override public void onComplete(Result result) { int statusCode = result.getResponse().getStatus(); if (statusCode != HttpStatus.OK_200) { if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { getInstance(id, callback); } } else { processResponseStatus(statusCode); } } else { callback.onSuccess(parseGetInstance(getContentAsString())); } } }); } catch (Exception e) { if (e.getCause() instanceof HttpResponseException) { int statusCode = ((HttpResponseException) e.getCause()).getResponse().getStatus(); // Authentication error - retry login and operation if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { getInstance(id, callback); } } } else { handleException(e, "get instance"); } } finally { // do not stop http client for asynchronous call } } // no else ... checkLogin() method will invoke the appropriate callback method }
From source file:de.fh_zwickau.informatik.sensor.ZWayApiHttp.java
@Override public synchronized Instance putInstance(Instance instance) { if (checkLogin()) { try {//from w ww .j av a 2 s. c o m startHttpClient(); Request request = mHttpClient .newRequest(getZAutomationTopLevelUrl() + "/" + PATH_INSTANCES + "/" + instance.getId()) .method(HttpMethod.PUT).header(HttpHeader.ACCEPT, "application/json") .header(HttpHeader.CONTENT_TYPE, "application/json") .cookie(new HttpCookie("ZWAYSession", mZWaySessionId)) .content(new StringContentProvider(new Gson().toJson(instance)), "application/json"); if (mUseRemoteService) { request.cookie(new HttpCookie("ZBW_SESSID", mZWayRemoteSessionId)); } ContentResponse response = request.send(); // Check HTTP status code int statusCode = response.getStatus(); if (statusCode != HttpStatus.OK_200) { // Authentication error - retry login and operation if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { return putInstance(instance); } } else { processResponseStatus(statusCode); } } else { return parsePutInstance(response.getContentAsString()); } } catch (Exception e) { if (e.getCause() instanceof HttpResponseException) { int statusCode = ((HttpResponseException) e.getCause()).getResponse().getStatus(); // Authentication error - retry login and operation if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { return putInstance(instance); } } } else { handleException(e, "put instance"); } } finally { stopHttpClient(); } } // no else ... checkLogin() method will invoke the appropriate callback method return null; }