org.springframework.web.client.RestClientException Java Examples

The following examples show how to use org.springframework.web.client.RestClientException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserApi.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
/**
 * Creates list of users with given input array
 * 
 * <p><b>0</b> - successful operation
 * @param body List of user object (required)
 * @return ResponseEntity&lt;Void&gt;
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public ResponseEntity<Void> createUsersWithArrayInputWithHttpInfo(List<User> body) throws RestClientException {
    Object postBody = body;
    
    // verify the required parameter 'body' is set
    if (body == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'body' when calling createUsersWithArrayInput");
    }
    
    String path = apiClient.expandPath("/user/createWithArray", Collections.<String, Object>emptyMap());

    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
    final MultiValueMap formParams = new LinkedMultiValueMap();

    final String[] accepts = { };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = { };
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

    String[] authNames = new String[] {  };

    ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {};
    return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
}
 
Example #2
Source File: KeycloakServiceBase.java    From camunda-bpm-identity-keycloak with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the Keycloak internal ID of a group.
 * @param groupId the userId as sent by the client
 * @return the Keycloak internal ID
 * @throws KeycloakGroupNotFoundException in case the group cannot be found
 * @throws RestClientException in case of technical errors
 */
protected String getKeycloakGroupID(String groupId) throws KeycloakGroupNotFoundException, RestClientException {
	String groupSearch;
	if (keycloakConfiguration.isUseGroupPathAsCamundaGroupId()) {
		groupSearch = "/group-by-path/" + groupId;
	} else {
		return groupId;
	}
	
	try {
		ResponseEntity<String> response = restTemplate.exchange(
				keycloakConfiguration.getKeycloakAdminUrl() + groupSearch, HttpMethod.GET,
				keycloakContextProvider.createApiRequestEntity(), String.class);
		return parseAsJsonObjectAndGetMemberAsString(response.getBody(), "id");
	} catch (JsonException je) {
		throw new KeycloakGroupNotFoundException(groupId + " not found - path unknown", je);
	}
}
 
Example #3
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * Test serialization of outer string types
 * <p><b>200</b> - Output string
 * @param body Input string as post body (optional)
 * @return ResponseEntity&lt;String&gt;
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public ResponseEntity<String> fakeOuterStringSerializeWithHttpInfo(String body) throws RestClientException {
    Object postBody = body;
    
    String path = apiClient.expandPath("/fake/outer/string", Collections.<String, Object>emptyMap());

    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
    final MultiValueMap formParams = new LinkedMultiValueMap();

    final String[] accepts = { 
        "*/*"
    };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = { };
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

    String[] authNames = new String[] {  };

    ParameterizedTypeReference<String> returnType = new ParameterizedTypeReference<String>() {};
    return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
}
 
Example #4
Source File: PushbulletNotifyAction.java    From davos with MIT License 6 votes vote down vote up
@Override
public void execute(PostDownloadExecution execution) {

    PushbulletRequest body = new PushbulletRequest();
    body.body = execution.fileName;
    body.title = "A new file has been downloaded";
    body.type = "note";

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.add("Authorization", "Bearer " + apiKey);

    try {

        LOGGER.info("Sending notification to Pushbullet for {}", execution.fileName);
        LOGGER.debug("API Key: {}", apiKey);
        HttpEntity<PushbulletRequest> httpEntity = new HttpEntity<PushbulletRequest>(body, headers);
        LOGGER.debug("Sending message to Pushbullet: {}", httpEntity);
        restTemplate.exchange("https://api.pushbullet.com/v2/pushes", HttpMethod.POST, httpEntity, Object.class);

    } catch (RestClientException | HttpMessageConversionException e ) {
        
        LOGGER.debug("Full stacktrace", e);
        LOGGER.error("Unable to complete notification to Pushbullet. Given error: {}", e.getMessage());
    }
}
 
Example #5
Source File: AppServiceImpl.java    From Moss with Apache License 2.0 6 votes vote down vote up
/**
 * 通过访问skywalking的地址获取skywalking中的AppId
 * @param traceBaseUrl
 * @return
 */
private List<Application> findAllApplications(String traceBaseUrl) {
    HttpHeaders headers = new HttpHeaders();
    MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
    headers.setContentType(type);

    RequestPayload requestPayload = payloadBuilder();
    String requestJson = JSON.toJSONString(requestPayload);
    HttpEntity<String> entity = new HttpEntity<String>(requestJson, headers);

    try {
        String applicationsForSkywalkingUrl = traceBaseUrl + "/api/applications";
        String data = restTemplate.postForObject(applicationsForSkywalkingUrl,  entity, String.class);
        log.info(data);
        ApplicationsResult applicationsResult = JSON.parseObject(data, ApplicationsResult.class);
        if (applicationsResult == null) {
            log.info("call /api/applications has exception");
            throw new ApplicationException("call /api/applications has exception");
        }
        return applicationsResult.getData().getApplications();
    } catch (RestClientException e) {
        log.info("call applications has exception" + e.getMessage());
    }

    return null;
}
 
Example #6
Source File: StoreApi.java    From tutorials with MIT License 6 votes vote down vote up
/**
 * Returns pet inventories by status
 * Returns a map of status codes to quantities
 * <p><b>200</b> - successful operation
 * @return ResponseEntity&lt;Map&lt;String, Integer&gt;&gt;
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public ResponseEntity<Map<String, Integer>> getInventoryWithHttpInfo() throws RestClientException {
    Object postBody = null;

    String path = apiClient.expandPath("/store/inventory", Collections.<String, Object>emptyMap());

    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
    final MultiValueMap formParams = new LinkedMultiValueMap();

    final String[] accepts = {
        "application/json"
    };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = { };
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

    String[] authNames = new String[] { "api_key" };

    ParameterizedTypeReference<Map<String, Integer>> returnType = new ParameterizedTypeReference<Map<String, Integer>>() {};
    return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
}
 
Example #7
Source File: ClientCertificateAuthentication.java    From spring-vault with Apache License 2.0 6 votes vote down vote up
private VaultToken createTokenUsingTlsCertAuthentication() {

		try {
			VaultResponse response = this.restOperations.postForObject(
					AuthenticationUtil.getLoginPath(this.options.getPath()), Collections.emptyMap(),
					VaultResponse.class);

			Assert.state(response.getAuth() != null, "Auth field must not be null");

			logger.debug("Login successful using TLS certificates");

			return LoginTokenUtil.from(response.getAuth());
		}
		catch (RestClientException e) {
			throw VaultLoginException.create("TLS Certificates", e);
		}
	}
 
Example #8
Source File: UserApi.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
/**
 * Create user
 * This can only be done by the logged in user.
 * <p><b>0</b> - successful operation
 * @param body Created user object (required)
 * @return ResponseEntity&lt;Void&gt;
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public ResponseEntity<Void> createUserWithHttpInfo(User body) throws RestClientException {
    Object postBody = body;
    
    // verify the required parameter 'body' is set
    if (body == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'body' when calling createUser");
    }
    
    String path = apiClient.expandPath("/user", Collections.<String, Object>emptyMap());

    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
    final MultiValueMap formParams = new LinkedMultiValueMap();

    final String[] accepts = { };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = { };
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

    String[] authNames = new String[] {  };

    ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {};
    return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
}
 
Example #9
Source File: RegistryService.java    From SkaETL with Apache License 2.0 6 votes vote down vote up
public void scaledown(ProcessDefinition processDefinition) {
    ConsumerState consumerState = consumerStateRepository.findByKey(processDefinition.getIdProcess());
    int nbInstance = consumerState.getNbInstance() - 1;
    //can't get less than 1 instance
    if (nbInstance >= 1) {
        ConsumerState newState = consumerState.withNbInstance(nbInstance);

        if (consumerState.getStatusProcess() == StatusProcess.ENABLE && consumerState.getRegistryWorkers().size() > nbInstance) {
            String last = Iterables.getLast(consumerState.getRegistryWorkers());
            RegistryWorker worker = workerRepository.findByKey(last);
            log.info("triggering deactivate on worker {} from {}", last, processDefinition);
            try {
                RestTemplate restTemplate = new RestTemplate();
                HttpEntity<ProcessDefinition> request = new HttpEntity<>(consumerState.getProcessDefinition());
                restTemplate.postForObject(worker.getBaseUrl() + "/manage/deactivate", request, String.class);
            } catch (RestClientException e) {
                log.error("an error occured while triggering deactivate on worker " + last + " from " + consumerState.getProcessDefinition(), e.getMessage());
            }
            newState.getRegistryWorkers().remove(last);

        }
        consumerStateRepository.save(newState);
    }
}
 
Example #10
Source File: NominatimGeocoder.java    From callerid-for-android with GNU General Public License v3.0 6 votes vote down vote up
public List<Address> getFromLocationName(String locationName, int maxResults)
		throws IOException {
	final Map<String,String> urlVariables = new HashMap<String, String>();
	urlVariables.put("location", locationName);
	urlVariables.put("maxResults", Integer.toString(maxResults));
	
	try{
		// Nominatim does not handle the HTTP request header "Accept" according to RFC.
		// If any Accept header other than */* is sent, Nominatim responses with HTTP 406 (Not Acceptable).
		// So instead of the rather simple line:
		// final Place[] places = restTemplate.getForObject("http://nominatim.openstreetmap.org/search?q={location}&format=json&addressdetails=1&limit={maxResults}", Place[].class, urlVariables);
		// we have to manually set the Accept header and make things a bit more complicated.
		
		final HttpHeaders requestHeaders = new HttpHeaders();
		requestHeaders.set("Accept", "*/*");
		final HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
		final ResponseEntity<Place[]> responseEntity = restTemplate.exchange("http://nominatim.openstreetmap.org/search?q={location}&format=json&addressdetails=1&limit={maxResults}",HttpMethod.GET, requestEntity, Place[].class, urlVariables);
		final Place[] places = responseEntity.getBody();
       	return parseResponse(places);
	}catch(RestClientException e){
		Ln.e(e);
		return new ArrayList<Address>();
	}
}
 
Example #11
Source File: InfluxDBService.java    From influx-proxy with Apache License 2.0 5 votes vote down vote up
@Transactional(rollbackFor = Exception.class)
public void deleteRetention(Long id) {
    //根据ID软删除本地信息
    ManagementInfoPo managementInfoPo = managementInfoService.deleteRetentionById(id);
    //再删除influxdb
    String deleteRetentionUrl = String.format(Constants.BASE_URL, managementInfoPo.getNodeUrl(), managementInfoPo.getDatabaseName());
    String deleteRetentionData = String.format(Constants.DELETE_RETENTION_URL, managementInfoPo.getRetentionName(), managementInfoPo.getDatabaseName());

    try {
        URI uri = getUri(deleteRetentionUrl, deleteRetentionData);
        restTemplate.postForObject(uri, null, String.class);
    } catch (RestClientException e) {
        throw new InfluxDBProxyException(e.getMessage());
    }
}
 
Example #12
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * 
 * <p><b>200</b> - Success
 * @param query  (required)
 * @param body  (required)
 * @return ResponseEntity&lt;Void&gt;
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public ResponseEntity<Void> testBodyWithQueryParamsWithHttpInfo(String query, User body) throws RestClientException {
    Object postBody = body;
    
    // verify the required parameter 'query' is set
    if (query == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'query' when calling testBodyWithQueryParams");
    }
    
    // verify the required parameter 'body' is set
    if (body == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'body' when calling testBodyWithQueryParams");
    }
    
    String path = apiClient.expandPath("/fake/body-with-query-params", Collections.<String, Object>emptyMap());

    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
    final MultiValueMap formParams = new LinkedMultiValueMap();

    queryParams.putAll(apiClient.parameterToMultiValueMap(null, "query", query));

    final String[] accepts = { };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = { 
        "application/json"
    };
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

    String[] authNames = new String[] {  };

    ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {};
    return apiClient.invokeAPI(path, HttpMethod.PUT, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
}
 
Example #13
Source File: WitDataGrabber.java    From Refactoring-Bot with MIT License 5 votes vote down vote up
/**
 * This method communicates with the wit-API. It returns an WitObject with the
 * input of a comment.
 * 
 * @param comment
 * @return witObject
 * @throws WitAPIException
 */
public WitObject getWitObjectFromComment(String comment) throws WitAPIException {
	// Build URI
	UriComponentsBuilder apiUriBuilder = UriComponentsBuilder.newInstance().scheme("https").host("api.wit.ai")
			.path("/message");

	// Set API-Version
	apiUriBuilder.queryParam("v", "20190122");
	apiUriBuilder.queryParam("q", comment);

	URI witUri = apiUriBuilder.build().encode().toUri();

	RestTemplate rest = new RestTemplate();

	HttpHeaders headers = new HttpHeaders();
	headers.set("User-Agent", USER_AGENT);
	headers.set("Authorization", "Bearer " + botConfig.getWitClientToken());
	HttpEntity<String> entity = new HttpEntity<>("parameters", headers);

	try {
		// Send request to the Wit-API
		return rest.exchange(witUri, HttpMethod.GET, entity, WitObject.class).getBody();
	} catch (RestClientException r) {
		throw new WitAPIException("Could not exchange data with wit.ai!");
	}

}
 
Example #14
Source File: ZosmfServiceV1Test.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@Test(expected = AuthenticationServiceException.class)
public void testAuthenticateException() {
    mockZosmfService("zosmf", 1433);
    when(restTemplate.exchange(
        anyString(),
        (HttpMethod) any(),
        (HttpEntity<?>) any(),
        (Class<?>) any()
    )).thenThrow(new RestClientException("any exception"));

    zosmfService.authenticate(new UsernamePasswordAuthenticationToken("user", "pass"));
}
 
Example #15
Source File: PetApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * uploads an image
 * 
 * <p><b>200</b> - successful operation
 * @param petId ID of pet to update (required)
 * @param additionalMetadata Additional data to pass to server (optional)
 * @param file file to upload (optional)
 * @return ResponseEntity&lt;ModelApiResponse&gt;
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public ResponseEntity<ModelApiResponse> uploadFileWithHttpInfo(Long petId, String additionalMetadata, File file) throws RestClientException {
    Object postBody = null;
    
    // verify the required parameter 'petId' is set
    if (petId == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'petId' when calling uploadFile");
    }
    
    // create path and map variables
    final Map<String, Object> uriVariables = new HashMap<String, Object>();
    uriVariables.put("petId", petId);
    String path = apiClient.expandPath("/pet/{petId}/uploadImage", uriVariables);

    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
    final MultiValueMap formParams = new LinkedMultiValueMap();

    if (additionalMetadata != null)
        formParams.add("additionalMetadata", additionalMetadata);
    if (file != null)
        formParams.add("file", new FileSystemResource(file));

    final String[] accepts = { 
        "application/json"
    };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = { 
        "multipart/form-data"
    };
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

    String[] authNames = new String[] { "petstore_auth" };

    ParameterizedTypeReference<ModelApiResponse> returnType = new ParameterizedTypeReference<ModelApiResponse>() {};
    return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
}
 
Example #16
Source File: PetApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Finds Pets by tags
 * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
 * <p><b>200</b> - successful operation
 * <p><b>400</b> - Invalid tag value
 * @param tags Tags to filter by (required)
 * @return ResponseEntity&lt;Set&lt;Pet&gt;&gt;
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
@Deprecated
public ResponseEntity<Set<Pet>> findPetsByTagsWithHttpInfo(Set<String> tags) throws RestClientException {
    Object postBody = null;
    
    // verify the required parameter 'tags' is set
    if (tags == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'tags' when calling findPetsByTags");
    }
    
    String path = apiClient.expandPath("/pet/findByTags", Collections.<String, Object>emptyMap());

    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
    final MultiValueMap formParams = new LinkedMultiValueMap();

    queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("csv".toUpperCase(Locale.ROOT)), "tags", tags));

    final String[] accepts = { 
        "application/xml", "application/json"
    };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = { };
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

    String[] authNames = new String[] { "petstore_auth" };

    ParameterizedTypeReference<Set<Pet>> returnType = new ParameterizedTypeReference<Set<Pet>>() {};
    return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
}
 
Example #17
Source File: SOAPTest.java    From riptide with MIT License 5 votes vote down vote up
@Test
void shouldFailToWriteFault() {
    final CompletableFuture<ClientHttpResponse> future = unit.post()
            .accept(TEXT_XML)
            .body(mock(SOAPFault.class))
            .call(pass());

    final CompletionException exception = assertThrows(CompletionException.class, future::join);
    assertThat(exception.getCause(), is(instanceOf(RestClientException.class)));
}
 
Example #18
Source File: ScoreCalcuService.java    From ExamStack with GNU General Public License v2.0 5 votes vote down vote up
private void postAnswerSheet(String uri, Object body) {
	try {
		restTemplate.postForLocation(uri, body);
	} catch (RestClientException e) {
		LOGGER.error("Received exception:", e);
	}
}
 
Example #19
Source File: RestClientTest.java    From micro-server with Apache License 2.0 5 votes vote down vote up
/**
 * More complex with Spring REST Template Based NIORestTemplate
 *
 **/
@Test
public void testCRUDSpring() throws InterruptedException, ExecutionException, RestClientException, URISyntaxException{
	
	
	assertThat(rest.getForEntity(new URI("http://localhost:8080/rest-app/rest/get"),List.class).get().getBody().get(0),is("ok"));
	
	assertThat(rest.postForEntity("http://localhost:8080/rest-app/rest/post", new HttpEntity(ImmutableMap.of(1,"hello")), ImmutableSet.class).get().getBody(),is(ImmutableSet.of("hello")));
	assertThat( rest.put("http://localhost:8080/rest-app/rest/put",new HttpEntity(ImmutableMap.of(1,"hello")),ImmutableSet.class).get()
								,is(nullValue()));
	assertThat(rest.delete("http://localhost:8080/rest-app/rest/delete").get(),is(nullValue()));
}
 
Example #20
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * creates an XmlItem
 * this route creates an XmlItem
 * <p><b>200</b> - successful operation
 * @param xmlItem XmlItem Body (required)
 * @return ResponseEntity&lt;Void&gt;
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public ResponseEntity<Void> createXmlItemWithHttpInfo(XmlItem xmlItem) throws RestClientException {
    Object postBody = xmlItem;
    
    // verify the required parameter 'xmlItem' is set
    if (xmlItem == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'xmlItem' when calling createXmlItem");
    }
    
    String path = apiClient.expandPath("/fake/create_xml_item", Collections.<String, Object>emptyMap());

    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
    final MultiValueMap formParams = new LinkedMultiValueMap();

    final String[] accepts = { };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = { 
        "application/xml", "application/xml; charset=utf-8", "application/xml; charset=utf-16", "text/xml", "text/xml; charset=utf-8", "text/xml; charset=utf-16"
    };
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

    String[] authNames = new String[] {  };

    ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {};
    return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
}
 
Example #21
Source File: PetApi.java    From tutorials with MIT License 5 votes vote down vote up
/**
 * Updates a pet in the store with form data
 * 
 * <p><b>405</b> - Invalid input
 * @param petId ID of pet that needs to be updated
 * @param name Updated name of the pet
 * @param status Updated status of the pet
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public void updatePetWithForm(Long petId, String name, String status) throws RestClientException {
    Object postBody = null;
    
    // verify the required parameter 'petId' is set
    if (petId == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'petId' when calling updatePetWithForm");
    }
    
    // create path and map variables
    final Map<String, Object> uriVariables = new HashMap<String, Object>();
    uriVariables.put("petId", petId);
    String path = UriComponentsBuilder.fromPath("/pet/{petId}").buildAndExpand(uriVariables).toUriString();
    
    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();
    
    if (name != null)
        formParams.add("name", name);
    if (status != null)
        formParams.add("status", status);

    final String[] accepts = { 
        "application/xml", "application/json"
    };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = { 
        "application/x-www-form-urlencoded"
    };
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

    String[] authNames = new String[] { "petstore_auth" };

    ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {};
    apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
}
 
Example #22
Source File: StoreApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Place an order for a pet
 * 
 * <p><b>200</b> - successful operation
 * <p><b>400</b> - Invalid Order
 * @param body order placed for purchasing the pet (required)
 * @return ResponseEntity&lt;Order&gt;
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public ResponseEntity<Order> placeOrderWithHttpInfo(Order body) throws RestClientException {
    Object postBody = body;
    
    // verify the required parameter 'body' is set
    if (body == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'body' when calling placeOrder");
    }
    
    String path = apiClient.expandPath("/store/order", Collections.<String, Object>emptyMap());

    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
    final MultiValueMap formParams = new LinkedMultiValueMap();

    final String[] accepts = { 
        "application/xml", "application/json"
    };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = { };
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

    String[] authNames = new String[] {  };

    ParameterizedTypeReference<Order> returnType = new ParameterizedTypeReference<Order>() {};
    return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
}
 
Example #23
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * test json serialization of form data
 * 
 * <p><b>200</b> - successful operation
 * @param param field1 (required)
 * @param param2 field2 (required)
 * @return ResponseEntity&lt;Void&gt;
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public ResponseEntity<Void> testJsonFormDataWithHttpInfo(String param, String param2) throws RestClientException {
    Object postBody = null;
    
    // verify the required parameter 'param' is set
    if (param == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'param' when calling testJsonFormData");
    }
    
    // verify the required parameter 'param2' is set
    if (param2 == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'param2' when calling testJsonFormData");
    }
    
    String path = apiClient.expandPath("/fake/jsonFormData", Collections.<String, Object>emptyMap());

    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
    final MultiValueMap formParams = new LinkedMultiValueMap();

    if (param != null)
        formParams.add("param", param);
    if (param2 != null)
        formParams.add("param2", param2);

    final String[] accepts = { };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = { 
        "application/x-www-form-urlencoded"
    };
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

    String[] authNames = new String[] {  };

    ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {};
    return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
}
 
Example #24
Source File: KeeperContainerServiceImpl.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
protected boolean checkIpAndPort(String host, int port) {

    getOrCreateRestTemplate();
    String url = "http://%s:%d/health";
    try {
      return restTemplate.getForObject(String.format(url, host, port), Boolean.class);

    } catch (RestClientException e) {
      logger.error("[healthCheck]Http connect occur exception. ", e);
    }

    return false;
  }
 
Example #25
Source File: NIORestClient.java    From micro-server with Apache License 2.0 5 votes vote down vote up
public <T> CompletableFuture<T> execute(String url, HttpMethod method,
		AsyncRequestCallback requestCallback,
		ResponseExtractor<T> responseExtractor, Object... urlVariables)
		throws RestClientException {
	return toCompletableFuture(template.execute(url, method,
			requestCallback, responseExtractor, urlVariables));
}
 
Example #26
Source File: UserApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Get user by user name
 * 
 * <p><b>200</b> - successful operation
 * <p><b>400</b> - Invalid username supplied
 * <p><b>404</b> - User not found
 * @param username The name that needs to be fetched. Use user1 for testing. (required)
 * @return ResponseEntity&lt;User&gt;
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public ResponseEntity<User> getUserByNameWithHttpInfo(String username) throws RestClientException {
    Object postBody = null;
    
    // verify the required parameter 'username' is set
    if (username == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'username' when calling getUserByName");
    }
    
    // create path and map variables
    final Map<String, Object> uriVariables = new HashMap<String, Object>();
    uriVariables.put("username", username);
    String path = apiClient.expandPath("/user/{username}", uriVariables);

    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
    final MultiValueMap formParams = new LinkedMultiValueMap();

    final String[] accepts = { 
        "application/xml", "application/json"
    };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = { };
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

    String[] authNames = new String[] {  };

    ParameterizedTypeReference<User> returnType = new ParameterizedTypeReference<User>() {};
    return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
}
 
Example #27
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * For this test, the body for this request much reference a schema named &#x60;File&#x60;.
 * <p><b>200</b> - Success
 * @param body  (required)
 * @return ResponseEntity&lt;Void&gt;
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public ResponseEntity<Void> testBodyWithFileSchemaWithHttpInfo(FileSchemaTestClass body) throws RestClientException {
    Object postBody = body;
    
    // verify the required parameter 'body' is set
    if (body == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'body' when calling testBodyWithFileSchema");
    }
    
    String path = apiClient.expandPath("/fake/body-with-file-schema", Collections.<String, Object>emptyMap());

    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
    final MultiValueMap formParams = new LinkedMultiValueMap();

    final String[] accepts = { };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = { 
        "application/json"
    };
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

    String[] authNames = new String[] {  };

    ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {};
    return apiClient.invokeAPI(path, HttpMethod.PUT, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
}
 
Example #28
Source File: PetApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Finds Pets by status
 * Multiple status values can be provided with comma separated strings
 * <p><b>200</b> - successful operation
 * <p><b>400</b> - Invalid status value
 * @param status Status values that need to be considered for filter (required)
 * @return ResponseEntity&lt;List&lt;Pet&gt;&gt;
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public ResponseEntity<List<Pet>> findPetsByStatusWithHttpInfo(List<String> status) throws RestClientException {
    Object postBody = null;
    
    // verify the required parameter 'status' is set
    if (status == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'status' when calling findPetsByStatus");
    }
    
    String path = apiClient.expandPath("/pet/findByStatus", Collections.<String, Object>emptyMap());

    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
    final MultiValueMap formParams = new LinkedMultiValueMap();

    queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("csv".toUpperCase(Locale.ROOT)), "status", status));

    final String[] accepts = { 
        "application/xml", "application/json"
    };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = { };
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

    String[] authNames = new String[] { "petstore_auth" };

    ParameterizedTypeReference<List<Pet>> returnType = new ParameterizedTypeReference<List<Pet>>() {};
    return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
}
 
Example #29
Source File: DiscoveredResourceUnitTests.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void resetsLinkOnFailedVerification() {

	verificationTriggersDiscovery();

	doThrow(RestClientException.class).when(this.operations)
			.headForHeaders(anyString());
	this.resource.verifyOrDiscover();

	then(this.resource.getLink()).isNull();
}
 
Example #30
Source File: UserApi.java    From tutorials with MIT License 5 votes vote down vote up
/**
 * Create user
 * This can only be done by the logged in user.
 * <p><b>0</b> - successful operation
 * @param body Created user object
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public void createUser(User body) throws RestClientException {
    Object postBody = body;
    
    // verify the required parameter 'body' is set
    if (body == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'body' when calling createUser");
    }
    
    String path = UriComponentsBuilder.fromPath("/user").build().toUriString();
    
    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

    final String[] accepts = { 
        "application/xml", "application/json"
    };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = { };
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

    String[] authNames = new String[] {  };

    ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {};
    apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
}