Example usage for org.springframework.web.util UriComponentsBuilder fromUriString

List of usage examples for org.springframework.web.util UriComponentsBuilder fromUriString

Introduction

In this page you can find the example usage for org.springframework.web.util UriComponentsBuilder fromUriString.

Prototype

public static UriComponentsBuilder fromUriString(String uri) 

Source Link

Document

Create a builder that is initialized with the given URI string.

Usage

From source file:org.springframework.web.socket.client.endpoint.StandardWebSocketClient.java

@Override
public WebSocketSession doHandshake(WebSocketHandler webSocketHandler, String uriTemplate,
        Object... uriVariables) throws WebSocketConnectFailureException {

    Assert.notNull(uriTemplate, "uriTemplate is required");
    UriComponents uriComponents = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(uriVariables)
            .encode();//  w  w  w. j  a  va 2  s.  c  om
    return doHandshake(webSocketHandler, null, uriComponents.toUri());
}

From source file:org.springframework.web.socket.client.jetty.JettyWebSocketClient.java

@Override
public WebSocketSession doHandshake(WebSocketHandler webSocketHandler, String uriTemplate,
        Object... uriVariables) throws WebSocketConnectFailureException {

    UriComponents uriComponents = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(uriVariables)
            .encode();/* w w w  .  j  a v  a  2s . c om*/
    return doHandshake(webSocketHandler, null, uriComponents.toUri());
}

From source file:org.springframework.web.socket.messaging.WebSocketStompClient.java

/**
 * An overloaded version of//w  w  w.j a v  a2  s . c  om
 * {@link #connect(String, StompSessionHandler, Object...)} that also accepts
 * {@link WebSocketHttpHeaders} to use for the WebSocket handshake and
 * {@link StompHeaders} for the STOMP CONNECT frame.
 * @param url the url to connect to
 * @param handshakeHeaders headers for the WebSocket handshake
 * @param connectHeaders headers for the STOMP CONNECT frame
 * @param handler the session handler
 * @param uriVariables URI variables to expand into the URL
 * @return ListenableFuture for access to the session when ready for use
 */
public ListenableFuture<StompSession> connect(String url, @Nullable WebSocketHttpHeaders handshakeHeaders,
        @Nullable StompHeaders connectHeaders, StompSessionHandler handler, Object... uriVariables) {

    Assert.notNull(url, "'url' must not be null");
    URI uri = UriComponentsBuilder.fromUriString(url).buildAndExpand(uriVariables).encode().toUri();
    return connect(uri, handshakeHeaders, connectHeaders, handler);
}

From source file:org.springframework.web.socket.sockjs.client.SockJsClient.java

@Override
public ListenableFuture<WebSocketSession> doHandshake(WebSocketHandler handler, String uriTemplate,
        Object... uriVars) {//from w  w  w .ja  va  2  s.  c  om

    Assert.notNull(uriTemplate, "uriTemplate must not be null");
    URI uri = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(uriVars).encode().toUri();
    return doHandshake(handler, null, uri);
}

From source file:org.springframework.xd.dirt.integration.bus.rabbit.RabbitBusCleaner.java

private Map<String, List<String>> doClean(String adminUri, String user, String pw, String vhost,
        String busPrefix, String entity, boolean isJob) {
    RestTemplate restTemplate = buildRestTemplate(adminUri, user, pw);
    List<String> removedQueues = isJob ? findJobQueues(adminUri, vhost, busPrefix, entity, restTemplate)
            : findStreamQueues(adminUri, vhost, busPrefix, entity, restTemplate);
    ExchangeCandidateCallback callback;/*from   w w w  .  j av a2s . c o  m*/
    if (isJob) {
        Collection<String> exchangeNames = JobEventsListenerPlugin.getEventListenerChannels(entity).values();
        final Set<String> jobExchanges = new HashSet<>();
        for (String exchange : exchangeNames) {
            jobExchanges.add(MessageBusSupport.applyPrefix(busPrefix, MessageBusSupport.applyPubSub(exchange)));
        }
        jobExchanges.add(MessageBusSupport.applyPrefix(busPrefix,
                MessageBusSupport.applyPubSub(JobEventsListenerPlugin.getEventListenerChannelName(entity))));
        callback = new ExchangeCandidateCallback() {

            @Override
            public boolean isCandidate(String exchangeName) {
                return jobExchanges.contains(exchangeName);
            }

        };
    } else {
        final String tapPrefix = MessageBusSupport.applyPrefix(busPrefix,
                MessageBusSupport.applyPubSub(AbstractStreamPlugin.constructTapPrefix(entity)));
        callback = new ExchangeCandidateCallback() {

            @Override
            public boolean isCandidate(String exchangeName) {
                return exchangeName.startsWith(tapPrefix);
            }
        };
    }
    List<String> removedExchanges = findExchanges(adminUri, vhost, busPrefix, entity, restTemplate, callback);
    // Delete the queues in reverse order to enable re-running after a partial success.
    // The queue search above starts with 0 and terminates on a not found.
    for (int i = removedQueues.size() - 1; i >= 0; i--) {
        String queueName = removedQueues.get(i);
        URI uri = UriComponentsBuilder.fromUriString(adminUri + "/api")
                .pathSegment("queues", "{vhost}", "{stream}").buildAndExpand(vhost, queueName).encode().toUri();
        restTemplate.delete(uri);
        if (logger.isDebugEnabled()) {
            logger.debug("deleted queue: " + queueName);
        }
    }
    Map<String, List<String>> results = new HashMap<>();
    if (removedQueues.size() > 0) {
        results.put("queues", removedQueues);
    }
    // Fanout exchanges for taps
    for (String exchange : removedExchanges) {
        URI uri = UriComponentsBuilder.fromUriString(adminUri + "/api")
                .pathSegment("exchanges", "{vhost}", "{name}").buildAndExpand(vhost, exchange).encode().toUri();
        restTemplate.delete(uri);
        if (logger.isDebugEnabled()) {
            logger.debug("deleted exchange: " + exchange);
        }
    }
    if (removedExchanges.size() > 0) {
        results.put("exchanges", removedExchanges);
    }
    return results;
}

From source file:org.springframework.xd.dirt.integration.bus.rabbit.RabbitBusCleaner.java

private List<String> findStreamQueues(String adminUri, String vhost, String busPrefix, String stream,
        RestTemplate restTemplate) {/*from   w  ww  . java  2  s  .c  o  m*/
    List<String> removedQueues = new ArrayList<>();
    int n = 0;
    while (true) { // exits when no queue found
        String queueName = MessageBusSupport.applyPrefix(busPrefix,
                AbstractMessageBusBinderPlugin.constructPipeName(stream, n++));
        URI uri = UriComponentsBuilder.fromUriString(adminUri + "/api")
                .pathSegment("queues", "{vhost}", "{stream}").buildAndExpand(vhost, queueName).encode().toUri();
        try {
            getQueueDetails(restTemplate, queueName, uri);
            removedQueues.add(queueName);
        } catch (HttpClientErrorException e) {
            if (e.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
                break; // No more for this stream
            }
            throw new RabbitAdminException("Failed to lookup queue " + queueName, e);
        }
        queueName = MessageBusSupport.constructDLQName(queueName);
        uri = UriComponentsBuilder.fromUriString(adminUri + "/api").pathSegment("queues", "{vhost}", "{stream}")
                .buildAndExpand(vhost, queueName).encode().toUri();
        try {
            getQueueDetails(restTemplate, queueName, uri);
            removedQueues.add(queueName);
        } catch (HttpClientErrorException e) {
            if (e.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
                continue; // DLQs are not mandatory
            }
            throw new RabbitAdminException("Failed to lookup queue " + queueName, e);
        }
    }
    return removedQueues;
}

From source file:org.springframework.xd.dirt.integration.bus.rabbit.RabbitBusCleaner.java

private List<String> findJobQueues(String adminUri, String vhost, String busPrefix, String job,
        RestTemplate restTemplate) {//  w w  w.j  a v a  2  s  .c o m
    List<String> removedQueues = new ArrayList<>();
    String jobQueueName = MessageBusSupport.applyPrefix(busPrefix, AbstractJobPlugin.getJobChannelName(job));
    URI uri = UriComponentsBuilder.fromUriString(adminUri + "/api").pathSegment("queues", "{vhost}", "{job}")
            .buildAndExpand(vhost, jobQueueName).encode().toUri();
    try {
        getQueueDetails(restTemplate, jobQueueName, uri);
        removedQueues.add(jobQueueName);
    } catch (HttpClientErrorException e) {
        if (!e.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
            throw new RabbitAdminException("Failed to lookup queue " + jobQueueName, e);
        }
    }
    String jobRequestsQueueName = MessageBusSupport.applyPrefix(busPrefix, MessageBusSupport.applyRequests(
            AbstractMessageBusBinderPlugin.constructPipeName(AbstractJobPlugin.getJobChannelName(job), 0)));
    uri = UriComponentsBuilder.fromUriString(adminUri + "/api").pathSegment("queues", "{vhost}", "{job}")
            .buildAndExpand(vhost, jobRequestsQueueName).encode().toUri();
    try {
        getQueueDetails(restTemplate, jobRequestsQueueName, uri);
        removedQueues.add(jobRequestsQueueName);
    } catch (HttpClientErrorException e) {
        if (!e.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
            throw new RabbitAdminException("Failed to lookup queue " + jobRequestsQueueName, e);
        }
    }
    return removedQueues;
}

From source file:sg.ncl.MainController.java

@RequestMapping(value = "/web_vnc/access_node/{teamName}/{expId}/{nodeId}", params = { "portNum" })
public String vncAccessNode(Model model, HttpSession session, RedirectAttributes redirectAttributes,
        @PathVariable String teamName, @PathVariable Long expId, @PathVariable String nodeId,
        @NotNull @RequestParam("portNum") Integer portNum)
        throws WebServiceRuntimeException, NoSuchAlgorithmException {
    Realization realization = invokeAndExtractRealization(teamName, expId);
    if (!checkPermissionRealizeExperiment(realization, session)) {
        log.warn("Permission denied to access experiment {} node for team: {}", realization.getExperimentName(),
                teamName);//from  w w w. j a  v  a2  s  .  co  m
        redirectAttributes.addFlashAttribute(MESSAGE, permissionDeniedMessage);
        return REDIRECT_EXPERIMENTS;
    }
    HttpEntity<String> request = createHttpEntityHeaderOnly();
    ResponseEntity response = restTemplate.exchange(properties.getStatefulExperiment(expId.toString()),
            HttpMethod.GET, request, String.class);
    StatefulExperiment statefulExperiment = extractStatefulExperiment(response.getBody().toString());
    getDeterUid(model, session);
    Map attributes = model.asMap();
    UriComponents uriComponents = UriComponentsBuilder.fromUriString(vncProperties.getHttp())
            .queryParam("host", vncProperties.getHost())
            .queryParam("path", qencode(getNodeQualifiedName(statefulExperiment, nodeId) + ":" + portNum,
                    (String) attributes.get(DETER_UID)))
            .build();
    log.info("VNC URI: {}", uriComponents.toString());
    return "redirect:" + uriComponents.toString();
}