/** * Performs a REST POST operation of a json string on the base * XOS REST URI with an optional additional URI suffix. * * @param uri URI suffix to append to base URI * @param json JSON string to post */ public void postRest(String uri, String json) { WebResource.Builder builder = getClientBuilder(uri); ClientResponse response; try { response = builder.post(ClientResponse.class, json); } catch (ClientHandlerException e) { log.warn("Unable to contact REST server: {}", e.getMessage()); return; } if (response.getStatus() != HTTP_CREATED) { log.info("REST POST request returned error code {}", response.getStatus()); } }
private StringBuilder logResponse(long id, ClientResponse response) { StringBuilder b = new StringBuilder(); printResponseLine(b, id, response); printResponseHeaders(b, id, response.getHeaders()); ByteArrayOutputStream out = new ByteArrayOutputStream(); InputStream in = response.getEntityInputStream(); try { ReaderWriter.writeTo(in, out); byte[] requestEntity = out.toByteArray(); printEntity(b, requestEntity); response.setEntityInputStream(new ByteArrayInputStream(requestEntity)); } catch (IOException ex) { throw new ClientHandlerException(ex); } log(b.toString()); return b; }
private static ClientResponse mockEntityClientResponse( TimelineClientImpl client, ClientResponse.Status status, boolean hasError, boolean hasRuntimeError) { ClientResponse response = mock(ClientResponse.class); if (hasRuntimeError) { doThrow(new ClientHandlerException(new ConnectException())).when(client) .doPostingObject(any(TimelineEntities.class), any(String.class)); return response; } doReturn(response).when(client) .doPostingObject(any(TimelineEntities.class), any(String.class)); when(response.getClientResponseStatus()).thenReturn(status); TimelinePutResponse.TimelinePutError error = new TimelinePutResponse.TimelinePutError(); error.setEntityId("test entity id"); error.setEntityType("test entity type"); error.setErrorCode(TimelinePutResponse.TimelinePutError.IO_EXCEPTION); TimelinePutResponse putResponse = new TimelinePutResponse(); if (hasError) { putResponse.addError(error); } when(response.getEntity(TimelinePutResponse.class)).thenReturn(putResponse); return response; }
/** * Performs a REST PUT operation on the base XOS REST URI with * an optional additional URI. * * @param uri URI suffix to append to base URI * @return JSON string returned by the PUT operation */ public String putRest(String uri) { WebResource.Builder builder = getClientBuilder(uri); ClientResponse response; try { response = builder.put(ClientResponse.class); } catch (ClientHandlerException e) { log.warn("Unable to contact REST server: {}", e.getMessage()); return ""; } if (response.getStatus() != HTTP_OK) { log.info("REST PUT request returned error code {}", response.getStatus()); } return response.getEntity(String.class); }
private static ClientResponse mockEntityClientResponse( TimelineWriter spyTimelineWriter, ClientResponse.Status status, boolean hasError, boolean hasRuntimeError) { ClientResponse response = mock(ClientResponse.class); if (hasRuntimeError) { doThrow(new ClientHandlerException(new ConnectException())).when( spyTimelineWriter).doPostingObject( any(TimelineEntities.class), any(String.class)); return response; } doReturn(response).when(spyTimelineWriter) .doPostingObject(any(TimelineEntities.class), any(String.class)); when(response.getClientResponseStatus()).thenReturn(status); TimelinePutResponse.TimelinePutError error = new TimelinePutResponse.TimelinePutError(); error.setEntityId("test entity id"); error.setEntityType("test entity type"); error.setErrorCode(TimelinePutResponse.TimelinePutError.IO_EXCEPTION); TimelinePutResponse putResponse = new TimelinePutResponse(); if (hasError) { putResponse.addError(error); } when(response.getEntity(TimelinePutResponse.class)).thenReturn(putResponse); return response; }
private List<JSONObject> getAMContainerInfoForRMWebService( Configuration conf, String appId) throws ClientHandlerException, UniformInterfaceException, JSONException { Client webServiceClient = Client.create(); String webAppAddress = WebAppUtils.getWebAppBindURL(conf, YarnConfiguration.RM_BIND_HOST, WebAppUtils.getRMWebAppURLWithScheme(conf)); WebResource webResource = webServiceClient.resource(webAppAddress); ClientResponse response = webResource.path("ws").path("v1").path("cluster").path("apps") .path(appId).path("appattempts").accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); JSONObject json = response.getEntity(JSONObject.class).getJSONObject("appAttempts"); JSONArray requests = json.getJSONArray("appAttempt"); List<JSONObject> amContainersList = new ArrayList<JSONObject>(); for (int i = 0; i < requests.length(); i++) { amContainersList.add(requests.getJSONObject(i)); } return amContainersList; }
private List<JSONObject> getAMContainerInfoForAHSWebService(Configuration conf, String appId) throws ClientHandlerException, UniformInterfaceException, JSONException { Client webServiceClient = Client.create(); String webAppAddress = WebAppUtils.getHttpSchemePrefix(conf) + WebAppUtils.getAHSWebAppURLWithoutScheme(conf); WebResource webResource = webServiceClient.resource(webAppAddress); ClientResponse response = webResource.path("ws").path("v1").path("applicationhistory").path("apps") .path(appId).path("appattempts").accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); JSONObject json = response.getEntity(JSONObject.class); JSONArray requests = json.getJSONArray("appAttempt"); List<JSONObject> amContainersList = new ArrayList<JSONObject>(); for (int i = 0; i < requests.length(); i++) { amContainersList.add(requests.getJSONObject(i)); } Collections.reverse(amContainersList); return amContainersList; }
@Override public ClientResponse handle(ClientRequest request) throws ClientHandlerException { long id = ++_id; StringBuilder requestString = new StringBuilder(); logRequest(id, request, requestString); LoggingBean loggingBean = new LoggingBean(); loggingBean.setCommandName(request.getMethod() + ":" + request.getURI()); loggingBean.setArgs(new String[] { request.getURI().getPath(), request.getURI().getQuery() }); ClientResponse response = getNext().handle(request); loggingBean.setResult(response.toString()); StringBuilder responseString = logResponse(id, response); LoggingBean detailsLoggingBean = new LoggingBean(); detailsLoggingBean.setArgs(new String[] { noPrifix(requestString).toString() }); detailsLoggingBean.setResult(noPrifix(responseString).toString()); loggingBean.getSubLogs().add(detailsLoggingBean); TestBaseProvider.instance().get().getLog().add(loggingBean); return response; }
@Test public void testDelegateConnectionTimeoutException() throws Exception { doThrow(new ClientHandlerException(new ConnectTimeoutException())).when(_delegate).doIt(); TestInterface service = _serviceFactory.create(_remoteEndPoint); try { service.doIt(); } catch (PartitionForwardingException e) { assertTrue(e.getCause() instanceof ConnectTimeoutException); } assertEquals(_metricRegistry.getMeters().get("bv.emodb.web.partition-forwarding.TestInterface.errors").getCount(), 1); verify(_delegateServiceFactory).create(_remoteEndPoint); verify(_delegate).doIt(); }
@Test public void test001AddTrigger() throws UniformInterfaceException, ClientHandlerException, JsonProcessingException{ WebResource webResource = resource(); Trigger trigger = new Trigger(); trigger.setAppId(TESTAPPID); trigger.setAppName(TESTAPPNAME); trigger.setBreachDurationSecs(120); trigger.setCallbackUrl(""); trigger.setMetric("Memory"); trigger.setMetricThreshold(30); trigger.setStatType(Trigger.AGGREGATE_TYPE_AVG); trigger.setStatWindowSecs(120); trigger.setThresholdType(Trigger.THRESHOLD_TYPE_LESS_THAN); trigger.setTriggerId(AutoScalerPolicyTrigger.TriggerId_LowerThreshold); trigger.setUnit("persent"); ClientResponse response = webResource.path("/triggers").type(MediaType.APPLICATION_JSON).post(ClientResponse.class,mapper.writeValueAsString(trigger)); assertEquals(response.getStatus(), STATUS200); }
@Override public ClientResponse handle(ClientRequest cr) throws ClientHandlerException { URIBuilder uriBuilder = new URIBuilder(cr.getURI()); String path = uriBuilder.getPath(); uriBuilder.setPath(converter.convertCommandPath(path)); try { cr.setURI(uriBuilder.build()); ClientResponse response = getNext().handle(cr); String newEntity = converter.convertResponse(path, response.getEntity(String.class)); response.setEntityInputStream(new ByteArrayInputStream(newEntity.getBytes())); return response; } catch (Exception ex) { throw new ClientHandlerException(ex); } }
public static Pair<Boolean, String> authentification(String u, String p) { try { AuthSnd st = new AuthSnd(u, p, "TheSecretStringIsMuchStrongerThanOneMillionOfTanks"); ClientResponse response = DataServer.getClientResponse(st, "login"); AuthRcv output = response.getEntity(AuthRcv.class); if (output.getErr() != null) { return new Pair<>(false, output.getErr()); } else { return new Pair<>(true, output.getRes()); } } catch (ClientHandlerException e) { e.printStackTrace(); return new Pair<>(false, e.getCause().getMessage()); } }
public static Pair<Boolean, String> getServerList() { try { ClientResponse response = DataServer.getClientResponse(null, "list_servers"); ServerListRcv output = response.getEntity(ServerListRcv.class); if (output.getErr() != null) { return new Pair<>(false, output.getErr()); } else { return new Pair<>(true, output.getRes()); } } catch (ClientHandlerException e) { e.printStackTrace(); return new Pair<>(false, e.getCause().getMessage()); } }
@Override public ClientResponse handle(ClientRequest request) throws ClientHandlerException { String uuid = UUID.randomUUID().toString(); if (LOGGER.isDebugEnabled()) { logRequest(uuid, request); } ClientResponse response = getNext().handle(request); if (LOGGER.isDebugEnabled()) { logResponse(uuid, response); } return response; }
@VisibleForTesting JSONObject callAPIWithRetries(APIInfo api, Object requestObject, ResourceCreator resourceCreator) throws AtlasServiceException { for (int i = 0; i < getNumberOfRetries(); i++) { WebResource resource = resourceCreator.createResource(); try { LOG.debug("Using resource {} for {} times", resource.getURI(), i + 1); return callAPIWithResource(api, resource, requestObject, JSONObject.class); } catch (ClientHandlerException che) { if (i == (getNumberOfRetries() - 1)) { throw che; } LOG.warn("Handled exception in calling api {}", api.getPath(), che); LOG.warn("Exception's cause: {}", che.getCause().getClass()); handleClientHandlerException(che); } } throw new AtlasServiceException(api, new RuntimeException("Could not get response after retries.")); }
@Test(expectedExceptions = IllegalArgumentException.class) public void shouldThrowExceptionIfActiveServerIsNotFound() { setupRetryParams(); when(client.resource(UriBuilder.fromUri("http://localhost:31000").build())).thenReturn(service); WebResource.Builder builder = setupBuilder(AtlasClient.API.STATUS, service); ClientResponse response = mock(ClientResponse.class); when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode()); when(response.getEntity(String.class)).thenReturn("{\"Status\":\"BECOMING_ACTIVE\"}"); when(builder.method(AtlasClient.API.STATUS.getMethod(), ClientResponse.class, null)). thenThrow(new ClientHandlerException("Simulating connection exception")). thenReturn(response). thenReturn(response); AtlasClient atlasClient = new AtlasClient(service, configuration); String serviceURL = atlasClient.determineActiveServiceURL( new String[] {"http://localhost:31000","http://localhost:41000"}, client); assertNull(serviceURL); }
public java.io.File getAsFile() throws ClientHandlerException, UniformInterfaceException, IOException, MimeTypeException, ClientException, ServerException { ClientResponse cr = wd.path3(path).getAsOctetStream( ClientResponse.class); checkError(cr); String[] bits = localName().split("[.]"); String ext = getDefaultMimeTypes().forName( cr.getHeaders().getFirst("Content-Type")).getExtension(); if (ext == null) ext = bits[bits.length - 1]; java.io.File tmp = createTempFile(bits[0], ext); try (OutputStream os = new FileOutputStream(tmp); InputStream is = cr.getEntity(InputStream.class)) { copy(is, os); } return tmp; }
/** * Determines the settings of the Hue bridge as a Json raw data String. * * @return The settings of the bridge if they could be determined. Null * otherwise. */ private String getSettingsJson() { WebResource webResource = client.resource(getUrl()); try { ClientResponse response = webResource.accept("application/json").get(ClientResponse.class); String settingsString = response.getEntity(String.class); if (response.getStatus() != 200) { logger.warn("Failed to connect to Hue bridge: HTTP error code: " + response.getStatus()); return null; } return settingsString; } catch(ClientHandlerException e) { logger.warn("Failed to connect to Hue bridge: HTTP request timed out."); return null; } }
ClientResponse.Status doUploadFile(WebResource webResource, File file, String sourceId, String fileTypeId) throws ClientHandlerException, UniformInterfaceException, IOException { try (InputStream is = new FileInputStream(file)) { FormDataMultiPart part = new FormDataMultiPart(); part.bodyPart( new FormDataBodyPart( FormDataContentDisposition .name("file") .fileName(file.getName()) .build(), is, MediaType.APPLICATION_OCTET_STREAM_TYPE)); ClientResponse response = webResource .path("/api/protected/file/upload/" + sourceId + "/" + fileTypeId) .type(MediaType.MULTIPART_FORM_DATA_TYPE) .post(ClientResponse.class, part); ClientResponse.Status result = response.getClientResponseStatus(); return result; } }
ClientResponse.Status doUploadFile(WebResource webResource, String resourceName, String sourceId, String fileTypeId) throws ClientHandlerException, UniformInterfaceException, IOException { try (InputStream is = getClass().getResourceAsStream(resourceName)) { FormDataMultiPart part = new FormDataMultiPart(); part.bodyPart( new FormDataBodyPart( FormDataContentDisposition .name("file") .fileName("testupload.xlsx") .build(), is, MediaType.APPLICATION_OCTET_STREAM_TYPE)); ClientResponse response = webResource .path("/api/protected/file/upload/" + sourceId + "/" + fileTypeId) .type(MediaType.MULTIPART_FORM_DATA_TYPE) .post(ClientResponse.class, part); ClientResponse.Status result = response.getClientResponseStatus(); return result; } }
@Override public ClientResponse handle(ClientRequest request) throws ClientHandlerException { String userAgent = ""; try { Properties prop = ResourceUtil.loadProperiesOnResourceFolder(Constant.RAPID_API_RESOURCE); userAgent = prop.getProperty(Constant.RAPID_SDK_USER_AGENT_PARAM); if (StringUtils.isBlank(userAgent)) { throw new Exception("Resource file " + Constant.RAPID_API_RESOURCE + " is invalid."); } } catch (Exception e) { LOGGER.error("User Agent could not be loaded", e); } request.getHeaders().putSingle(HttpHeaders.USER_AGENT, userAgent); if (this.apiVersion != null) { request.getHeaders().putSingle("X-EWAY-APIVERSION", this.apiVersion); } return getNext().handle(request); }
public static ClientResponse mockEntityClientResponse( TimelineWriter spyTimelineWriter, ClientResponse.Status status, boolean hasError, boolean hasRuntimeError) { ClientResponse response = mock(ClientResponse.class); if (hasRuntimeError) { doThrow(new ClientHandlerException(new ConnectException())).when( spyTimelineWriter).doPostingObject( any(TimelineEntities.class), any(String.class)); return response; } doReturn(response).when(spyTimelineWriter) .doPostingObject(any(TimelineEntities.class), any(String.class)); when(response.getClientResponseStatus()).thenReturn(status); TimelinePutResponse.TimelinePutError error = new TimelinePutResponse.TimelinePutError(); error.setEntityId("test entity id"); error.setEntityType("test entity type"); error.setErrorCode(TimelinePutResponse.TimelinePutError.IO_EXCEPTION); TimelinePutResponse putResponse = new TimelinePutResponse(); if (hasError) { putResponse.addError(error); } when(response.getEntity(TimelinePutResponse.class)).thenReturn(putResponse); return response; }
private List<JSONObject> getAMContainerInfoForRMWebService( Configuration conf, String appId) throws ClientHandlerException, UniformInterfaceException, JSONException { Client webServiceClient = Client.create(); String webAppAddress = WebAppUtils.getRMWebAppURLWithScheme(conf); WebResource webResource = webServiceClient.resource(webAppAddress); ClientResponse response = webResource.path("ws").path("v1").path("cluster").path("apps") .path(appId).path("appattempts").accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); JSONObject json = response.getEntity(JSONObject.class).getJSONObject("appAttempts"); JSONArray requests = json.getJSONArray("appAttempt"); List<JSONObject> amContainersList = new ArrayList<JSONObject>(); for (int i = 0; i < requests.length(); i++) { amContainersList.add(requests.getJSONObject(i)); } return amContainersList; }
private void publishApplicationAttemptEvent( final TimelineClient timelineClient, String appAttemptId, DSEvent appEvent, String domainId, UserGroupInformation ugi) { final TimelineEntity entity = new TimelineEntity(); entity.setEntityId(appAttemptId); entity.setEntityType(DSEntity.DS_APP_ATTEMPT.toString()); entity.setDomainId(domainId); entity.addPrimaryFilter(USER_TIMELINE_FILTER_NAME, ugi.getShortUserName()); TimelineEvent event = new TimelineEvent(); event.setEventType(appEvent.toString()); event.setTimestamp(System.currentTimeMillis()); entity.addEvent(event); try { TimelinePutResponse response = timelineClient.putEntities(entity); processTimelineResponseErrors(response); } catch (YarnException | IOException | ClientHandlerException e) { LOG.error("App Attempt " + (appEvent.equals(DSEvent.DS_APP_ATTEMPT_START) ? "start" : "end") + " event could not be published for " + appAttemptId.toString(), e); } }
/** * Process url. * * @return the client response * @throws Exception the exception */ private ClientResponse processUrl() throws Exception { ClientConfig clientConfig = new DefaultClientConfig(); clientConfig.getFeatures().put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE ); Client client = Client.create( clientConfig ); WebResource webResource = createWebResource( client ); webResource.accept( MediaType.APPLICATION_JSON ); webResource.type( MediaType.APPLICATION_JSON ); try { ClientResponse response = webResource.get( ClientResponse.class ); if ( response.getStatus() != 200 ) { setStatus( STATUS_URL_NOK ); throw new RuntimeException( "Failed : HTTP error code : " + response.getStatus() ); } return response; } catch ( ClientHandlerException e ) { setStatus( STATUS_URL_NOK ); throw new Exception( e ); } }
private static void waitForOk(String pingUrl) { boolean ok = false; for (int connectAttempts = 0; connectAttempts < PING_ATTEMPTS; connectAttempts++) { waitMoment(); try { if (Client.create().resource(pingUrl).get(ClientResponse.class).getStatus() == Response.Status.OK.getStatusCode()) { ok = true; break; } } catch (ClientHandlerException e) { // Can happen } } if (!ok) { throw new IllegalStateException("No service returned OK from " + pingUrl); } }
/** * Get the serialized representation of the request entity. This is used when generating the client * signature, because this is the representation that the server will receive and use when it generates * the server-side signature to compare to the client-side signature. * * @see com.sun.jersey.client.urlconnection.URLConnectionClientHandler */ private byte[] getSerializedEntity(ClientRequest request) { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { // By using the RequestWriter parent class, we match the behavior of entity writing from // for example, com.sun.jersey.client.urlconnection.URLConnectionClientHandler. writeRequestEntity(request, new RequestEntityWriterListener() { public void onRequestEntitySize(long size) throws IOException { } public OutputStream onGetOutputStream() throws IOException { return outputStream; } }); } catch (IOException e) { throw new ClientHandlerException("Unable to serialize request entity", e); } return outputStream.toByteArray(); }
@Test public void testHandle_exception() throws Exception { URI uri = new URI("/test"); RuntimeException e = new RuntimeException(); when(restRequest.getMethod()).thenReturn("GET"); when(restRequest.getURI()).thenReturn(uri); when(next.handle(restRequest)).thenThrow(e); try { filter.handle(restRequest); fail("Exception is expected"); } catch (ClientHandlerException expected) { assertEquals(e, expected.getCause()); } Collection<DebugData> datas = DebugContext.getContext().getDebugData(); assertNotNull(datas); assertEquals(1, datas.size()); DebugData data = datas.iterator().next(); assertEquals("GET", data.get("Method")); assertEquals("/test", data.get("Url")); assertEquals(isAsync, data.get("Async")); assertNotNull(data.get("CalledFrom")); assertNotNull(data.get("Error")); }
@Override public ClientResponse handle(ClientRequest request) throws ClientHandlerException { MultivaluedMap headers = request.getHeaders(); try { if(cloudSpace != null) { headers.add("x-tmrk-cloudspace", cloudSpace); } String signature = sign(request, headers); headers.add("x-tmrk-authorization", new StringBuilder().append("CloudApi AccessKey=").append(getAccessKey()).append(" SignatureType=").append("HmacSHA256").append(" Signature=").append(signature).toString()); } catch (Exception ex) { throw new ClientHandlerException("Error signing request headers", ex); } return getNext().handle(request); }
@Override public ClientResponse handle(ClientRequest request) throws ClientHandlerException { addTokenToRequest(request); ClientResponse response = getNext().handle(request); // Handle a redirect if (response.getClientResponseStatus() == ClientResponse.Status.FOUND) { if (response.getHeaders().containsKey(HttpHeaders.LOCATION)) { String location = response.getHeaders().getFirst(HttpHeaders.LOCATION); final ClientRequest newRequest = ClientRequest.create().build(URI.create(location), request.getMethod()); // Handle the token from the existing response, add to this new request checkResponseForToken(response); addTokenToRequest(newRequest); // Call handler to perform redirect to new page response = handle(newRequest); } } checkResponseForToken(response); return response; }
@Override public ClientResponse handle(ClientRequest request) throws ClientHandlerException { ClientResponse response = getNext().handle(request); int status = response.getStatus(); if (status >= 400 && status < 600) { if (isSupportedType(response.getType())) { ServiceErrorRestRep serviceError; try { serviceError = response.getEntity(ServiceErrorRestRep.class); } catch (Exception e) { // Cause to fall-through to default exception log.error("Error parsing error message", e); serviceError = null; } if (serviceError != null) { logAndThrow(new ServiceErrorException(status, serviceError)); } } // Fallback for unknown entity types String content = response.getEntity(String.class); logAndThrow(new ViPRHttpException(status, content)); } return response; }
private static ClientResponse mockClientResponse(TimelineClientImpl client, ClientResponse.Status status, boolean hasError, boolean hasRuntimeError) { ClientResponse response = mock(ClientResponse.class); if (hasRuntimeError) { doThrow(new ClientHandlerException(new ConnectException())).when(client) .doPostingEntities(any(TimelineEntities.class)); return response; } doReturn(response).when(client) .doPostingEntities(any(TimelineEntities.class)); when(response.getClientResponseStatus()).thenReturn(status); TimelinePutResponse.TimelinePutError error = new TimelinePutResponse.TimelinePutError(); error.setEntityId("test entity id"); error.setEntityType("test entity type"); error.setErrorCode(TimelinePutResponse.TimelinePutError.IO_EXCEPTION); TimelinePutResponse putResponse = new TimelinePutResponse(); if (hasError) { putResponse.addError(error); } when(response.getEntity(TimelinePutResponse.class)).thenReturn(putResponse); return response; }
private void logResponse(long id, ClientResponse response) { StringBuilder b = new StringBuilder(); printResponseLine(b, id, response); printResponseHeaders(b, id, response.getHeaders()); ByteArrayOutputStream out = new ByteArrayOutputStream(); InputStream in = response.getEntityInputStream(); try { ReaderWriter.writeTo(in, out); byte[] requestEntity = out.toByteArray(); printEntity(b, requestEntity); response.setEntityInputStream(new ByteArrayInputStream(requestEntity)); } catch (IOException ex) { throw new ClientHandlerException(ex); } log(b); }
public List<DataSetRegistrationResult> registerDataSets( List<DataSet> datasets, NodeCredentials credentials ) throws NodeIllegalStatusException, AuthenticationException, RestWSUnknownException { try { WebResource wr = getResource( "/datasetservice/register" ); ClientResponse cr = wr.post( ClientResponse.class, new SecuredRequestWrapper( credentials, new JaxbBaseList( datasets ) ) ); if ( cr.getClientResponseStatus().equals( Status.BAD_REQUEST ) ) { throw new NodeIllegalStatusException(); } else if ( cr.getClientResponseStatus().equals( Status.UNAUTHORIZED ) ) { throw new AuthenticationException(); } JaxbBaseList<DataSetRegistrationResult> list = cr.getEntity( new GenericType<JaxbBaseList<DataSetRegistrationResult>>() { } ); return list.getList(); } catch ( ClientHandlerException ex ) { throw new RestWSUnknownException( ex.getMessage() ); } }
public List<DataSetRegistrationAcceptanceDecision> checkStatus( List<DataSetDTO> dataSets, NodeCredentials credentials ) throws AuthenticationException, RestWSUnknownException { try { WebResource wr = getResource( "/datasetservice/checkStatus" ); ClientResponse cr = wr.post( ClientResponse.class, new SecuredRequestWrapper( credentials, new JaxbBaseList( dataSets ) ) ); if ( cr.getClientResponseStatus().equals( Status.UNAUTHORIZED ) ) { throw new AuthenticationException(); } JaxbBaseList<DataSetRegistrationAcceptanceDecision> list = cr.getEntity( new GenericType<JaxbBaseList<DataSetRegistrationAcceptanceDecision>>() { } ); return list.getList(); } catch ( ClientHandlerException ex ) { throw new RestWSUnknownException( ex.getMessage() ); } }
public List<DataSetDeregistrationResult> deregisterDataSets( List<DataSetDTO> datasets, String reason, NodeCredentials credentials ) throws AuthenticationException, RestWSUnknownException { DataSetDeregistrationRequest dsDeregistrationReq = new DataSetDeregistrationRequest( reason, datasets ); try { WebResource wr = getResource( "/datasetservice/deregister" ); ClientResponse cr = wr.post( ClientResponse.class, new SecuredRequestWrapper( credentials, dsDeregistrationReq ) ); if ( cr.getClientResponseStatus().equals( Status.UNAUTHORIZED ) ) { throw new AuthenticationException(); } JaxbBaseList<DataSetDeregistrationResult> list = cr.getEntity( new GenericType<JaxbBaseList<DataSetDeregistrationResult>>() { } ); return list.getList(); } catch ( ClientHandlerException ex ) { throw new RestWSUnknownException( ex.getMessage() ); } }
public ValidationResult verify( DataSet dataset ) { try { WebResource wr = getResource( "/datasetservice/verify" ); ClientResponse cr = wr.post( ClientResponse.class, dataset ); if ( cr.getClientResponseStatus().equals( Status.CONFLICT ) ) { return ValidationResult.INVALID; } else if ( cr.getClientResponseStatus().equals( Status.OK ) ) { return ValidationResult.VALID; } return ValidationResult.CANT_VALIDATE; } catch ( ClientHandlerException ex ) { return ValidationResult.CANT_VALIDATE; } }