本文整理汇总了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");
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
示例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));
}
}
示例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);
}
示例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);
}
示例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失败");
}
}
}
示例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);
}
示例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");
}
示例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();
}
示例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));
}
}
示例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);
}