Search in sources :

Example 11 with Hashtable

use of java.util.Hashtable in project tomcat by apache.

the class HttpUtils method parseQueryString.

/**
     *
     * Parses a query string passed from the client to the
     * server and builds a <code>HashTable</code> object
     * with key-value pairs.
     * The query string should be in the form of a string
     * packaged by the GET or POST method, that is, it
     * should have key-value pairs in the form <i>key=value</i>,
     * with each pair separated from the next by a &amp; character.
     *
     * <p>A key can appear more than once in the query string
     * with different values. However, the key appears only once in
     * the hashtable, with its value being
     * an array of strings containing the multiple values sent
     * by the query string.
     *
     * <p>The keys and values in the hashtable are stored in their
     * decoded form, so
     * any + characters are converted to spaces, and characters
     * sent in hexadecimal notation (like <i>%xx</i>) are
     * converted to ASCII characters.
     *
     * @param s                a string containing the query to be parsed
     *
     * @return                a <code>HashTable</code> object built
     *                         from the parsed key-value pairs
     *
     * @exception IllegalArgumentException        if the query string
     *                                                is invalid
     *
     */
public static Hashtable<String, String[]> parseQueryString(String s) {
    String[] valArray = null;
    if (s == null) {
        throw new IllegalArgumentException();
    }
    Hashtable<String, String[]> ht = new Hashtable<>();
    StringBuilder sb = new StringBuilder();
    StringTokenizer st = new StringTokenizer(s, "&");
    while (st.hasMoreTokens()) {
        String pair = st.nextToken();
        int pos = pair.indexOf('=');
        if (pos == -1) {
            // should give more detail about the illegal argument
            throw new IllegalArgumentException();
        }
        String key = parseName(pair.substring(0, pos), sb);
        String val = parseName(pair.substring(pos + 1, pair.length()), sb);
        if (ht.containsKey(key)) {
            String[] oldVals = ht.get(key);
            valArray = new String[oldVals.length + 1];
            for (int i = 0; i < oldVals.length; i++) valArray[i] = oldVals[i];
            valArray[oldVals.length] = val;
        } else {
            valArray = new String[1];
            valArray[0] = val;
        }
        ht.put(key, valArray);
    }
    return ht;
}
Also used : StringTokenizer(java.util.StringTokenizer) Hashtable(java.util.Hashtable)

Example 12 with Hashtable

use of java.util.Hashtable in project tomcat by apache.

the class ServiceRefFactory method getObjectInstance.

/**
     * Create a new serviceref instance.
     *
     * @param obj The reference object describing the webservice
     */
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    if (obj instanceof ServiceRef) {
        Reference ref = (Reference) obj;
        // ClassLoader
        ClassLoader tcl = Thread.currentThread().getContextClassLoader();
        if (tcl == null)
            tcl = this.getClass().getClassLoader();
        ServiceFactory factory = ServiceFactory.newInstance();
        javax.xml.rpc.Service service = null;
        // Service Interface
        RefAddr tmp = ref.get(ServiceRef.SERVICE_INTERFACE);
        String serviceInterface = null;
        if (tmp != null)
            serviceInterface = (String) tmp.getContent();
        // WSDL
        tmp = ref.get(ServiceRef.WSDL);
        String wsdlRefAddr = null;
        if (tmp != null)
            wsdlRefAddr = (String) tmp.getContent();
        // PortComponent
        Hashtable<String, QName> portComponentRef = new Hashtable<>();
        // Create QName object
        QName serviceQname = null;
        tmp = ref.get(ServiceRef.SERVICE_LOCAL_PART);
        if (tmp != null) {
            String serviceLocalPart = (String) tmp.getContent();
            tmp = ref.get(ServiceRef.SERVICE_NAMESPACE);
            if (tmp == null) {
                serviceQname = new QName(serviceLocalPart);
            } else {
                String serviceNamespace = (String) tmp.getContent();
                serviceQname = new QName(serviceNamespace, serviceLocalPart);
            }
        }
        Class<?> serviceInterfaceClass = null;
        // Create service object
        if (serviceInterface == null) {
            if (serviceQname == null) {
                throw new NamingException("Could not create service-ref instance");
            }
            try {
                if (wsdlRefAddr == null) {
                    service = factory.createService(serviceQname);
                } else {
                    service = factory.createService(new URL(wsdlRefAddr), serviceQname);
                }
            } catch (Exception e) {
                NamingException ex = new NamingException("Could not create service");
                ex.initCause(e);
                throw ex;
            }
        } else {
            // Loading service Interface
            try {
                serviceInterfaceClass = tcl.loadClass(serviceInterface);
            } catch (ClassNotFoundException e) {
                NamingException ex = new NamingException("Could not load service Interface");
                ex.initCause(e);
                throw ex;
            }
            if (serviceInterfaceClass == null) {
                throw new NamingException("Could not load service Interface");
            }
            try {
                if (wsdlRefAddr == null) {
                    if (!Service.class.isAssignableFrom(serviceInterfaceClass)) {
                        throw new NamingException("service Interface should extend javax.xml.rpc.Service");
                    }
                    service = factory.loadService(serviceInterfaceClass);
                } else {
                    service = factory.loadService(new URL(wsdlRefAddr), serviceInterfaceClass, new Properties());
                }
            } catch (Exception e) {
                NamingException ex = new NamingException("Could not create service");
                ex.initCause(e);
                throw ex;
            }
        }
        if (service == null) {
            throw new NamingException("Cannot create service object");
        }
        serviceQname = service.getServiceName();
        serviceInterfaceClass = service.getClass();
        if (wsdlRefAddr != null) {
            try {
                WSDLFactory wsdlfactory = WSDLFactory.newInstance();
                WSDLReader reader = wsdlfactory.newWSDLReader();
                reader.setFeature("javax.wsdl.importDocuments", true);
                Definition def = reader.readWSDL((new URL(wsdlRefAddr)).toExternalForm());
                javax.wsdl.Service wsdlservice = def.getService(serviceQname);
                @SuppressWarnings("unchecked") Map<String, ?> ports = wsdlservice.getPorts();
                Method m = serviceInterfaceClass.getMethod("setEndpointAddress", new Class[] { java.lang.String.class, java.lang.String.class });
                for (Iterator<String> i = ports.keySet().iterator(); i.hasNext(); ) {
                    String portName = i.next();
                    Port port = wsdlservice.getPort(portName);
                    String endpoint = getSOAPLocation(port);
                    m.invoke(service, new Object[] { port.getName(), endpoint });
                    portComponentRef.put(endpoint, new QName(port.getName()));
                }
            } catch (Exception e) {
                if (e instanceof InvocationTargetException) {
                    Throwable cause = e.getCause();
                    if (cause instanceof ThreadDeath) {
                        throw (ThreadDeath) cause;
                    }
                    if (cause instanceof VirtualMachineError) {
                        throw (VirtualMachineError) cause;
                    }
                }
                NamingException ex = new NamingException("Error while reading Wsdl File");
                ex.initCause(e);
                throw ex;
            }
        }
        ServiceProxy proxy = new ServiceProxy(service);
        // Use port-component-ref
        for (int i = 0; i < ref.size(); i++) if (ServiceRef.SERVICEENDPOINTINTERFACE.equals(ref.get(i).getType())) {
            String serviceendpoint = "";
            String portlink = "";
            serviceendpoint = (String) ref.get(i).getContent();
            if (ServiceRef.PORTCOMPONENTLINK.equals(ref.get(i + 1).getType())) {
                i++;
                portlink = (String) ref.get(i).getContent();
            }
            portComponentRef.put(serviceendpoint, new QName(portlink));
        }
        proxy.setPortComponentRef(portComponentRef);
        // Instantiate service with proxy class
        Class<?>[] interfaces = null;
        Class<?>[] serviceInterfaces = serviceInterfaceClass.getInterfaces();
        interfaces = new Class[serviceInterfaces.length + 1];
        for (int i = 0; i < serviceInterfaces.length; i++) {
            interfaces[i] = serviceInterfaces[i];
        }
        interfaces[interfaces.length - 1] = javax.xml.rpc.Service.class;
        Object proxyInstance = null;
        try {
            proxyInstance = Proxy.newProxyInstance(tcl, interfaces, proxy);
        } catch (IllegalArgumentException e) {
            proxyInstance = Proxy.newProxyInstance(tcl, serviceInterfaces, proxy);
        }
        // Use handler
        if (((ServiceRef) ref).getHandlersSize() > 0) {
            HandlerRegistry handlerRegistry = service.getHandlerRegistry();
            ArrayList<String> soaproles = new ArrayList<>();
            while (((ServiceRef) ref).getHandlersSize() > 0) {
                HandlerRef handlerRef = ((ServiceRef) ref).getHandler();
                HandlerInfo handlerInfo = new HandlerInfo();
                // Loading handler Class
                tmp = handlerRef.get(HandlerRef.HANDLER_CLASS);
                if ((tmp == null) || (tmp.getContent() == null))
                    break;
                Class<?> handlerClass = null;
                try {
                    handlerClass = tcl.loadClass((String) tmp.getContent());
                } catch (ClassNotFoundException e) {
                    break;
                }
                // Load all datas relative to the handler : SOAPHeaders, config init element,
                // portNames to be set on
                ArrayList<QName> headers = new ArrayList<>();
                Hashtable<String, String> config = new Hashtable<>();
                ArrayList<String> portNames = new ArrayList<>();
                for (int i = 0; i < handlerRef.size(); i++) if (HandlerRef.HANDLER_LOCALPART.equals(handlerRef.get(i).getType())) {
                    String localpart = "";
                    String namespace = "";
                    localpart = (String) handlerRef.get(i).getContent();
                    if (HandlerRef.HANDLER_NAMESPACE.equals(handlerRef.get(i + 1).getType())) {
                        i++;
                        namespace = (String) handlerRef.get(i).getContent();
                    }
                    QName header = new QName(namespace, localpart);
                    headers.add(header);
                } else if (HandlerRef.HANDLER_PARAMNAME.equals(handlerRef.get(i).getType())) {
                    String paramName = "";
                    String paramValue = "";
                    paramName = (String) handlerRef.get(i).getContent();
                    if (HandlerRef.HANDLER_PARAMVALUE.equals(handlerRef.get(i + 1).getType())) {
                        i++;
                        paramValue = (String) handlerRef.get(i).getContent();
                    }
                    config.put(paramName, paramValue);
                } else if (HandlerRef.HANDLER_SOAPROLE.equals(handlerRef.get(i).getType())) {
                    String soaprole = "";
                    soaprole = (String) handlerRef.get(i).getContent();
                    soaproles.add(soaprole);
                } else if (HandlerRef.HANDLER_PORTNAME.equals(handlerRef.get(i).getType())) {
                    String portName = "";
                    portName = (String) handlerRef.get(i).getContent();
                    portNames.add(portName);
                }
                // Set the handlers informations
                handlerInfo.setHandlerClass(handlerClass);
                handlerInfo.setHeaders(headers.toArray(new QName[headers.size()]));
                handlerInfo.setHandlerConfig(config);
                if (!portNames.isEmpty()) {
                    Iterator<String> iter = portNames.iterator();
                    while (iter.hasNext()) initHandlerChain(new QName(iter.next()), handlerRegistry, handlerInfo, soaproles);
                } else {
                    Enumeration<QName> e = portComponentRef.elements();
                    while (e.hasMoreElements()) initHandlerChain(e.nextElement(), handlerRegistry, handlerInfo, soaproles);
                }
            }
        }
        return proxyInstance;
    }
    return null;
}
Also used : ServiceFactory(javax.xml.rpc.ServiceFactory) Port(javax.wsdl.Port) ArrayList(java.util.ArrayList) Properties(java.util.Properties) URL(java.net.URL) RefAddr(javax.naming.RefAddr) HandlerRegistry(javax.xml.rpc.handler.HandlerRegistry) NamingException(javax.naming.NamingException) HandlerRef(org.apache.naming.HandlerRef) HandlerInfo(javax.xml.rpc.handler.HandlerInfo) Reference(javax.naming.Reference) Hashtable(java.util.Hashtable) QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition) Service(javax.xml.rpc.Service) Method(java.lang.reflect.Method) NamingException(javax.naming.NamingException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) WSDLFactory(javax.wsdl.factory.WSDLFactory) Service(javax.xml.rpc.Service) ServiceRef(org.apache.naming.ServiceRef) WSDLReader(javax.wsdl.xml.WSDLReader)

Example 13 with Hashtable

use of java.util.Hashtable in project tomcat by apache.

the class WebdavStatus method deleteResource.

/**
     * Delete a resource.
     *
     * @param path Path of the resource which is to be deleted
     * @param req Servlet request
     * @param resp Servlet response
     * @param setStatus Should the response status be set on successful
     *                  completion
     * @return <code>true</code> if the delete is successful
     * @throws IOException If an IO error occurs
     */
private boolean deleteResource(String path, HttpServletRequest req, HttpServletResponse resp, boolean setStatus) throws IOException {
    String ifHeader = req.getHeader("If");
    if (ifHeader == null)
        ifHeader = "";
    String lockTokenHeader = req.getHeader("Lock-Token");
    if (lockTokenHeader == null)
        lockTokenHeader = "";
    if (isLocked(path, ifHeader + lockTokenHeader)) {
        resp.sendError(WebdavStatus.SC_LOCKED);
        return false;
    }
    WebResource resource = resources.getResource(path);
    if (!resource.exists()) {
        resp.sendError(WebdavStatus.SC_NOT_FOUND);
        return false;
    }
    if (!resource.isDirectory()) {
        if (!resource.delete()) {
            resp.sendError(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
            return false;
        }
    } else {
        Hashtable<String, Integer> errorList = new Hashtable<>();
        deleteCollection(req, path, errorList);
        if (!resource.delete()) {
            errorList.put(path, Integer.valueOf(WebdavStatus.SC_INTERNAL_SERVER_ERROR));
        }
        if (!errorList.isEmpty()) {
            sendReport(req, resp, errorList);
            return false;
        }
    }
    if (setStatus) {
        resp.setStatus(WebdavStatus.SC_NO_CONTENT);
    }
    return true;
}
Also used : Hashtable(java.util.Hashtable) WebResource(org.apache.catalina.WebResource)

Example 14 with Hashtable

use of java.util.Hashtable in project tomcat by apache.

the class MbeansDescriptorsIntrospectionSource method createManagedBean.

/**
     * XXX Find if the 'className' is the name of the MBean or
     *       the real class ( I suppose first )
     * XXX Read (optional) descriptions from a .properties, generated
     *       from source
     * XXX Deal with constructors
     *
     * @param registry The Bean registry (not used)
     * @param domain The bean domain (not used)
     * @param realClass The class to analyze
     * @param type The bean type
     * @return ManagedBean The create MBean
     */
public ManagedBean createManagedBean(Registry registry, String domain, Class<?> realClass, String type) {
    ManagedBean mbean = new ManagedBean();
    Method[] methods = null;
    Hashtable<String, Method> attMap = new Hashtable<>();
    // key: attribute val: getter method
    Hashtable<String, Method> getAttMap = new Hashtable<>();
    // key: attribute val: setter method
    Hashtable<String, Method> setAttMap = new Hashtable<>();
    // key: operation val: invoke method
    Hashtable<String, Method> invokeAttMap = new Hashtable<>();
    methods = realClass.getMethods();
    initMethods(realClass, methods, attMap, getAttMap, setAttMap, invokeAttMap);
    try {
        Enumeration<String> en = attMap.keys();
        while (en.hasMoreElements()) {
            String name = en.nextElement();
            AttributeInfo ai = new AttributeInfo();
            ai.setName(name);
            Method gm = getAttMap.get(name);
            if (gm != null) {
                //ai.setGetMethodObj( gm );
                ai.setGetMethod(gm.getName());
                Class<?> t = gm.getReturnType();
                if (t != null)
                    ai.setType(t.getName());
            }
            Method sm = setAttMap.get(name);
            if (sm != null) {
                //ai.setSetMethodObj(sm);
                Class<?> t = sm.getParameterTypes()[0];
                if (t != null)
                    ai.setType(t.getName());
                ai.setSetMethod(sm.getName());
            }
            ai.setDescription("Introspected attribute " + name);
            if (log.isDebugEnabled())
                log.debug("Introspected attribute " + name + " " + gm + " " + sm);
            if (gm == null)
                ai.setReadable(false);
            if (sm == null)
                ai.setWriteable(false);
            if (sm != null || gm != null)
                mbean.addAttribute(ai);
        }
        for (Entry<String, Method> entry : invokeAttMap.entrySet()) {
            String name = entry.getKey();
            Method m = entry.getValue();
            if (m != null) {
                OperationInfo op = new OperationInfo();
                op.setName(name);
                op.setReturnType(m.getReturnType().getName());
                op.setDescription("Introspected operation " + name);
                Class<?>[] parms = m.getParameterTypes();
                for (int i = 0; i < parms.length; i++) {
                    ParameterInfo pi = new ParameterInfo();
                    pi.setType(parms[i].getName());
                    pi.setName("param" + i);
                    pi.setDescription("Introspected parameter param" + i);
                    op.addParameter(pi);
                }
                mbean.addOperation(op);
            } else {
                log.error("Null arg method for [" + name + "]");
            }
        }
        if (log.isDebugEnabled())
            log.debug("Setting name: " + type);
        mbean.setName(type);
        return mbean;
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}
Also used : OperationInfo(org.apache.tomcat.util.modeler.OperationInfo) Hashtable(java.util.Hashtable) Method(java.lang.reflect.Method) ParameterInfo(org.apache.tomcat.util.modeler.ParameterInfo) AttributeInfo(org.apache.tomcat.util.modeler.AttributeInfo) ManagedBean(org.apache.tomcat.util.modeler.ManagedBean)

Example 15 with Hashtable

use of java.util.Hashtable in project tomcat by apache.

the class JmxPasswordTest method setUp.

@Before
public void setUp() throws Exception {
    this.datasource.setDriverClassName(Driver.class.getName());
    this.datasource.setUrl("jdbc:tomcat:test");
    this.datasource.setPassword(password);
    this.datasource.setUsername(username);
    this.datasource.getConnection().close();
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    String domain = "tomcat.jdbc";
    Hashtable<String, String> properties = new Hashtable<>();
    properties.put("type", "ConnectionPool");
    properties.put("class", this.getClass().getName());
    oname = new ObjectName(domain, properties);
    ConnectionPool pool = datasource.createPool();
    org.apache.tomcat.jdbc.pool.jmx.ConnectionPool jmxPool = new org.apache.tomcat.jdbc.pool.jmx.ConnectionPool(pool);
    mbs.registerMBean(jmxPool, oname);
}
Also used : ConnectionPool(org.apache.tomcat.jdbc.pool.ConnectionPool) Hashtable(java.util.Hashtable) Driver(org.apache.tomcat.jdbc.test.driver.Driver) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer) Before(org.junit.Before)

Aggregations

Hashtable (java.util.Hashtable)1278 Test (org.junit.Test)367 ArrayList (java.util.ArrayList)267 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)142 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)137 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)136 HashMap (java.util.HashMap)89 Bundle (org.osgi.framework.Bundle)82 BundleContext (org.osgi.framework.BundleContext)75 Configuration (org.osgi.service.cm.Configuration)75 Map (java.util.Map)73 IOException (java.io.IOException)67 ServiceRegistration (org.osgi.framework.ServiceRegistration)64 Enumeration (java.util.Enumeration)63 Dictionary (java.util.Dictionary)61 InitialContext (javax.naming.InitialContext)54 Vector (java.util.Vector)53 URL (java.net.URL)49 CUCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal)47 File (java.io.File)45