Search in sources :

Example 1 with Connection

use of com.ing.ifsa.api.Connection 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)

Aggregations

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 ServiceRequest (com.ing.ifsa.api.ServiceRequest)1 ServiceURI (com.ing.ifsa.api.ServiceURI)1 IFSAException (com.ing.ifsa.exceptions.IFSAException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SenderException (nl.nn.adapterframework.core.SenderException)1 TimeOutException (nl.nn.adapterframework.core.TimeOutException)1