Search in sources :

Example 1 with ServiceURI

use of com.ing.ifsa.api.ServiceURI in project iaf by ibissource.

the class IfsaRequesterSender method sendMessage.

/**
 * Execute a request to the IFSA service.
 * @return in Request/Reply, the retrieved message or TIMEOUT, otherwise null
 */
public String sendMessage(String dummyCorrelationId, String message, Map params) throws SenderException, TimeOutException {
    Connection conn = null;
    Map udzMap = null;
    try {
        String realServiceId;
        // Extract parameters
        if (params != null && params.size() > 0) {
            // Use first param as serviceId
            realServiceId = (String) params.get("serviceId");
            if (realServiceId == null) {
                realServiceId = getServiceId();
            }
            String occurrence = (String) params.get("occurrence");
            if (occurrence != null) {
                int i = realServiceId.indexOf('/', realServiceId.indexOf('/', realServiceId.indexOf('/', realServiceId.indexOf('/') + 1) + 1) + 1);
                int j = realServiceId.indexOf('/', i + 1);
                realServiceId = realServiceId.substring(0, i + 1) + occurrence + realServiceId.substring(j);
            }
            // Use remaining params as outgoing UDZs
            udzMap = new HashMap(params);
            udzMap.remove("serviceId");
            udzMap.remove("occurrence");
        } else {
            realServiceId = getServiceId();
        }
        // Open connection to the Application ID
        conn = ConnectionManager.getConnection(getApplicationId());
        // Create the request, and set the Service URI to the Service ID
        ServiceRequest request = new ServiceRequest(new BusinessMessage(message));
        request.setServiceURI(new ServiceURI(realServiceId));
        addUdzMapToRequest(udzMap, request);
        if (isSynchronous()) {
            // RR handling
            if (timeOut > 0) {
                request.setTimeout(timeOut);
            }
            RequestReplyAccessBean rrBean = RequestReplyAccessBean.getInstance();
            ServiceReply reply = rrBean.sendReceive(conn, request);
            return reply.getBusinessMessage().getText();
        } else {
            // FF handling
            FireForgetAccessBean ffBean = FireForgetAccessBean.getInstance();
            ffBean.send(conn, request);
            return null;
        }
    } catch (com.ing.ifsa.exceptions.TimeoutException toe) {
        throw new TimeOutException(toe);
    } catch (IFSAException e) {
        throw new SenderException(e);
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}
Also used : RequestReplyAccessBean(com.ing.ifsa.api.RequestReplyAccessBean) HashMap(java.util.HashMap) Connection(com.ing.ifsa.api.Connection) BusinessMessage(com.ing.ifsa.api.BusinessMessage) ServiceRequest(com.ing.ifsa.api.ServiceRequest) TimeOutException(nl.nn.adapterframework.core.TimeOutException) ServiceURI(com.ing.ifsa.api.ServiceURI) ServiceReply(com.ing.ifsa.api.ServiceReply) FireForgetAccessBean(com.ing.ifsa.api.FireForgetAccessBean) IFSAException(com.ing.ifsa.exceptions.IFSAException) SenderException(nl.nn.adapterframework.core.SenderException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ServiceURI

use of com.ing.ifsa.api.ServiceURI in project iaf by ibissource.

the class IfsaProviderListener method populateThreadContext.

public void populateThreadContext(Object rawMessage, Map threadContext, Session session) throws ListenerException {
    ServiceRequest request = (ServiceRequest) rawMessage;
    // Get variables from the IFSA Service Request, in as good manner
    // as possible to emulate the way that the JMS IfsaProviderListener works
    String mode = getMessageProtocol().equals("RR") ? "NON_PERSISTENT" : "PERSISTENT";
    String id = request.getUniqueId();
    String cid = id;
    if (log.isDebugEnabled()) {
        log.debug("Setting correlation ID to MessageId");
    }
    Date dTimeStamp = new Date();
    String messageText = getStringFromRawMessage(rawMessage, threadContext);
    String fullIfsaServiceName = null;
    ServiceURI requestedService = request.getServiceURI();
    String ifsaServiceName = null, ifsaGroup = null, ifsaOccurrence = null, ifsaVersion = null;
    ifsaServiceName = requestedService.getService();
    ifsaGroup = requestedService.getGroup();
    ifsaOccurrence = requestedService.getOccurrence();
    ifsaVersion = requestedService.getVersion();
    if (log.isDebugEnabled()) {
        log.debug(getLogPrefix() + "got message for [" + fullIfsaServiceName + "] with JMSDeliveryMode=[" + mode + "] \n  JMSMessageID=[" + id + "] \n  JMSCorrelationID=[" + cid + "] \n  ifsaServiceName=[" + ifsaServiceName + "] \n  ifsaGroup=[" + ifsaGroup + "] \n  ifsaOccurrence=[" + ifsaOccurrence + "] \n  ifsaVersion=[" + ifsaVersion + "] \n  Timestamp=[" + dTimeStamp.toString() + "] \n  ReplyTo=[none" + "] \n  MessageHeaders=[<unknown>" + "] \n  Message=[" + messageText + "\n]");
    }
    threadContext.put("id", id);
    threadContext.put(IPipeLineSession.technicalCorrelationIdKey, cid);
    threadContext.put("timestamp", dTimeStamp);
    threadContext.put("replyTo", "none");
    threadContext.put("messageText", messageText);
    threadContext.put("fullIfsaServiceName", fullIfsaServiceName);
    threadContext.put("ifsaServiceName", ifsaServiceName);
    threadContext.put("ifsaGroup", ifsaGroup);
    threadContext.put("ifsaOccurrence", ifsaOccurrence);
    threadContext.put("ifsaVersion", ifsaVersion);
    Map udz = request.getAllUserDefinedZones();
    if (udz != null) {
        String contextDump = "ifsaUDZ:";
        for (Iterator it = udz.keySet().iterator(); it.hasNext(); ) {
            String key = (String) it.next();
            String value = (String) udz.get(key);
            contextDump = contextDump + "\n " + key + "=[" + value + "]";
            threadContext.put(key, value);
        }
        if (log.isDebugEnabled()) {
            log.debug(getLogPrefix() + contextDump);
        }
    }
}
Also used : ServiceURI(com.ing.ifsa.api.ServiceURI) Iterator(java.util.Iterator) Map(java.util.Map) ServiceRequest(com.ing.ifsa.api.ServiceRequest) Date(java.util.Date)

Aggregations

ServiceRequest (com.ing.ifsa.api.ServiceRequest)2 ServiceURI (com.ing.ifsa.api.ServiceURI)2 Map (java.util.Map)2 BusinessMessage (com.ing.ifsa.api.BusinessMessage)1 Connection (com.ing.ifsa.api.Connection)1 FireForgetAccessBean (com.ing.ifsa.api.FireForgetAccessBean)1 RequestReplyAccessBean (com.ing.ifsa.api.RequestReplyAccessBean)1 ServiceReply (com.ing.ifsa.api.ServiceReply)1 IFSAException (com.ing.ifsa.exceptions.IFSAException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 SenderException (nl.nn.adapterframework.core.SenderException)1 TimeOutException (nl.nn.adapterframework.core.TimeOutException)1