Search in sources :

Example 1 with ChipGatewayResponse

use of org.openecard.addons.cg.impl.ChipGatewayResponse in project open-ecard by ecsec.

the class TCTokenHandler method processBinding.

/**
 * Performs the actual ChipGateway procedure.
 * Connects the given card, establishes the HTTP channel and talks to the server. Afterwards disconnects the card.
 *
 * @param token The TCToken containing the connection parameters.
 * @return A TCTokenResponse indicating success or failure.
 * @throws DispatcherException If there was a problem dispatching a request from the server.
 * @throws ChipGatewayException If there was a transport error.
 */
private ChipGatewayResponse processBinding(@Nonnull TCToken token) throws InvalidTCTokenElement, RedirectionBaseError, InvalidRedirectUrlException {
    ChipGatewayResponse response = new ChipGatewayResponse();
    response.setToken(token);
    String binding = token.getBinding();
    switch(binding) {
        case "http://ws.openecard.org/binding/chipgateway":
            {
                ChipGatewayTask task = new ChipGatewayTask(token, ctx);
                FutureTask<TerminateType> cgTask = new FutureTask<>(task);
                Thread cgThread = new Thread(cgTask, "ChipGateway-" + THREAD_NUM.getAndIncrement());
                cgThread.start();
                // wait for computation to finish
                waitForTask(token, cgTask, cgThread);
                break;
            }
        default:
            // unknown binding
            throw new InvalidTCTokenElement(ELEMENT_VALUE_INVALID, "Binding");
    }
    return response;
}
Also used : FutureTask(java.util.concurrent.FutureTask) ChipGatewayResponse(org.openecard.addons.cg.impl.ChipGatewayResponse) InvalidTCTokenElement(org.openecard.addons.cg.ex.InvalidTCTokenElement) ChipGatewayTask(org.openecard.addons.cg.impl.ChipGatewayTask)

Example 2 with ChipGatewayResponse

use of org.openecard.addons.cg.impl.ChipGatewayResponse in project open-ecard by ecsec.

the class TCTokenHandler method handleNoCardActivate.

/**
 * Activates the client according to the received TCToken.
 *
 * @param token The activation TCToken.
 * @return The response containing the result of the activation process.
 */
public BindingResult handleNoCardActivate(TCToken token) {
    if (LOG.isDebugEnabled()) {
        try {
            WSMarshaller m = WSMarshallerFactory.createInstance();
            LOG.debug("TCToken:\n{}", m.doc2str(m.marshal(token)));
        } catch (TransformerException | WSMarshallerException ex) {
        // it's no use
        }
    }
    try {
        // process binding and follow redirect addresses afterwards
        ChipGatewayResponse response = processBinding(token);
        // fill in values, so it is usuable by the transport module
        response.finishResponse();
        return response;
    } catch (RedirectionBaseError ex) {
        LOG.error(ex.getMessage(), ex);
        return ex.getBindingResult();
    } catch (FatalActivationError ex) {
        LOG.error(ex.getMessage(), ex);
        return ex.getBindingResult();
    }
}
Also used : FatalActivationError(org.openecard.addons.cg.ex.FatalActivationError) WSMarshallerException(org.openecard.ws.marshal.WSMarshallerException) ChipGatewayResponse(org.openecard.addons.cg.impl.ChipGatewayResponse) WSMarshaller(org.openecard.ws.marshal.WSMarshaller) TransformerException(javax.xml.transform.TransformerException) RedirectionBaseError(org.openecard.addons.cg.ex.RedirectionBaseError)

Aggregations

ChipGatewayResponse (org.openecard.addons.cg.impl.ChipGatewayResponse)2 FutureTask (java.util.concurrent.FutureTask)1 TransformerException (javax.xml.transform.TransformerException)1 FatalActivationError (org.openecard.addons.cg.ex.FatalActivationError)1 InvalidTCTokenElement (org.openecard.addons.cg.ex.InvalidTCTokenElement)1 RedirectionBaseError (org.openecard.addons.cg.ex.RedirectionBaseError)1 ChipGatewayTask (org.openecard.addons.cg.impl.ChipGatewayTask)1 WSMarshaller (org.openecard.ws.marshal.WSMarshaller)1 WSMarshallerException (org.openecard.ws.marshal.WSMarshallerException)1