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 synchronized ZWaveController getZWaveController() { if (checkLogin()) { try {/*from w w w. j a va 2 s . c o m*/ startHttpClient(); Request request = mHttpClient.newRequest(getZWaveTopLevelUrl() + "/" + ZWAVE_PATH_CONTROLLER) .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 getZWaveController(); } } else { processResponseStatus(statusCode); } } else { return parseGetZWaveController(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 getZWaveController(); } } } else { handleException(e, "get zwave controller"); } } 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 getZWaveController(final IZWayCallback<ZWaveController> callback) { if (checkLogin()) { try {/*from w w w. j a va 2 s .co m*/ startHttpClient(); Request request = mHttpClient.newRequest(getZWaveTopLevelUrl() + "/" + ZWAVE_PATH_CONTROLLER) .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 { getZWaveController(callback); } } else { processResponseStatus(statusCode); } } else { callback.onSuccess(parseGetZWaveController(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 { getZWaveController(callback); } } } else { handleException(e, "get zwave controller"); } } 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 void getZWaveInclusion(int flag) { if (checkLogin()) { try {// w w w . ja v a 2s . c om startHttpClient(); String path = URLEncoder .encode(StringUtils.replace(ZWAVE_PATH_INCLUSION, "{flag}", String.valueOf(flag)), "UTF-8"); Request request = mHttpClient.newRequest(getZWaveTopLevelUrl() + "/" + path).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 { getZWaveInclusion(flag); } } else { processResponseStatus(statusCode); } } else { return; } } 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 { getZWaveInclusion(flag); } } } else { handleException(e, "get zwave inclusion"); } } finally { stopHttpClient(); } } // no else ... checkLogin() method will invoke the appropriate callback method }
From source file:de.fh_zwickau.informatik.sensor.ZWayApiHttp.java
@Override public synchronized void getZWaveExclusion(int flag) { if (checkLogin()) { try {/*from www . ja v a 2 s . c o m*/ startHttpClient(); String path = URLEncoder .encode(StringUtils.replace(ZWAVE_PATH_EXCLUSION, "{flag}", String.valueOf(flag)), "UTF-8"); Request request = mHttpClient.newRequest(getZWaveTopLevelUrl() + "/" + path).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 { getZWaveExclusion(flag); } } else { processResponseStatus(statusCode); } } else { return; } } 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 { getZWaveExclusion(flag); } } } else { handleException(e, "get zwave exclusion"); } } finally { stopHttpClient(); } } // no else ... checkLogin() method will invoke the appropriate callback method }
From source file:de.fh_zwickau.informatik.sensor.ZWayApiHttp.java
@Override public void updateControllerData(String field, String value) { if (checkLogin()) { try {/*from w ww. j a v a2 s.c o m*/ startHttpClient(); String path = URLEncoder.encode(ZWAVE_PATH_CONTROLLER_DATA + "." + field + "=" + value, "UTF-8"); Request request = mHttpClient.newRequest(getZWaveTopLevelUrl() + "/" + path).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 { updateControllerData(field, value); } } else { processResponseStatus(statusCode); } } else { return; } } 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 { updateControllerData(field, value); } } } else { logger.warn("Request updateControllerData(field, value) failed: {}", e.getMessage()); mCaller.apiError(e.getMessage(), false); } } finally { stopHttpClient(); } } // no else ... checkLogin() method will invoke the appropriate callback method }
From source file:de.fh_zwickau.informatik.sensor.ZWayApiHttp.java
@Override public void getZWaveDeviceThermostatModeSet(int nodeId, int mode) { if (checkLogin()) { try {/*from w ww .jav a 2 s .c o m*/ startHttpClient(); String path = URLEncoder.encode(StringUtils .replace(ZWAVE_PATH_DEVICES_CC_THERMOSTAT_SET, "{nodeId}", String.valueOf(nodeId)) .replace("{mode}", String.valueOf(mode)), "UTF-8"); Request request = mHttpClient.newRequest(getZWaveTopLevelUrl() + "/" + path).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 { getZWaveDeviceThermostatModeSet(nodeId, mode); } } else { processResponseStatus(statusCode); } } else { return; } } 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 { getZWaveDeviceThermostatModeSet(nodeId, mode); } } } else { handleException(e, "get zwave device thermostat mode set"); } } finally { stopHttpClient(); } } // no else ... checkLogin() method will invoke the appropriate callback method }