Search in sources :

Example 1 with MSSStatusReq

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

the class MssClient method createStatusRequest.

/**
 * Create a status request for a signature response.
 *
 * @param apTransId new AP transaction id
 * @param sigResp Original MSS_SignatureResp
 * @return Created MSS_StatusReq
 * @throws IllegalArgumentException if the given signature response does not contain all the necessary data to create an MSS_StatusReq
 */
public MSSStatusReq createStatusRequest(final MSSSignatureResp sigResp, final String apTransId) throws IllegalArgumentException {
    if (sigResp == null)
        throw new IllegalArgumentException("Invalid Signature Response (null)");
    if (sigResp.getMSSPInfo() == null)
        throw new IllegalArgumentException("Invalid Signature Response MSSP Info (null)");
    final MeshMemberType msspId = sigResp.getMSSPInfo().getMSSPID();
    if (msspId == null)
        throw new IllegalArgumentException("Invalid Signature Response MSSP ID");
    MSSStatusReq req = mssObjFactory.createMSSStatusReq();
    this.initializeRequestMessage(req, apTransId);
    req.getMSSPInfo().setMSSPID(msspId);
    req.setMSSPTransID(sigResp.getMSSPTransID());
    return req;
}
Also used : MSSStatusReq(fi.laverca.jaxb.mss.MSSStatusReq) MeshMemberType(fi.laverca.jaxb.mss.MeshMemberType)

Example 2 with MSSStatusReq

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

the class MssClient method sendMat.

/**
 * Sends an MSS request.
 *
 * @param req Abstract request type
 * @param context Context
 * @param security WSSE security headers
 * @throws IOException if a HTTP communication error occurred i.e. a SOAP fault was generated by the <i>local</i> SOAP client stub.
 */
private MessageAbstractType sendMat(final MessageAbstractType req, final LavercaContext context, final Security security) throws AxisFault, IOException {
    AbstractSoapBindingStub port = null;
    try {
        Long timeout = null;
        if (req instanceof MSSSignatureReq) {
            timeout = ((MSSSignatureReq) req).getTimeOut();
            port = (MSS_SignatureBindingStub) this.mssService.getMSS_SignaturePort(this.MSSP_SI_URL);
        } else if (req instanceof MSSReceiptReq) {
            port = (MSS_ReceiptBindingStub) this.mssService.getMSS_ReceiptPort(this.MSSP_RC_URL);
        } else if (req instanceof MSSHandshakeReq) {
            port = (MSS_HandshakeBindingStub) this.mssService.getMSS_HandshakePort(this.MSSP_HS_URL);
        } else if (req instanceof MSSStatusReq) {
            port = (MSS_StatusQueryBindingStub) this.mssService.getMSS_StatusQueryPort(this.MSSP_ST_URL);
        } else if (req instanceof MSSProfileReq) {
            port = (MSS_ProfileQueryBindingStub) this.mssService.getMSS_ProfileQueryPort(this.MSSP_PR_URL);
        } else if (req instanceof MSSRegistrationReq) {
            port = (MSS_RegistrationBindingStub) this.mssService.getMSS_RegistrationPort(this.MSSP_RG_URL);
        }
        if (port == null) {
            throw new IOException("Invalid request type");
        }
        if (timeout != null) {
            // ETSI TS 102 204 defines TimeOut in seconds instead of milliseconds
            port.setTimeout(timeout.intValue() * 1000);
        }
    } catch (ServiceException se) {
        log.error("Failed to get port: " + se.getMessage());
        throw new IOException(se.getMessage());
    }
    try {
        if (port._getCall() == null) {
            port._createCall();
        }
    } catch (Exception e) {
        log.fatal("Could not do port._createCall()", e);
    }
    // Set tools for each context.
    port.setProperty(ComponentsHTTPSender.HTTPCLIENT_INSTANCE, this.getHttpClient());
    LavercaSSLTrustManager.getInstance().setExpectedServerCerts(this.expectedServerCerts);
    MessageAbstractType resp = null;
    if (port instanceof MSS_SignatureBindingStub) {
        resp = ((MSS_SignatureBindingStub) port).MSS_Signature((MSSSignatureReq) req);
    } else if (port instanceof MSS_StatusQueryBindingStub) {
        resp = ((MSS_StatusQueryBindingStub) port).MSS_StatusQuery((MSSStatusReq) req);
    } else if (port instanceof MSS_ReceiptBindingStub) {
        resp = ((MSS_ReceiptBindingStub) port).MSS_Receipt((MSSReceiptReq) req);
    } else if (port instanceof MSS_HandshakeBindingStub) {
        resp = ((MSS_HandshakeBindingStub) port).MSS_Handshake((MSSHandshakeReq) req);
    } else if (port instanceof MSS_ProfileQueryBindingStub) {
        resp = ((MSS_ProfileQueryBindingStub) port).MSS_ProfileQuery((MSSProfileReq) req);
    } else if (port instanceof MSS_RegistrationBindingStub) {
        resp = ((MSS_RegistrationBindingStub) port).MSS_Registration((MSSRegistrationReq) req, security);
    } else {
        throw new IOException("Invalid call parameters");
    }
    if (context != null) {
        try {
            context.setMessageContext(port.getMessageContext());
        } catch (ServiceException e) {
            log.warn("Unable to pass context", e);
        }
    }
    return resp;
}
Also used : MSSProfileReq(fi.laverca.jaxb.mss.MSSProfileReq) MSSRegistrationReq(fi.laverca.jaxb.mss.MSSRegistrationReq) MSS_ReceiptBindingStub(fi.laverca.mss.ws.MSS_ReceiptBindingStub) MSSHandshakeReq(fi.laverca.jaxb.mss.MSSHandshakeReq) MSS_ProfileQueryBindingStub(fi.laverca.mss.ws.MSS_ProfileQueryBindingStub) MSS_StatusQueryBindingStub(fi.laverca.mss.ws.MSS_StatusQueryBindingStub) IOException(java.io.IOException) MSSSignatureReq(fi.laverca.jaxb.mss.MSSSignatureReq) MSSStatusReq(fi.laverca.jaxb.mss.MSSStatusReq) MSS_RegistrationBindingStub(fi.laverca.mss.ws.MSS_RegistrationBindingStub) GeneralSecurityException(java.security.GeneralSecurityException) ServiceException(javax.xml.rpc.ServiceException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) MSS_HandshakeBindingStub(fi.laverca.mss.ws.MSS_HandshakeBindingStub) ServiceException(javax.xml.rpc.ServiceException) MSS_SignatureBindingStub(fi.laverca.mss.ws.MSS_SignatureBindingStub) MSSReceiptReq(fi.laverca.jaxb.mss.MSSReceiptReq) MessageAbstractType(fi.laverca.jaxb.mss.MessageAbstractType) AbstractSoapBindingStub(fi.laverca.util.AbstractSoapBindingStub)

Example 3 with MSSStatusReq

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

Aggregations

MSSStatusReq (fi.laverca.jaxb.mss.MSSStatusReq)3 IOException (java.io.IOException)2 MSSHandshakeReq (fi.laverca.jaxb.mss.MSSHandshakeReq)1 MSSProfileReq (fi.laverca.jaxb.mss.MSSProfileReq)1 MSSReceiptReq (fi.laverca.jaxb.mss.MSSReceiptReq)1 MSSReceiptResp (fi.laverca.jaxb.mss.MSSReceiptResp)1 MSSRegistrationReq (fi.laverca.jaxb.mss.MSSRegistrationReq)1 MSSSignatureReq (fi.laverca.jaxb.mss.MSSSignatureReq)1 MSSSignatureResp (fi.laverca.jaxb.mss.MSSSignatureResp)1 MSSStatusResp (fi.laverca.jaxb.mss.MSSStatusResp)1 MeshMemberType (fi.laverca.jaxb.mss.MeshMemberType)1 MessageAbstractType (fi.laverca.jaxb.mss.MessageAbstractType)1 MssException (fi.laverca.mss.MssException)1 MSS_HandshakeBindingStub (fi.laverca.mss.ws.MSS_HandshakeBindingStub)1 MSS_ProfileQueryBindingStub (fi.laverca.mss.ws.MSS_ProfileQueryBindingStub)1 MSS_ReceiptBindingStub (fi.laverca.mss.ws.MSS_ReceiptBindingStub)1 MSS_RegistrationBindingStub (fi.laverca.mss.ws.MSS_RegistrationBindingStub)1 MSS_SignatureBindingStub (fi.laverca.mss.ws.MSS_SignatureBindingStub)1 MSS_StatusQueryBindingStub (fi.laverca.mss.ws.MSS_StatusQueryBindingStub)1 AbstractSoapBindingStub (fi.laverca.util.AbstractSoapBindingStub)1