Search in sources :

Example 16 with Enumeration

use of java.util.Enumeration in project jetty.project by eclipse.

the class Request method getLocales.

/* ------------------------------------------------------------ */
/*
     * @see javax.servlet.ServletRequest#getLocales()
     */
@Override
public Enumeration<Locale> getLocales() {
    MetaData.Request metadata = _metaData;
    if (metadata == null)
        return Collections.enumeration(__defaultLocale);
    List<String> acceptable = metadata.getFields().getQualityCSV(HttpHeader.ACCEPT_LANGUAGE);
    // handle no locale
    if (acceptable.isEmpty())
        return Collections.enumeration(__defaultLocale);
    List<Locale> locales = acceptable.stream().map(language -> {
        language = HttpFields.stripParameters(language);
        String country = "";
        int dash = language.indexOf('-');
        if (dash > -1) {
            country = language.substring(dash + 1).trim();
            language = language.substring(0, dash).trim();
        }
        return new Locale(language, country);
    }).collect(Collectors.toList());
    return Collections.enumeration(locales);
}
Also used : Attributes(org.eclipse.jetty.util.Attributes) Enumeration(java.util.Enumeration) ServletException(javax.servlet.ServletException) Context(org.eclipse.jetty.server.handler.ContextHandler.Context) UrlEncoded(org.eclipse.jetty.util.UrlEncoded) MultiPartInputStreamParser(org.eclipse.jetty.util.MultiPartInputStreamParser) InetAddress(java.net.InetAddress) AsyncListener(javax.servlet.AsyncListener) Locale(java.util.Locale) MetaData(org.eclipse.jetty.http.MetaData) Map(java.util.Map) HttpStatus(org.eclipse.jetty.http.HttpStatus) HttpSession(javax.servlet.http.HttpSession) Collection(java.util.Collection) RequestDispatcher(javax.servlet.RequestDispatcher) ServletRequestAttributeEvent(javax.servlet.ServletRequestAttributeEvent) ServletRequestAttributeListener(javax.servlet.ServletRequestAttributeListener) IO(org.eclipse.jetty.util.IO) MultipartConfigElement(javax.servlet.MultipartConfigElement) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) EventListener(java.util.EventListener) List(java.util.List) Principal(java.security.Principal) ServletResponse(javax.servlet.ServletResponse) URIUtil(org.eclipse.jetty.util.URIUtil) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MimeTypes(org.eclipse.jetty.http.MimeTypes) BadMessageException(org.eclipse.jetty.http.BadMessageException) AttributesMap(org.eclipse.jetty.util.AttributesMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HttpScheme(org.eclipse.jetty.http.HttpScheme) ServletInputStream(javax.servlet.ServletInputStream) HttpVersion(org.eclipse.jetty.http.HttpVersion) Session(org.eclipse.jetty.server.session.Session) StringUtil(org.eclipse.jetty.util.StringUtil) ArrayList(java.util.ArrayList) HttpUpgradeHandler(javax.servlet.http.HttpUpgradeHandler) AsyncContext(javax.servlet.AsyncContext) HttpHeader(org.eclipse.jetty.http.HttpHeader) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpURI(org.eclipse.jetty.http.HttpURI) Charset(java.nio.charset.Charset) Cookie(javax.servlet.http.Cookie) HttpFields(org.eclipse.jetty.http.HttpFields) ServletRequest(javax.servlet.ServletRequest) HttpCookie(org.eclipse.jetty.http.HttpCookie) MultiMap(org.eclipse.jetty.util.MultiMap) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) InputStreamReader(java.io.InputStreamReader) File(java.io.File) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) HostPortHttpField(org.eclipse.jetty.http.HostPortHttpField) HttpMethod(org.eclipse.jetty.http.HttpMethod) Part(javax.servlet.http.Part) HttpField(org.eclipse.jetty.http.HttpField) Log(org.eclipse.jetty.util.log.Log) DispatcherType(javax.servlet.DispatcherType) ServletContext(javax.servlet.ServletContext) BufferedReader(java.io.BufferedReader) Logger(org.eclipse.jetty.util.log.Logger) Collections(java.util.Collections) ServletRequestWrapper(javax.servlet.ServletRequestWrapper) InputStream(java.io.InputStream) Locale(java.util.Locale) MetaData(org.eclipse.jetty.http.MetaData)

Example 17 with Enumeration

use of java.util.Enumeration in project vert.x by eclipse.

the class BareCommand method configureFromSystemProperties.

protected void configureFromSystemProperties(Object options, String prefix) {
    Properties props = System.getProperties();
    Enumeration e = props.propertyNames();
    // Uhh, properties suck
    while (e.hasMoreElements()) {
        String propName = (String) e.nextElement();
        String propVal = props.getProperty(propName);
        if (propName.startsWith(prefix)) {
            String fieldName = propName.substring(prefix.length());
            Method setter = getSetter(fieldName, options.getClass());
            if (setter == null) {
                log.warn("No such property to configure on options: " + options.getClass().getName() + "." + fieldName);
                continue;
            }
            Class<?> argType = setter.getParameterTypes()[0];
            Object arg;
            try {
                if (argType.equals(String.class)) {
                    arg = propVal;
                } else if (argType.equals(int.class)) {
                    arg = Integer.valueOf(propVal);
                } else if (argType.equals(long.class)) {
                    arg = Long.valueOf(propVal);
                } else if (argType.equals(boolean.class)) {
                    arg = Boolean.valueOf(propVal);
                } else {
                    log.warn("Invalid type for setter: " + argType);
                    continue;
                }
            } catch (IllegalArgumentException e2) {
                log.warn("Invalid argtype:" + argType + " on options: " + options.getClass().getName() + "." + fieldName);
                continue;
            }
            try {
                setter.invoke(options, arg);
            } catch (Exception ex) {
                throw new VertxException("Failed to invoke setter: " + setter, ex);
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) Method(java.lang.reflect.Method) Properties(java.util.Properties) SocketException(java.net.SocketException)

Example 18 with Enumeration

use of java.util.Enumeration in project jetty.project by eclipse.

the class AnnotationParser method parse.

protected void parse(Set<? extends Handler> handlers, Bundle bundle) throws Exception {
    URI uri = _bundleToUri.get(bundle);
    if (!_alreadyParsed.add(uri)) {
        return;
    }
    String bundleClasspath = (String) bundle.getHeaders().get(Constants.BUNDLE_CLASSPATH);
    if (bundleClasspath == null) {
        bundleClasspath = ".";
    }
    //order the paths first by the number of tokens in the path second alphabetically.
    TreeSet<String> paths = new TreeSet<String>(new Comparator<String>() {

        public int compare(String o1, String o2) {
            int paths1 = new StringTokenizer(o1, "/", false).countTokens();
            int paths2 = new StringTokenizer(o2, "/", false).countTokens();
            if (paths1 == paths2) {
                return o1.compareTo(o2);
            }
            return paths2 - paths1;
        }
    });
    boolean hasDotPath = false;
    StringTokenizer tokenizer = new StringTokenizer(bundleClasspath, ",;", false);
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken().trim();
        if (!token.startsWith("/")) {
            token = "/" + token;
        }
        if (token.equals("/.")) {
            hasDotPath = true;
        } else if (!token.endsWith(".jar") && !token.endsWith("/")) {
            paths.add(token + "/");
        } else {
            paths.add(token);
        }
    }
    //however it makes our life so much easier during development.
    if (bundle.getEntry("/.classpath") != null) {
        if (bundle.getEntry("/bin/") != null) {
            paths.add("/bin/");
        } else if (bundle.getEntry("/target/classes/") != null) {
            paths.add("/target/classes/");
        }
    }
    Enumeration classes = bundle.findEntries("/", "*.class", true);
    if (classes == null) {
        return;
    }
    while (classes.hasMoreElements()) {
        URL classUrl = (URL) classes.nextElement();
        String path = classUrl.getPath();
        //remove the longest path possible:
        String name = null;
        for (String prefixPath : paths) {
            if (path.startsWith(prefixPath)) {
                name = path.substring(prefixPath.length());
                break;
            }
        }
        if (name == null && hasDotPath) {
            //remove the starting '/'
            name = path.substring(1);
        }
        if (name == null) {
            //or the bundle classpath wasn't simply ".", so skip it
            continue;
        }
        //transform into a classname to pass to the resolver
        String shortName = name.replace('/', '.').substring(0, name.length() - 6);
        if (!isParsed(shortName)) {
            try (InputStream classInputStream = classUrl.openStream()) {
                scanClass(handlers, getResource(bundle), classInputStream);
            }
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) Enumeration(java.util.Enumeration) TreeSet(java.util.TreeSet) InputStream(java.io.InputStream) URI(java.net.URI) URL(java.net.URL)

Example 19 with Enumeration

use of java.util.Enumeration in project jetty.project by eclipse.

the class MailSessionReference method getObjectInstance.

/**
     * Create a javax.mail.Session instance based on the information passed in the Reference
     * @see javax.naming.spi.ObjectFactory#getObjectInstance(java.lang.Object, javax.naming.Name, javax.naming.Context, java.util.Hashtable)
     * @param ref the Reference
     * @param arg1 not used
     * @param arg2 not used
     * @param arg3 not used
     * @return the object found
     * @throws Exception if unable to get object instance
     */
public Object getObjectInstance(Object ref, Name arg1, Context arg2, Hashtable arg3) throws Exception {
    if (ref == null)
        return null;
    Reference reference = (Reference) ref;
    Properties props = new Properties();
    String user = null;
    String password = null;
    Enumeration refs = reference.getAll();
    while (refs.hasMoreElements()) {
        RefAddr refAddr = (RefAddr) refs.nextElement();
        String name = refAddr.getType();
        String value = (String) refAddr.getContent();
        if (name.equalsIgnoreCase("user"))
            user = value;
        else if (name.equalsIgnoreCase("pwd"))
            password = value;
        else
            props.put(name, value);
    }
    if (password == null)
        return Session.getInstance(props);
    else
        return Session.getInstance(props, new PasswordAuthenticator(user, password));
}
Also used : RefAddr(javax.naming.RefAddr) StringRefAddr(javax.naming.StringRefAddr) Enumeration(java.util.Enumeration) Reference(javax.naming.Reference) Properties(java.util.Properties)

Example 20 with Enumeration

use of java.util.Enumeration in project jetty.project by eclipse.

the class HttpMethodsServlet method doTrace.

/**
     * @see HttpServlet#doTrace(HttpServletRequest, HttpServletResponse)
     */
protected void doTrace(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.addHeader("Content-Type", "message/http");
    StringBuffer msg = new StringBuffer();
    msg.append(request.getMethod()).append(' ');
    msg.append(request.getRequestURI()).append(' ');
    msg.append(request.getProtocol()).append("\n");
    // Now the headers
    Enumeration enNames = request.getHeaderNames();
    while (enNames.hasMoreElements()) {
        String name = (String) enNames.nextElement();
        Enumeration enValues = request.getHeaders(name);
        while (enValues.hasMoreElements()) {
            String value = (String) enValues.nextElement();
            msg.append(name).append(": ").append(value).append("\n");
        }
    }
    msg.append("\n");
    response.getWriter().print(msg.toString());
}
Also used : Enumeration(java.util.Enumeration)

Aggregations

Enumeration (java.util.Enumeration)1179 IOException (java.io.IOException)202 ArrayList (java.util.ArrayList)141 File (java.io.File)102 HashMap (java.util.HashMap)86 Properties (java.util.Properties)85 Vector (java.util.Vector)83 List (java.util.List)77 HashSet (java.util.HashSet)65 Hashtable (java.util.Hashtable)63 Map (java.util.Map)59 Set (java.util.Set)59 URL (java.net.URL)57 ZipEntry (java.util.zip.ZipEntry)55 ServletContext (javax.servlet.ServletContext)53 Iterator (java.util.Iterator)50 InputStream (java.io.InputStream)47 ZipFile (java.util.zip.ZipFile)46 FileInputStream (java.io.FileInputStream)40 X509Certificate (java.security.cert.X509Certificate)37