Example usage for javax.resource.spi IllegalStateException IllegalStateException

List of usage examples for javax.resource.spi IllegalStateException IllegalStateException

Introduction

In this page you can find the example usage for javax.resource.spi IllegalStateException IllegalStateException.

Prototype

public IllegalStateException(Throwable cause) 

Source Link

Document

Constructs a new throwable with the specified cause.

Usage

From source file:com.github.mrstampy.gameboot.concurrent.GameBootConcurrentConfiguration.java

private void checkSize(int val, String name) throws IllegalStateException {
    if (val <= 0)
        throw new IllegalStateException(name + " must be > 0");
}

From source file:com.github.mrstampy.gameboot.otp.netty.client.ClientHandler.java

private void unencrypted(ChannelHandlerContext ctx, byte[] msg) throws Exception {
    Response r = getResponse(msg);
    lastResponse = r;/*  w ww .j  a v  a2 s  .  c o m*/

    boolean c = ctx.pipeline().get(SslHandler.class) != null;

    log.info("Unencrypted: on {} channel\n{}", (c ? "secured" : "unsecured"), mapper.writeValueAsString(r));

    if (!ok(r.getResponseCode()))
        return;

    if (ResponseCode.INFO == r.getResponseCode()) {
        Object[] payload = r.getPayload();
        if (payload == null || payload.length == 0 || !(payload[0] instanceof Map<?, ?>)) {
            throw new IllegalStateException("Expecting map of systemId:[value]");
        }

        systemId = (Long) ((Map<?, ?>) payload[0]).get("systemId");

        log.info("Setting system id {}", systemId);
        clearChannel = ctx.channel();
        return;
    }

    JsonNode node = mapper.readTree(msg);
    JsonNode response = node.get("payload");

    boolean hasKey = response != null && response.isArray() && response.size() == 1;

    if (hasKey) {
        log.info("Setting key");
        otpKey = response.get(0).binaryValue();
        return;
    }

    switch (r.getType()) {
    case OtpKeyRequest.TYPE:
        log.info("Deleting key");
        otpKey = null;
        break;
    default:
        break;
    }
}

From source file:com.github.mrstampy.gameboot.otp.websocket.WebSocketEndpoint.java

private void unencrypted(Session ctx, byte[] msg) throws Exception {
    Response r = getResponse(msg);
    lastResponse = r;//from ww w  .j  a va 2 s.com

    log.info("Unencrypted: on session {}\n{}", ctx.getId(), mapper.writeValueAsString(r));

    if (!ok(r.getResponseCode()))
        return;

    if (ResponseCode.INFO == r.getResponseCode()) {
        Object[] payload = r.getPayload();
        if (payload == null || payload.length == 0 || !(payload[0] instanceof Map<?, ?>)) {
            throw new IllegalStateException("Expecting map of systemId:[value]");
        }

        systemId = (Long) ((Map<?, ?>) payload[0]).get("systemId");

        log.info("Setting system id {}", systemId);
        this.session = ctx;
        return;
    }

    JsonNode node = mapper.readTree(msg);
    JsonNode response = node.get("payload");

    boolean hasKey = response != null && response.isArray() && response.size() == 1;

    if (hasKey) {
        log.info("Setting key");
        otpKey = response.get(0).binaryValue();
        return;
    }

    switch (r.getType()) {
    case OtpKeyRequest.TYPE:
        log.info("Deleting key");
        otpKey = null;
        break;
    default:
        break;
    }
}

From source file:org.eurekastreams.server.service.restlets.ActionResource.java

/**
 * GET the activites.//ww  w  . j a  v a 2  s  . c o  m
 *
 * @param variant
 *            the variant.
 * @return the JSON.
 * @throws ResourceException
 *             the exception.
 */
@SuppressWarnings("unchecked")
@Override
public Representation represent(final Variant variant) throws ResourceException {
    String jsString = "";

    try {
        // get the action
        Object springBean = applicationContextHolder.getContext().getBean(actionKey);

        // get parameter
        Serializable actionParameter = getRequestObject();

        // create ServiceActionContext.
        PrincipalActionContext actionContext = new ClientPrincipalActionContextImpl(actionParameter, principal,
                clientUniqueId);
        actionContext.setActionId(actionKey);

        log.debug("executing action: " + actionKey + " for user: " + principal.getAccountId());

        Serializable result = "empty result";
        if (springBean instanceof ServiceAction) {
            ServiceAction action = (ServiceAction) springBean;
            if (readOnly && !action.isReadOnly()) {
                throw new IllegalStateException("Action requested is not read-only.");
            }
            result = serviceActionController.execute(actionContext, action);
        } else if (springBean instanceof TaskHandlerServiceAction) {
            TaskHandlerServiceAction action = (TaskHandlerServiceAction) springBean;
            if (readOnly && !action.isReadOnly()) {
                throw new IllegalStateException("Action requested is not read-only.");
            }
            result = serviceActionController.execute(actionContext, action);
        }

        StringWriter writer = new StringWriter();
        JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(writer);
        jsonGenerator.writeObject(result);
        writer.close();

        jsString = writer.toString();
    } catch (Exception ex) {
        log.error("Error excecuting action " + actionKey + " from restlet.", ex);
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error executing action.");
    }

    Representation rep = new StringRepresentation(jsString, MediaType.TEXT_PLAIN);
    rep.setExpirationDate(new Date(0L));
    return rep;
}