Search in sources :

Example 1 with SynchHandlerException

use of fi.laverca.util.SynchHandler.SynchHandlerException in project laverca by laverca.

the class ClientBase method send.

/**
 * Sends a request and waits for the response.
 *
 * <p>Usage example:
 * <pre>
 *   try {
 *       Response resp = client.send(req);
 *       // Handle response
 *   } catch (IOException ioe) {
 *       // Handle error
 *   }
 * </pre>
 *
 * @param req The request object to send
 * @return The request object being sent. This can be used to cancel the polling.
 *
 * @throws IOException if an HTTP communication error occurs or if the service returns a SOAP Fault
 */
public Resp send(final Req req) throws IOException {
    LavercaContext _context = new LavercaContext();
    MSSSignatureResp _sigResp = null;
    log.debug("Sending sigReq");
    _sigResp = this.mssClient.send(req.sigReq, _context);
    log.debug("Got resp");
    if (req.isSynchronous()) {
        return this.createResp(req.sigReq, _sigResp, null);
    } else {
        req.sigResp = _sigResp;
        req.context = _context;
        // Init the task and add it to the Req object
        try {
            req.ft = this.initializeTask(req, _sigResp, new SynchHandler<Req, Resp>());
        } catch (SynchHandlerException e) {
            if (e.getCause() instanceof IOException)
                throw e;
            else
                throw new IOException(e.getCause());
        }
        log.debug("Starting calling");
        this.threadExecutor.execute(req.ft);
        try {
            return req.waitForResponse();
        } catch (InterruptedException | ExecutionException e) {
            throw new IOException(e);
        }
    }
}
Also used : LavercaContext(fi.laverca.util.LavercaContext) SynchHandler(fi.laverca.util.SynchHandler) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) SynchHandlerException(fi.laverca.util.SynchHandler.SynchHandlerException) MSSSignatureResp(fi.laverca.jaxb.mss.MSSSignatureResp)

Aggregations

MSSSignatureResp (fi.laverca.jaxb.mss.MSSSignatureResp)1 LavercaContext (fi.laverca.util.LavercaContext)1 SynchHandler (fi.laverca.util.SynchHandler)1 SynchHandlerException (fi.laverca.util.SynchHandler.SynchHandlerException)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1