Example usage for java.net URISyntaxException getStackTrace

List of usage examples for java.net URISyntaxException getStackTrace

Introduction

In this page you can find the example usage for java.net URISyntaxException getStackTrace.

Prototype

public StackTraceElement[] getStackTrace() 

Source Link

Document

Provides programmatic access to the stack trace information printed by #printStackTrace() .

Usage

From source file:org.onebusaway.alexa.MainSpeechlet.java

public SpeechletResponse onIntent(final IntentRequest request, final Session session)
        throws SpeechletException {
    try {//  w ww.j  ava  2  s .  c om
        Optional<ObaUserDataItem> optUserData = obaDao.getUserData(session);
        if (optUserData.isPresent()) {
            return getAuthedSpeechlet(optUserData.get()).onIntent(request, session);
        } else {
            return anonSpeechlet.onIntent(request, session);
        }
    } catch (URISyntaxException e) {
        log.error("Intent exception: " + e.getMessage());
        log.error("Backtrace:\n" + e.getStackTrace());
        throw new SpeechletException("Error creating user data on Intent using ObaBaseUrl: " + e);
    } catch (Exception e) {
        log.error("Intent exception: " + e.getMessage());
        log.error("Backtrace:\n" + e.getStackTrace());
        throw e;
    }
}

From source file:org.onebusaway.alexa.MainSpeechlet.java

public SpeechletResponse onLaunch(LaunchRequest request, Session session) throws SpeechletException {
    Optional<ObaUserDataItem> optUserData = obaDao.getUserData(session);
    if (optUserData.isPresent()) {
        try {/*from  w w w. ja  v a2  s  . c o  m*/
            return getAuthedSpeechlet(optUserData.get()).onLaunch(request, session);
        } catch (URISyntaxException e) {
            log.error("Launch exception: " + e.getMessage());
            log.error("Backtrace:\n" + e.getStackTrace());
            throw new SpeechletException("Error creating user data on Launch using ObaBaseUrl: " + e);
        }
    } else {
        return anonSpeechlet.onLaunch(request, session);
    }
}

From source file:com.excilys.ebi.gatling.recorder.ui.component.RunningFrame.java

private boolean addRequest(HttpRequest request) {
    URI uri = null;/*from  ww w .j  av a2  s .c om*/
    try {
        uri = new URI(request.getUri());
    } catch (URISyntaxException ex) {
        logger.error("Can't create URI from request uri (" + request.getUri() + ")" + ex.getStackTrace());
        // FIXME error handling
        return false;
    }

    if (configuration.getFilterStrategy() != FilterStrategy.NONE) {

        String p = EMPTY;
        boolean add = true;
        if (configuration.getFilterStrategy() == FilterStrategy.ONLY)
            add = true;
        else if (configuration.getFilterStrategy() == FilterStrategy.EXCEPT)
            add = false;

        for (Pattern pattern : configuration.getPatterns()) {
            switch (pattern.getPatternType()) {
            case ANT:
                p = SelectorUtils.ANT_HANDLER_PREFIX;
                break;
            case JAVA:
                p = SelectorUtils.REGEX_HANDLER_PREFIX;
                break;
            }
            p += pattern.getPattern() + SelectorUtils.PATTERN_HANDLER_SUFFIX;
            if (SelectorUtils.matchPath(p, uri.getPath()))
                return add;
        }
        return !add;
    }
    return true;
}

From source file:com.excilys.ebi.gatling.recorder.ui.component.RunningFrame.java

private void processRequest(ResponseReceivedEvent event) {

    HttpRequest request = event.getRequest();

    URI uri = null;//from   w  w w .j  av  a 2  s  . co  m
    try {
        uri = new URI(request.getUri());
    } catch (URISyntaxException ex) {
        logger.error("Can't create URI from request uri (" + request.getUri() + ")" + ex.getStackTrace());
    }

    events.addElement(request.getMethod() + " | " + request.getUri());
    executedEvents.ensureIndexIsVisible(events.getSize() - 1);

    int id = ++numberOfRequests;
    event.setId(id);

    /* URLs */
    if (urlBase == null) {
        protocol = uri.getScheme();
        host = uri.getHost();
        port = uri.getPort();
        urlBase = protocol + "://" + host;
        urlBaseString = "PROTOCOL + \"://\" + HOST";
        if (port != -1) {
            urlBase += ":" + port;
            urlBaseString += " + \":\" + PORT";
        }
    }

    String requestUrlBase = uri.getScheme() + "://" + uri.getHost();
    if (uri.getPort() != -1)
        requestUrlBase += ":" + uri.getPort();
    if (requestUrlBase.equals(urlBase))
        event.setWithUrlBase(true);
    else
        urls.put("url_" + id, requestUrlBase + uri.getPath());

    String headerAuthorization = event.getRequest().getHeader("Authorization");
    request.removeHeader("Authorization");
    if (headerAuthorization != null) {
        if (basicAuth == null) {
            // Split on " " and take 2nd group (Basic credentialsInBase64==)
            String credentials = new String(Base64.decodeBase64(headerAuthorization.split(" ")[1].getBytes()));
            basicAuth = new BasicAuth(requestUrlBase, credentials.split(":")[0], credentials.split(":")[1]);
            event.setBasicAuth(basicAuth);
        } else {
            if (requestUrlBase.equals(basicAuth.getUrlBase()))
                event.setBasicAuth(basicAuth);
            else
                basicAuth = null;
        }
    }

    /* Headers */
    Map<String, String> requestHeaders = new TreeMap<String, String>();
    for (Entry<String, String> entry : request.getHeaders())
        requestHeaders.put(entry.getKey(), entry.getValue());
    requestHeaders.remove("Cookie");

    int bestChoice = 0;
    String headerKey = EMPTY;
    MapDifference<String, String> diff;
    Map<String, String> fullHeaders = new TreeMap<String, String>();
    boolean containsHeaders = false;

    if (headers.size() > 0) {
        for (Entry<String, Map<String, String>> header : headers.entrySet()) {

            fullHeaders = new TreeMap<String, String>(header.getValue());
            containsHeaders = false;

            if (header.getValue().containsKey("headers")) {
                fullHeaders.putAll(headers.get(header.getValue().get("headers")));
                fullHeaders.remove("headers");
                containsHeaders = true;
            }

            diff = Maps.difference(fullHeaders, requestHeaders);
            logger.debug(diff.toString());
            if (diff.areEqual()) {
                headerKey = header.getKey();
                bestChoice = 1;
                break;
            } else if (diff.entriesOnlyOnLeft().size() == 0 && diff.entriesDiffering().size() == 0
                    && !containsHeaders) {
                // header are included in requestHeaders
                headerKey = header.getKey();
                bestChoice = 2;
            } else if (bestChoice > 2 && diff.entriesOnlyOnRight().size() == 0
                    && diff.entriesDiffering().size() == 0 && !containsHeaders) {
                // requestHeaders are included in header
                headerKey = header.getKey();
                bestChoice = 3;
            }
        }
    }

    switch (bestChoice) {
    case 1:
        event.setHeadersId(headerKey);
        break;
    case 2:
        diff = Maps.difference(headers.get(headerKey), requestHeaders);
        TreeMap<String, String> tm2 = new TreeMap<String, String>(diff.entriesOnlyOnRight());
        headers.put("headers_" + id, tm2);
        headers.get("headers_" + id).put("headers", headerKey);
        event.setHeadersId("headers_" + id);
        break;
    case 3:
        diff = Maps.difference(headers.get(headerKey), requestHeaders);
        TreeMap<String, String> tm3 = new TreeMap<String, String>(diff.entriesInCommon());
        headers.put("headers_" + id, tm3);
        event.setHeadersId("headers_" + id);
        headers.remove(headerKey);
        tm3 = new TreeMap<String, String>(diff.entriesOnlyOnLeft());
        headers.put(headerKey, tm3);
        headers.get(headerKey).put("headers", "headers_" + id);
        break;
    default:
        headers.put("headers_" + id, requestHeaders);
        event.setHeadersId("headers_" + id);
    }

    /* Add check if status is not in 20X */
    if ((event.getResponse().getStatus().getCode() < 200) || (event.getResponse().getStatus().getCode() > 210))
        event.setWithCheck(true);

    /* Params */
    QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());
    event.getRequestParams().putAll((decoder.getParameters()));

    /* Content */
    if (request.getContent().capacity() > 0) {
        String content = new String(request.getContent().array());
        // We check if it's a form validation and so we extract post params
        if ("application/x-www-form-urlencoded".equals(request.getHeader("Content-Type"))) {
            decoder = new QueryStringDecoder("http://localhost/?" + content);
            event.getRequestParams().putAll(decoder.getParameters());
        } else {
            event.setWithBody(true);
            dumpRequestBody(id, content);
        }
    }

    listEvents.add(event);
}

From source file:org.commonjava.test.http.stream.StreamServlet.java

@Override
protected void service(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {
    String wholePath;//from www . j  a v  a  2s.  c  o  m
    try {
        wholePath = new URI(req.getRequestURI()).getPath();
    } catch (final URISyntaxException e) {
        throw new ServletException("Cannot parse request URI", e);
    }

    String path = wholePath;
    if (path.length() > 1) {
        path = path.substring(1);
    }

    final String key = getAccessKey(req.getMethod(), wholePath);

    logger.info("Request: {}", key);
    final Integer i = accessesByPath.get(key);
    if (i == null) {
        accessesByPath.put(key, 1);
    } else {
        accessesByPath.put(key, i + 1);
    }

    logger.info("Looking for resource: '{}'", path);
    try (InputStream in = resolver.get(path); OutputStream out = resp.getOutputStream()) {
        if (in != null) {
            logger.info("Found: {}", in);
            resp.setStatus(200);
            IOUtils.copy(in, out);
        } else {
            logger.info("Not found: {}", path);
            resp.setStatus(404);
        }
    } catch (Exception e) {
        logger.info("Error retrieving: " + path + ". Reason: " + e.getMessage(), e);

        resp.setStatus(500);
        resp.getWriter().write(StringUtils.join(e.getStackTrace(), "\n"));
    }
}