Example usage for org.dom4j Element getNamespace

List of usage examples for org.dom4j Element getNamespace

Introduction

In this page you can find the example usage for org.dom4j Element getNamespace.

Prototype

Namespace getNamespace();

Source Link

Document

Returns the Namespace of this element if one exists otherwise Namespace.NO_NAMESPACE is returned.

Usage

From source file:org.jivesoftware.openfire.net.SASLAuthentication.java

License:Open Source License

/**
 * Handles the SASL authentication packet. The entity may be sending an initial
 * authentication request or a response to a challenge made by the server. The returned
 * value indicates whether the authentication has finished either successfully or not or
 * if the entity is expected to send a response to a challenge.
 *
 * @param session the session that is authenticating with the server.
 * @param doc the stanza sent by the authenticating entity.
 * @return value that indicates whether the authentication has finished either successfully
 *         or not or if the entity is expected to send a response to a challenge.
 * @throws UnsupportedEncodingException If UTF-8 charset is not supported.
 *///from w ww .j a v a  2s . com
public static Status handle(LocalSession session, Element doc) throws UnsupportedEncodingException {
    Status status;
    String mechanism;
    if (doc.getNamespace().asXML().equals(SASL_NAMESPACE)) {
        ElementType type = ElementType.valueof(doc.getName());
        switch (type) {
        case ABORT:
            authenticationFailed(session, Failure.ABORTED);
            status = Status.failed;
            break;
        case AUTH:
            mechanism = doc.attributeValue("mechanism");
            // http://xmpp.org/rfcs/rfc6120.html#sasl-errors-invalid-mechanism
            // The initiating entity did not specify a mechanism
            if (mechanism == null) {
                authenticationFailed(session, Failure.INVALID_MECHANISM);
                status = Status.failed;
                break;
            }
            // Store the requested SASL mechanism by the client
            session.setSessionData("SaslMechanism", mechanism);
            //Log.debug("SASLAuthentication.doHandshake() AUTH entered: "+mechanism);
            if (mechanism.equalsIgnoreCase("ANONYMOUS") && mechanisms.contains("ANONYMOUS")) {
                status = doAnonymousAuthentication(session);
            } else if (mechanism.equalsIgnoreCase("EXTERNAL")) {
                status = doExternalAuthentication(session, doc);
            } else if (mechanisms.contains(mechanism)) {
                // The selected SASL mechanism requires the server to send a challenge
                // to the client
                try {
                    Map<String, String> props = new TreeMap<String, String>();
                    props.put(Sasl.QOP, "auth");
                    if (mechanism.equals("GSSAPI")) {
                        props.put(Sasl.SERVER_AUTH, "TRUE");
                    }
                    SaslServer ss = Sasl.createSaslServer(mechanism, "xmpp",
                            JiveGlobals.getProperty("xmpp.fqdn", session.getServerName()), props,
                            new XMPPCallbackHandler());

                    if (ss == null) {
                        authenticationFailed(session, Failure.INVALID_MECHANISM);
                        return Status.failed;
                    }

                    // evaluateResponse doesn't like null parameter
                    byte[] token = new byte[0];
                    String value = doc.getTextTrim();
                    if (value.length() > 0) {
                        if (!BASE64_ENCODED.matcher(value).matches()) {
                            authenticationFailed(session, Failure.INCORRECT_ENCODING);
                            return Status.failed;
                        }
                        // If auth request includes a value then validate it
                        token = StringUtils.decodeBase64(value);
                        if (token == null) {
                            token = new byte[0];
                        }
                    }
                    if (mechanism.equals("DIGEST-MD5")) {
                        // RFC2831 (DIGEST-MD5) says the client MAY provide an initial response on subsequent
                        // authentication. Java SASL does not (currently) support this and thows an exception
                        // if we try.  This violates the RFC, so we just strip any initial token.
                        token = new byte[0];
                    }
                    byte[] challenge = ss.evaluateResponse(token);
                    if (ss.isComplete()) {
                        authenticationSuccessful(session, ss.getAuthorizationID(), challenge);
                        status = Status.authenticated;
                    } else {
                        // Send the challenge
                        sendChallenge(session, challenge);
                        status = Status.needResponse;
                    }
                    session.setSessionData("SaslServer", ss);
                } catch (SaslException e) {
                    Log.info("User Login Failed. " + e.getMessage());
                    authenticationFailed(session, Failure.NOT_AUTHORIZED);
                    status = Status.failed;
                }
            } else {
                Log.warn("Client wants to do a MECH we don't support: '" + mechanism + "'");
                authenticationFailed(session, Failure.INVALID_MECHANISM);
                status = Status.failed;
            }
            break;
        case RESPONSE:
            // Store the requested SASL mechanism by the client
            mechanism = (String) session.getSessionData("SaslMechanism");
            if (mechanism.equalsIgnoreCase("EXTERNAL")) {
                status = doExternalAuthentication(session, doc);
            } else if (mechanism.equalsIgnoreCase("JIVE-SHAREDSECRET")) {
                status = doSharedSecretAuthentication(session, doc);
            } else if (mechanisms.contains(mechanism)) {
                SaslServer ss = (SaslServer) session.getSessionData("SaslServer");
                if (ss != null) {
                    boolean ssComplete = ss.isComplete();
                    String response = doc.getTextTrim();
                    if (!BASE64_ENCODED.matcher(response).matches()) {
                        authenticationFailed(session, Failure.INCORRECT_ENCODING);
                        return Status.failed;
                    }
                    try {
                        if (ssComplete) {
                            authenticationSuccessful(session, ss.getAuthorizationID(), null);
                            status = Status.authenticated;
                        } else {
                            byte[] data = StringUtils.decodeBase64(response);
                            if (data == null) {
                                data = new byte[0];
                            }
                            byte[] challenge = ss.evaluateResponse(data);
                            if (ss.isComplete()) {
                                authenticationSuccessful(session, ss.getAuthorizationID(), challenge);
                                status = Status.authenticated;
                            } else {
                                // Send the challenge
                                sendChallenge(session, challenge);
                                status = Status.needResponse;
                            }
                        }
                    } catch (SaslException e) {
                        Log.debug("SASLAuthentication: SaslException", e);
                        authenticationFailed(session, Failure.NOT_AUTHORIZED);
                        status = Status.failed;
                    }
                } else {
                    Log.error("SaslServer is null, should be valid object instead.");
                    authenticationFailed(session, Failure.NOT_AUTHORIZED);
                    status = Status.failed;
                }
            } else {
                Log.warn("Client responded to a MECH we don't support: '" + mechanism + "'");
                authenticationFailed(session, Failure.INVALID_MECHANISM);
                status = Status.failed;
            }
            break;
        default:
            authenticationFailed(session, Failure.NOT_AUTHORIZED);
            status = Status.failed;
            // Ignore
            break;
        }
    } else {
        Log.debug("SASLAuthentication: Unknown namespace sent in auth element: " + doc.asXML());
        authenticationFailed(session, Failure.MALFORMED_REQUEST);
        status = Status.failed;
    }
    // Check if SASL authentication has finished so we can clean up temp information
    if (status == Status.failed || status == Status.authenticated) {
        // Remove the SaslServer from the Session
        session.removeSessionData("SaslServer");
        // Remove the requested SASL mechanism by the client
        session.removeSessionData("SaslMechanism");
    }
    return status;
}

From source file:org.jivesoftware.openfire.plugin.Xep227Exporter.java

License:Apache License

/**
 * Adding offline messages, if there are some.
 * // w  ww.j av  a 2s .  com
 * @param hostname
 *            host name
 * @param userElement
 *            DOM element
 * @param userName
 *            user name
 */
@SuppressWarnings("unchecked")
private void exportOfflineMessages(String hostname, Element userElement, String userName) {
    Collection<OfflineMessage> offlineMessages = offlineMessagesStore.getMessages(userName, false);

    if (!offlineMessages.isEmpty()) {
        Element offlineElement = userElement.addElement(OFFLINE_MESSAGES_ELEMENT_NAME);

        for (OfflineMessage offMessage : offlineMessages) {

            Element messageElement = offlineElement.addElement(new QName(MESSAGE_ELEMENT_NAME, JABBER_MSG_NS));
            for (Object att : offMessage.getElement().attributes()) {
                Attribute attribute = (Attribute) att;
                messageElement.addAttribute(attribute.getQName(), attribute.getValue());
            }

            for (Iterator<Element> iterator = offMessage.getElement().elementIterator(); iterator.hasNext();) {
                Element element = iterator.next();
                messageElement.add(element.createCopy(new QName(element.getName(),
                        (element.getNamespace() == Namespace.NO_NAMESPACE ? JABBER_MSG_NS
                                : element.getNamespace()))));

            }

            /**
             * Adding delay element
             */
            Element delayElement = messageElement.addElement("delay", "urn:xmpp:delay");
            delayElement.addAttribute(FROM_NAME, hostname);
            delayElement.addAttribute("stamp", XMPPDateTimeFormat.format(offMessage.getCreationDate()));
            delayElement.addText("Offline Storage");
        }

    }

}

From source file:org.jivesoftware.openfire.websocket.StreamManagementPacketRouter.java

License:Open Source License

@Override
public void route(Element wrappedElement) throws UnknownStanzaException {

    if (StreamManager.NAMESPACE_V3.equals(wrappedElement.getNamespace().getStringValue())) {
        session.getStreamManager().process(wrappedElement, session.getAddress());
    } else {//from w ww. j  av a  2s  .c o m
        super.route(wrappedElement);
        if (isUnsolicitedAckExpected()) {
            session.getStreamManager().sendServerAcknowledgement();
        }
    }
}

From source file:org.jivesoftware.openfire.websocket.XmppWebSocket.java

License:Open Source License

private void initiateSession(Element stanza) {

    String host = stanza.attributeValue("to");
    StreamError streamError = null;/* w ww . j  a va2 s .co  m*/
    Locale language = Locale
            .forLanguageTag(stanza.attributeValue(QName.get("lang", XMLConstants.XML_NS_URI), "en"));
    if (STREAM_FOOTER.equals(stanza.getName())) {
        // an error occurred while setting up the session
        Log.warn("Client closed stream before session was established");
    } else if (!STREAM_HEADER.equals(stanza.getName())) {
        streamError = new StreamError(StreamError.Condition.unsupported_stanza_type);
        Log.warn("Closing session due to incorrect stream header. Tag: " + stanza.getName());
    } else if (!FRAMING_NAMESPACE.equals(stanza.getNamespace().getURI())) {
        // Validate the stream namespace (https://tools.ietf.org/html/rfc7395#section-3.3.2)
        streamError = new StreamError(StreamError.Condition.invalid_namespace);
        Log.warn("Closing session due to invalid namespace in stream header. Namespace: "
                + stanza.getNamespace().getURI());
    } else if (!validateHost(host)) {
        streamError = new StreamError(StreamError.Condition.host_unknown);
        Log.warn("Closing session due to incorrect hostname in stream header. Host: " + host);
    } else {
        // valid stream; initiate session
        xmppSession = SessionManager.getInstance().createClientSession(wsConnection, language);
        xmppSession.setSessionData("ws", Boolean.TRUE);
    }

    if (xmppSession == null) {
        closeStream(streamError);
    } else {
        openStream(language.toLanguageTag(), stanza.attributeValue("from"));
        configureStream();
    }
}

From source file:org.jivesoftware.smack.PacketReader.java

License:Open Source License

private void parseFailure(Element failureEl) throws Exception {
    if ("urn:ietf:params:xml:ns:xmpp-tls".equals(failureEl.getNamespace().getURI())) {
        throw new Exception("TLS negotiation has failed");
    } else if ("http://jabber.org/protocol/compress".equals(failureEl.getNamespace().getURI())) {
        connection.streamCompressionDenied();
    } else {/*from w ww.j  a v  a 2s.c  o  m*/
        final Failure failure = new Failure(failureEl);
        processPacket(failure);
        connection.getSASLAuthentication().authenticationFailed(failure.getCondition());
    }
}

From source file:org.jivesoftware.smack.PacketReader.java

License:Open Source License

private IQ parseIQ(Element doc) {
    Element pingEl = doc.element(Ping.ELEMENT);
    if (pingEl != null && pingEl.getNamespace().getURI().equals(Ping.NAMESPACE)) {
        return new Ping(doc);
    }/*from  w  w  w.  ja v a  2 s  . c o m*/

    Element bindEl = doc.element(Bind.ELEMENT);
    if (bindEl != null && bindEl.getNamespace().getURI().equals(Bind.NAMESPACE)) {
        return new Bind(doc);
    }

    Element query = doc.element("query");
    if (query != null) {
        if ("jabber:iq:roster".equals(query.getNamespaceURI())) {
            return new Roster(doc);
        }
        if ("jabber:iq:auth".equals(query.getNamespaceURI())) {
            return new Authentication(doc);
        }
    }

    return new IQ(doc);
}

From source file:org.jivesoftware.smack.PacketReader.java

License:Open Source License

private void parseFeatures(Element doc) throws Exception {
    boolean startTLSReceived = false;
    Element startTLSEl = doc.element("starttls");
    if (startTLSEl != null && startTLSEl.getNamespace().getURI().equals("urn:ietf:params:xml:ns:xmpp-tls")) {
        startTLSReceived = true;/*www.  j a va2 s . c  om*/
        connection.startTLSReceived(startTLSEl.element("required") != null);
    }

    Element mechanismsEl = doc.element("mechanisms");
    if (mechanismsEl != null
            && mechanismsEl.getNamespace().getURI().equals("urn:ietf:params:xml:ns:xmpp-sasl")) {
        connection.getSASLAuthentication()
                .setAvailableSASLMethods(PacketParserUtils.parseMechanisms(mechanismsEl));
    }

    Element bindEl = doc.element("bind");
    if (bindEl != null && bindEl.getNamespace().getURI().equals("urn:ietf:params:xml:ns:xmpp-bind")) {
        connection.getSASLAuthentication().bindingRequired();
    }

    Element cEl = doc.element("c");
    if (cEl != null && cEl.getNamespace().getURI().equals("http://jabber.org/protocol/caps")) {
        String node = doc.attributeValue("node");
        String ver = doc.attributeValue("ver");
        if (ver != null && node != null) {
            String capsNode = node + "#" + ver;
            connection.setServiceCapsNode(capsNode);
        }
    }

    Element sessionEl = doc.element("session");
    if (sessionEl != null && sessionEl.getNamespace().getURI().equals("urn:ietf:params:xml:ns:xmpp-session")) {
        connection.getSASLAuthentication().sessionsSupported();
    }

    Element verEl = doc.element("ver");
    if (verEl != null && verEl.getNamespace().getURI().equals("urn:xmpp:features:rosterver")) {
        connection.setRosterVersioningSupported();
    }

    Element compressionEl = doc.element("compression");
    if (compressionEl != null
            && compressionEl.getNamespace().getURI().equals("http://jabber.org/features/compress")) {
        connection.setAvailableCompressionMethods(PacketParserUtils.parseCompressionMethods(compressionEl));
    }

    for (Plugin plugin : connection.getPlugins()) {
        plugin.checkSupport(doc);
    }

    if (!connection.isSecureConnection()) {
        if (!startTLSReceived && connection.getConfiguration()
                .getSecurityMode() == ConnectionConfiguration.SecurityMode.required) {
            throw new XMPPException(
                    "Server does not support security (TLS), "
                            + "but security required by connection configuration.",
                    new PacketError(Condition.forbidden));
        }
    }

    if (!startTLSReceived || connection.getConfiguration()
            .getSecurityMode() == ConnectionConfiguration.SecurityMode.disabled) {
        releaseConnectionIDLock();
    }
}

From source file:org.jivesoftware.smack.util.PacketParserUtils.java

License:Open Source License

/**
 * Parses stream error packets.//  w  ww .j  a v  a2  s  . c o m
 * 
 * @param doc
 *            the XML parser.
 * @return an stream error packet.
 * @throws Exception
 *             if an exception occurs while parsing the packet.
 */
public static StreamError parseStreamError(Element el) throws IOException, XmlPullParserException {
    String code = null;
    Element condEl = (Element) el.elements().iterator().next();
    if (condEl.getNamespace().getURI().equals(StreamError.NAMESPACE)) {
        code = condEl.getName();
    }
    String text = condEl.elementText("text");
    return new StreamError(code, text);
}

From source file:org.jivesoftware.xmpp.workgroup.WorkgroupIQHandler.java

License:Open Source License

private void handleIQSet(IQ packet) {
    IQ reply;/* w  w  w  . ja  v  a2 s  .c  om*/
    // TODO: verify namespace and send error if wrong
    Element iq = packet.getChildElement();

    JID sender = packet.getFrom();
    reply = IQ.createResultIQ(packet);
    reply.setFrom(workgroup.getJID());
    String queryName = iq.getName();
    String queryNamespace = iq.getNamespace().toString();

    if ("join-queue".equals(queryName)) {
        InterceptorManager interceptorManager = QueueInterceptorManager.getInstance();
        try {
            interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true, false);
            // Received a Join Queue request from a visitor, create a new request.
            UserRequest request = new UserRequest(packet, workgroup);
            // Let the workgroup process the new request
            if (!workgroup.queueRequest(request)) {
                // It was not possible to add the request to a queue so answer that the
                // workgroup is not accepting new join-queue requests
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.service_unavailable));
            }
            interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true, true);
        } catch (PacketRejectedException e) {
            workgroup.rejectPacket(packet, e);
            reply = null;
        }
    } else if ("depart-queue".equals(queryName)) {
        // Visitor is departing queue
        try {
            Request request = UserRequest.getRequest(workgroup, sender);
            InterceptorManager interceptorManager = QueueInterceptorManager.getInstance();
            try {
                interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true, false);
                request.cancel(Request.CancelType.DEPART);
                iq.add(request.getSessionElement());
                interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true, true);
            } catch (PacketRejectedException e) {
                workgroup.rejectPacket(packet, e);
                reply = null;
            }
        } catch (NotFoundException e) {
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.item_not_found));
            Log.debug("Request not found" + " while departing queue:", e);
        }
    } else if ("offer-accept".equals(queryName)) {
        try {
            InterceptorManager interceptorManager = OfferInterceptorManager.getInstance();
            String id = iq.attributeValue("id");
            String jid = iq.attributeValue("jid");
            if (id != null || jid != null) {
                Request request;
                if (id != null) {
                    // Search request by its unique ID
                    request = Request.getRequest(id);
                } else {
                    // Old version of FP refers to requests by the user's jid. This old version
                    // implements transfers and invitations on the client and not the server side.
                    // Therefore, for each user's jid there is always a unique Request
                    request = UserRequest.getRequest(workgroup, new JID(jid));
                }
                Offer offer = request.getOffer();
                if (offer != null && offer.isOutstanding()) {
                    AgentSession agentSession = agentManager.getAgentSession(packet.getFrom());
                    if (agentSession == null) {
                        reply.setChildElement(packet.getChildElement().createCopy());
                        reply.setError(new PacketError(PacketError.Condition.item_not_found));
                        Log.debug("Agent not found while accepting offer");
                    } else {
                        try {
                            interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true,
                                    false);
                            offer.accept(agentSession);
                            interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true,
                                    true);
                        } catch (PacketRejectedException e) {
                            workgroup.rejectPacket(packet, e);
                            reply = null;
                        }
                    }
                } else {
                    reply.setChildElement(packet.getChildElement().createCopy());
                    reply.setError(new PacketError(PacketError.Condition.not_acceptable));
                }
            }
        } catch (NotFoundException e) {
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.item_not_found));
            Log.debug("Request not found " + "while accepting offer: ", e);
        } catch (AgentNotFoundException e) {
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.item_not_found));
            Log.debug("Agent not found " + "while accepting offer: ", e);
        }
    } else if ("offer-reject".equals(queryName)) {
        try {
            InterceptorManager interceptorManager = OfferInterceptorManager.getInstance();
            String id = iq.attributeValue("id");
            String jid = iq.attributeValue("jid");
            if (id != null || jid != null) {
                Request request;
                if (id != null) {
                    // Search request by its unique ID
                    request = Request.getRequest(id);
                } else {
                    // Old version of FP refers to requests by the user's jid. This old version
                    // implements transfers and invitations on the client and not the server side.
                    // Therefore, for each user's jid there is always a unique Request
                    request = UserRequest.getRequest(workgroup, new JID(jid));
                }
                Offer offer = request.getOffer();
                if (offer != null) {
                    AgentSession agentSession = agentManager.getAgentSession(packet.getFrom());
                    if (agentSession == null) {
                        reply.setChildElement(packet.getChildElement().createCopy());
                        reply.setError(new PacketError(PacketError.Condition.item_not_found));
                        Log.debug("Agent not found while accepting offer");
                    } else {
                        try {
                            interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true,
                                    false);
                            offer.reject(agentSession);
                            interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true,
                                    true);
                        } catch (PacketRejectedException e) {
                            workgroup.rejectPacket(packet, e);
                            reply = null;
                        }
                    }
                }
            }
        } catch (NotFoundException e) {
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.item_not_found));
            Log.debug("Request not found " + "while rejecting offer: ", e);
        } catch (AgentNotFoundException e) {
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.item_not_found));
            Log.debug("Agent not found " + "while accepting offer: ", e);
        }
    } else if ("invite".equals(queryName)) {
        // Get the type of inviation (i.e. entity type is being invited)
        InvitationRequest request = new InvitationRequest(packet, workgroup);
        workgroup.processInvitation(request, packet);
        reply = null;
    } else if ("transfer".equals(queryName)) {
        // Get the type of transfer (i.e. entity type is going to get the transfer offer)
        TransferRequest request = new TransferRequest(packet, workgroup);
        workgroup.processTransfer(request, packet);
        reply = null;
    } else if ("jabber:iq:private".equals(queryNamespace)) {
        // IQ private for agents global macro storage
        setIQPrivate(packet);
    } else if ("agent-info".equals(queryName)) {
        if (!JiveGlobals.getBooleanProperty("xmpp.live.agent.change-properties", true)) {
            // Answer that agents are not allowed to change their properties (feature disabled)
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.service_unavailable));
        } else {
            try {
                AgentSession agentSession = agentManager.getAgentSession(packet.getFrom());
                if (agentSession == null) {
                    reply = IQ.createResultIQ(packet);
                    reply.setChildElement(packet.getChildElement().createCopy());
                    reply.setError(new PacketError(PacketError.Condition.item_not_found));
                } else {
                    String allowsToChange = agentSession.getAgent().getProperties()
                            .getProperty("change-properties");
                    if (!"false".equals(allowsToChange)) {
                        // Set the new agent's info
                        agentSession.getAgent().updateAgentInfo(packet);
                    } else {
                        // Answer that this agent is not allowed to change his properties
                        reply = IQ.createResultIQ(packet);
                        reply.setChildElement(packet.getChildElement().createCopy());
                        reply.setError(new PacketError(PacketError.Condition.service_unavailable));
                    }
                }
            } catch (AgentNotFoundException e) {
                reply = IQ.createResultIQ(packet);
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.item_not_found));
            }
        }
    } else {
        // Check all Workgroup Providers for handling this SET request. If
        // none are found, send bad request error.
        for (WorkgroupProvider provider : providerManager.getWorkgroupProviders()) {
            // Handle packet?
            if (provider.handleSet(packet)) {
                // If provider accepts responsibility, hand off packet.
                provider.executeSet(packet, workgroup);
                return;
            }
        }

        dropPacket(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.bad_request));
    }

    if (reply != null) {
        workgroup.send(reply);
    }
}

From source file:org.lushlife.guicexml.XmlModule.java

License:Apache License

@Override
protected void configure() {
    InputStream stream = null;//from ww w .  ja v a2s.c  o  m
    try {
        log.log(GuiceXmlLogMessage.READ_XML_FILE, url);
        if (url == null) {
            return;
        }
        stream = url.openStream();
        if (stream == null) {
            return;
        }
        Element rootElement = XML.getRootElement(stream);
        for (Object obj : rootElement.elements()) {
            Element element = (Element) obj;

            if (Boolean.valueOf(element.attributeValue("disabled"))) {
                log.log(GuiceXmlLogMessage.DISABLED, element.asXML());
                configure();
            }

            Namespace namespace = element.getNamespace();
            // no namespace
            if (namespace.getText().isEmpty()) {
                configureDefaultNameSpace(element);
                continue;
            }
            // default namespace
            if ("http://code.google.com/p/guice-xml".equals(namespace.getStringValue())) {
                configureDefaultNameSpace(element);
                continue;
            }
            // urn import
            if (namespace.getText().startsWith("urn:import:")) {
                String packageName = namespace.getText().substring("urn:import:".length());
                String className = element.getName();
                ComponentXmlReader.create(packageName, className, element, propertyManagement)
                        .bind(this.binder());
                continue;
            }
            // NameSpaceBinding
            ComponentXmlReader.create(namespace, element.getName(), element, propertyManagement)
                    .bind(this.binder());

        }
    } catch (Exception e) {
        addError(e);
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
            }
        }
    }
}