Search in sources :

Example 16 with MalformedURLException

use of java.net.MalformedURLException in project tomcat by apache.

the class ErrorDispatcher method dispatch.

//*********************************************************************
// Private utility methods
/**
     * Dispatches the given JSP parse error to the configured error handler.
     *
     * The given error code is localized. If it is not found in the
     * resource bundle for localized error messages, it is used as the error
     * message.
     *
     * @param where Error location
     * @param errCode Error code
     * @param args Arguments for parametric replacement
     * @param e Parsing exception
     * @throws JasperException An error occurred
     */
private void dispatch(Mark where, String errCode, Object[] args, Exception e) throws JasperException {
    String file = null;
    String errMsg = null;
    int line = -1;
    int column = -1;
    boolean hasLocation = false;
    // Localize
    if (errCode != null) {
        errMsg = Localizer.getMessage(errCode, args);
    } else if (e != null) {
        // give a hint about what's wrong
        errMsg = e.getMessage();
    }
    // Get error location
    if (where != null) {
        if (jspcMode) {
            // Get the full URL of the resource that caused the error
            try {
                file = where.getURL().toString();
            } catch (MalformedURLException me) {
                // Fallback to using context-relative path
                file = where.getFile();
            }
        } else {
            // Get the context-relative resource path, so as to not
            // disclose any local filesystem details
            file = where.getFile();
        }
        line = where.getLineNumber();
        column = where.getColumnNumber();
        hasLocation = true;
    }
    // Get nested exception
    Exception nestedEx = e;
    if ((e instanceof SAXException) && (((SAXException) e).getException() != null)) {
        nestedEx = ((SAXException) e).getException();
    }
    if (hasLocation) {
        errHandler.jspError(file, line, column, errMsg, nestedEx);
    } else {
        errHandler.jspError(errMsg, nestedEx);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) MalformedURLException(java.net.MalformedURLException) SAXException(org.xml.sax.SAXException) JasperException(org.apache.jasper.JasperException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 17 with MalformedURLException

use of java.net.MalformedURLException in project tomcat by apache.

the class TestStandardJarScanner method skipsInvalidClasspathURLNoFilePartNoFileScheme.

/**
     * Tomcat should ignore URLs which do not have a file part and do not use the file scheme.
     */
@Test
public void skipsInvalidClasspathURLNoFilePartNoFileScheme() {
    StandardJarScanner scanner = new StandardJarScanner();
    LoggingCallback callback = new LoggingCallback();
    TesterServletContext context = new TesterServletContext() {

        @Override
        public ClassLoader getClassLoader() {
            URLClassLoader urlClassLoader;
            try {
                urlClassLoader = new URLClassLoader(new URL[] { new URL("http://felix.extensions:9/") });
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);
            }
            return urlClassLoader;
        }
    };
    scanner.scan(JarScanType.PLUGGABILITY, context, callback);
}
Also used : TesterServletContext(org.apache.tomcat.unittest.TesterServletContext) MalformedURLException(java.net.MalformedURLException) URLClassLoader(java.net.URLClassLoader) URL(java.net.URL) Test(org.junit.Test)

Example 18 with MalformedURLException

use of java.net.MalformedURLException in project tomcat by apache.

the class NamingContextListener method addService.

/**
     * Set the specified web service in the naming context.
     *
     * @param service the web service descriptor
     */
public void addService(ContextService service) {
    if (service.getWsdlfile() != null) {
        URL wsdlURL = null;
        try {
            wsdlURL = new URL(service.getWsdlfile());
        } catch (MalformedURLException e) {
        // Ignore and carry on
        }
        if (wsdlURL == null) {
            try {
                wsdlURL = ((Context) container).getServletContext().getResource(service.getWsdlfile());
            } catch (MalformedURLException e) {
            // Ignore and carry on
            }
        }
        if (wsdlURL == null) {
            try {
                wsdlURL = ((Context) container).getServletContext().getResource("/" + service.getWsdlfile());
                log.debug("  Changing service ref wsdl file for /" + service.getWsdlfile());
            } catch (MalformedURLException e) {
                log.error(sm.getString("naming.wsdlFailed", e));
            }
        }
        if (wsdlURL == null)
            service.setWsdlfile(null);
        else
            service.setWsdlfile(wsdlURL.toString());
    }
    if (service.getJaxrpcmappingfile() != null) {
        URL jaxrpcURL = null;
        try {
            jaxrpcURL = new URL(service.getJaxrpcmappingfile());
        } catch (MalformedURLException e) {
        // Ignore and carry on
        }
        if (jaxrpcURL == null) {
            try {
                jaxrpcURL = ((Context) container).getServletContext().getResource(service.getJaxrpcmappingfile());
            } catch (MalformedURLException e) {
            // Ignore and carry on
            }
        }
        if (jaxrpcURL == null) {
            try {
                jaxrpcURL = ((Context) container).getServletContext().getResource("/" + service.getJaxrpcmappingfile());
                log.debug("  Changing service ref jaxrpc file for /" + service.getJaxrpcmappingfile());
            } catch (MalformedURLException e) {
                log.error(sm.getString("naming.wsdlFailed", e));
            }
        }
        if (jaxrpcURL == null)
            service.setJaxrpcmappingfile(null);
        else
            service.setJaxrpcmappingfile(jaxrpcURL.toString());
    }
    // Create a reference to the resource.
    Reference ref = new ServiceRef(service.getName(), service.getType(), service.getServiceqname(), service.getWsdlfile(), service.getJaxrpcmappingfile());
    // Adding the additional port-component-ref, if any
    Iterator<String> portcomponent = service.getServiceendpoints();
    while (portcomponent.hasNext()) {
        String serviceendpoint = portcomponent.next();
        StringRefAddr refAddr = new StringRefAddr(ServiceRef.SERVICEENDPOINTINTERFACE, serviceendpoint);
        ref.add(refAddr);
        String portlink = service.getPortlink(serviceendpoint);
        refAddr = new StringRefAddr(ServiceRef.PORTCOMPONENTLINK, portlink);
        ref.add(refAddr);
    }
    // Adding the additional parameters, if any
    Iterator<String> handlers = service.getHandlers();
    while (handlers.hasNext()) {
        String handlername = handlers.next();
        ContextHandler handler = service.getHandler(handlername);
        HandlerRef handlerRef = new HandlerRef(handlername, handler.getHandlerclass());
        Iterator<String> localParts = handler.getLocalparts();
        while (localParts.hasNext()) {
            String localPart = localParts.next();
            String namespaceURI = handler.getNamespaceuri(localPart);
            handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_LOCALPART, localPart));
            handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_NAMESPACE, namespaceURI));
        }
        Iterator<String> params = handler.listProperties();
        while (params.hasNext()) {
            String paramName = params.next();
            String paramValue = (String) handler.getProperty(paramName);
            handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_PARAMNAME, paramName));
            handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_PARAMVALUE, paramValue));
        }
        for (int i = 0; i < handler.getSoapRolesSize(); i++) {
            handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_SOAPROLE, handler.getSoapRole(i)));
        }
        for (int i = 0; i < handler.getPortNamesSize(); i++) {
            handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_PORTNAME, handler.getPortName(i)));
        }
        ((ServiceRef) ref).addHandler(handlerRef);
    }
    try {
        if (log.isDebugEnabled()) {
            log.debug("  Adding service ref " + service.getName() + "  " + ref);
        }
        createSubcontexts(envCtx, service.getName());
        envCtx.bind(service.getName(), ref);
    } catch (NamingException e) {
        log.error(sm.getString("naming.bindFailed", e));
    }
}
Also used : NamingContext(org.apache.naming.NamingContext) Context(org.apache.catalina.Context) ContextHandler(org.apache.tomcat.util.descriptor.web.ContextHandler) MalformedURLException(java.net.MalformedURLException) StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) NamingException(javax.naming.NamingException) ServiceRef(org.apache.naming.ServiceRef) URL(java.net.URL) HandlerRef(org.apache.naming.HandlerRef)

Example 19 with MalformedURLException

use of java.net.MalformedURLException in project tomcat by apache.

the class ContextConfig method getContextWebXmlSource.

/**
     * Identify the application web.xml to be used and obtain an input source
     * for it.
     * @return an input source to the context web.xml
     */
protected InputSource getContextWebXmlSource() {
    InputStream stream = null;
    InputSource source = null;
    URL url = null;
    String altDDName = null;
    // Open the application web.xml file, if it exists
    ServletContext servletContext = context.getServletContext();
    try {
        if (servletContext != null) {
            altDDName = (String) servletContext.getAttribute(Globals.ALT_DD_ATTR);
            if (altDDName != null) {
                try {
                    stream = new FileInputStream(altDDName);
                    url = new File(altDDName).toURI().toURL();
                } catch (FileNotFoundException e) {
                    log.error(sm.getString("contextConfig.altDDNotFound", altDDName));
                } catch (MalformedURLException e) {
                    log.error(sm.getString("contextConfig.applicationUrl"));
                }
            } else {
                stream = servletContext.getResourceAsStream(Constants.ApplicationWebXml);
                try {
                    url = servletContext.getResource(Constants.ApplicationWebXml);
                } catch (MalformedURLException e) {
                    log.error(sm.getString("contextConfig.applicationUrl"));
                }
            }
        }
        if (stream == null || url == null) {
            if (log.isDebugEnabled()) {
                log.debug(sm.getString("contextConfig.applicationMissing") + " " + context);
            }
        } else {
            source = new InputSource(url.toExternalForm());
            source.setByteStream(stream);
        }
    } finally {
        if (source == null && stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
            // Ignore
            }
        }
    }
    return source;
}
Also used : InputSource(org.xml.sax.InputSource) MalformedURLException(java.net.MalformedURLException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) ServletContext(javax.servlet.ServletContext) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL) FileInputStream(java.io.FileInputStream)

Example 20 with MalformedURLException

use of java.net.MalformedURLException in project zeppelin by apache.

the class ZeppelinHubRealm method isZeppelinHubUrlValid.

/**
   * Perform a Simple URL check by using <code>URI(url).toURL()</code>.
   * If the url is not valid, the try-catch condition will catch the exceptions and return false,
   * otherwise true will be returned.
   * 
   * @param url
   * @return
   */
protected boolean isZeppelinHubUrlValid(String url) {
    boolean valid;
    try {
        new URI(url).toURL();
        valid = true;
    } catch (URISyntaxException | MalformedURLException e) {
        LOG.error("Zeppelinhub url is not valid, default ZeppelinHub url will be used.", e);
        valid = false;
    }
    return valid;
}
Also used : MalformedURLException(java.net.MalformedURLException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

MalformedURLException (java.net.MalformedURLException)1319 URL (java.net.URL)984 IOException (java.io.IOException)397 File (java.io.File)324 ArrayList (java.util.ArrayList)132 HttpURLConnection (java.net.HttpURLConnection)108 InputStream (java.io.InputStream)106 HashMap (java.util.HashMap)89 URISyntaxException (java.net.URISyntaxException)78 URI (java.net.URI)76 Map (java.util.Map)69 URLClassLoader (java.net.URLClassLoader)65 InputStreamReader (java.io.InputStreamReader)61 BufferedReader (java.io.BufferedReader)58 FileNotFoundException (java.io.FileNotFoundException)53 URLConnection (java.net.URLConnection)52 HashSet (java.util.HashSet)50 Test (org.junit.Test)45 JSONException (org.json.JSONException)38 FileInputStream (java.io.FileInputStream)33