Search in sources :

Example 11 with Parameter

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

the class RabbitMQRPCMessageSender method processResponse.

private RabbitMQMessage processResponse(String correlationID) throws IOException {
    QueueingConsumer consumer = dualChannel.getConsumer();
    QueueingConsumer.Delivery delivery = null;
    RabbitMQMessage message = new RabbitMQMessage();
    String replyToQueue = dualChannel.getReplyToQueue();
    String queueAutoDeclareStr = epProperties.get(RabbitMQConstants.QUEUE_AUTODECLARE);
    boolean queueAutoDeclare = true;
    if (!StringUtils.isEmpty(queueAutoDeclareStr)) {
        queueAutoDeclare = Boolean.parseBoolean(queueAutoDeclareStr);
    }
    if (queueAutoDeclare && !RabbitMQUtils.isQueueAvailable(dualChannel.getChannel(), replyToQueue)) {
        log.info("Reply-to queue : " + replyToQueue + " not available, hence creating a new one");
        RabbitMQUtils.declareQueue(dualChannel, replyToQueue, epProperties);
    }
    int timeout = RabbitMQConstants.DEFAULT_REPLY_TO_TIMEOUT;
    String timeoutStr = epProperties.get(RabbitMQConstants.REPLY_TO_TIMEOUT);
    if (!StringUtils.isEmpty(timeoutStr)) {
        try {
            timeout = Integer.parseInt(timeoutStr);
        } catch (NumberFormatException e) {
            log.warn("Number format error in reading replyto timeout value. Proceeding with default value (30000ms)", e);
        }
    }
    try {
        if (log.isDebugEnabled()) {
            log.debug("Waiting for delivery from reply to queue " + replyToQueue + " corr id : " + correlationID);
        }
        delivery = consumer.nextDelivery(timeout);
        if (delivery != null) {
            if (!StringUtils.isEmpty(delivery.getProperties().getCorrelationId())) {
                if (delivery.getProperties().getCorrelationId().equals(correlationID)) {
                    if (log.isDebugEnabled()) {
                        log.debug("Found matching response with correlation ID : " + correlationID + ".");
                    }
                } else {
                    log.error("Response not queued in " + replyToQueue + " for correlation ID : " + correlationID);
                    return null;
                }
            }
        } else {
            log.error("Response not queued in " + replyToQueue);
        }
    } catch (ShutdownSignalException e) {
        log.error("Error receiving message from RabbitMQ broker " + e.getLocalizedMessage());
    } catch (InterruptedException e) {
        log.error("Error receiving message from RabbitMQ broker " + e.getLocalizedMessage());
    } catch (ConsumerCancelledException e) {
        log.error("Error receiving message from RabbitMQ broker" + e.getLocalizedMessage());
    }
    if (delivery != null) {
        log.debug("Processing response from reply-to queue");
        AMQP.BasicProperties properties = delivery.getProperties();
        Map<String, Object> headers = properties.getHeaders();
        message.setBody(delivery.getBody());
        message.setDeliveryTag(delivery.getEnvelope().getDeliveryTag());
        message.setReplyTo(properties.getReplyTo());
        message.setMessageId(properties.getMessageId());
        // get content type from message
        String contentType = properties.getContentType();
        if (contentType == null) {
            // if not get content type from transport parameter
            contentType = epProperties.get(RabbitMQConstants.REPLY_TO_CONTENT_TYPE);
            if (contentType == null) {
                // if none is given, set to default content type
                log.warn("Setting default content type " + RabbitMQConstants.DEFAULT_CONTENT_TYPE);
                contentType = RabbitMQConstants.DEFAULT_CONTENT_TYPE;
            }
        }
        message.setContentType(contentType);
        message.setContentEncoding(properties.getContentEncoding());
        message.setCorrelationId(properties.getCorrelationId());
        if (headers != null) {
            message.setHeaders(headers);
            if (headers.get(RabbitMQConstants.SOAP_ACTION) != null) {
                message.setSoapAction(headers.get(RabbitMQConstants.SOAP_ACTION).toString());
            }
        }
    }
    return message;
}
Also used : ConsumerCancelledException(com.rabbitmq.client.ConsumerCancelledException) QueueingConsumer(com.rabbitmq.client.QueueingConsumer) RabbitMQMessage(org.apache.axis2.transport.rabbitmq.RabbitMQMessage) ShutdownSignalException(com.rabbitmq.client.ShutdownSignalException) AMQP(com.rabbitmq.client.AMQP)

Example 12 with Parameter

use of org.apache.axis2.transport.testkit.message.RESTMessage.Parameter 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 13 with Parameter

use of org.apache.axis2.transport.testkit.message.RESTMessage.Parameter in project MassBank-web by MassBank.

the class MassBankAPI method execBatchJob.

/**
 * バッチ処理を行う
 */
public String execBatchJob(String type, String mailAddress, String[] queryStrings, String[] instrumentTypes, String ionMode) throws AxisFault {
    String jobId = "";
    // クエリをテンポラリファイルに書き出す
    String tempFileName = "";
    try {
        tempFileName = queryStrsToTempFile(queryStrings);
    } catch (AxisFault ex) {
        throw ex;
    }
    // ---------------------------------------
    // パラメータチェック
    // ---------------------------------------
    HashMap<String, Object> mapParam = new HashMap<String, Object>();
    // massTypes は強制的にallを指定
    String[] keys = { "instrumentTypes", "massTypes", "ionMode" };
    Object[] vals = { instrumentTypes, new String[] { "all" }, ionMode };
    for (int i = 0; i < keys.length; i++) {
        mapParam.put(keys[i], vals[i]);
    }
    ApiParameter apiParam = new ApiParameter("execBatchJob", mapParam);
    if (!apiParam.check()) {
        // パラメータ不正の場合、SOAPFault を返す
        String errDetail = apiParam.getErrorDetail();
        throw new AxisFault("Invalid parameter : " + errDetail);
    }
    String param = apiParam.getCgiParam();
    if (param.charAt(0) == '&') {
        param = param.substring(1);
    }
    // ジョブ情報をセットする
    MessageContext context = MessageContext.getCurrentMessageContext();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    String time = sdf.format(new Date());
    JobInfo jobInfo = new JobInfo();
    jobInfo.setSessionId("");
    jobInfo.setIpAddr((String) context.getProperty(MessageContext.REMOTE_ADDR));
    jobInfo.setMailAddr(mailAddress);
    jobInfo.setTimeStamp(time);
    jobInfo.setQueryFileName("");
    jobInfo.setQueryFileSize("");
    jobInfo.setSearchParam(param);
    jobInfo.setTempName(tempFileName);
    JobManager jobMgr = new JobManager();
    try {
        jobId = jobMgr.addJobInfo(jobInfo);
        jobMgr.end();
    } catch (SQLException ex) {
        throw new AxisFault("System error! [code=100]");
    }
    return jobId;
}
Also used : AxisFault(org.apache.axis2.AxisFault) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) JobManager(massbank.JobManager) Date(java.util.Date) JobInfo(massbank.JobInfo) MessageContext(org.apache.axis2.context.MessageContext) SimpleDateFormat(java.text.SimpleDateFormat)

Example 14 with Parameter

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

the class BinaryBuilder method processDocument.

public OMElement processDocument(DataSource dataSource, String contentType, MessageContext msgContext) throws AxisFault {
    QName wrapperQName = BaseConstants.DEFAULT_BINARY_WRAPPER;
    if (msgContext.getAxisService() != null) {
        Parameter wrapperParam = msgContext.getAxisService().getParameter(BaseConstants.WRAPPER_PARAM);
        if (wrapperParam != null) {
            wrapperQName = BaseUtils.getQNameFromString(wrapperParam.getValue());
        }
    }
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMElement wrapper = factory.createOMElement(wrapperQName, null);
    DataHandler dataHandler = new DataHandler(dataSource);
    wrapper.addChild(factory.createOMText(dataHandler, true));
    msgContext.setDoingMTOM(true);
    return wrapper;
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) QName(javax.xml.namespace.QName) Parameter(org.apache.axis2.description.Parameter) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler)

Example 15 with Parameter

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

the class AbstractPollTableEntry method loadConfiguration.

@Override
public boolean loadConfiguration(ParameterInclude params) throws AxisFault {
    Parameter param = params.getParameter(BaseConstants.TRANSPORT_POLL_INTERVAL);
    pollInterval = BaseConstants.DEFAULT_POLL_INTERVAL;
    if (param != null && param.getValue() instanceof String) {
        String s = (String) param.getValue();
        int multiplier;
        if (s.endsWith("ms")) {
            s = s.substring(0, s.length() - 2);
            multiplier = 1;
        } else {
            multiplier = 1000;
        }
        try {
            pollInterval = Integer.parseInt(s) * multiplier;
        } catch (NumberFormatException e) {
            log.error("Invalid poll interval : " + param.getValue() + ",  default to : " + (BaseConstants.DEFAULT_POLL_INTERVAL / 1000) + "sec", e);
        }
    }
    return true;
}
Also used : Parameter(org.apache.axis2.description.Parameter)

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