Package winstone

Examples of winstone.WinstoneException


            throws IOException {
        // Get the incoming packet flag
        byte headerBuffer[] = new byte[4];
        int headerBytesRead = in.read(headerBuffer);
        if (headerBytesRead != 4)
            throw new WinstoneException(AJP_RESOURCES
                    .getString("Ajp13Listener.InvalidHeader"));
        else if ((headerBuffer[0] != 0x12) || (headerBuffer[1] != 0x34))
            throw new WinstoneException(AJP_RESOURCES
                    .getString("Ajp13Listener.InvalidHeader"));

        // Read in the whole packet
        int packetLength = ((headerBuffer[2] & 0xFF) << 8)
                + (headerBuffer[3] & 0xFF);
        if (packetLength == 0)
            return offset;

        // Look for packet length
        byte bodyLengthBuffer[] = new byte[2];
        in.read(bodyLengthBuffer);
        int bodyLength = ((bodyLengthBuffer[0] & 0xFF) << 8)
                + (bodyLengthBuffer[1] & 0xFF);
        int packetBytesRead = in.read(buffer, offset, bodyLength);

        if (packetBytesRead < bodyLength)
            throw new WinstoneException(AJP_RESOURCES
                    .getString("Ajp13Listener.ShortPacket"));
        else
            return packetBytesRead + offset;
    }
View Full Code Here


        // Get the filename and parse the xml doc
        String realmFileName = args.get(FILE_NAME_ARGUMENT) == null ? DEFAULT_FILE_NAME
                : (String) args.get(FILE_NAME_ARGUMENT);
        File realmFile = new File(realmFileName);
        if (!realmFile.exists())
            throw new WinstoneException(REALM_RESOURCES.getString(
                    "FileRealm.FileNotFound", realmFile.getPath()));
        try {
            InputStream inFile = new FileInputStream(realmFile);
            Document doc = this.parseStreamToXML(inFile);
            inFile.close();
            Node rootElm = doc.getDocumentElement();
            for (int n = 0; n < rootElm.getChildNodes().getLength(); n++) {
                Node child = rootElm.getChildNodes().item(n);

                if ((child.getNodeType() == Node.ELEMENT_NODE)
                        && (child.getNodeName().equals(ELEM_USER))) {
                    String userName = null;
                    String password = null;
                    String roleList = null;
                    // Loop through for attributes
                    for (int j = 0; j < child.getAttributes().getLength(); j++) {
                        Node thisAtt = child.getAttributes().item(j);
                        if (thisAtt.getNodeName().equals(ATT_USERNAME))
                            userName = thisAtt.getNodeValue();
                        else if (thisAtt.getNodeName().equals(ATT_PASSWORD))
                            password = thisAtt.getNodeValue();
                        else if (thisAtt.getNodeName().equals(ATT_ROLELIST))
                            roleList = thisAtt.getNodeValue();
                    }

                    if ((userName == null) || (password == null)
                            || (roleList == null))
                        Logger.log(Logger.FULL_DEBUG, REALM_RESOURCES,
                                "FileRealm.SkippingUser", userName);
                    else {
                        // Parse the role list into an array and sort it
                        StringTokenizer st = new StringTokenizer(roleList, ",");
                        List rl = new ArrayList();
                        for (; st.hasMoreTokens();) {
                            String currentRole = st.nextToken();
                            if (rolesAllowed.contains(currentRole))
                                rl.add(currentRole);
                        }
                        Object roleArray[] = rl.toArray();
                        Arrays.sort(roleArray);
                        this.passwords.put(userName, password);
                        this.roles.put(userName, Arrays.asList(roleArray));
                    }
                }
            }
            Logger.log(Logger.DEBUG, REALM_RESOURCES, "FileRealm.Initialised",
                    "" + this.passwords.size());
        } catch (java.io.IOException err) {
            throw new WinstoneException(REALM_RESOURCES
                    .getString("FileRealm.ErrorLoading"), err);
        }
    }
View Full Code Here

            factory.setCoalescing(true);
            factory.setIgnoringElementContentWhitespace(true);
            DocumentBuilder builder = factory.newDocumentBuilder();
            return builder.parse(in);
        } catch (Throwable errParser) {
            throw new WinstoneException(REALM_RESOURCES
                    .getString("FileRealm.XMLParseError"), errParser);
        }
    }
View Full Code Here

            // Check the key manager factory
            KeyManagerFactory kmf = KeyManagerFactory.getInstance(this.keyManagerType);
           
            File ksFile = new File(keyStoreName);
            if (!ksFile.exists() || !ksFile.isFile())
                throw new WinstoneException(SSL_RESOURCES.getString(
                        "HttpsListener.KeyStoreNotFound", ksFile.getPath()));
            InputStream in = new FileInputStream(ksFile);
            char[] passwordChars = password == null ? null : password.toCharArray();
            KeyStore ks = KeyStore.getInstance("JKS");
            ks.load(in, passwordChars);
            kmf.init(ks, passwordChars);
            Logger.log(Logger.FULL_DEBUG, SSL_RESOURCES,
                    "HttpsListener.KeyCount", ks.size() + "");
            for (Enumeration e = ks.aliases(); e.hasMoreElements();) {
                String alias = (String) e.nextElement();
                Logger.log(Logger.FULL_DEBUG, SSL_RESOURCES,
                        "HttpsListener.KeyFound", new String[] { alias,
                                ks.getCertificate(alias) + "" });
            }

            SSLContext context = SSLContext.getInstance("SSL");
            context.init(kmf.getKeyManagers(), null, null);
            Arrays.fill(passwordChars, 'x');
            return context;
        } catch (IOException err) {
            throw err;
        } catch (Throwable err) {
            throw new WinstoneException(SSL_RESOURCES
                    .getString("HttpsListener.ErrorGettingContext"), err);
        }
    }
View Full Code Here

            ByteArrayOutputStream headerArrayStream = new ByteArrayOutputStream();
            for (Iterator i = this.owner.getHeaders().iterator(); i.hasNext();) {
                String header = (String) i.next();
                int colonPos = header.indexOf(':');
                if (colonPos == -1)
                    throw new WinstoneException(Ajp13Listener.AJP_RESOURCES.getString(
                            "Ajp13OutputStream.NoColonHeader", header));
                String headerName = header.substring(0, colonPos).trim();
                String headerValue = header.substring(colonPos + 1).trim();
                byte headerCode[] = (byte[]) headerCodes.get(headerName
                        .toLowerCase());
                if (headerCode == null) {
                    headerArrayStream.write(getStringBlock(headerName));
                } else {
                    headerArrayStream.write(headerCode);
                }
                headerArrayStream.write(getStringBlock(headerValue));
            }

            for (Iterator i = this.owner.getCookies().iterator(); i.hasNext();) {
                Cookie cookie = (Cookie) i.next();
                String cookieText = this.owner.writeCookie(cookie);
                int colonPos = cookieText.indexOf(':');
                if (colonPos == -1)
                    throw new WinstoneException(Ajp13Listener.AJP_RESOURCES.getString(
                            "Ajp13OutputStream.NoColonHeader", cookieText));
                String headerName = cookieText.substring(0, colonPos).trim();
                String headerValue = cookieText.substring(colonPos + 1).trim();
                byte headerCode[] = (byte[]) headerCodes.get(headerName.toLowerCase());
                if (headerCode == null) {
View Full Code Here

        // Get the incoming packet flag
        byte headerBuffer[] = new byte[4];
        int headerBytesRead = in.read(headerBuffer);
        handler.setRequestStartTime();
        if (headerBytesRead != 4)
            throw new WinstoneException(Ajp13Listener.AJP_RESOURCES
                    .getString("Ajp13IncomingPacket.InvalidHeader"));
        else if ((headerBuffer[0] != 0x12) || (headerBuffer[1] != 0x34))
            throw new WinstoneException(Ajp13Listener.AJP_RESOURCES
                    .getString("Ajp13IncomingPacket.InvalidHeader"));

        // Read in the whole packet
        packetLength = ((headerBuffer[2] & 0xFF) << 8)
                + (headerBuffer[3] & 0xFF);
        packetBytes = new byte[packetLength];
        int packetBytesRead = in.read(packetBytes);

        if (packetBytesRead < packetLength)
            throw new WinstoneException(Ajp13Listener.AJP_RESOURCES
                    .getString("Ajp13IncomingPacket.ShortPacket"));
        // Ajp13Listener.packetDump(packetBytes, packetBytesRead);
    }
View Full Code Here

    public byte parsePacket(String encoding) throws IOException {
        int position = 0;
        this.packetType = packetBytes[position++];

        if (this.packetType != SERVER_FORWARD_REQUEST)
            throw new WinstoneException(Ajp13Listener.AJP_RESOURCES.getString(
                    "Ajp13IncomingPacket.UnknownPacketType", this.packetType
                            + ""));

        // Check for terminator
        if (packetBytes[packetLength - 1] != (byte) 255)
            throw new WinstoneException(Ajp13Listener.AJP_RESOURCES
                    .getString("Ajp13IncomingPacket.InvalidTerminator"));

        this.method = decodeMethodType(packetBytes[position++]);
        Logger.log(Logger.FULL_DEBUG, Ajp13Listener.AJP_RESOURCES,
                "Ajp13IncomingPacket.Method", method);
View Full Code Here

            } else if (param instanceof String) {
                return new String[] {(String) param};
            } else if (param instanceof String[]) {
                return (String[]) param;
            } else {
                throw new WinstoneException(Launcher.RESOURCES.getString(
                        "WinstoneRequest.UnknownParameterType", name + " - "
                                + param.getClass()));
            }
        }
    }
View Full Code Here

TOP

Related Classes of winstone.WinstoneException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.