Search in sources :

Example 1 with Path

use of com.predic8.membrane.core.config.Path in project irontest by zheng-wang.

the class WSDLResource method getOperationInfo.

@GET
@Path("/{wsdlUrl}/bindings/{bindingName}/operations/{operationName}")
public SOAPOperationInfo getOperationInfo(@PathParam("wsdlUrl") String wsdlUrl, @PathParam("bindingName") String bindingName, @PathParam("operationName") String operationName) {
    SOAPOperationInfo info = new SOAPOperationInfo();
    WSDLParser parser = new WSDLParser();
    Definitions definition = parser.parse(wsdlUrl);
    StringWriter writer = new StringWriter();
    SOARequestCreator creator = new SOARequestCreator(definition, new RequestTemplateCreator(), new MarkupBuilder(writer));
    creator.createRequest(null, operationName, bindingName);
    info.setSampleRequest(writer.toString());
    return info;
}
Also used : RequestTemplateCreator(com.predic8.wstool.creator.RequestTemplateCreator) StringWriter(java.io.StringWriter) Definitions(com.predic8.wsdl.Definitions) MarkupBuilder(groovy.xml.MarkupBuilder) SOAPOperationInfo(io.irontest.models.teststep.SOAPOperationInfo) WSDLParser(com.predic8.wsdl.WSDLParser) SOARequestCreator(com.predic8.wstool.creator.SOARequestCreator) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with Path

use of com.predic8.membrane.core.config.Path in project service-proxy by membrane.

the class IndexInterceptor method getServiceInfo.

private ServiceInfo getServiceInfo(Exchange exc, AbstractServiceProxy sp) {
    if (sp.getInterceptors().size() == 1 && sp.getInterceptors().get(0) instanceof IndexInterceptor)
        return null;
    ServiceProxyKey k = (ServiceProxyKey) sp.getKey();
    ServiceInfo ri = new ServiceInfo();
    ri.method = k.getMethod();
    // NOTE: when running as servlet, we have no idea what the protocol was
    ri.ssl = sp.getSslInboundContext() != null;
    String protocol = ri.ssl ? "https" : "http";
    String host = k.isHostWildcard() ? new HostColonPort(ri.ssl, exc.getRequest().getHeader().getHost()).host : fullfillRegexp(ServiceProxyKey.createHostPattern(k.getHost()));
    if (host == null || host.length() == 0)
        host = exc.getHandler().getLocalAddress().getHostAddress().toString();
    int port = k.getPort();
    if (port == -1 || !exc.getHandler().isMatchLocalPort())
        port = exc.getHandler().getLocalPort();
    String path;
    if (!k.isUsePathPattern()) {
        path = "/";
    } else if (k.isPathRegExp()) {
        path = fullfillRegexp(k.getPath());
    } else {
        path = "/" + StringUtils.removeStart(k.getPath(), "/");
    }
    if (!"".equals(exc.getHandler().getContextPath(exc))) {
        path = StringUtils.removeEnd(exc.getHandler().getContextPath(exc), "/") + "/" + StringUtils.removeStart(path, "/");
    }
    ri.name = sp.getName();
    if (path != null)
        ri.url = protocol + "://" + host + ":" + port + path;
    ri.host = k.isHostWildcard() ? "" : StringEscapeUtils.escapeHtml(k.getHost());
    ri.port = k.getPort() == -1 ? "" : "" + k.getPort();
    ri.path = k.isUsePathPattern() ? "<tt>" + StringEscapeUtils.escapeHtml(k.getPath()) + "</tt>" + (k.isPathRegExp() ? " (regex)" : "") : "";
    return ri;
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) HostColonPort(com.predic8.membrane.core.transport.http.HostColonPort)

Example 3 with Path

use of com.predic8.membrane.core.config.Path in project service-proxy by membrane.

the class OAuth2AuthorizationServerInterceptor method init.

@Override
public void init(Router router) throws Exception {
    name = "OAuth 2 Authorization Server";
    setFlow(Flow.Set.REQUEST_RESPONSE);
    this.setRouter(router);
    addSupportedAuthorizationGrants();
    getWellknownFile().init(router, this);
    getConsentPageFile().init(router, getConsentFile());
    if (userDataProvider == null)
        throw new Exception("No userDataProvider configured. - Cannot work without one.");
    if (getClientList() == null)
        throw new Exception("No clientList configured. - Cannot work without one.");
    if (getClaimList() == null)
        throw new Exception("No scopeList configured. - Cannot work without one");
    if (getLocation() == null) {
        log.warn("===========================================================================================");
        log.warn("IMPORTANT: No location configured - Authorization code and implicit flows are not available");
        log.warn("===========================================================================================");
        loginViewDisabled = true;
    }
    if (getConsentFile() == null && !isLoginViewDisabled()) {
        log.warn("==============================================================================================");
        log.warn("IMPORTANT: No consentFile configured - Authorization code and implicit flows are not available");
        log.warn("==============================================================================================");
        loginViewDisabled = true;
    }
    if (getPath() == null)
        throw new Exception("No path configured. - Cannot work without one");
    userDataProvider.init(router);
    getClientList().init(router);
    getClaimList().init(router);
    jwtGenerator = new JwtGenerator();
    sessionManager.init(router);
    statistics = new OAuth2Statistics();
    addDefaultProcessors();
    new CleanupThread(sessionManager, accountBlocker).start();
}
Also used : JwtGenerator(com.predic8.membrane.core.interceptor.oauth2.tokengenerators.JwtGenerator) CleanupThread(com.predic8.membrane.core.interceptor.authentication.session.CleanupThread)

Example 4 with Path

use of com.predic8.membrane.core.config.Path in project service-proxy by membrane.

the class RESTInterceptor method dispatchRequest.

private Outcome dispatchRequest(Exchange exc) throws Exception {
    String path = router.getUriFactory().create(exc.getDestinations().get(0)).getPath();
    for (Method m : getClass().getMethods()) {
        Mapping a = m.getAnnotation(Mapping.class);
        if (a == null)
            continue;
        Matcher matcher = Pattern.compile(a.value()).matcher(path);
        if (matcher.matches()) {
            Object[] parameters;
            switch(m.getParameterTypes().length) {
                case 2:
                    parameters = new Object[] { new QueryParameter(URLParamUtil.getParams(router.getUriFactory(), exc), matcher), getRelativeRootPath(path) };
                    break;
                case 3:
                    parameters = new Object[] { new QueryParameter(URLParamUtil.getParams(router.getUriFactory(), exc), matcher), getRelativeRootPath(path), exc };
                    break;
                default:
                    throw new InvalidParameterException("@Mapping is supposed to annotate a 2-parameter method.");
            }
            exc.setResponse((Response) m.invoke(this, parameters));
            return Outcome.RETURN;
        }
    }
    return Outcome.CONTINUE;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) Matcher(java.util.regex.Matcher) Mapping(com.predic8.membrane.core.interceptor.administration.Mapping) Method(java.lang.reflect.Method)

Example 5 with Path

use of com.predic8.membrane.core.config.Path in project service-proxy by membrane.

the class WSDLPublisherInterceptor method handleRequest.

@Override
public Outcome handleRequest(final Exchange exc) throws Exception {
    if (!"GET".equals(exc.getRequest().getMethod()))
        return Outcome.CONTINUE;
    try {
        String resource = null;
        if (exc.getRequestURI().endsWith("?wsdl") || exc.getRequestURI().endsWith("?WSDL")) {
            processDocuments(exc);
            exc.setResponse(WebServerInterceptor.createResponse(router.getResolverMap(), resource = wsdl));
            exc.getResponse().getHeader().setContentType(MimeType.TEXT_XML);
        }
        if (exc.getRequestURI().contains("?xsd=")) {
            Map<String, String> params = URLParamUtil.getParams(router.getUriFactory(), exc);
            if (params.containsKey("xsd")) {
                int n = Integer.parseInt(params.get("xsd"));
                String path;
                processDocuments(exc);
                synchronized (paths) {
                    if (!paths.containsKey(n)) {
                        exc.setResponse(Response.forbidden("Unknown parameter. You may only retrieve documents referenced by the WSDL.").build());
                        return Outcome.ABORT;
                    }
                    path = paths.get(n);
                }
                exc.setResponse(WebServerInterceptor.createResponse(router.getResolverMap(), resource = path));
                exc.getResponse().getHeader().setContentType(MimeType.TEXT_XML);
            }
        }
        if (resource != null) {
            WSDLInterceptor wi = new WSDLInterceptor();
            wi.setRewriteEndpoint(false);
            wi.setPathRewriter(new RelativePathRewriter(exc, resource));
            wi.handleResponse(exc);
            return Outcome.RETURN;
        }
    } catch (NumberFormatException e) {
        exc.setResponse(HttpUtil.setHTMLErrorResponse(Response.internalServerError(), "Bad parameter format.", ""));
        return Outcome.ABORT;
    } catch (ResourceRetrievalException e) {
        exc.setResponse(Response.notFound().build());
        return Outcome.ABORT;
    }
    return Outcome.CONTINUE;
}
Also used : WSDLInterceptor(com.predic8.membrane.core.interceptor.WSDLInterceptor) ResourceRetrievalException(com.predic8.membrane.core.resolver.ResourceRetrievalException)

Aggregations

Exchange (com.predic8.membrane.core.exchange.Exchange)8 Test (org.junit.Test)6 Request (com.predic8.membrane.core.http.Request)4 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)4 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)4 Process2 (com.predic8.membrane.examples.Process2)3 Definitions (com.predic8.wsdl.Definitions)3 WSDLParser (com.predic8.wsdl.WSDLParser)3 File (java.io.File)3 IOException (java.io.IOException)3 StringWriter (java.io.StringWriter)3 ParseException (com.floreysoft.jmte.message.ParseException)2 Header (com.predic8.membrane.core.http.Header)2 Response (com.predic8.membrane.core.http.Response)2 AbstractServiceProxy (com.predic8.membrane.core.rules.AbstractServiceProxy)2 ProxiesXmlUtil (com.predic8.membrane.examples.ProxiesXmlUtil)2 RequestTemplateCreator (com.predic8.wstool.creator.RequestTemplateCreator)2 SOARequestCreator (com.predic8.wstool.creator.SOARequestCreator)2 MarkupBuilder (groovy.xml.MarkupBuilder)2 MalformedURLException (java.net.MalformedURLException)2