當前位置: 首頁>>代碼示例>>Java>>正文


Java UriComponentsBuilder類代碼示例

本文整理匯總了Java中org.springframework.web.util.UriComponentsBuilder的典型用法代碼示例。如果您正苦於以下問題:Java UriComponentsBuilder類的具體用法?Java UriComponentsBuilder怎麽用?Java UriComponentsBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


UriComponentsBuilder類屬於org.springframework.web.util包,在下文中一共展示了UriComponentsBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: confirmEmail

import org.springframework.web.util.UriComponentsBuilder; //導入依賴的package包/類
/**
 * This method activates the e-mail change using a token
 * @param token E-mail change activation token
 * @param uriComponentsBuilder {@link UriComponentsBuilder}
 * @return The ModelAndView for sign in
 */
@PreAuthorize("permitAll()")
@GetMapping(value = "changeEmail/thanks")
public
ModelAndView confirmEmail(
        @RequestParam final String token,
        final UriComponentsBuilder uriComponentsBuilder
) {
    SSLContextHelper.disable();

    final RestTemplate restTemplate = new RestTemplate();
    final HttpEntity<Object> entity = new HttpEntity<>(new HttpHeaders());

    final UriComponents uriComponents
            = uriComponentsBuilder.path("/api/v1.0/settings/changeEmail/token/{token}").buildAndExpand(token);

    ResponseEntity<Void> response;

    try {
        response = restTemplate
                .exchange(uriComponents.toUri(),
                          HttpMethod.PUT,
                          entity,
                          Void.class);
    } catch (HttpClientErrorException e) /* IF 404 */ {
        return new ModelAndView("tokenNotFound");
    }

    /* IF 200 */
    return new ModelAndView("redirect:/signIn");
}
 
開發者ID:JonkiPro,項目名稱:REST-Web-Services,代碼行數:37,代碼來源:SettingsController.java

示例2: apiApplicationsByApplicationNameGet

import org.springframework.web.util.UriComponentsBuilder; //導入依賴的package包/類
/**
 * 
 * 
 * <p><b>200</b> - Success
 * @param applicationName The applicationName parameter
 * @return HierarchicalModel
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public HierarchicalModel apiApplicationsByApplicationNameGet(String applicationName) throws RestClientException {
    Object postBody = null;
    
    // verify the required parameter 'applicationName' is set
    if (applicationName == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'applicationName' when calling apiApplicationsByApplicationNameGet");
    }
    
    // create path and map variables
    final Map<String, Object> uriVariables = new HashMap<String, Object>();
    uriVariables.put("applicationName", applicationName);
    String path = UriComponentsBuilder.fromPath("/api/applications/{applicationName}").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>();

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

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

    ParameterizedTypeReference<HierarchicalModel> returnType = new ParameterizedTypeReference<HierarchicalModel>() {};
    return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
}
 
開發者ID:jopache,項目名稱:Settings,代碼行數:38,代碼來源:ApplicationsApi.java

示例3: setup

import org.springframework.web.util.UriComponentsBuilder; //導入依賴的package包/類
@BeforeClass
public static void setup() {
	UriComponentsBuilder builder = ServletUriComponentsBuilder.fromUriString("dummy");
	linkHeaderBuilder = new HateoasLinkHeaderBuilder(builder);

	Pageable nextPageable = mock(Pageable.class);
	when(nextPageable.getPageNumber()).thenReturn(4);

	Pageable prevPageable = mock(Pageable.class);
	when(prevPageable.getPageNumber()).thenReturn(2);

	page = mock(Page.class);
	when(page.nextPageable()).thenReturn(nextPageable);
	when(page.previousPageable()).thenReturn(prevPageable);
	when(page.getTotalPages()).thenReturn(6);
}
 
開發者ID:cmateosl,項目名稱:role-api,代碼行數:17,代碼來源:HateoasLinkHeaderBuilderTest.java

示例4: apiApplicationsGet

import org.springframework.web.util.UriComponentsBuilder; //導入依賴的package包/類
/**
 * 
 * 
 * <p><b>200</b> - Success
 * @return HierarchicalModel
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public HierarchicalModel apiApplicationsGet() throws RestClientException {
    Object postBody = null;
    
    String path = UriComponentsBuilder.fromPath("/api/applications").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 = { 
        "text/plain", "application/json", "text/json"
    };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = { };
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

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

    ParameterizedTypeReference<HierarchicalModel> returnType = new ParameterizedTypeReference<HierarchicalModel>() {};
    return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
}
 
開發者ID:jopache,項目名稱:Settings,代碼行數:29,代碼來源:ApplicationsApi.java

示例5: apiAuthorizationLoginPost

import org.springframework.web.util.UriComponentsBuilder; //導入依賴的package包/類
/**
 * 
 * 
 * <p><b>200</b> - Success
 * @param model The model parameter
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public void apiAuthorizationLoginPost(LoginModel model) throws RestClientException {
    Object postBody = model;
    
    String path = UriComponentsBuilder.fromPath("/api/authorization/login").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 = { };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = { 
        "application/json-patch+json", "application/json", "text/json", "application/_*+json"
    };
    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);
}
 
開發者ID:jopache,項目名稱:Settings,代碼行數:29,代碼來源:AuthorizationApi.java

示例6: buildHttpRequestEntity

import org.springframework.web.util.UriComponentsBuilder; //導入依賴的package包/類
private RequestEntity buildHttpRequestEntity(WxApiMethodInfo wxApiMethodInfo, Object[] args) {
        UriComponentsBuilder builder = wxApiMethodInfo.fromArgs(args);
        // 替換accessToken
        builder.replaceQueryParam(WX_ACCESS_TOKEN_PARAM_NAME, wxAccessTokenManager.getToken());
        HttpHeaders httpHeaders = null;
        Object body = null;
        if (wxApiMethodInfo.getRequestMethod() == WxApiRequest.Method.JSON) {
            httpHeaders = buildJsonHeaders();
//            body = getStringBody(wxApiMethodInfo, args);
            body = getObjectBody(wxApiMethodInfo, args);
        } else if (wxApiMethodInfo.getRequestMethod() == WxApiRequest.Method.XML) {
            httpHeaders = buildXmlHeaders();
            // 暫時不支持xml轉換。。。
            body = getObjectBody(wxApiMethodInfo, args);
        } else if (wxApiMethodInfo.getRequestMethod() == WxApiRequest.Method.FORM) {
            body = getFormBody(wxApiMethodInfo, args);
        }
        return new RequestEntity(body, httpHeaders, wxApiMethodInfo.getRequestMethod().getHttpMethod(), builder.build().toUri());
    }
 
開發者ID:FastBootWeixin,項目名稱:FastBootWeixin,代碼行數:20,代碼來源:WxApiExecutor.java

示例7: contributeMethodArgument

import org.springframework.web.util.UriComponentsBuilder; //導入依賴的package包/類
@Override
public void contributeMethodArgument(MethodParameter parameter, Object value, UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {
    Class<?> paramType = parameter.getNestedParameterType();
    if (Map.class.isAssignableFrom(paramType)) {
        return;
    }
    WxApiParam wxApiParam = parameter.getParameterAnnotation(WxApiParam.class);
    String name = (wxApiParam == null || StringUtils.isEmpty(wxApiParam.name()) ? parameter.getParameterName() : wxApiParam.name());
    WxAppAssert.notNull(name, "請添加編譯器的-parameter或者為參數添加注解名稱");
    if (value == null) {
        if (wxApiParam != null) {
            if (!wxApiParam.required() || !wxApiParam.defaultValue().equals(ValueConstants.DEFAULT_NONE)) {
                return;
            }
        }
        builder.queryParam(name);
    } else if (value instanceof Collection) {
        for (Object element : (Collection<?>) value) {
            element = formatUriValue(conversionService, TypeDescriptor.nested(parameter, 1), element);
            builder.queryParam(name, element);
        }
    } else {
        builder.queryParam(name, formatUriValue(conversionService, new TypeDescriptor(parameter), value));
    }
}
 
開發者ID:FastBootWeixin,項目名稱:FastBootWeixin,代碼行數:26,代碼來源:WxApiParamContributor.java

示例8: createCustomer

import org.springframework.web.util.UriComponentsBuilder; //導入依賴的package包/類
@SuppressWarnings({ "unchecked", "rawtypes" })
@RequestMapping(value = "/customer/", method = RequestMethod.POST)
public ResponseEntity<?> createCustomer(@RequestBody Customer customer, UriComponentsBuilder ucBuilder) {
	logger.info("Creating Customer : {}", customer);
	
	System.out.println(customerService.customerExist(customer));
	
	if (customerService.customerExist(customer)) {
		logger.error("Unable to create a customer with username {}", customer.getUsername());
		return new ResponseEntity(new CustomErrorType("A customer with username " + 
		customer.getUsername() + " already exists."),HttpStatus.CONFLICT);
	}
	
	Customer currentCustomer = customerService.createCustomer(customer);
	Long currentCustomerId = currentCustomer.getCustomerId();
	JSONObject customerInfo = new JSONObject();
	customerInfo.put("customerId", currentCustomerId);

	HttpHeaders headers = new HttpHeaders();
	headers.setLocation(ucBuilder.path("/api/customer/{customerId").buildAndExpand(customer.getCustomerId()).toUri());;
	return new ResponseEntity<JSONObject>(customerInfo, HttpStatus.CREATED);
}
 
開發者ID:dockersamples,項目名稱:atsea-sample-shop-app,代碼行數:23,代碼來源:CustomerController.java

示例9: setupHttpClient

import org.springframework.web.util.UriComponentsBuilder; //導入依賴的package包/類
private void setupHttpClient(String connectionToken, String protocolVersion){

 if(client != null){
  client.close();
 }
 
 UriComponentsBuilder urlBuilder = UriComponentsBuilder.fromUriString("/signalr/connect");
	  urlBuilder.queryParam("transport", "webSockets");
	  urlBuilder.queryParam("clientProtocol", protocolVersion);
	  urlBuilder.queryParam("connectionToken", connectionToken);
	  urlBuilder.queryParam("connectionData", "[{\"name\":\"corehub\"}]");
	
	  String endPoint = urlBuilder.build().encode().toUriString();
 
 HttpClientOptions options = new HttpClientOptions();
 
 options.setMaxWebsocketFrameSize(1000000);
 options.setMaxWebsocketMessageSize(1000000);
 
 client = vertx.createHttpClient(options);
 connectToBittrex(endPoint);
}
 
開發者ID:AlxGDev,項目名稱:BittrexGatherer,代碼行數:23,代碼來源:BittrexRemoteVerticle.java

示例10: refreshToken

import org.springframework.web.util.UriComponentsBuilder; //導入依賴的package包/類
public WxAccessToken refreshToken() {
    UriComponentsBuilder builder = UriComponentsBuilder.newInstance()
            .scheme("https").host(wxProperties.getUrl().getHost()).path(wxProperties.getUrl().getRefreshToken())
            .queryParam("grant_type", "client_credential")
            .queryParam("appid", wxProperties.getAppid())
            .queryParam("secret", wxProperties.getAppsecret());
    String result = wxApiTemplate.getForObject(builder.toUriString(), String.class);
    if (WxAccessTokenException.hasException(result)) {
        throw new WxAccessTokenException(result);
    } else {
        try {
            return jsonConverter.readValue(result, WxAccessToken.class);
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
            throw new WxAppException("獲取Token時轉換Json失敗");
        }
    }
}
 
開發者ID:FastBootWeixin,項目名稱:FastBootWeixin,代碼行數:19,代碼來源:WxTokenServer.java

示例11: login

import org.springframework.web.util.UriComponentsBuilder; //導入依賴的package包/類
@PostMapping(value = SUBPATH_LOGIN)
public ResponseEntity<UserDto> login(@RequestBody UserDto userDto,
                                     UriComponentsBuilder uriComponentsBuilder){
    HttpHeaders headers = ApplicationUtil.getHttpHeaders(uriComponentsBuilder,SUBPATH_LOGIN);
    logger.info("================userInfo================username: " + userDto.getUsername() + ",pw: " + userDto.getPassword());
    Subject subject = SecurityUtils.getSubject();
    UsernamePasswordToken token = new UsernamePasswordToken(userDto.getUsername(),userDto.getPassword());
    //User user = new User("root","root","root","root");
    //userDao.save(user);
    try{
        subject.login(token);
    } catch (AuthenticationException e){
        logger.error("======登錄失敗======");
        throw new ResultException(ErrorCode.USERNAMEORPASSWORD.getDesc(),ErrorCode.USERNAMEORPASSWORD);
    }
    UserDto loginUserDto = (UserDto) SecurityUtils.getSubject().getSession().getAttribute("user");

    return new ResponseEntity<>(loginUserDto,headers, HttpStatus.OK);
}
 
開發者ID:ZhuXS,項目名稱:Spring-Shiro-Spark,代碼行數:20,代碼來源:AuthController.java

示例12: generateVariantPlaylist

import org.springframework.web.util.UriComponentsBuilder; //導入依賴的package包/類
private void generateVariantPlaylist(HttpServletRequest request, int id, Player player, List<Pair<Integer, Dimension>> bitRates, PrintWriter writer) {
        writer.println("#EXTM3U");
        writer.println("#EXT-X-VERSION:1");
//        writer.println("#EXT-X-TARGETDURATION:" + SEGMENT_DURATION);

        String contextPath = getContextPath(request);
        for (Pair<Integer, Dimension> bitRate : bitRates) {
            Integer kbps = bitRate.getFirst();
            writer.println("#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=" + kbps * 1000L);
            UriComponentsBuilder url = (UriComponentsBuilder.fromUriString(contextPath + "ext/hls/hls.m3u8")
                    .queryParam("id", id)
                    .queryParam("player", player.getId())
                    .queryParam("bitRate", kbps));
            jwtSecurityService.addJWTToken(url);
            writer.print(url.toUriString());
            Dimension dimension = bitRate.getSecond();
            if (dimension != null) {
                writer.print("@" + dimension.width + "x" + dimension.height);
            }
            writer.println();
        }
//        writer.println("#EXT-X-ENDLIST");
    }
 
開發者ID:airsonic,項目名稱:airsonic,代碼行數:24,代碼來源:HLSController.java

示例13: createStreamUrl

import org.springframework.web.util.UriComponentsBuilder; //導入依賴的package包/類
private String createStreamUrl(HttpServletRequest request, Player player, int id, int offset, int duration, Pair<Integer, Dimension> bitRate) {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(getContextPath(request) + "ext/stream/stream.ts");
    builder.queryParam("id", id);
    builder.queryParam("hls", "true");
    builder.queryParam("timeOffset", offset);
    builder.queryParam("player", player.getId());
    builder.queryParam("duration", duration);
    if (bitRate != null) {
        builder.queryParam("maxBitRate", bitRate.getFirst());
        Dimension dimension = bitRate.getSecond();
        if (dimension != null) {
            builder.queryParam("size", dimension.width);
            builder.queryParam("x", dimension.height);
        }
    }
    jwtSecurityService.addJWTToken(builder);
    return builder.toUriString();
}
 
開發者ID:airsonic,項目名稱:airsonic,代碼行數:19,代碼來源:HLSController.java

示例14: contributeMethodArgument

import org.springframework.web.util.UriComponentsBuilder; //導入依賴的package包/類
@Override
public void contributeMethodArgument(MethodParameter parameter, Object value,
		UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {

	Class<?> paramType = parameter.getParameterType();
	if (Map.class.isAssignableFrom(paramType) || MultipartFile.class.equals(paramType) ||
			"javax.servlet.http.Part".equals(paramType.getName())) {
		return;
	}

	RequestParam annot = parameter.getParameterAnnotation(RequestParam.class);
	String name = StringUtils.isEmpty(annot.value()) ? parameter.getParameterName() : annot.value();

	if (value == null) {
		builder.queryParam(name);
	}
	else if (value instanceof Collection) {
		for (Object element : (Collection<?>) value) {
			element = formatUriValue(conversionService, TypeDescriptor.nested(parameter, 1), element);
			builder.queryParam(name, element);
		}
	}
	else {
		builder.queryParam(name, formatUriValue(conversionService, new TypeDescriptor(parameter), value));
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:RequestParamMethodArgumentResolver.java

示例15: createOrder

import org.springframework.web.util.UriComponentsBuilder; //導入依賴的package包/類
@SuppressWarnings({ "unchecked", "rawtypes" })
@RequestMapping(value = "/order/", method = RequestMethod.POST)
public ResponseEntity<?> createOrder(@RequestBody Order order, UriComponentsBuilder ucBuilder) {
	logger.info("Creating order : {}", order);

	if (orderService.orderExists(order)) {
		logger.error("Unable to create. An order with id {} already exist", order.getOrderId());
		return new ResponseEntity(new CustomErrorType("Unable to create. An order with id " + 
		order.getOrderId() + " already exists."),HttpStatus.CONFLICT);
	}
			
	Order currentOrder = orderService.createOrder(order);
	Long currentOrderId = currentOrder.getOrderId();
	JSONObject orderInfo = new JSONObject();
	orderInfo.put("orderId", currentOrderId);

	HttpHeaders headers = new HttpHeaders();
	headers.setLocation(ucBuilder.path("/api/order/").buildAndExpand(order.getOrderId()).toUri());
	return new ResponseEntity<JSONObject>(orderInfo, HttpStatus.CREATED);
}
 
開發者ID:dockersamples,項目名稱:atsea-sample-shop-app,代碼行數:21,代碼來源:OrderController.java


注:本文中的org.springframework.web.util.UriComponentsBuilder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。