@Override public void init() throws ServletException { LightblueClientConfiguration configuration = configuration(); dataServiceUri = getInitParamOrDefault("dataServiceURI", configuration.getDataServiceURI()); if (dataServiceUri == null) { throw new LightblueServletException("No dataServiceURI defined in configuration or in" + " init parameter. Configuration checked was, " + configuration); } // Get rid of trailing slashes. dataServiceUri = dataServiceUri.replaceAll("/+$", ""); }
LOGGER.debug("Calling service (streaming): {}", req.toString()); InputStream stream = httpTransport.executeRequestGetStream(req, configuration.getDataServiceURI()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Response received from service, streaming");
@Override public DefaultLightblueBulkDataResponse bulkData(DataBulkRequest lightblueRequests) throws LightblueHttpClientException, LightblueBulkResponseException, LightblueParseException, LightblueException { HttpResponse response = callService(lightblueRequests, configuration.getDataServiceURI()); try { return new DefaultLightblueBulkDataResponse( response.getBody(), response.getHeaders(), mapper, lightblueRequests); } catch (LightblueParseException e) { throw new LightblueParseException("Unable to parse response " + response, e); } }
@Override public LightblueDiagnosticsResponse diagnostics() throws LightblueParseException, LightblueResponseException, LightblueException { HttpResponse response = callService(new LightblueDiagnosticsRequest(), configuration.getDataServiceURI()); try { return new DefaultLightblueDiagnosticsResponse(response.getBody(), response.getHeaders(), mapper); } catch (LightblueParseException e) { throw new LightblueParseException("Unable to parse response " + response, e); } } }
@Override public DefaultLightblueDataResponse data(LightblueDataRequest lightblueRequest) throws LightblueParseException, LightblueResponseException, LightblueHttpClientException, LightblueException { if (!lightblueRequest.hasExecution()) { lightblueRequest.execution(configuration.getExecution()); } HttpResponse response = callService(lightblueRequest, configuration.getDataServiceURI()); return new DefaultLightblueDataResponse( response.getBody(), response.getHeaders(), mapper); }
@Override public int getLockCount(String callerId, String resourceId) throws LightblueException { LightblueRequest req = new LockingRequest( "count", getDomain(), callerId, resourceId, null, false, HttpMethod.POST); HttpResponse r = callService(req, configuration.getDataServiceURI()); LockResponse response = new LockResponse(r.getBody(), r.getHeaders()); if (response.getJson() != null) { return response.parseAsInt(); } else { return 0; } }
@Override public boolean ping(String callerId, String resourceId) throws LightblueException { LightblueRequest req = new LockingRequest( "ping", getDomain(), callerId, resourceId, null, true, HttpMethod.POST); HttpResponse r = callService(req, configuration.getDataServiceURI()); LockResponse response = new LockResponse(r.getBody(), r.getHeaders()); if (response.getJson() != null) { return response.parseAsBoolean(); } else { return false; } }
@Override public boolean acquire(String callerId, String resourceId, Long ttl) throws LightblueException { LightblueRequest req = new LockingRequest("acquire", getDomain(), callerId, resourceId, ttl, false, HttpMethod.POST); HttpResponse r = callService(req, configuration.getDataServiceURI()); LockResponse response = new LockResponse(r.getBody(), r.getHeaders()); if (response.getJson() != null) { return response.parseAsBoolean(); } else { return false; } }
@Override public boolean release(String callerId, String resourceId) throws LightblueException { LightblueRequest req = new LockingRequest( "release", getDomain(), callerId, resourceId, null, false, HttpMethod.POST); HttpResponse r = callService(req, configuration.getDataServiceURI()); LockResponse response = new LockResponse(r.getBody(), r.getHeaders()); if (response.getJson() != null) { return response.parseAsBoolean(); } else { return false; } }