Package com.gatehill.apibms.core.exception

Examples of com.gatehill.apibms.core.exception.ServiceException


            try {
                port = ServerUtil.getFreePort();
                LOGGER.debug("No port specified - got free port {}", port);

            } catch (IOException e) {
                throw new ServiceException("Error getting free port", e);
            }
        }

        if (null != running.get(port)) {
            throw new ServiceException("Server already running on port " + port);
        }

        final Undertow server = Undertow.builder()
                .addHttpListener(port, host)
                .setHandler(new HttpHandler() {
View Full Code Here


                            candidates.size(), responseMatcher.getClass().getName(), request, endpoint.getUrl());
            }
        }

        // 0 found after checking a matcher, or more than 1 found after checking all matchers
        throw new ServiceException("Unable to find a single, distinct response definition matching request for resource "
                + endpoint.getUrl());
    }
View Full Code Here

                return endpoint;
            }
        }

        if (!shouldIgnoreMissingPath(exchange.getRequestPath())) {
            throw new ServiceException("Unknown endpoint path: " + exchange.getRequestPath());
        } else {
            return null;
        }
    }
View Full Code Here

            try (FileInputStream inputStream = FileUtils.openInputStream(markdownFile)) {
                return parseMarkdown(inputStream);
            }

        } catch (IOException e) {
            throw new ServiceException("Error parsing markdown file: " + markdownFile, e);
        }
    }
View Full Code Here

            // convert MD to HTML
            LOGGER.debug("Converting markdown InputStream to String");
            return new Markdown4jProcessor().process(markdownStream);

        } catch (IOException e) {
            throw new ServiceException("Error parsing markdown stream", e);
        }
    }
View Full Code Here

            try (InputStream inputStream = IOUtils.toInputStream(html)) {
                return tidy.parseDOM(inputStream, System.out);
            }

        } catch (IOException e) {
            throw new ServiceException("Error converting HTML to XHTML document", e);
        }
    }
View Full Code Here

            final NodeList nodes = (NodeList) xPath.evaluate("/html/body",
                    doc.getDocumentElement(), XPathConstants.NODESET);

            if (nodes.getLength() != 1) {
                throw new ServiceException("XHTML should be exactly 1 body element");
            }

            final Node body = nodes.item(0);

            // build endpoint definitions
            if (body.hasChildNodes()) {
                ResourceDefinition currentEndpoint = null;

                for (int i = 0; i < body.getChildNodes().getLength(); i++) {
                    final Node child = body.getChildNodes().item(i);
                    LOGGER.debug("Found {}: {}", child.getNodeName(), child.getTextContent());

                    if (child.getNodeType() == Node.ELEMENT_NODE) {

                        // <h1>My API</h1>
                        if (isApiTitle(child.getNodeName())) {
                            definition.setName(child.getTextContent());
                            LOGGER.info("Found API: {}", definition.getName());
                        }

                        // <h2>GET /message</h2>
                        if (isEndpointHTTP(child.getNodeName())) {
                            // start of a new endpoint
                            currentEndpoint = new ResourceDefinition();
                            definition.addEndpoint(currentEndpoint);

                            LOGGER.info("Found endpoint: {}", currentEndpoint.getName());

                            final String[] http = child.getTextContent().split(" ");
                            currentEndpoint.setUrl(http[1]);

                            final RequestDefinition request = new RequestDefinition();
                            currentEndpoint.getRequests().add(request);
                            request.setVerb(http[0]);
                        }

                        // <ul><li><p>Response 200 (text/plain)</p>
                        if (isEndpointResponse(child.getNodeName())) {
                            final ResponseDefinition response = parseResponseDefinition(child);
                            populateResponseBody(response, child);
                            currentEndpoint.getResponses().put(response.getCode(), response);
                        }
                    }
                }
            }

            LOGGER.debug("Document parsed: {}", definition);
            return definition;

        } catch (XPathExpressionException e) {
            throw new ServiceException("Error creating mock from document: " + doc, e);
        }
    }
View Full Code Here

        final XPath xPath = XPathFactory.newInstance().newXPath();

        final NodeList nodes = (NodeList) xPath.evaluate("li/pre/code", child, XPathConstants.NODESET);

        if (nodes.getLength() != 1) {
            throw new ServiceException("Response definition should have exactly 1 preformatted code element");
        }

        final Node code = nodes.item(0);

        final String textContent = code.getTextContent().trim();
View Full Code Here

        final XPath xPath = XPathFactory.newInstance().newXPath();

        final NodeList nodes = (NodeList) xPath.evaluate("li/p", child, XPathConstants.NODESET);

        if (nodes.getLength() != 1) {
            throw new ServiceException("Response definition should have exactly 1 paragraph element");
        }

        final Node p = nodes.item(0);

        // build definition
        final ResponseDefinition response = new ResponseDefinition();

        final String textContent = p.getTextContent().trim();
        final String[] responseCode = textContent.split(" ");
        if (!"Response".equals(responseCode[0])) {
            throw new ServiceException("Response definition should start with 'Response'");
        }

        // HTTP response code
        response.setCode(Integer.parseInt(responseCode[1]));
View Full Code Here

TOP

Related Classes of com.gatehill.apibms.core.exception.ServiceException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.