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.dataservices.core.DBUtils.java

/**
 * Get roles using the AuthorizationProvider using the config given.
 *
 * @param authProviderConfig xml config.
 * @return role array/*from   w w w . jav a2 s.c  o m*/
 * @throws DataServiceFault
 */
public static String[] getAllRolesUsingAuthorizationProvider(String authProviderConfig)
        throws DataServiceFault {
    try {
        AuthorizationProvider authorizationProvider;
        if (authProviderConfig != null && !authProviderConfig.isEmpty()) {
            StAXOMBuilder builder = new StAXOMBuilder(
                    new ByteArrayInputStream(authProviderConfig.getBytes(StandardCharsets.UTF_8)));
            OMElement documentElement = builder.getDocumentElement();
            authorizationProvider = generateAuthProviderFromXMLOMElement(documentElement);
        } else {
            authorizationProvider = new UserStoreAuthorizationProvider();
        }
        return authorizationProvider.getAllRoles();
    } catch (XMLStreamException e) {
        throw new DataServiceFault(e,
                "Error reading XML file data - " + authProviderConfig + " Error - " + e.getMessage());
    }
}

From source file:org.wso2.carbon.dataservices.core.description.config.SQLConfig.java

private void processDynamicAuth() throws DataServiceFault {
    String dynAuthMapping = this.getProperty(RDBMS.DYNAMIC_USER_AUTH_MAPPING);
    if (!DBUtils.isEmptyString(dynAuthMapping)) {
        OMElement dynUserAuthPropEl;//from  w  ww . j  a va 2s  . c  o m
        try {
            dynUserAuthPropEl = AXIOMUtil.stringToOM(dynAuthMapping);
        } catch (XMLStreamException e) {
            throw new DataServiceFault(e,
                    "Error in reading dynamic user auth mapping configuration: " + e.getMessage());
        }
        OMElement dynUserAuthConfEl = dynUserAuthPropEl.getFirstElement();
        if (dynUserAuthConfEl == null) {
            throw new DataServiceFault("Invalid dynamic user auth mapping configuration");
        }
        this.primaryDynAuth = new ConfigurationBasedAuthenticator(dynUserAuthConfEl.toString());
    }
    String dynAuthClass = this.getProperty(RDBMS.DYNAMIC_USER_AUTH_CLASS);
    if (!DBUtils.isEmptyString(dynAuthClass)) {
        try {
            DynamicUserAuthenticator authObj = (DynamicUserAuthenticator) Class.forName(dynAuthClass)
                    .newInstance();
            if (this.primaryDynAuth == null) {
                this.primaryDynAuth = authObj;
            } else {
                this.secondaryDynAuth = authObj;
            }
        } catch (Exception e) {
            throw new DataServiceFault(e, "Error in creating dynamic user authenticator: " + e.getMessage());
        }
    }
}

From source file:org.wso2.carbon.dataservices.core.description.query.QueryFactory.java

private static SQLQuery createSQLQuery(DataService dataService, OMElement queryEl) throws DataServiceFault {
    String queryId, configId, sql, inputNamespace;
    boolean returnGeneratedKeys = false;
    boolean isReturnUpdatedRowCount = false;
    EventTrigger[] eventTriggers;//w  ww .j  a v a 2 s . com
    String[] keyColumns;
    Result result;
    try {
        queryId = getQueryId(queryEl);
        configId = getConfigId(queryEl);
        sql = getSQLQueryForDatasource(queryEl, dataService, configId);
        eventTriggers = getEventTriggers(dataService, queryEl);
        String returnRowIdStr = queryEl
                .getAttributeValue(new QName(DBConstants.DBSFields.RETURN_GENERATED_KEYS));
        if (returnRowIdStr != null) {
            returnGeneratedKeys = Boolean.parseBoolean(returnRowIdStr);
        }
        String returnUpdatedRowCountStr = queryEl
                .getAttributeValue(new QName(DBSFields.RETURN_UPDATED_ROW_COUNT));
        if (null != returnUpdatedRowCountStr) {
            isReturnUpdatedRowCount = Boolean.parseBoolean(returnUpdatedRowCountStr);
        }
        keyColumns = extractKeyColumns(queryEl);
        result = getResultFromQueryElement(dataService, queryEl);
        inputNamespace = extractQueryInputNamespace(dataService, result, queryEl);
    } catch (XMLStreamException e) {
        throw new DataServiceFault(e, "Error in parsing SQL query element");
    } catch (SQLException e) {
        throw new DataServiceFault(e, DBConstants.FaultCodes.CONNECTION_UNAVAILABLE_ERROR, e.getMessage());
    }
    SQLQuery query = new SQLQuery(dataService, queryId, configId, returnGeneratedKeys, isReturnUpdatedRowCount,
            keyColumns, sql, getQueryParamsFromQueryElement(queryEl), result, eventTriggers[0],
            eventTriggers[1], extractAdvancedProps(queryEl), inputNamespace);

    return query;
}

From source file:org.wso2.carbon.esb.connector.SendMessage.java

@Override
public void connect(MessageContext messageContext) throws ConnectException {
    String targetIpAddress = (String) messageContext.getProperty(SNMPConstants.TARGET_IP_ADDRESS);
    String targetPort = (String) messageContext.getProperty(SNMPConstants.TARGET_PORT);
    String oidValue = (String) messageContext.getProperty(SNMPConstants.OID_VALUE);
    String snmpVersion = (String) messageContext.getProperty(SNMPConstants.SNMP_VERSION);
    String community = (String) messageContext.getProperty(SNMPConstants.COMMUNITY);
    String retries = (String) messageContext.getProperty(SNMPConstants.RETRIES);
    String timeout = (String) messageContext.getProperty(SNMPConstants.TIMEOUT);
    try {//from  w  ww . ja v  a 2  s  .  co m
        //Create Transport Mapping
        snmp = (Snmp) messageContext.getProperty(SNMPConstants.SNMP);
        //Create PDU
        PDU pdu = new PDU();
        // To specify the system up time
        pdu.add(new VariableBinding(SnmpConstants.sysUpTime, new OctetString(new Date().toString())));
        // variable binding for Enterprise Specific objects, Severity (should be defined in MIB file)
        addPDU(oidValue, pdu);
        pdu.setType(PDU.NOTIFICATION);
        //Send the PDU
        snmp.send(pdu, getTarget(community, targetIpAddress, targetPort, snmpVersion, retries, timeout));
        OMElement element;
        String responseMessage = "Sending V2 Trap to " + targetIpAddress + " on Port " + targetPort;
        String result = SNMPConstants.START_TAG + responseMessage + SNMPConstants.END_TAG;
        element = transformMessages(result);
        preparePayload(messageContext, element);
        stop();//TODO :  use finally to  destroy or connection pool
    } catch (XMLStreamException e) {
        handleException("Error occur when constructing OMElement" + e.getMessage(), e, messageContext);
    } catch (IOException e) {
        handleException(
                "Error in Sending V2 Trap to " + targetIpAddress + " on Port " + targetPort + e.getMessage(), e,
                messageContext);
    }
}

From source file:org.wso2.carbon.event.builder.core.internal.CarbonEventBuilderService.java

private void editEventBuilderConfiguration(String filename, AxisConfiguration axisConfiguration,
        String eventBuilderConfigXml, String originalEventBuilderName)
        throws EventBuilderConfigurationException {
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    try {//from ww w . j a  v  a2s .  c  o  m
        OMElement omElement = AXIOMUtil.stringToOM(eventBuilderConfigXml);
        if (getActiveEventBuilderConfiguration(originalEventBuilderName, tenantId) != null) {
            ConfigurationValidator.validateEventBuilderConfiguration(omElement);
        }
        String mappingType = EventBuilderConfigHelper.getInputMappingType(omElement);
        if (mappingType != null) {
            EventBuilderConfiguration eventBuilderConfigurationObject = EventBuilderConfigBuilder
                    .getEventBuilderConfiguration(omElement, mappingType, tenantId);
            if (!(eventBuilderConfigurationObject.getEventBuilderName().equals(originalEventBuilderName))) {
                if (!isEventBuilderAlreadyExists(tenantId,
                        eventBuilderConfigurationObject.getEventBuilderName())) {
                    EventBuilderConfigurationFileSystemInvoker.delete(filename, axisConfiguration);
                    EventBuilderConfigurationFileSystemInvoker.save(omElement, filename, axisConfiguration);
                } else {
                    throw new EventBuilderConfigurationException("There is already an Event Builder "
                            + eventBuilderConfigurationObject.getEventBuilderName() + " with the same name");
                }
            } else {
                EventBuilderConfigurationFileSystemInvoker.delete(filename, axisConfiguration);
                EventBuilderConfigurationFileSystemInvoker.save(omElement, filename, axisConfiguration);
            }
        } else {
            throw new EventBuilderConfigurationException(
                    "Mapping type of the Event Builder " + originalEventBuilderName + " cannot be null");
        }
    } catch (XMLStreamException e) {
        String errMsg = "Error while creating the XML object";
        log.error(errMsg);
        throw new EventBuilderConfigurationException(errMsg + ":" + e.getMessage(), e);
    }
}

From source file:org.wso2.carbon.event.builder.core.internal.type.xml.XMLInputMapper.java

private Object[][] processMultipleEvents(Object obj) throws EventBuilderProcessingException {
    if (obj instanceof String) {
        String textMessage = (String) obj;
        try {// w w  w .j a  v  a 2s .  c o  m
            obj = AXIOMUtil.stringToOM(textMessage);
        } catch (XMLStreamException e) {
            throw new EventBuilderProcessingException("Error parsing incoming XML event : " + e.getMessage(),
                    e);
        }
    }
    if (obj instanceof OMElement) {
        OMElement events;
        try {
            events = (OMElement) this.parentSelectorXpath.selectSingleNode(obj);
            if (events == null) {
                throw new RuntimeException("Parent Selector XPath \"" + parentSelectorXpath.toString()
                        + "\" cannot be processed on event:" + obj.toString());
            }

            List<Object[]> objArrayList = new ArrayList<Object[]>();
            Iterator childIterator = events.getChildElements();
            while (childIterator.hasNext()) {
                Object eventObj = childIterator.next();
                objArrayList.add(processSingleEvent(eventObj));
                /**
                 * Usually the global lookup '//' is used in the XPATH expression which works fine for 'single event mode'.
                 * However, if global lookup is used, it will return the first element from the whole document as specified in
                 * XPATH-2.0 Specification. Therefore the same XPATH expression that works fine in 'single event mode' will
                 * always return the first element of a batch in 'batch mode'. Therefore to return what the
                 * user expects, each child element is removed after sending to simulate an iteration for the
                 * global lookup.
                 */
                childIterator.remove();
            }
            return objArrayList.toArray(new Object[objArrayList.size()][]);
        } catch (JaxenException e) {
            throw new EventBuilderProcessingException(
                    "Unable to parse XPath for parent selector: " + e.getMessage(), e);
        }
    }
    return null;
}

From source file:org.wso2.carbon.event.builder.core.internal.type.xml.XMLInputMapper.java

private Object[] processSingleEvent(Object obj) throws EventBuilderProcessingException {
    Object[] outObjArray = null;/*from w  w  w .j  av  a2 s . com*/
    OMElement eventOMElement = null;
    if (obj instanceof String) {
        String textMessage = (String) obj;
        try {
            eventOMElement = AXIOMUtil.stringToOM(textMessage);
        } catch (XMLStreamException e) {
            throw new EventBuilderProcessingException("Error parsing incoming XML event : " + e.getMessage(),
                    e);
        }
    } else if (obj instanceof OMElement) {
        eventOMElement = (OMElement) obj;
    }

    if (eventOMElement != null) {
        OMNamespace omNamespace = null;
        if (this.xPathDefinitions == null || this.xPathDefinitions.isEmpty()) {
            omNamespace = eventOMElement.getNamespace();
        }
        List<Object> objList = new ArrayList<Object>();
        for (XPathData xpathData : attributeXpathList) {
            AXIOMXPath xpath = xpathData.getXpath();
            OMElement omElementResult = null;
            String type = xpathData.getType();
            try {
                if (omNamespace != null) {
                    xpath.addNamespaces(eventOMElement);
                }
                omElementResult = (OMElement) xpath.selectSingleNode(eventOMElement);
                Class<?> beanClass = Class.forName(type);
                Object returnedObj = null;
                if (omElementResult != null) {
                    returnedObj = BeanUtil.deserialize(beanClass, omElementResult,
                            reflectionBasedObjectSupplier, null);
                } else if (xpathData.getDefaultValue() != null) {
                    if (!beanClass.equals(String.class)) {
                        Class<?> stringClass = String.class;
                        Method valueOfMethod = beanClass.getMethod("valueOf", stringClass);
                        returnedObj = valueOfMethod.invoke(null, xpathData.getDefaultValue());
                    } else {
                        returnedObj = xpathData.getDefaultValue();
                    }
                    //                        throw new  EventBuilderProcessingException ("Unable to parse XPath to retrieve required attribute. Sending defaults.");
                    //                        log.warn();
                } else {
                    throw new EventBuilderProcessingException("Unable to parse XPath " + xpathData.getXpath()
                            + " to retrieve required attribute.");
                }
                objList.add(returnedObj);
            } catch (JaxenException e) {
                throw new EventBuilderProcessingException("Error parsing xpath for " + xpath, e);
            } catch (ClassNotFoundException e) {
                throw new EventBuilderProcessingException("Cannot find specified class for type " + type);
            } catch (AxisFault axisFault) {
                throw new EventBuilderProcessingException("Error de-serializing OMElement " + omElementResult,
                        axisFault);
            } catch (NoSuchMethodException e) {
                throw new EventBuilderProcessingException(
                        "Error trying to convert default value to specified target type.", e);
            } catch (InvocationTargetException e) {
                throw new EventBuilderProcessingException(
                        "Error trying to convert default value to specified target type.", e);
            } catch (IllegalAccessException e) {
                throw new EventBuilderProcessingException(
                        "Error trying to convert default value to specified target type.", e);
            }
        }
        outObjArray = objList.toArray(new Object[objList.size()]);
    }
    return outObjArray;
}

From source file:org.wso2.carbon.event.input.adaptor.manager.core.internal.CarbonInputEventAdaptorManagerService.java

public void editActiveInputEventAdaptorConfiguration(String eventAdaptorConfiguration, String eventAdaptorName,
        AxisConfiguration axisConfiguration) throws InputEventAdaptorManagerConfigurationException {
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();

    try {//w  w w . j  a  v  a 2  s  .c  o  m
        OMElement omElement = AXIOMUtil.stringToOM(eventAdaptorConfiguration);
        omElement.toString();
        InputEventAdaptorConfiguration eventAdaptorConfigurationObject = InputEventAdaptorConfigurationHelper
                .fromOM(omElement);
        if (!eventAdaptorConfigurationObject.getName().equals(eventAdaptorName)) {
            if (checkAdaptorValidity(tenantId, eventAdaptorConfigurationObject.getName())) {
                validateToEditEventAdaptorConfiguration(tenantId, eventAdaptorName, axisConfiguration,
                        omElement);
            } else {
                throw new InputEventAdaptorManagerConfigurationException(
                        "There is a event adaptor already registered with the same name");
            }
        } else {
            validateToEditEventAdaptorConfiguration(tenantId, eventAdaptorName, axisConfiguration, omElement);
        }

    } catch (XMLStreamException e) {
        log.error("Error while creating the xml object");
        throw new InputEventAdaptorManagerConfigurationException("Not a valid xml object, " + e.getMessage(),
                e);
    }
}

From source file:org.wso2.carbon.event.input.adaptor.manager.core.internal.CarbonInputEventAdaptorManagerService.java

public void editInactiveInputEventAdaptorConfiguration(String eventAdaptorConfiguration, String filename,
        AxisConfiguration axisConfiguration) throws InputEventAdaptorManagerConfigurationException {
    try {/*  w  ww. j  a  v a2  s .c om*/
        OMElement omElement = AXIOMUtil.stringToOM(eventAdaptorConfiguration);
        omElement.toString();
        int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
        InputEventAdaptorConfiguration eventAdaptorConfigurationObject = InputEventAdaptorConfigurationHelper
                .fromOM(omElement);
        if (checkAdaptorValidity(tenantId, eventAdaptorConfigurationObject.getName())) {
            if (InputEventAdaptorConfigurationHelper
                    .validateEventAdaptorConfiguration(eventAdaptorConfigurationObject)) {
                undeployInactiveInputEventAdaptorConfiguration(filename, axisConfiguration);
                InputEventAdaptorConfigurationFilesystemInvoker.save(omElement,
                        eventAdaptorConfigurationObject.getName(), filename, axisConfiguration);
            } else {
                log.error("There is no event adaptor type called " + eventAdaptorConfigurationObject.getType()
                        + " is available");
                throw new InputEventAdaptorManagerConfigurationException(
                        "There is no Input Event Adaptor type called "
                                + eventAdaptorConfigurationObject.getType() + " is available ");
            }
        } else {
            throw new InputEventAdaptorManagerConfigurationException(
                    "There is a Input Event Adaptor with the same name");
        }
    } catch (XMLStreamException e) {
        log.error("Error while creating the xml object");
        throw new InputEventAdaptorManagerConfigurationException("Not a valid xml object " + e.getMessage(), e);
    }
}

From source file:org.wso2.carbon.event.output.adaptor.manager.core.internal.CarbonOutputEventAdaptorManagerService.java

@Override
public void editActiveOutputEventAdaptorConfiguration(String eventAdaptorConfiguration, String eventAdaptorName,
        AxisConfiguration axisConfiguration) throws OutputEventAdaptorManagerConfigurationException {
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();

    try {//from w  w  w .j av a2s .c o  m
        OMElement omElement = AXIOMUtil.stringToOM(eventAdaptorConfiguration);
        omElement.toString();
        OutputEventAdaptorConfiguration eventAdaptorConfigurationObject = OutputEventAdaptorConfigurationHelper
                .fromOM(omElement);
        if (!eventAdaptorConfigurationObject.getName().equals(eventAdaptorName)) {
            if (checkAdaptorValidity(tenantId, eventAdaptorConfigurationObject.getName())) {
                validateEventAdaptorConfiguration(tenantId, eventAdaptorName, axisConfiguration, omElement);
            } else {
                throw new OutputEventAdaptorManagerConfigurationException(
                        "There is a Output Event Adaptor already registered with the same name");
            }
        } else {
            validateEventAdaptorConfiguration(tenantId, eventAdaptorName, axisConfiguration, omElement);
        }

    } catch (XMLStreamException e) {
        log.error("Error while creating the xml object");
        throw new OutputEventAdaptorManagerConfigurationException("Not a valid xml object, " + e.getMessage(),
                e);
    }
}