Search in sources :

Example 26 with TransportOutDescription

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

the class SMSManager method init.

/**
 * Initialize the SMS Maneger with TransportOutDiscription
 * if the Maneger is already inited  it will set the Transport Outdetails
 * in the Current Implimentation Manage
 * @param transportOutDescription
 * @param configurationContext
 */
public void init(TransportOutDescription transportOutDescription, ConfigurationContext configurationContext) throws AxisFault {
    if (!inited) {
        basicInit(transportOutDescription, configurationContext);
    }
    Parameter formatterClass = transportOutDescription.getParameter(SMSTransportConstents.FORMATTER_CLASS);
    if (formatterClass == null) {
        messageFormatter = new DefaultSMSMessageFormatterImpl();
    } else {
        try {
            messageFormatter = (SMSMessageFormatter) Class.forName((String) formatterClass.getValue()).newInstance();
        } catch (Exception e) {
            throw new AxisFault("Error while instentiating the Class: " + formatterClass.getValue(), e);
        }
    }
    currentImplimentation.setTransportOutDetails(transportOutDescription);
    Parameter invertS_n_D = transportOutDescription.getParameter(SMSTransportConstents.INVERT_SOURCE_AND_DESTINATION);
    if (invertS_n_D != null) {
        String val = (String) invertS_n_D.getValue();
        if ("false".equals(val)) {
            invertSourceAndDestination = false;
        } else if ("true".equals(val)) {
            invertSourceAndDestination = true;
        } else {
            log.warn("Invalid parameter value set to the parameter invert_source_and_destination," + "setting the default value :true ");
            invertSourceAndDestination = true;
        }
    }
    inited = true;
}
Also used : AxisFault(org.apache.axis2.AxisFault) Parameter(org.apache.axis2.description.Parameter)

Example 27 with TransportOutDescription

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

the class MailTestEnvironment method createTransportOutDescription.

public TransportOutDescription createTransportOutDescription() throws Exception {
    TransportOutDescription trpOutDesc = new TransportOutDescription(MailConstants.TRANSPORT_NAME);
    trpOutDesc.setSender(new MailTransportSender());
    trpOutDesc.addParameter(new Parameter(MailConstants.TRANSPORT_MAIL_DEBUG, "true"));
    for (Map.Entry<String, String> prop : getOutProperties().entrySet()) {
        trpOutDesc.addParameter(new Parameter(prop.getKey(), prop.getValue()));
    }
    return trpOutDesc;
}
Also used : Parameter(org.apache.axis2.description.Parameter) Map(java.util.Map) TransportOutDescription(org.apache.axis2.description.TransportOutDescription)

Example 28 with TransportOutDescription

use of org.apache.axis2.description.TransportOutDescription in project wso2-synapse by wso2.

the class ProxyConfigBuilder method getProxyProfiles.

/**
 * Looks for a transport parameter named proxyProfiles and initializes a map of ProxyProfileConfig.
 * The syntax for defining a proxy profiles is as follows.
 * {@code
 * <parameter name="proxyProfiles">
 *      <profile>
 *          <targetHosts>example.com, *.sample.com</targetHosts>
 *          <proxyHost>localhost</proxyHost>
 *          <proxyPort>3128</proxyPort>
 *          <proxyUserName>squidUser</proxyUserName>
 *          <proxyPassword>password</proxyPassword>
 *          <bypass>xxx.sample.com</bypass>
 *      </profile>
 *      <profile>
 *          <targetHosts>localhost</targetHosts>
 *          <proxyHost>localhost</proxyHost>
 *          <proxyPort>7443</proxyPort>
 *      </profile>
 *      <profile>
 *          <targetHosts>*</targetHosts>
 *          <proxyHost>localhost</proxyHost>
 *          <proxyPort>7443</proxyPort>
 *          <bypass>test.com, direct.com</bypass>
 *      </profile>
 * </parameter>
 * }
 *
 * @param transportOut transport out description
 * @return map of <code>ProxyProfileConfig<code/> if configured in axis2.xml; otherwise null
 * @throws AxisFault if proxy profile is not properly configured
 */
private Map<String, ProxyProfileConfig> getProxyProfiles(TransportOutDescription transportOut) throws AxisFault {
    Parameter proxyProfilesParam = transportOut.getParameter("proxyProfiles");
    if (proxyProfilesParam == null) {
        return null;
    }
    if (log.isDebugEnabled()) {
        log.debug(name + " Loading proxy profiles for the HTTP/S sender");
    }
    OMElement proxyProfilesParamEle = proxyProfilesParam.getParameterElement();
    Iterator<?> profiles = proxyProfilesParamEle.getChildrenWithName(Q_PROFILE);
    Map<String, ProxyProfileConfig> proxyProfileMap = new HashMap<String, ProxyProfileConfig>();
    while (profiles.hasNext()) {
        OMElement profile = (OMElement) profiles.next();
        OMElement targetHostsEle = profile.getFirstChildWithName(Q_TARGET_HOSTS);
        if (targetHostsEle == null || targetHostsEle.getText().isEmpty()) {
            String msg = "Each proxy profile must define at least one host " + "or a wildcard matcher under the targetHosts element";
            log.error(name + " " + msg);
            throw new AxisFault(msg);
        }
        HttpHost proxy = getHttpProxy(profile, targetHostsEle.getText());
        UsernamePasswordCredentials proxyCredentials = getUsernamePasswordCredentials(profile);
        Set<String> proxyBypass = getProxyBypass(profile);
        ProxyProfileConfig proxyProfileConfig = new ProxyProfileConfig(proxy, proxyCredentials, proxyBypass);
        String[] targetHosts = targetHostsEle.getText().split(",");
        for (String endpoint : targetHosts) {
            endpoint = endpoint.trim();
            if (!proxyProfileMap.containsKey(endpoint)) {
                proxyProfileMap.put(endpoint, proxyProfileConfig);
            } else {
                log.warn(name + " Multiple proxy profiles were found for the endpoint: " + endpoint + ". Ignoring the excessive profiles.");
            }
        }
    }
    if (proxyProfileMap.size() > 0) {
        log.info(name + " Proxy profiles initialized for " + proxyProfileMap.size() + " targetHosts");
        return proxyProfileMap;
    }
    return null;
}
Also used : ProxyProfileConfig(org.apache.synapse.transport.http.conn.ProxyProfileConfig) AxisFault(org.apache.axis2.AxisFault) HashMap(java.util.HashMap) HttpHost(org.apache.http.HttpHost) Parameter(org.apache.axis2.description.Parameter) OMElement(org.apache.axiom.om.OMElement) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 29 with TransportOutDescription

use of org.apache.axis2.description.TransportOutDescription in project wso2-synapse by wso2.

the class DynamicProfileReloader method extractConfigurationFilePath.

/**
 * Set the configuration file path from custom SSL config
 *
 * @param transportOut TransportOutDescription of the configuration
 * @return File Path String
 */
protected String extractConfigurationFilePath(ParameterInclude transportOut) {
    String path = null;
    Parameter profileParam = transportOut.getParameter(PROFILE_CONFIG_NAME);
    // No Separate configuration file configured. Therefore using Axis2 Configuration
    if (profileParam != null) {
        OMElement profileParamElem = profileParam.getParameterElement();
        path = profileParamElem.getFirstChildWithName(new QName(PATH_CONFIG_NAME)).getText();
    }
    return path;
}
Also used : QName(javax.xml.namespace.QName) Parameter(org.apache.axis2.description.Parameter) OMElement(org.apache.axiom.om.OMElement)

Example 30 with TransportOutDescription

use of org.apache.axis2.description.TransportOutDescription in project wso2-synapse by wso2.

the class Axis2TransportHelper method getPendingSenderThreadCount.

/**
 * Determines the total number of pending sender threads (active + queued).
 *
 * @return the total number of pending sender threads (active + queued).
 */
public int getPendingSenderThreadCount() {
    int pendingThreads = 0;
    Map<String, TransportOutDescription> trpOuts = configurationContext.getAxisConfiguration().getTransportsOut();
    for (TransportOutDescription trpOut : trpOuts.values()) {
        TransportSender trpSnd = trpOut.getSender();
        if (trpSnd instanceof ManagementSupport) {
            int inUse = ((ManagementSupport) trpSnd).getActiveThreadCount();
            int inQue = ((ManagementSupport) trpSnd).getQueueSize();
            if ((inUse + inQue) > 0) {
                if (log.isDebugEnabled()) {
                    log.debug(new StringBuilder("Transport Sender : ").append(trpSnd.getName()).append(" currently using : ").append(inUse).append(" threads with ").append(inQue).append(" requests already queued...").toString());
                }
                pendingThreads += (inUse + inQue);
            }
        }
    }
    return pendingThreads;
}
Also used : TransportSender(org.apache.axis2.transport.TransportSender) ManagementSupport(org.apache.axis2.transport.base.ManagementSupport) TransportOutDescription(org.apache.axis2.description.TransportOutDescription)

Aggregations

TransportOutDescription (org.apache.axis2.description.TransportOutDescription)28 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)20 Parameter (org.apache.axis2.description.Parameter)17 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)16 MessageContext (org.apache.axis2.context.MessageContext)11 AxisFault (org.apache.axis2.AxisFault)9 QName (javax.xml.namespace.QName)7 OMElement (org.apache.axiom.om.OMElement)6 AxisService (org.apache.axis2.description.AxisService)6 TransportInDescription (org.apache.axis2.description.TransportInDescription)6 IOException (java.io.IOException)4 Map (java.util.Map)4 ServiceContext (org.apache.axis2.context.ServiceContext)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 HashMap (java.util.HashMap)3 OperationContext (org.apache.axis2.context.OperationContext)3 InOutAxisOperation (org.apache.axis2.description.InOutAxisOperation)3 OutTransportInfo (org.apache.axis2.transport.OutTransportInfo)3 VFSOutTransportInfo (org.apache.synapse.commons.vfs.VFSOutTransportInfo)3