Search in sources :

Example 1 with ParameterIncludeImpl

use of org.apache.axis2.description.ParameterIncludeImpl in project wso2-axis2-transports by wso2.

the class RabbitMQUtils method resolveTransportDescription.

/**
 * Resolve transport parameters
 *
 * @param trpDesc                   axis2 transport parameters
 * @param secretResolver            secure vault encryption resolver
 * @param rabbitMQConnectionFactory a rabbitmq connection factory
 * @return pool size for connection and channel pooling
 */
public static int resolveTransportDescription(ParameterInclude trpDesc, SecretResolver secretResolver, RabbitMQConnectionFactory rabbitMQConnectionFactory) throws AxisRabbitMQException {
    int poolSize = RabbitMQConstants.DEFAULT_POOL_SIZE;
    for (Parameter parameter : trpDesc.getParameters()) {
        String name = parameter.getName();
        if (StringUtils.equals(name, RabbitMQConstants.PARAM_POOL_SIZE)) {
            try {
                poolSize = Integer.parseInt((String) parameter.getValue());
            } catch (NumberFormatException e) {
                throw new AxisRabbitMQException("Pool size must be an integer value.");
            }
        } else {
            Map<String, String> parameters = new HashMap<>();
            ParameterIncludeImpl pi = new ParameterIncludeImpl();
            try {
                pi.deserializeParameters((OMElement) parameter.getValue());
            } catch (AxisFault axisFault) {
                throw new AxisRabbitMQException("Error reading parameters for RabbitMQ connection factory " + name, axisFault);
            }
            for (Parameter p : pi.getParameters()) {
                OMElement paramElement = p.getParameterElement();
                String propertyValue = p.getValue().toString();
                if (paramElement != null) {
                    OMAttribute attribute = paramElement.getAttribute(new QName(RabbitMQConstants.SECURE_VAULT_NAMESPACE, RabbitMQConstants.SECRET_ALIAS_ATTRIBUTE));
                    if (attribute != null && attribute.getAttributeValue() != null && !attribute.getAttributeValue().isEmpty()) {
                        if (secretResolver == null) {
                            throw new SecureVaultException("Axis2 Secret Resolver is null. Cannot resolve " + "encrypted entry for " + p.getName());
                        }
                        if (secretResolver.isTokenProtected(attribute.getAttributeValue())) {
                            propertyValue = secretResolver.resolve(attribute.getAttributeValue());
                        }
                    }
                }
                parameters.put(p.getName(), propertyValue);
            }
            rabbitMQConnectionFactory.addConnectionFactoryConfiguration(name, parameters);
        }
    }
    return poolSize;
}
Also used : AxisFault(org.apache.axis2.AxisFault) HashMap(java.util.HashMap) ParameterIncludeImpl(org.apache.axis2.description.ParameterIncludeImpl) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) SecureVaultException(org.wso2.securevault.SecureVaultException) Parameter(org.apache.axis2.description.Parameter) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 2 with ParameterIncludeImpl

use of org.apache.axis2.description.ParameterIncludeImpl in project wso2-axis2-transports by wso2.

the class XMPPListener method initializeConnectionFactories.

/**
 * Extract connection details & connect to those xmpp servers.
 * @param transportIn TransportInDescription
 */
private void initializeConnectionFactories(TransportInDescription transportIn) throws AxisFault {
    Iterator serversToListenOn = transportIn.getParameters().iterator();
    while (serversToListenOn.hasNext()) {
        Parameter connection = (Parameter) serversToListenOn.next();
        log.info("Trying to establish connection for : " + connection.getName());
        ParameterIncludeImpl pi = new ParameterIncludeImpl();
        try {
            pi.deserializeParameters((OMElement) connection.getValue());
        } catch (AxisFault axisFault) {
            log.error("Error reading parameters");
        }
        Iterator params = pi.getParameters().iterator();
        serverCredentials = new XMPPServerCredentials();
        while (params.hasNext()) {
            Parameter param = (Parameter) params.next();
            if (XMPPConstants.XMPP_SERVER_URL.equals(param.getName())) {
                serverCredentials.setServerUrl((String) param.getValue());
            } else if (XMPPConstants.XMPP_SERVER_USERNAME.equals(param.getName())) {
                serverCredentials.setAccountName((String) param.getValue());
            } else if (XMPPConstants.XMPP_SERVER_PASSWORD.equals(param.getName())) {
                serverCredentials.setPassword((String) param.getValue());
            } else if (XMPPConstants.XMPP_SERVER_TYPE.equals(param.getName())) {
                serverCredentials.setServerType((String) param.getValue());
            } else if (XMPPConstants.XMPP_DOMAIN_NAME.equals(param.getName())) {
                serverCredentials.setDomainName((String) param.getValue());
            }
        }
        XMPPConnectionFactory xmppConnectionFactory = new XMPPConnectionFactory();
        xmppConnectionFactory.connect(serverCredentials);
        connectionFactories.put(serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl(), xmppConnectionFactory);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) XMPPServerCredentials(org.apache.axis2.transport.xmpp.util.XMPPServerCredentials) XMPPConnectionFactory(org.apache.axis2.transport.xmpp.util.XMPPConnectionFactory) ParameterIncludeImpl(org.apache.axis2.description.ParameterIncludeImpl) Iterator(java.util.Iterator) Parameter(org.apache.axis2.description.Parameter)

Aggregations

AxisFault (org.apache.axis2.AxisFault)2 Parameter (org.apache.axis2.description.Parameter)2 ParameterIncludeImpl (org.apache.axis2.description.ParameterIncludeImpl)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 QName (javax.xml.namespace.QName)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 OMElement (org.apache.axiom.om.OMElement)1 XMPPConnectionFactory (org.apache.axis2.transport.xmpp.util.XMPPConnectionFactory)1 XMPPServerCredentials (org.apache.axis2.transport.xmpp.util.XMPPServerCredentials)1 SecureVaultException (org.wso2.securevault.SecureVaultException)1