Search in sources :

Example 6 with ResourceRetrievalException

use of com.predic8.membrane.core.resolver.ResourceRetrievalException in project service-proxy by membrane.

the class MembraneAuthorizationService method init.

@Override
public void init() throws Exception {
    if (src == null)
        throw new Exception("No wellknown file source configured. - Cannot work without one");
    if (dynamicRegistration != null) {
        dynamicRegistration.init(router);
        supportsDynamicRegistration = true;
    }
    try {
        String[] urls = src.split(Pattern.quote(" "));
        if (urls.length == 1) {
            String url = urls[0] + "/.well-known/openid-configuration";
            parseSrc(dynamicRegistration != null ? dynamicRegistration.retrieveOpenIDConfiguration(url) : router.getResolverMap().resolve(url));
        } else if (urls.length == 2) {
            String internalUrl = urls[1] + "/.well-known/openid-configuration";
            parseSrc(dynamicRegistration != null ? dynamicRegistration.retrieveOpenIDConfiguration(internalUrl) : router.getResolverMap().resolve(internalUrl));
            publicAuthorizationEndpoint = urls[0] + new URI(authorizationEndpoint).getPath();
        } else if (urls.length > 2)
            throw new RuntimeException("src property is not set correctly: " + src);
    } catch (ResourceRetrievalException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    adjustScope();
    prepareClaimsForLoginUrl();
}
Also used : IOException(java.io.IOException) URI(java.net.URI) IOException(java.io.IOException) ResourceRetrievalException(com.predic8.membrane.core.resolver.ResourceRetrievalException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ResourceRetrievalException(com.predic8.membrane.core.resolver.ResourceRetrievalException)

Example 7 with ResourceRetrievalException

use of com.predic8.membrane.core.resolver.ResourceRetrievalException in project service-proxy by membrane.

the class SOAPProxy method parseWSDL.

/**
 * @return error or null for success
 */
private void parseWSDL() throws Exception {
    WSDLParserContext ctx = new WSDLParserContext();
    ctx.setInput(ResolverMap.combine(router.getBaseLocation(), wsdl));
    try {
        WSDLParser wsdlParser = new WSDLParser();
        wsdlParser.setResourceResolver(resolverMap.toExternalResolver().toExternalResolver());
        Definitions definitions = wsdlParser.parse(ctx);
        List<Service> services = definitions.getServices();
        if (services.size() != 1)
            throw new IllegalArgumentException("There are " + services.size() + " services defined in the WSDL, but exactly 1 is required for soapProxy.");
        Service service = services.get(0);
        if (StringUtils.isEmpty(name))
            name = StringUtils.isEmpty(service.getName()) ? definitions.getName() : service.getName();
        List<Port> ports = service.getPorts();
        Port port = selectPort(ports, portName);
        String location = port.getAddress().getLocation();
        if (location == null)
            throw new IllegalArgumentException("In the WSDL, there is no @location defined on the port.");
        try {
            URL url = new URL(location);
            target.setHost(url.getHost());
            if (url.getPort() != -1)
                target.setPort(url.getPort());
            else
                target.setPort(url.getDefaultPort());
            if (key.getPath() == null) {
                key.setUsePathPattern(true);
                key.setPathRegExp(false);
                key.setPath(url.getPath());
            } else {
                String query = "";
                if (url.getQuery() != null) {
                    query = "?" + url.getQuery();
                }
                targetPath = url.getPath() + query;
            }
            if (location.startsWith("https")) {
                SSLParser sslOutboundParser = new SSLParser();
                target.setSslParser(sslOutboundParser);
            }
            ((ServiceProxyKey) key).setMethod("*");
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException("WSDL endpoint location '" + location + "' is not an URL.", e);
        }
        return;
    } catch (Exception e) {
        Throwable f = e;
        while (f.getCause() != null && !(f instanceof ResourceRetrievalException)) f = f.getCause();
        if (f instanceof ResourceRetrievalException) {
            ResourceRetrievalException rre = (ResourceRetrievalException) f;
            if (rre.getStatus() >= 400)
                throw rre;
            Throwable cause = rre.getCause();
            if (cause != null) {
                if (cause instanceof UnknownHostException)
                    throw (UnknownHostException) cause;
                else if (cause instanceof ConnectException)
                    throw (ConnectException) cause;
            }
        }
        throw new IllegalArgumentException("Could not download the WSDL '" + wsdl + "'.", e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) UnknownHostException(java.net.UnknownHostException) Definitions(com.predic8.wsdl.Definitions) Port(com.predic8.wsdl.Port) Service(com.predic8.wsdl.Service) URL(java.net.URL) ResourceRetrievalException(com.predic8.membrane.core.resolver.ResourceRetrievalException) ConnectException(java.net.ConnectException) MalformedURLException(java.net.MalformedURLException) UnknownHostException(java.net.UnknownHostException) ResourceRetrievalException(com.predic8.membrane.core.resolver.ResourceRetrievalException) SSLParser(com.predic8.membrane.core.config.security.SSLParser) WSDLParser(com.predic8.wsdl.WSDLParser) WSDLParserContext(com.predic8.wsdl.WSDLParserContext) ConnectException(java.net.ConnectException)

Aggregations

ResourceRetrievalException (com.predic8.membrane.core.resolver.ResourceRetrievalException)6 WSDLInterceptor (com.predic8.membrane.core.interceptor.WSDLInterceptor)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 SSLParser (com.predic8.membrane.core.config.security.SSLParser)1 Exchange (com.predic8.membrane.core.exchange.Exchange)1 Response (com.predic8.membrane.core.http.Response)1 Definitions (com.predic8.wsdl.Definitions)1 Port (com.predic8.wsdl.Port)1 Service (com.predic8.wsdl.Service)1 WSDLParser (com.predic8.wsdl.WSDLParser)1 WSDLParserContext (com.predic8.wsdl.WSDLParserContext)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ConnectException (java.net.ConnectException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1