Search in sources :

Example 1 with MSSSignatureResp

use of fi.laverca.jaxb.mss.MSSSignatureResp in project laverca by laverca.

the class ClientBase method initializeTask.

/**
 * Initializes a FutureTask for polling for the signature via StatusRequests.
 *
 * This is used by {@link #call(MssRequest, ResponseHandler)}.
 *
 * @param req     The request object to send
 * @param sigResp A response to the original signature request
 * @param handler A response handler for receiving asynch responses.
 * @return A FutureTask wrapping the StatusRequest poll logic
 *
 * @throws IOException if an HTTP communication error occurs or if the service returns a SOAP Fault
 */
protected FutureTask<Resp> initializeTask(final Req req, final MSSSignatureResp sigResp, final ResponseHandler<Req, Resp> handler) throws IOException {
    Callable<Resp> callable = new Callable<Resp>() {

        @Override
        public Resp call() throws Exception {
            long timeout = ClientBase.this.timeout;
            long now = System.currentTimeMillis();
            // Note that the transaction generally times out at the server at 180 s
            long deadline = now + timeout;
            Resp resp = null;
            ProgressUpdate update = new ProgressUpdate(timeout, now);
            MSSStatusResp statResp = null;
            long waitPeriod = ClientBase.this.initialWait;
            while (true) {
                // Sleep for the rest of the interval
                long timeToWait = waitPeriod - (System.currentTimeMillis() - now);
                if (timeToWait > 0)
                    Thread.sleep(timeToWait);
                now = System.currentTimeMillis();
                waitPeriod = ClientBase.this.subsequentWait;
                if (now > deadline) {
                    log.trace("Timed out");
                    handler.onError(req, new MssException("Timed out"));
                    break;
                }
                MSSStatusReq statReq = null;
                try {
                    statReq = ClientBase.this.mssClient.createStatusRequest(sigResp, req.sigReq.getAPInfo().getAPTransID());
                } catch (Throwable t) {
                    log.trace("Failed creating status request", t);
                    handler.onError(req, t);
                    break;
                }
                try {
                    log.trace("Sending statReq");
                    statResp = ClientBase.this.mssClient.send(statReq);
                    log.trace("Got statResp");
                    resp = ClientBase.this.createResp(req.sigReq, sigResp, statResp);
                    boolean done = isDone(resp);
                    boolean batchSignDone = resp.isBatchSignatureComplete();
                    long statusCode = parseStatus(statResp.getStatus());
                    if (StatusCodes.OUTSTANDING_TRANSACTION.equals(statusCode) || !batchSignDone) {
                        log.trace("Got an outstanding Status Response. Continuing to wait for a final answer.");
                        handler.onOutstandingProgress(req, update);
                        continue;
                    } else if (done) {
                        log.info("Got a final Status Response. Ending the wait.");
                        handler.onResponse(req, resp);
                        break;
                    } else {
                        log.warn("Got an abnormal Status Response. (" + statusCode + ") Ending the wait.");
                        MssException fe = new MssException("Abnormal status code " + statusCode);
                        handler.onError(req, fe);
                        break;
                    }
                } catch (AxisFault af) {
                    log.trace("Got SOAP fault", af);
                    handler.onError(req, af);
                    break;
                } catch (IOException ioe) {
                    log.trace("Got IOException", ioe);
                    throw ioe;
                }
            }
            return resp;
        }
    };
    return new FutureTask<Resp>(callable);
}
Also used : AxisFault(org.apache.axis.AxisFault) MssException(fi.laverca.mss.MssException) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) MSSStatusReq(fi.laverca.jaxb.mss.MSSStatusReq) MSSStatusResp(fi.laverca.jaxb.mss.MSSStatusResp) FutureTask(java.util.concurrent.FutureTask) MSSSignatureResp(fi.laverca.jaxb.mss.MSSSignatureResp) MSSReceiptResp(fi.laverca.jaxb.mss.MSSReceiptResp) MSSStatusResp(fi.laverca.jaxb.mss.MSSStatusResp)

Example 2 with MSSSignatureResp

use of fi.laverca.jaxb.mss.MSSSignatureResp in project laverca by laverca.

the class ClientBase method call.

/**
 * Sends a request and waits for the response.
 * Polls the server with status requests while waiting.
 *
 * <p>Response and exceptions are mainly delivered to the given response handler.
 * May also throw SOAP faults also as IOException, which is why using
 * {@link #send(MssRequest, ResponseHandler) or #callSynch(MssRequest)} instead is preferred.
 *
 * <p>Usage example:
 * <pre>
 *   try {
 *       Req req = client.call(req, new ResponseHandler&#60;Req, Resp&#62;() {
 *           &#64;Override
 *           public void onError(Req req, Throwable throwable) {
 *               // Handle error
 *           }
 *           &#64;Override
 *           public void onResponse(Req req, Resp resp) {
 *               // Handle response
 *           }
 *           &#64;Override
 *           public void onOutstandingProgress(Req req, ProgressUpdate prgUpdate) {
 *               // Handle outstanding request
 *           }
 *       });
 *   } catch (IOException e) {
 *       // Handle error
 *   }
 * </pre>
 *
 * @param req The request object to send
 * @param handler A response handler for receiving asynch responses.
 *
 * @return The request object being sent. This can be used to cancel the polling.
 *
 * @throws IllegalArgumentException if handler is null
 * @throws IOException if an IOException was caught when sending the request.
 * @deprecated Use {@link #send(MssRequest, ResponseHandler) or #callSynch(MssRequest)} instead
 */
@Deprecated
public Req call(final Req req, final ResponseHandler<Req, Resp> handler) throws IOException {
    if (handler == null) {
        throw new IllegalArgumentException("Null response handler not allowed.");
    }
    LavercaContext _context = new LavercaContext();
    MSSSignatureResp _sigResp = null;
    try {
        log.debug("Sending sigReq");
        _sigResp = this.mssClient.send(req.sigReq, _context);
        log.debug("Got resp");
        req.sigResp = _sigResp;
        req.context = _context;
    } catch (AxisFault af) {
        log.error("Got SOAP fault", af);
        handler.onError(req, af);
        return req;
    } catch (IOException ioe) {
        log.error("Got IOException ", ioe);
        throw ioe;
    }
    // Init the task and add it to the Req object
    req.ft = this.initializeTask(req, _sigResp, handler);
    log.debug("Starting calling");
    this.threadExecutor.execute(req.ft);
    return req;
}
Also used : AxisFault(org.apache.axis.AxisFault) LavercaContext(fi.laverca.util.LavercaContext) IOException(java.io.IOException) MSSSignatureResp(fi.laverca.jaxb.mss.MSSSignatureResp)

Example 3 with MSSSignatureResp

use of fi.laverca.jaxb.mss.MSSSignatureResp in project laverca by laverca.

the class ClientBase method send.

/**
 * Sends a request without waiting for a response. {@link ResponseHandler} is used to deliver the response and possible errors.
 *
 * <p>Usage example:
 * <pre>
 *     Req req = client.send(req, ResponseHandler&#60;Req, Resp&#62;() {
 *         &#64;Override
 *         public void onError(Req req, Throwable throwable) {
 *             // Handle error
 *         }
 *         &#64;Override
 *         public void onResponse(Req req, Resp resp) {
 *             // Handle response
 *         }
 *         &#64;Override
 *         public void onOutstandingProgress(Req req, ProgressUpdate prgUpdate) {
 *             // Handle outstanding request
 *         }
 *     });
 * </pre>
 *
 * @param req The request object to send
 * @param handler A response handler for receiving asynch responses.
 *
 * @return The request object being sent. This can be used to cancel the polling.
 */
public Req send(final Req req, final ResponseHandler<Req, Resp> handler) {
    if (handler == null) {
        throw new IllegalArgumentException("Null response handler not allowed.");
    }
    LavercaContext _context = new LavercaContext();
    MSSSignatureResp _sigResp = null;
    try {
        log.debug("Sending sigReq");
        _sigResp = this.mssClient.send(req.sigReq, _context);
        log.debug("Got resp");
        req.sigResp = _sigResp;
        req.context = _context;
        // Init the task and add it to the Req object
        req.ft = this.initializeTask(req, _sigResp, handler);
    } catch (IOException ioe) {
        handler.onError(req, ioe);
        return req;
    }
    log.debug("Starting calling");
    this.threadExecutor.execute(req.ft);
    return req;
}
Also used : LavercaContext(fi.laverca.util.LavercaContext) IOException(java.io.IOException) MSSSignatureResp(fi.laverca.jaxb.mss.MSSSignatureResp)

Example 4 with MSSSignatureResp

use of fi.laverca.jaxb.mss.MSSSignatureResp 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)

Example 5 with MSSSignatureResp

use of fi.laverca.jaxb.mss.MSSSignatureResp in project laverca by laverca.

the class MSS_SignatureBindingStub method MSS_Signature.

@Override
public MSSSignatureResp MSS_Signature(MSSSignatureReq req) throws java.rmi.RemoteException {
    if (super.cachedEndpoint == null) {
        throw new org.apache.axis.NoEndPointException();
    }
    Call _call1 = this.createCall(SOAPConstants.SOAP12_CONSTANTS, null, _operations[0]);
    _call1.setProperty(Call.SEND_TYPE_ATTR, Boolean.FALSE);
    _call1.setProperty(AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);
    _call1.setSOAPActionURI("#MSS_Signature");
    this.setRequestHeaders(_call1);
    Object _resp = _call1.invoke(new Object[] { req });
    if (_resp instanceof java.rmi.RemoteException) {
        throw (java.rmi.RemoteException) _resp;
    } else {
        return (MSSSignatureResp) _resp;
    }
}
Also used : Call(org.apache.axis.client.Call) MSSSignatureResp(fi.laverca.jaxb.mss.MSSSignatureResp)

Aggregations

MSSSignatureResp (fi.laverca.jaxb.mss.MSSSignatureResp)5 IOException (java.io.IOException)4 LavercaContext (fi.laverca.util.LavercaContext)3 AxisFault (org.apache.axis.AxisFault)2 MSSReceiptResp (fi.laverca.jaxb.mss.MSSReceiptResp)1 MSSStatusReq (fi.laverca.jaxb.mss.MSSStatusReq)1 MSSStatusResp (fi.laverca.jaxb.mss.MSSStatusResp)1 MssException (fi.laverca.mss.MssException)1 SynchHandler (fi.laverca.util.SynchHandler)1 SynchHandlerException (fi.laverca.util.SynchHandler.SynchHandlerException)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 FutureTask (java.util.concurrent.FutureTask)1 Call (org.apache.axis.client.Call)1