Example usage for org.dom4j QName get

List of usage examples for org.dom4j QName get

Introduction

In this page you can find the example usage for org.dom4j QName get.

Prototype

public static QName get(String qualifiedName, String uri) 

Source Link

Usage

From source file:com.test.android.push.xmpp.handler.IQRegisterHandler.java

License:Open Source License

/**
 * Constructor./*from w  ww.  j a va2 s.  co  m*/
 */
public IQRegisterHandler() {
    androidService = ServiceLocator.getUserService();
    probeResponse = DocumentHelper.createElement(QName.get("query", NAMESPACE));
    probeResponse.addElement("username");
    probeResponse.addElement("password");
    probeResponse.addElement("userId");
}

From source file:com.vmware.o11n.plugin.powershell.remote.impl.winrm.Action.java

License:Open Source License

public Element getElement() {
    return DocumentHelper.createElement(QName.get("Action", Namespaces.NS_ADDRESSING))
            .addAttribute("mustUnderstand", "true").addText(uri);
}

From source file:com.vmware.o11n.plugin.powershell.remote.impl.winrm.OptionSet.java

License:Open Source License

public Element getElement() {
    final Element optionSet = DocumentHelper.createElement(QName.get("OptionSet", Namespaces.NS_WSMAN_DMTF));
    for (KeyValuePair p : keyValuePairs) {
        optionSet.addElement(QName.get("Option", Namespaces.NS_WSMAN_DMTF)).addAttribute("Name", p.getKey())
                .addText(p.getValue());//w w  w  . ja v  a 2  s .  c om
    }
    return optionSet;
}

From source file:com.vmware.o11n.plugin.powershell.remote.impl.winrm.ClientState.java

License:Open Source License

private void cleanUp() {
    if (commandId == null)
        return;/*ww w  .ja  va  2s  .  c  o m*/
    log.debug("cleanUp shellId {} commandId {} ", shellId, commandId);
    final Element bodyContent = DocumentHelper.createElement(QName.get("Signal", Namespaces.NS_WIN_SHELL))
            .addAttribute("CommandId", commandId);
    bodyContent.addElement(QName.get("Code", Namespaces.NS_WIN_SHELL))
            .addText("http://schemas.microsoft.com/wbem/wsman/1/windows/shell/signal/terminate");
    final Document requestDocument = getRequestDocument(Action.WS_SIGNAL, ResourceURI.RESOURCE_URI_CMD, null,
            shellId, bodyContent);
    @SuppressWarnings("unused")
    Document responseDocument = sendMessage(requestDocument, SoapAction.SIGNAL);

}

From source file:com.vmware.o11n.plugin.powershell.remote.impl.winrm.ClientState.java

License:Open Source License

/**
 * Loops endlessly and provides output stream content to the OverthereProcessOutputHandler instance 
 * @param handler - instance of OverthereProcessOutputHandler that will collect the output
 *//*from  w w  w  . j a v  a  2s  .c o  m*/
synchronized public void getCommandOutput(WinRmCapturingOverthereProcessOutputHandler handler) {
    log.debug("getCommandOutput shellId {} commandId {} ", shellId, commandId);
    final Element bodyContent = DocumentHelper.createElement(QName.get("Receive", Namespaces.NS_WIN_SHELL));
    bodyContent.addElement(QName.get("DesiredStream", Namespaces.NS_WIN_SHELL))
            .addAttribute("CommandId", commandId).addText("stdout stderr");
    final Document requestDocument = getRequestDocument(Action.WS_RECEIVE, ResourceURI.RESOURCE_URI_CMD, null,
            shellId, bodyContent);

    for (;;) {
        Document responseDocument = sendMessage(requestDocument, SoapAction.RECEIVE);

        //  If no output is available before the wsman:OperationTimeout expires, 
        //  the server MUST return a WSManFault with the Code attribute equal to "2150858793". 
        //  When the client receives this fault, it SHOULD issue another Receive request. 
        //  The client SHOULD continue to issue Receive messages as soon as the previous ReceiveResponse has been received.
        final List<?> faults = FaultExtractor.FAULT_CODE.getXPath().selectNodes(responseDocument);
        if (!faults.isEmpty()) {
            String faultCode = ((Attribute) faults.get(0)).getText();
            final List<?> faultMessages = FaultExtractor.FAULT_MESSAGE.getXPath().selectNodes(responseDocument);
            String faultMessage = ((Element) faultMessages.get(0)).getText();
            log.debug("fault code {} message", faultCode);
            if (faultCode.equalsIgnoreCase("2150858793")) {
                continue;
            } else {
                log.debug("fault code {}", faultCode);
                throw new WinRMRuntimeIOException(faultMessage);
            }
        }

        String stdout = handleStream(responseDocument, ResponseExtractor.STDOUT);
        handler.handleOutputChunk(stdout);

        String stderr = handleStream(responseDocument, ResponseExtractor.STDERR);
        BufferedReader stderrReader = new BufferedReader(new StringReader(stderr));
        try {
            for (;;) {
                String line = stderrReader.readLine();
                if (line == null) {
                    break;
                }
                handler.handleErrorLine(line);
            }
        } catch (IOException exc) {
            throw new RuntimeIOException("Unexpected I/O exception while reading stderr", exc);
        }

        if (chunk == 0) {
            try {
                exitCode = getFirstElement(responseDocument, ResponseExtractor.EXIT_CODE);
                log.debug("exit code {}", exitCode);
            } catch (Exception e) {
                log.debug("not found");
            }
        }
        chunk++;

        /* We may need to get additional output if the stream has not finished.
                                The CommandState will change from Running to Done like so:
                                @example
                
                                 from...
                                 <rsp:CommandState CommandId="..." State="http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandState/Running"/>
                                 to...
                                 <rsp:CommandState CommandId="..." State="http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandState/Done">
                                     <rsp:ExitCode>0</rsp:ExitCode>
                                 </rsp:CommandState>
                             */
        final List<?> list = ResponseExtractor.STREAM_DONE.getXPath().selectNodes(responseDocument);
        if (!list.isEmpty()) {
            exitCode = getFirstElement(responseDocument, ResponseExtractor.EXIT_CODE);
            log.debug("exit code {}", exitCode);
            break;
        }

        if (handler.isDone() == true) {
            break;
        }
    }
    //logger.debug("all the command output has been fetched (chunk={})", chunk);
}

From source file:com.vmware.o11n.plugin.powershell.remote.impl.winrm.ClientState.java

License:Open Source License

private String runCommand(String command) {
    log.debug("runCommand shellId {} command {}", shellId, command);
    final Element bodyContent = DocumentHelper.createElement(QName.get("CommandLine", Namespaces.NS_WIN_SHELL));

    String encoded = command;/* w ww. j  av a2s  .  c om*/
    if (!command.startsWith("\""))
        encoded = "\"" + encoded;
    if (!command.endsWith("\""))
        encoded = encoded + "\"";

    log.debug("Encoded command is {}", encoded);

    bodyContent.addElement(QName.get("Command", Namespaces.NS_WIN_SHELL)).addText(encoded);

    final Document requestDocument = getRequestDocument(Action.WS_COMMAND, ResourceURI.RESOURCE_URI_CMD,
            OptionSet.RUN_COMMAND, shellId, bodyContent);
    Document responseDocument = sendMessage(requestDocument, SoapAction.COMMAND_LINE);

    return getFirstElement(responseDocument, ResponseExtractor.COMMAND_ID);
}

From source file:com.vmware.o11n.plugin.powershell.remote.impl.winrm.ClientState.java

License:Open Source License

synchronized public void sendCmdToInputStream(String command, boolean shouldEncode) {
    log.debug("runCommand shellId {} command {}", shellId, command);
    final Element bodyContent = DocumentHelper.createElement(QName.get("Send", Namespaces.NS_WIN_SHELL));
    String encoded = null;//from ww  w  .  j a  va  2 s .c  o m
    if (shouldEncode) {
        try {
            encoded = new String(Base64.encodeBase64(command.getBytes()), CHARSET_UTF_8);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }

    String cmdToSent = shouldEncode ? encoded : command;
    log.debug("Encoded command is {}", cmdToSent);

    bodyContent.addElement(QName.get("Stream", Namespaces.NS_WIN_SHELL)).addText(cmdToSent)
            .addAttribute("Name", "stdin").addAttribute("CommandId", commandId);

    final Document requestDocument = getRequestDocument(Action.WS_SEND, ResourceURI.RESOURCE_URI_CMD,
            OptionSet.RUN_COMMAND, shellId, bodyContent);
    sendMessage(requestDocument, SoapAction.COMMAND_LINE);
}

From source file:com.vmware.o11n.plugin.powershell.remote.impl.winrm.ClientState.java

License:Open Source License

private String openShell() {
    log.debug("openShell");

    final Element bodyContent = DocumentHelper.createElement(QName.get("Shell", Namespaces.NS_WIN_SHELL));
    bodyContent.addElement(QName.get("InputStreams", Namespaces.NS_WIN_SHELL)).addText("stdin");
    bodyContent.addElement(QName.get("OutputStreams", Namespaces.NS_WIN_SHELL)).addText("stdout stderr");

    final Document requestDocument = getRequestDocument(Action.WS_ACTION, ResourceURI.RESOURCE_URI_CMD,
            OptionSet.OPEN_SHELL, null, bodyContent);
    Document responseDocument = sendMessage(requestDocument, SoapAction.SHELL);

    return getFirstElement(responseDocument, ResponseExtractor.SHELL_ID);

}

From source file:com.vmware.o11n.plugin.powershell.remote.impl.winrm.ClientState.java

License:Open Source License

private Document getRequestDocument(Action action, ResourceURI resourceURI, OptionSet optionSet, String shelId,
        Element bodyContent) {/*from  w w  w .  j  av  a2  s.c  om*/
    Document doc = DocumentHelper.createDocument();
    final Element envelope = doc.addElement(QName.get("Envelope", Namespaces.NS_SOAP_ENV));
    envelope.add(getHeader(action, resourceURI, optionSet, shelId));

    final Element body = envelope.addElement(QName.get("Body", Namespaces.NS_SOAP_ENV));

    if (bodyContent != null)
        body.add(bodyContent);

    return doc;
}

From source file:com.vmware.o11n.plugin.powershell.remote.impl.winrm.ClientState.java

License:Open Source License

private Element getHeader(Action action, ResourceURI resourceURI, OptionSet optionSet, String shellId) {
    final Element header = DocumentHelper.createElement(QName.get("Header", Namespaces.NS_SOAP_ENV));
    header.addElement(QName.get("To", Namespaces.NS_ADDRESSING)).addText(targetURL.toString());
    final Element replyTo = header.addElement(QName.get("ReplyTo", Namespaces.NS_ADDRESSING));
    replyTo.addElement(QName.get("Address", Namespaces.NS_ADDRESSING)).addAttribute("mustUnderstand", "true")
            .addText("http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous");
    header.addElement(QName.get("MaxEnvelopeSize", Namespaces.NS_WSMAN_DMTF))
            .addAttribute("mustUnderstand", "true").addText("" + envelopSize);
    header.addElement(QName.get("MessageID", Namespaces.NS_ADDRESSING)).addText(getUUID());
    header.addElement(QName.get("Locale", Namespaces.NS_WSMAN_DMTF)).addAttribute("mustUnderstand", "false")
            .addAttribute("xml:lang", locale);
    header.addElement(QName.get("DataLocale", Namespaces.NS_WSMAN_MSFT)).addAttribute("mustUnderstand", "false")
            .addAttribute("xml:lang", locale);
    header.addElement(QName.get("OperationTimeout", Namespaces.NS_WSMAN_DMTF)).addText(timeout);
    header.add(action.getElement());//from   w ww  .j  a  va  2 s. c  o m
    if (shellId != null) {
        header.addElement(QName.get("SelectorSet", Namespaces.NS_WSMAN_DMTF))
                .addElement(QName.get("Selector", Namespaces.NS_WSMAN_DMTF)).addAttribute("Name", "ShellId")
                .addText(shellId);
    }
    header.add(resourceURI.getElement());
    if (optionSet != null) {
        header.add(optionSet.getElement());
    }

    return header;
}