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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations