예제 #1
0
  @Get
  public void represent() {

    try {
      proxyGalInterface =
          getRestManager()
              .getClientObjectKey(-1, getClientInfo().getAddress())
              .getGatewayInterface();
      Version version = proxyGalInterface.getVersion();

      Detail _det = new Detail();
      _det.setVersion(version);

      Info _info = new Info();
      Status _st = new Status();
      _st.setCode((short) GatewayConstants.SUCCESS);
      _info.setStatus(_st);

      _info.setDetail(_det);
      getResponse().setEntity(Util.marshal(_info), MediaType.APPLICATION_XML);
      return;

    } catch (NullPointerException npe) {
      Info info = new Info();
      Status _st = new Status();
      _st.setCode((short) GatewayConstants.GENERAL_ERROR);
      _st.setMessage(npe.getMessage());
      info.setStatus(_st);
      Info.Detail detail = new Info.Detail();
      info.setDetail(detail);
      getResponse().setEntity(Util.marshal(info), MediaType.APPLICATION_XML);
      return;

    } catch (Exception e) {
      Info info = new Info();
      Status _st = new Status();
      _st.setCode((short) GatewayConstants.GENERAL_ERROR);
      _st.setMessage(e.getMessage());
      info.setStatus(_st);
      Info.Detail detail = new Info.Detail();
      info.setDetail(detail);
      getResponse().setEntity(Util.marshal(info), MediaType.APPLICATION_XML);
      return;
    }
  }
  @Get
  public void resetMethod(String body) {

    String urilistener = null;
    String timeoutString = null;
    Long timeout = -1l;
    short warmStartValue = 0x00;

    Parameter urilistenerParam =
        getRequest().getResourceRef().getQueryAsForm().getFirst(Resources.URI_PARAM_URILISTENER);
    if (urilistenerParam != null) {
      urilistener = urilistenerParam.getValue().trim();
    }
    Parameter timeoutParam =
        getRequest().getResourceRef().getQueryAsForm().getFirst(Resources.URI_PARAM_TIMEOUT);
    if (timeoutParam != null) {
      timeoutString = timeoutParam.getValue().trim();
      try {
        timeout = Long.decode("0x" + timeoutString);
      } catch (NumberFormatException nfe) {
        Info info = new Info();
        Status _st = new Status();
        _st.setCode((short) GatewayConstants.GENERAL_ERROR);
        _st.setMessage(nfe.getMessage());
        info.setStatus(_st);
        Info.Detail detail = new Info.Detail();
        info.setDetail(detail);
        getResponse().setEntity(Util.marshal(info), MediaType.APPLICATION_XML);
        return;
      }
      if (!Util.isUnsigned32(timeout)) {
        Info info = new Info();
        Status _st = new Status();
        _st.setCode((short) GatewayConstants.GENERAL_ERROR);
        _st.setMessage("Wrong timeout");
        info.setStatus(_st);
        Info.Detail detail = new Info.Detail();
        info.setDetail(detail);
        getResponse().setEntity(Util.marshal(info), MediaType.APPLICATION_XML);
        return;
      }
    } else {
      // The timeout parameter is optional. If not provided we use a
      // default.
      timeout = (long) INTERNAL_TIMEOUT;
    }

    // TODO Set the right warm start value.
    String warmparamString = null;

    Parameter warmparam =
        getRequest()
            .getResourceRef()
            .getQueryAsForm()
            .getFirst(Resources.URI_PARAM_START_MODE_RESET);
    if (warmparam != null) {
      warmparamString = warmparam.getValue().trim();
      try {
        warmStartValue = Short.decode(warmparamString);
      } catch (NumberFormatException nfe) {
        Info info = new Info();
        Status _st = new Status();
        _st.setCode((short) GatewayConstants.GENERAL_ERROR);
        _st.setMessage(nfe.getMessage());
        info.setStatus(_st);
        Info.Detail detail = new Info.Detail();
        info.setDetail(detail);
        getResponse().setEntity(Util.marshal(info), MediaType.APPLICATION_XML);
        return;
      }

    } else {
      // The warm start value is mandatory!!
      Info info = new Info();
      Status _st = new Status();
      _st.setCode((short) GatewayConstants.GENERAL_ERROR);
      _st.setMessage("The warm start value is mandatory");
      info.setStatus(_st);
      Info.Detail detail = new Info.Detail();
      info.setDetail(detail);
      getResponse().setEntity(Util.marshal(info), MediaType.APPLICATION_XML);
      return;
    }

    if (urilistenerParam == null) {
      // Sync reset
      try {
        proxyGalInterface =
            getRestManager()
                .getClientObjectKey(-1, getClientInfo().getAddress())
                .getGatewayInterface();

        Status result = proxyGalInterface.resetDongleSync(timeout, warmStartValue);
        Info info = new Info();
        info.setStatus(result);
        getResponse().setEntity(Util.marshal(info), MediaType.TEXT_XML);

      } catch (Exception e) {
        Info info = new Info();
        Status _st = new Status();
        _st.setCode((short) GatewayConstants.GENERAL_ERROR);
        _st.setMessage(e.getMessage());
        info.setStatus(_st);
        Info.Detail detail = new Info.Detail();
        info.setDetail(detail);
        getResponse().setEntity(Util.marshal(info), MediaType.APPLICATION_XML);
        return;
      }
    } else {
      // Async reset
      try {
        ClientResources rcmal =
            getRestManager()
                .getClientObjectKey(
                    Util.getPortFromUriListener(urilistener), getClientInfo().getAddress());
        proxyGalInterface = rcmal.getGatewayInterface();
        if (!urilistener.equals("")) {
          rcmal.getClientEventListener().setResetDestination(urilistener);
        }
        proxyGalInterface.resetDongle(timeout, warmStartValue);
        Info.Detail detail = new Info.Detail();
        Info infoToReturn = new Info();
        Status status = new Status();
        status.setCode((short) GatewayConstants.SUCCESS);
        infoToReturn.setStatus(status);
        infoToReturn.setRequestIdentifier(Util.getRequestIdentifier());
        infoToReturn.setDetail(detail);
        getResponse().setEntity(Util.marshal(infoToReturn), MediaType.TEXT_XML);
        return;
      } catch (Exception e) {
        Info info = new Info();
        Status _st = new Status();
        _st.setCode((short) GatewayConstants.GENERAL_ERROR);
        _st.setMessage("The warm start value is mandatory");
        info.setStatus(_st);
        Info.Detail detail = new Info.Detail();
        info.setDetail(detail);
        getResponse().setEntity(Util.marshal(info), MediaType.APPLICATION_XML);
        return;
      }
    }
  }