Search in sources :

Example 31 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.

the class JMSMessageReceiver method processThoughEngine.

/**
 * Process the new message through Axis2
 *
 * @param message the JMS message
 * @param ut      the UserTransaction used for receipt
 * @return true if the caller should commit
 * @throws JMSException, on JMS exceptions
 * @throws AxisFault     on Axis2 errors
 */
private boolean processThoughEngine(Message message, UserTransaction ut) throws JMSException, AxisFault {
    MessageContext msgContext = endpoint.createMessageContext();
    // set the JMS Message ID as the Message ID of the MessageContext
    try {
        msgContext.setMessageID(message.getJMSMessageID());
        String jmsCorrelationID = message.getJMSCorrelationID();
        if (jmsCorrelationID != null && jmsCorrelationID.length() > 0) {
            msgContext.setProperty(JMSConstants.JMS_COORELATION_ID, jmsCorrelationID);
        } else {
            msgContext.setProperty(JMSConstants.JMS_COORELATION_ID, message.getJMSMessageID());
        }
    } catch (JMSException ignore) {
    }
    String soapAction = JMSUtils.getProperty(message, BaseConstants.SOAPACTION);
    ContentTypeInfo contentTypeInfo = endpoint.getContentTypeRuleSet().getContentTypeInfo(message);
    if (contentTypeInfo == null) {
        throw new AxisFault("Unable to determine content type for message " + msgContext.getMessageID());
    }
    // set the message property OUT_TRANSPORT_INFO
    // the reply is assumed to be over the JMSReplyTo destination, using
    // the same incoming connection factory, if a JMSReplyTo is available
    Destination replyTo = message.getJMSReplyTo();
    if (replyTo == null) {
        // does the service specify a default reply destination ?
        String jndiReplyDestinationName = endpoint.getJndiReplyDestinationName();
        if (jndiReplyDestinationName != null) {
            replyTo = jmsConnectionFactory.getDestination(jndiReplyDestinationName, endpoint.getReplyDestinationType());
        }
    }
    if (replyTo != null) {
        msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, new JMSOutTransportInfo(jmsConnectionFactory, replyTo, contentTypeInfo.getPropertyName()));
    }
    // Setting JMSXDeliveryCount header on the message context
    try {
        int deliveryCount = message.getIntProperty(JMS_MESSAGE_DELIVERY_COUNT_HEADER);
        msgContext.setProperty(JMSConstants.DELIVERY_COUNT, deliveryCount);
    } catch (NumberFormatException nfe) {
        if (log.isDebugEnabled()) {
            log.debug("JMSXDeliveryCount is not set in the received message");
        }
    }
    JMSUtils.setSOAPEnvelope(message, msgContext, contentTypeInfo.getContentType());
    if (ut != null) {
        msgContext.setProperty(BaseConstants.USER_TRANSACTION, ut);
    }
    msgContext.setProperty(JMSConstants.PARAM_JMS_HYPHEN_MODE, endpoint.getHyphenSupport());
    jmsListener.handleIncomingMessage(msgContext, JMSUtils.getTransportHeaders(message, msgContext), soapAction, contentTypeInfo.getContentType());
    Object o = msgContext.getProperty(BaseConstants.SET_ROLLBACK_ONLY);
    if (o != null) {
        if ((o instanceof Boolean && ((Boolean) o)) || (o instanceof String && Boolean.valueOf((String) o))) {
            return false;
        }
    }
    return true;
}
Also used : AxisFault(org.apache.axis2.AxisFault) ContentTypeInfo(org.apache.axis2.transport.jms.ctype.ContentTypeInfo) MessageContext(org.apache.axis2.context.MessageContext)

Example 32 with MessageContext

use of org.apache.axis2.context.MessageContext 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 33 with MessageContext

use of org.apache.axis2.context.MessageContext 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 34 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.

the class AbstractTransportSender method createResponseMessageContext.

/**
 * Create a new axis MessageContext for an incoming response message
 * through this transport, for the given outgoing message
 *
 * @param outMsgCtx the outgoing message
 * @return the newly created message context
 */
public MessageContext createResponseMessageContext(MessageContext outMsgCtx) {
    MessageContext responseMsgCtx = null;
    try {
        responseMsgCtx = outMsgCtx.getOperationContext().getMessageContext(WSDL2Constants.MESSAGE_LABEL_IN);
    } catch (AxisFault af) {
        log.error("Error getting IN message context from the operation context", af);
    }
    if (responseMsgCtx == null) {
        responseMsgCtx = new MessageContext();
        responseMsgCtx.setOperationContext(outMsgCtx.getOperationContext());
    }
    responseMsgCtx.setIncomingTransportName(getTransportName());
    responseMsgCtx.setTransportOut(transportOut);
    responseMsgCtx.setTransportIn(transportIn);
    responseMsgCtx.setMessageID(UUIDGenerator.getUUID());
    responseMsgCtx.setDoingREST(outMsgCtx.isDoingREST());
    responseMsgCtx.setProperty(MessageContext.TRANSPORT_IN, outMsgCtx.getProperty(MessageContext.TRANSPORT_IN));
    responseMsgCtx.setAxisMessage(outMsgCtx.getOperationContext().getAxisOperation().getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE));
    responseMsgCtx.setTo(null);
    return responseMsgCtx;
}
Also used : AxisFault(org.apache.axis2.AxisFault) MessageContext(org.apache.axis2.context.MessageContext)

Example 35 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.

the class ProtocolEndpoint method createMessageContext.

public MessageContext createMessageContext() throws AxisFault {
    MessageContext msgContext = listener.createMessageContext();
    if (service != null) {
        msgContext.setAxisService(service);
        // find the operation for the message, or default to one
        Parameter operationParam = service.getParameter(BaseConstants.OPERATION_PARAM);
        QName operationQName = (operationParam != null ? BaseUtils.getQNameFromString(operationParam.getValue()) : BaseConstants.DEFAULT_OPERATION);
        AxisOperation operation = service.getOperation(operationQName);
        if (operation != null) {
            msgContext.setAxisOperation(operation);
            msgContext.setAxisMessage(operation.getMessage(WSDL2Constants.MESSAGE_LABEL_IN));
            msgContext.setSoapAction("urn:" + operation.getName().getLocalPart());
        }
    }
    return msgContext;
}
Also used : AxisOperation(org.apache.axis2.description.AxisOperation) QName(javax.xml.namespace.QName) Parameter(org.apache.axis2.description.Parameter) MessageContext(org.apache.axis2.context.MessageContext)

Aggregations

MessageContext (org.apache.axis2.context.MessageContext)35 AxisFault (org.apache.axis2.AxisFault)25 OMElement (org.apache.axiom.om.OMElement)13 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)12 IOException (java.io.IOException)11 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)11 XMLStreamException (javax.xml.stream.XMLStreamException)9 QName (javax.xml.namespace.QName)8 MessageFormatter (org.apache.axis2.transport.MessageFormatter)8 AxisOperation (org.apache.axis2.description.AxisOperation)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)5 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)5 SOAPFactory (org.apache.axiom.soap.SOAPFactory)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 OMFactory (org.apache.axiom.om.OMFactory)4 Options (org.apache.axis2.client.Options)4 Message (org.jivesoftware.smack.packet.Message)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 OutputStream (java.io.OutputStream)3