Search in sources :

Example 21 with Parameter

use of org.apache.axis2.transport.testkit.message.RESTMessage.Parameter in project wso2-axis2-transports by wso2.

the class JMSSenderTestCase method testTransactionCommandParameter.

/**
 * Test case for EI-1244.
 * test transport.jms.TransactionCommand parameter in transport url when sending the message.
 * This will verify the fixes which prevent possible OOM issue when publishing messages to a broker using jms.
 *
 * @throws Exception
 */
public void testTransactionCommandParameter() throws Exception {
    JMSSender jmsSender = PowerMockito.spy(new JMSSender());
    JMSOutTransportInfo jmsOutTransportInfo = Mockito.mock(JMSOutTransportInfo.class);
    JMSMessageSender jmsMessageSender = Mockito.mock(JMSMessageSender.class);
    Session session = Mockito.mock(Session.class);
    Mockito.doReturn(session).when(jmsMessageSender).getSession();
    PowerMockito.whenNew(JMSOutTransportInfo.class).withArguments(any(String.class)).thenReturn(jmsOutTransportInfo);
    Mockito.doReturn(jmsMessageSender).when(jmsOutTransportInfo).createJMSSender(any(MessageContext.class));
    PowerMockito.doNothing().when(jmsSender, "sendOverJMS", ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any());
    jmsSender.init(new ConfigurationContext(new AxisConfiguration()), new TransportOutDescription("jms"));
    MessageContext messageContext = new MessageContext();
    // append the transport.jms.TransactionCommand
    String targetAddress = "jms:/SimpleStockQuoteService?transport.jms.ConnectionFactoryJNDIName=" + "QueueConnectionFactory&transport.jms.TransactionCommand=begin" + "&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory";
    Transaction transaction = new TestJMSTransaction();
    messageContext.setProperty(JMSConstants.JMS_XA_TRANSACTION, transaction);
    jmsSender.sendMessage(messageContext, targetAddress, null);
    Map<Transaction, ArrayList<JMSMessageSender>> jmsMessageSenderMap = Whitebox.getInternalState(JMSSender.class, "jmsMessageSenderMap");
    Assert.assertEquals("Transaction not added to map", 1, jmsMessageSenderMap.size());
    List senderList = jmsMessageSenderMap.get(transaction);
    Assert.assertNotNull("List is null", senderList);
    Assert.assertEquals("List is empty", 1, senderList.size());
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ArrayList(java.util.ArrayList) Transaction(javax.transaction.Transaction) ArrayList(java.util.ArrayList) List(java.util.List) MessageContext(org.apache.axis2.context.MessageContext) Session(javax.jms.Session) TransportOutDescription(org.apache.axis2.description.TransportOutDescription)

Example 22 with Parameter

use of org.apache.axis2.transport.testkit.message.RESTMessage.Parameter in project wso2-axis2-transports by wso2.

the class XMPPSender method getConnectionDetailsFromAxisConfiguration.

/**
 * Extract connection details from axis2.xml's transportsender section
 * @param serverCredentials
 * @param transportOut
 */
private void getConnectionDetailsFromAxisConfiguration(TransportOutDescription transportOut) {
    if (transportOut != null) {
        Parameter serverUrl = transportOut.getParameter(XMPPConstants.XMPP_SERVER_URL);
        if (serverUrl != null) {
            serverCredentials.setServerUrl(Utils.getParameterValue(serverUrl));
        }
        Parameter userName = transportOut.getParameter(XMPPConstants.XMPP_SERVER_USERNAME);
        if (userName != null) {
            serverCredentials.setAccountName(Utils.getParameterValue(userName));
        }
        Parameter password = transportOut.getParameter(XMPPConstants.XMPP_SERVER_PASSWORD);
        if (password != null) {
            serverCredentials.setPassword(Utils.getParameterValue(password));
        }
        Parameter serverType = transportOut.getParameter(XMPPConstants.XMPP_SERVER_TYPE);
        if (serverType != null) {
            serverCredentials.setServerType(Utils.getParameterValue(serverType));
        }
        Parameter domainName = transportOut.getParameter(XMPPConstants.XMPP_DOMAIN_NAME);
        if (serverUrl != null) {
            serverCredentials.setDomainName(Utils.getParameterValue(domainName));
        }
    }
}
Also used : Parameter(org.apache.axis2.description.Parameter)

Example 23 with Parameter

use of org.apache.axis2.transport.testkit.message.RESTMessage.Parameter in project wso2-axis2-transports by wso2.

the class XMPPSender method getParameterListForOperation.

/**
 * Retrieves list of parameter names & their type for a given operation
 * @param operation
 */
private static String getParameterListForOperation(AxisOperation operation) {
    // Logic copied from BuilderUtil.buildsoapMessage(...)
    StringBuffer paramList = new StringBuffer();
    AxisMessage axisMessage = operation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
    XmlSchemaElement xmlSchemaElement = axisMessage.getSchemaElement();
    if (xmlSchemaElement != null) {
        XmlSchemaType schemaType = xmlSchemaElement.getSchemaType();
        if (schemaType instanceof XmlSchemaComplexType) {
            XmlSchemaComplexType complexType = ((XmlSchemaComplexType) schemaType);
            XmlSchemaParticle particle = complexType.getParticle();
            if (particle instanceof XmlSchemaSequence || particle instanceof XmlSchemaAll) {
                XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) particle;
                Iterator iterator = xmlSchemaGroupBase.getItems().getIterator();
                while (iterator.hasNext()) {
                    XmlSchemaElement innerElement = (XmlSchemaElement) iterator.next();
                    QName qName = innerElement.getQName();
                    if (qName == null && innerElement.getSchemaTypeName().equals(org.apache.ws.commons.schema.constants.Constants.XSD_ANYTYPE)) {
                        break;
                    }
                    long minOccurs = innerElement.getMinOccurs();
                    boolean nillable = innerElement.isNillable();
                    String name = qName != null ? qName.getLocalPart() : innerElement.getName();
                    String type = innerElement.getSchemaTypeName().toString();
                    paramList.append("," + type + " " + name);
                }
            }
        }
    }
    // remove first ","
    String list = paramList.toString();
    return list.replaceFirst(",", "");
}
Also used : XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) QName(javax.xml.namespace.QName) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlSchemaGroupBase(org.apache.ws.commons.schema.XmlSchemaGroupBase) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaAll(org.apache.ws.commons.schema.XmlSchemaAll) Iterator(java.util.Iterator) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) AxisMessage(org.apache.axis2.description.AxisMessage)

Example 24 with Parameter

use of org.apache.axis2.transport.testkit.message.RESTMessage.Parameter in project wso2-axis2-transports by wso2.

the class JMSTransportDescriptionFactory method setupConnectionFactoryConfig.

private void setupConnectionFactoryConfig(ParameterInclude trpDesc, String name, String connFactName, String type) throws AxisFault {
    OMElement element = createParameterElement(JMSConstants.DEFAULT_CONFAC_NAME, null);
    element.addChild(createParameterElement(Context.INITIAL_CONTEXT_FACTORY, MockContextFactory.class.getName()));
    element.addChild(createParameterElement(JMSConstants.PARAM_CONFAC_JNDI_NAME, connFactName));
    if (type != null) {
        element.addChild(createParameterElement(JMSConstants.PARAM_CONFAC_TYPE, type));
    }
    element.addChild(createParameterElement(JMSConstants.PARAM_CONCURRENT_CONSUMERS, Integer.toString(concurrentConsumers)));
    trpDesc.addParameter(new Parameter(name, element));
}
Also used : Parameter(org.apache.axis2.description.Parameter) OMElement(org.apache.axiom.om.OMElement)

Example 25 with Parameter

use of org.apache.axis2.transport.testkit.message.RESTMessage.Parameter in project wso2-axis2-transports by wso2.

the class PollTableEntry method loadConfiguration.

@Override
public boolean loadConfiguration(ParameterInclude paramIncl) throws AxisFault {
    String address = ParamUtils.getOptionalParam(paramIncl, MailConstants.TRANSPORT_MAIL_ADDRESS);
    if (address == null) {
        return false;
    } else {
        try {
            emailAddress = new InternetAddress(address);
        } catch (AddressException e) {
            throw new AxisFault("Invalid email address specified by '" + MailConstants.TRANSPORT_MAIL_ADDRESS + "' parameter :: " + e.getMessage());
        }
        List<Parameter> params = paramIncl.getParameters();
        Properties props = new Properties();
        for (Parameter p : params) {
            if (p.getName().startsWith("mail.")) {
                props.setProperty(p.getName(), (String) p.getValue());
            }
            if (MailConstants.MAIL_POP3_USERNAME.equals(p.getName()) || MailConstants.MAIL_IMAP_USERNAME.equals(p.getName())) {
                userName = (String) p.getValue();
            }
            if (MailConstants.MAIL_POP3_PASSWORD.equals(p.getName()) || MailConstants.MAIL_IMAP_PASSWORD.equals(p.getName())) {
                password = (String) p.getValue();
            }
            if (MailConstants.TRANSPORT_MAIL_PROTOCOL.equals(p.getName())) {
                protocol = (String) p.getValue();
            }
        }
        session = Session.getInstance(props, null);
        MailUtils.setupLogging(session, log, paramIncl);
        contentType = ParamUtils.getOptionalParam(paramIncl, MailConstants.TRANSPORT_MAIL_CONTENT_TYPE);
        try {
            String replyAddress = ParamUtils.getOptionalParam(paramIncl, MailConstants.TRANSPORT_MAIL_REPLY_ADDRESS);
            if (replyAddress != null) {
                this.replyAddress = new InternetAddress(replyAddress);
            }
        } catch (AddressException e) {
            throw new AxisFault("Invalid email address specified by '" + MailConstants.TRANSPORT_MAIL_REPLY_ADDRESS + "' parameter :: " + e.getMessage());
        }
        folder = ParamUtils.getOptionalParam(paramIncl, MailConstants.TRANSPORT_MAIL_FOLDER);
        addPreserveHeaders(ParamUtils.getOptionalParam(paramIncl, MailConstants.TRANSPORT_MAIL_PRESERVE_HEADERS));
        addRemoveHeaders(ParamUtils.getOptionalParam(paramIncl, MailConstants.TRANSPORT_MAIL_REMOVE_HEADERS));
        String option = ParamUtils.getOptionalParam(paramIncl, MailConstants.TRANSPORT_MAIL_ACTION_AFTER_PROCESS);
        actionAfterProcess = MailTransportListener.MOVE.equals(option) ? PollTableEntry.MOVE : PollTableEntry.DELETE;
        option = ParamUtils.getOptionalParam(paramIncl, MailConstants.TRANSPORT_MAIL_ACTION_AFTER_FAILURE);
        actionAfterFailure = MailTransportListener.MOVE.equals(option) ? PollTableEntry.MOVE : PollTableEntry.DELETE;
        moveAfterProcess = ParamUtils.getOptionalParam(paramIncl, MailConstants.TRANSPORT_MAIL_MOVE_AFTER_PROCESS);
        moveAfterFailure = ParamUtils.getOptionalParam(paramIncl, MailConstants.TRANSPORT_MAIL_MOVE_AFTER_FAILURE);
        String processInParallel = ParamUtils.getOptionalParam(paramIncl, MailConstants.TRANSPORT_MAIL_PROCESS_IN_PARALLEL);
        if (processInParallel != null) {
            processingMailInParallel = Boolean.parseBoolean(processInParallel);
            if (log.isDebugEnabled() && processingMailInParallel) {
                log.debug("Parallel mail processing enabled for : " + address);
            }
        }
        String pollInParallel = ParamUtils.getOptionalParam(paramIncl, BaseConstants.TRANSPORT_POLL_IN_PARALLEL);
        if (pollInParallel != null) {
            setConcurrentPollingAllowed(Boolean.parseBoolean(pollInParallel));
            if (log.isDebugEnabled() && isConcurrentPollingAllowed()) {
                log.debug("Concurrent mail polling enabled for : " + address);
            }
        }
        String strMaxRetryCount = ParamUtils.getOptionalParam(paramIncl, MailConstants.MAX_RETRY_COUNT);
        if (strMaxRetryCount != null) {
            maxRetryCount = Integer.parseInt(strMaxRetryCount);
        }
        String strReconnectTimeout = ParamUtils.getOptionalParam(paramIncl, MailConstants.RECONNECT_TIMEOUT);
        if (strReconnectTimeout != null) {
            reconnectTimeout = Integer.parseInt(strReconnectTimeout) * 1000;
        }
        return super.loadConfiguration(paramIncl);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) InternetAddress(javax.mail.internet.InternetAddress) AddressException(javax.mail.internet.AddressException) Parameter(org.apache.axis2.description.Parameter) Properties(java.util.Properties)

Aggregations

Parameter (org.apache.axis2.description.Parameter)23 AxisFault (org.apache.axis2.AxisFault)10 AxisService (org.apache.axis2.description.AxisService)6 QName (javax.xml.namespace.QName)4 MessageContext (org.apache.axis2.context.MessageContext)4 Iterator (java.util.Iterator)3 OMElement (org.apache.axiom.om.OMElement)3 AxisOperation (org.apache.axis2.description.AxisOperation)3 AMQP (com.rabbitmq.client.AMQP)2 List (java.util.List)2 Map (java.util.Map)2 TransportOutDescription (org.apache.axis2.description.TransportOutDescription)2 ConsumerCancelledException (com.rabbitmq.client.ConsumerCancelledException)1 QueueingConsumer (com.rabbitmq.client.QueueingConsumer)1 ShutdownSignalException (com.rabbitmq.client.ShutdownSignalException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 PrintWriter (java.io.PrintWriter)1