Example usage for javax.xml.stream XMLStreamException getMessage

List of usage examples for javax.xml.stream XMLStreamException getMessage

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.wso2.carbon.proxyadmin.ProxyData.java

public OMElement retrieveOM() throws ProxyAdminException {
    OMFactory fac = OMAbstractFactory.getOMFactory();

    OMNamespace syn = SynapseConstants.SYNAPSE_OMNAMESPACE;
    OMNamespace nullNS = fac.createOMNamespace("", "");

    OMElement proxy = fac.createOMElement("proxy", syn);
    proxy.addAttribute("name", name, nullNS);

    // adds any transports listed in the configuration
    if (transports != null) {
        proxy.addAttribute("transports", createCSString(transports), nullNS);
    }//  www  .  j ava 2 s  .co  m

    if (pinnedServers != null) {
        proxy.addAttribute("pinnedServers", createCSString(pinnedServers), nullNS);
    }

    if (serviceGroup != null) {
        proxy.addAttribute("serviceGroup", serviceGroup, nullNS);
    }

    // adds the state of statistics and tracing
    if (enableStatistics) {
        proxy.addAttribute(XMLConfigConstants.STATISTICS_ATTRIB_NAME, XMLConfigConstants.STATISTICS_ENABLE,
                nullNS);
    } else {
        proxy.addAttribute(XMLConfigConstants.STATISTICS_ATTRIB_NAME, XMLConfigConstants.STATISTICS_DISABLE,
                nullNS);
    }

    if (enableTracing) {
        proxy.addAttribute(XMLConfigConstants.TRACE_ATTRIB_NAME, XMLConfigConstants.TRACE_ENABLE, nullNS);
    } else {
        proxy.addAttribute(XMLConfigConstants.TRACE_ATTRIB_NAME, XMLConfigConstants.TRACE_DISABLE, nullNS);
    }

    if (startOnLoad) {
        proxy.addAttribute("startOnLoad", "true", nullNS);
    } else {
        proxy.addAttribute("startOnLoad", "false", nullNS);
    }

    // creates the target section of the configuration
    OMElement element = fac.createOMElement("target", syn);
    if (inSeqKey != null) {
        element.addAttribute("inSequence", inSeqKey, nullNS);
    } else if (inSeqXML != null) {
        try {
            element.addChild(createElement(inSeqXML));
        } catch (XMLStreamException e) {
            String msg = "Unable to build the \"inSequence\" element";
            log.error(msg + e.getMessage());
            throw new ProxyAdminException(msg, e);
        }
    }

    if (outSeqKey != null) {
        element.addAttribute("outSequence", outSeqKey, nullNS);
    } else if (outSeqXML != null) {
        try {
            element.addChild(createElement(outSeqXML));
        } catch (XMLStreamException e) {
            String msg = "Unable to build the \"outSequence\" element";
            log.error(msg + e.getMessage());
            throw new ProxyAdminException(msg, e);
        }
    }

    if (faultSeqKey != null) {
        element.addAttribute("faultSequence", faultSeqKey, nullNS);
    } else if (faultSeqXML != null) {
        try {
            element.addChild(createElement(faultSeqXML));
        } catch (XMLStreamException e) {
            String msg = "Unable to build the \"faultSequence\" element";
            log.error(msg + e.getMessage());
            throw new ProxyAdminException(msg, e);
        }
    }

    if (endpointKey != null) {
        element.addAttribute("endpoint", endpointKey, nullNS);
    } else if (endpointXML != null && !"".equals(endpointXML)) {
        try {
            element.addChild(createElement(endpointXML));
        } catch (XMLStreamException e) {
            String msg = "Unable to build the \"endpoint\" element";
            log.error(msg + e.getMessage());
            throw new ProxyAdminException(msg, e);
        }
    }
    proxy.addChild(element);

    // creates the publishWSDL section of the configuration
    element = fac.createOMElement("publishWSDL", syn);
    if (publishWSDLEndpoint != null) {
        publishWSDL = true;
        element.addAttribute("endpoint", publishWSDLEndpoint, nullNS);
    } else if (wsdlKey != null) {
        publishWSDL = true;
        element.addAttribute("key", wsdlKey, nullNS);
    } else if (wsdlURI != null) {
        publishWSDL = true;
        element.addAttribute("uri", wsdlURI, nullNS);
    } else if (wsdlDef != null) {
        publishWSDL = true;
        try {
            element.addChild(createElement(wsdlDef));
        } catch (XMLStreamException e) {
            String msg = "Unable to build the in line WSDL definition";
            log.error(msg + e.getMessage());
            throw new ProxyAdminException(msg, e);
        }
    }

    if (publishWSDL) {
        // builds the additional resources (if any) required by the WSDL
        if (wsdlResources != null && wsdlResources.length != 0) {
            OMElement resource;
            Entry wsdlResource;
            for (int i = 0; i < wsdlResources.length; i++) {
                wsdlResource = wsdlResources[i];
                resource = fac.createOMElement("resource", syn);
                resource.addAttribute("location", wsdlResource.getKey(), nullNS);
                resource.addAttribute("key", wsdlResource.getValue(), nullNS);
                element.addChild(resource);
            }
        }
        proxy.addChild(element);
    }

    // creates the additional service level parameter list of the configuration
    if (serviceParams != null && serviceParams.length != 0) {
        Entry serviceParam;
        String value;
        for (int i = 0; i < serviceParams.length; i++) {
            serviceParam = serviceParams[i];
            if (serviceParam != null) {
                element = fac.createOMElement("parameter", syn);
                element.addAttribute("name", serviceParam.getKey(), nullNS);
                value = serviceParam.getValue();
                if (value.startsWith("<")) {
                    try {
                        byte[] bytes = null;
                        try {
                            bytes = value.getBytes("UTF8");
                        } catch (UnsupportedEncodingException e) {
                            log.error("Unable to extract bytes in UTF-8 encoding. "
                                    + "Extracting bytes in the system default encoding" + e.getMessage());
                            bytes = value.getBytes();
                        }
                        element.addChild(
                                new StAXOMBuilder(new ByteArrayInputStream(bytes)).getDocumentElement());
                    } catch (XMLStreamException e) {
                        String msg = "Service parameter: " + serviceParam.getKey()
                                + " has an invalid XML as its value";
                        log.error(msg);
                        throw new ProxyAdminException(msg, e);
                    }
                } else {
                    element.setText(value);
                }
                proxy.addChild(element);
            }
        }
    }

    if (enableSecurity) {
        element = fac.createOMElement("enableSec", syn);
        proxy.addChild(element);
    }

    if (policies != null) {
        for (ProxyServicePolicyInfo policy : policies) {
            proxy.addChild(policy.toOM(fac, syn, nullNS));
        }
    }

    if (description != null) {
        element = fac.createOMElement("description", syn);
        element.setText(description);
        proxy.addChild(element);
    }

    return proxy;
}

From source file:org.wso2.carbon.wsdl2form.WSDL2FormGenerator.java

private String generateTryitExternal(AxisService service, ConfigurationContext configCtx,
        ByteArrayOutputStream wsdl2Bos, String serviceName, String operationName, String endpointName,
        Map fileResourcesMap, boolean fullPage, boolean needSOAPAction)
        throws ParserConfigurationException, TransformerException, FileNotFoundException, CarbonException {
    if (log.isDebugEnabled()) {
        try {/*from   w  w w .  ja  v  a  2  s  .c  om*/
            XMLStreamReader streamReader = XMLInputFactory.newInstance()
                    .createXMLStreamReader(new ByteArrayInputStream(wsdl2Bos.toByteArray()));
            StAXOMBuilder stAXOMBuilder = new StAXOMBuilder(streamReader);
            OMElement ele = stAXOMBuilder.getDocumentElement();
            log.debug("output ==> " + ele.toString());
        } catch (XMLStreamException e) {
            log.error(e.getMessage(), e);
        }
    }

    String serviceContextRoot = configCtx.getServiceContextPath();
    if (!serviceContextRoot.endsWith("/")) {
        serviceContextRoot = serviceContextRoot + "/";
    }
    Map<String, String> paramMap = new HashMap<String, String>();

    DOMSource xmlSource = Util.getSigStream(service, wsdl2Bos, null);

    Util.FileInfo jsFileLocation = Util.getOutputFileLocation(".stub.js");
    File jsFile = jsFileLocation.getFile();
    OutputStream jsStubOutputStream = new FileOutputStream(jsFile);
    Result jsStubResult = new StreamResult(jsStubOutputStream);
    Util.generateStub(xmlSource, jsStubResult, null);

    File[] files0 = jsFile.getParentFile().listFiles(new FileFilter() {
        public boolean accept(File pathname) {
            return pathname.getName().endsWith(".stub.js");
        }
    });
    if ((files0 != null) && (files0[0] != null) && (files0[0].getAbsoluteFile() != null)) {
        String absolutePath = files0[0].getAbsoluteFile().getAbsolutePath();
        fileResourcesMap.put(jsFileLocation.getUuid(), absolutePath);
    }
    Util.FileInfo htmlFileLocation = Util.getOutputFileLocation(".html");
    File tryItOutFile = htmlFileLocation.getFile();
    OutputStream tryItOutFileStream = new FileOutputStream(tryItOutFile);
    Result tryItResult = new StreamResult(tryItOutFileStream);

    paramMap.put("js-global-params", "carbon/global-params.js");
    paramMap.put("proxyAddress", "carbon/admin/jsp/WSRequestXSSproxy_ajaxprocessor.jsp");
    paramMap.put("js-service-stub", "filedownload?id=" + jsFileLocation.getUuid());
    paramMap.put("js-WSRequest", "carbon/admin/js/WSRequest.js");
    paramMap.put("js-jQuery", "carbon/admin/js/jquery-1.5.2.min.js");
    paramMap.put("js-jQueryUI", "carbon/admin/js/jquery-ui-1.8.11.custom.min.js");
    paramMap.put("js-corners", "carbon/tryit/extras/jquery.corner.js");
    paramMap.put("js-editArea", "carbon/editarea/edit_area_full.js");
    paramMap.put("xslt-location", "carbon/tryit/xslt/prettyprinter.xslt");
    paramMap.put("css-images", "carbon/tryit/images/");
    paramMap.put("css-jQueryUI", "carbon/admin/css/smoothness/jquery-ui-1.8.11.custom.css");
    paramMap.put("show-alternate", "false");
    paramMap.put("fixendpoints", "true");

    Util.generateTryit(xmlSource, tryItResult, paramMap);

    File[] files1 = tryItOutFile.getParentFile().listFiles(new FileFilter() {
        public boolean accept(File pathname) {
            return pathname.getName().endsWith(".html");
        }
    });
    if ((files1 != null) && (files1[0] != null) && (files1[0].getAbsoluteFile() != null)) {
        fileResourcesMap.put(htmlFileLocation.getUuid(), files1[0].getAbsoluteFile().getAbsolutePath());
    }

    return "../.." + ServerConstants.ContextPaths.DOWNLOAD_PATH + "?id=" + htmlFileLocation.getUuid();
}

From source file:org.wso2.siddhi.extension.map.CreateFromXMLFunctionExtension.java

@Override
protected Object execute(Object data) {
    if (data instanceof String) {
        try {/*w w w.ja  va  2 s.  c  o  m*/
            OMElement parentElement = AXIOMUtil.stringToOM(data.toString());
            return getMapFromXML(parentElement);
        } catch (XMLStreamException e) {
            throw new ExecutionPlanRuntimeException("Input data cannot be parsed to xml: " + e.getMessage(), e);
        }
    } else {
        throw new ExecutionPlanRuntimeException("Data should be a string");
    }
}

From source file:org.wso2.wsf.jython.messagereceiver.PythonScriptReceiver.java

/**
 * Retreives information from incoming message. Apply business logic to the innformation retreived. Creates a out
 * message from the result.//w w w  .java2 s .co m
 *
 * @param inMessage  Incominng message.
 * @param outMessage Outgoing message.
 * @throws AxisFault AxisFault.
 */
public void invokeBusinessLogic(MessageContext inMessage, MessageContext outMessage) throws AxisFault {
    SOAPEnvelope soapEnvelope = inMessage.getEnvelope();
    try {
        String pMethod;

        try {
            pMethod = getPythonMethod(inMessage);
        } catch (XMLStreamException e) {
            throw new AxisFault(e.getMessage());
        }

        String pReader = readPythonScript(inMessage);

        if (pReader == null) {
            throw new AxisFault("Unable to load Python file");
        }
        if (pMethod == null) {
            throw new AxisFault("Unable to read the method");
        }

        OMElement payload = soapEnvelope.getBody().getFirstElement();
        Object args = payload;
        if (payload != null) {
            // We neet to get the Axis Message from the incomming message so that we can get its schema.
            // We need the schema in order to unwrap the parameters.
            AxisMessage axisMessage = inMessage.getAxisOperation()
                    .getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
            XmlSchemaElement xmlSchemaElement = axisMessage.getSchemaElement();
            if (xmlSchemaElement != null) {
                // Once the schema is obtained we iterate through the schema looking for the elemants in the payload.
                // for Each element we extract its value and create a parameter which can be passed into the
                // pythonscript function.
                XmlSchemaType schemaType = xmlSchemaElement.getSchemaType();
                if (schemaType instanceof XmlSchemaComplexType) {
                    XmlSchemaComplexType complexType = ((XmlSchemaComplexType) schemaType);
                    List<Object> params = handleComplexTypeInRequest(complexType, payload,
                            new ArrayList<String>());
                    args = params.toArray();
                } else if (xmlSchemaElement.getSchemaTypeName() == Constants.XSD_ANYTYPE) {
                    args = payload;
                }
            }
        } else {
            // This validates whether the user has sent a bad SOAP message
            // with a non-XML payload.
            if (soapEnvelope.getBody().getFirstOMChild() != null) {
                OMText textPayLoad = (OMText) soapEnvelope.getBody().getFirstOMChild();
                //we allow only a sequence of spaces
                if (textPayLoad.getText().trim().length() > 0) {
                    throw new AxisFault("Non-XML payload is not allowed. PayLoad inside the SOAP body"
                            + " needs to be an XML element.");
                }
            }
        }

        //Setting up the out message 
        AxisMessage outAxisMessage = inMessage.getAxisOperation()
                .getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
        boolean annotated = false;
        Parameter parameter = outAxisMessage.getParameter(PythonScriptEngineConstants.ANNOTATED);
        if (parameter != null) {
            annotated = (Boolean) parameter.getValue();
        }
        // annotated=true is done for a test . delete it after the proj is finished!
        // annotated = true;

        Object response = PythonScriptEngine.invoke(pMethod, pReader, (java.lang.Object[]) (args));
        if (log.isDebugEnabled()) {
            log.debug("object returned from jython : " + response);
        }

        // Create the outgoing message
        SOAPFactory fac;
        if (inMessage.isSOAP11()) {
            fac = OMAbstractFactory.getSOAP11Factory();
        } else {
            fac = OMAbstractFactory.getSOAP12Factory();
        }
        SOAPEnvelope envelope = fac.getDefaultEnvelope();
        SOAPBody body = envelope.getBody();
        XmlSchemaElement xmlSchemaElement = outAxisMessage.getSchemaElement();
        OMElement outElement;
        String prefix = "ws";
        if (xmlSchemaElement != null) {
            QName elementQName = xmlSchemaElement.getSchemaTypeName();
            OMNamespace namespace = fac.createOMNamespace(elementQName.getNamespaceURI(), prefix);
            outElement = fac.createOMElement(xmlSchemaElement.getName(), namespace);
            XmlSchemaType schemaType = xmlSchemaElement.getSchemaType();
            if (schemaType instanceof XmlSchemaComplexType) {
                XmlSchemaComplexType complexType = ((XmlSchemaComplexType) schemaType);
                handleComplexTypeInResponse(complexType, outElement, response, fac, false);
                body.addChild(outElement);
            } else if (xmlSchemaElement.getSchemaTypeName() == Constants.XSD_ANYTYPE) {
                if (!PythonScriptEngine.isNull(response)) {
                    // If its anyType that means we have to add xsi:type
                    OMElement element = buildResponse(false, response, xmlSchemaElement);
                    if (element != null) {
                        body.addChild(element);
                    }
                }
            }
        } else if (!PythonScriptEngine.isNull(response)) {
            OMElement element = buildResponse(annotated, response, xmlSchemaElement);
            if (log.isDebugEnabled()) {
                log.debug("The built element is : " + element.toString());
            }
            if (element != null) {
                body.addChild(element);
            }
        }
        outMessage.setEnvelope(envelope);
    } catch (Throwable throwable) {
        AxisFault fault = AxisFault.makeFault(throwable);
        // This is a workaround to avoid Axis2 sending the SOAPFault with a
        // http-400 code when sending using SOAP1. We explicitly set the
        // FualtCode to 'Receiver'.
        fault.setFaultCode(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI
                .equals(soapEnvelope.getNamespace().getNamespaceURI())
                        ? SOAP12Constants.SOAP_DEFAULT_NAMESPACE_PREFIX + ":"
                                + SOAP12Constants.FAULT_CODE_RECEIVER
                        : SOAP12Constants.SOAP_DEFAULT_NAMESPACE_PREFIX + ":"
                                + SOAP11Constants.FAULT_CODE_RECEIVER);
        throw fault;
    }

}

From source file:spypunk.tailthis.configuration.xml.ConfigurationXMLWriter.java

public void save(final Configuration configuration) throws Exception {

    FileUtils.forceMkdir(configurationFile.getParentFile());
    final XMLOutputFactory xof = XMLOutputFactory.newInstance();
    XMLStreamWriter xtw = null;//from ww  w .  j  a  v a  2  s  .co  m

    try {
        xtw = new IndentingXMLStreamWriter(xof.createXMLStreamWriter(new FileWriter(configurationFile)));

        xtw.writeStartElement(ConfigurationXMLConstants.TAILTHIS_ELEMENT_NAME);

        xtw.writeStartElement(ConfigurationXMLConstants.REMEMBER_LAST_OPENED_FILES_ELEMENT_NAME);
        xtw.writeCharacters(configuration.getRememberLastOpenedFiles().toString());
        xtw.writeEndElement();

        xtw.writeStartElement(ConfigurationXMLConstants.LAST_FOLDER_ELEMENT_NAME);
        xtw.writeCharacters(configuration.getLastFolder().getAbsolutePath());
        xtw.writeEndElement();

        xtw.writeStartElement(ConfigurationXMLConstants.LAST_OPENED_FILES_ELEMENT_NAME);

        for (final File lastOpenedFile : configuration.getLastOpenedFiles()) {
            xtw.writeStartElement(ConfigurationXMLConstants.LAST_OPENED_FILE_ELEMENT_NAME);
            xtw.writeCharacters(lastOpenedFile.getAbsolutePath());
            xtw.writeEndElement();
        }

        xtw.writeEndElement();

        xtw.writeStartElement(ConfigurationXMLConstants.UPDATE_PERIOD_ELEMENT_NAME);
        xtw.writeCharacters(configuration.getUpdatePeriod().toString());
        xtw.writeEndElement();

        xtw.writeStartElement(ConfigurationXMLConstants.ALWAYS_ON_TOP_ELEMENT_NAME);
        xtw.writeCharacters(configuration.getAlwaysOnTop().toString());
        xtw.writeEndElement();

        xtw.writeStartElement(ConfigurationXMLConstants.LOCALE_ELEMENT_NAME);
        xtw.writeCharacters(configuration.getLocale().getKey());
        xtw.writeEndElement();

        xtw.writeStartElement(ConfigurationXMLConstants.HIGHLIGHTINGS_ELEMENT_NAME);

        for (final Highlighting highlighting : configuration.getHighlightings()) {
            xtw.writeStartElement(ConfigurationXMLConstants.HIGHLIGHTING_ELEMENT_NAME);
            xtw.writeAttribute(ConfigurationXMLConstants.BACKGROUND_COLOR_ATTRIBUTE_NAME,
                    highlighting.getBackgroundColor().getKey());
            xtw.writeAttribute(ConfigurationXMLConstants.FOREGROUND_COLOR_ATTRIBUTE_NAME,
                    highlighting.getForegroundColor().getKey());
            xtw.writeCharacters(highlighting.getPattern().pattern());
            xtw.writeEndElement();
        }

        xtw.writeEndElement();

        xtw.writeEndElement();

        xtw.flush();
    } finally {
        if (xtw != null) {
            try {
                xtw.close();
            } catch (final XMLStreamException e) {
                LOGGER.warn(e.getMessage(), e);
            }
        }
    }
}