Example #1
0
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    String fowarding = "/guestbook";
    RequestDispatcher rd = req.getRequestDispatcher(fowarding);

    try {
      rd.forward(req, resp);
    } catch (ServletException e) {
      e.printStackTrace();
    }
  }
  public int doStartTag() throws JspException {
    try {
      HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
      ModuleContext context = (ModuleContext) request.getSession().getAttribute("context");

      String viewObject = request.getParameter("viewObject");
      viewObject = (viewObject == null || viewObject.equals("")) ? "xava_view" : viewObject;
      View view = (View) context.get(request, viewObject);

      MetaReference metaReference = view.getMetaReference(reference).cloneMetaReference();
      metaReference.setName(reference);
      String prefix = request.getParameter("propertyPrefix");
      prefix = prefix == null ? "" : prefix;
      String application = request.getParameter("application");
      String module = request.getParameter("module");
      String referenceKey = Ids.decorate(application, module, prefix + reference);
      request.setAttribute(referenceKey, metaReference);
      String editorURL =
          "reference.jsp?referenceKey="
              + referenceKey
              + "&onlyEditor=true&frame=false&composite=false&descriptionsList=true";
      String editorPrefix = Module.isPortlet() ? "/WEB-INF/jsp/xava/" : "/xava/";
      try {
        pageContext.include(editorPrefix + editorURL);
      } catch (ServletException ex) {
        Throwable cause = ex.getRootCause() == null ? ex : ex.getRootCause();
        log.error(cause.getMessage(), cause);
        pageContext.include(editorPrefix + "editors/notAvailableEditor.jsp");
      } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
        pageContext.include(editorPrefix + "editors/notAvailableEditor.jsp");
      }
    } catch (Exception ex) {
      log.error(ex.getMessage(), ex);
      throw new JspException(XavaResources.getString("descriptionsList_tag_error", reference));
    }
    return SKIP_BODY;
  }
  /*
   * Procesamiento de peticiones GET y POST
   * @param request
   * @param response
   * @throws ServletException
   * @throws IOException
   */
  public final void service(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    // Comprobar si es un GET
    if (request.getMethod().equalsIgnoreCase("GET")) {
      return;
    }

    // Se trata de un POST

    // La respuesta es JSON
    response.setContentType("application/json; charset=UTF-8");

    // Crear los filtros definidos para todos los servicios
    es.tid.frawa.service.servlet.Filter[] filters = new es.tid.frawa.service.servlet.Filter[0];

    PrintWriter output = null;

    StringBuffer input = null;

    String action = "";

    try {
      // Crea una sesión si no existe (esta opción está marcada en el modelo de servicios)
      request.getSession(true);

      // Invocar el método startService() de los filtros
      for (int i = 0; i < filters.length; i++) {
        filters[i].startService(request, response);
      }

      // Invocar el método frawaService() de la clase derivada (si está implementado)
      if (!frawaService(request, response)) {
        // Ha retornado false, por tanto abortamos el procesamiento del servicio
        return;
      }

      // Mensaje por defecto para los filtros que no necesitan el texto JSON
      StringBuffer soapStr = new StringBuffer("");

      // Leer el mensaje JSON

      if (request.getParameter("JSONAction") != null
          && request.getParameter("JSONAction").length() > 0) {
        action = request.getParameter("JSONAction");
        String tmp = request.getParameter("JSON");
        if (tmp == null || tmp.length() == 0) {
          throw new Exception(
              getClass().getName()
                  + ".service() JSONAction viene en la URL pero no viene el parámetro JSON con los datos");
        }
        input = new StringBuffer(tmp);
      } else {
        action = request.getHeader("JSONAction");
        if (action == null || action.length() == 0) {
          throw new Exception(
              getClass().getName() + ".service() La cabecera HTTP JSONAction no esta definida");
        }
        // new es.tid.frawa.common.TdiFrawaTraceListener().trace(getClass().getName()+".service()
        // Leyendo mensaje JSON");
        BufferedReader input_r = new BufferedReader(request.getReader());
        input = new StringBuffer();
        String line = input_r.readLine();
        while (line != null) {
          input.append(line);
          line = input_r.readLine();
        }
      }

      // Invocar el método beforeParse() de los filtros
      for (int i = 0; i < filters.length; i++) {
        filters[i].beforeParse(request, response, input.toString());
      }

      //
      // Invocar al servicio adecuado en función del header JSONAction
      //

      if (action.equals("http://www.qualipso.org/advdoc/ws/storage/CreateFolder")) {

        // SERVICIO: CreateFolder

        // Parámetro de entrada al servicio
        CreateFolder_req inbean = new CreateFolder_req();
        inbean.fromJSON(input.toString());

        // Invocar el método beforeService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].beforeService(request, response, inbean, "QualiPSoStorage", action);
        }

        // Parámetro de salida del servicio
        CreateFolder_resp outbean = new CreateFolder_resp();

        // Crear un objeto que implementa la operación
        CreateFolderService serviceImplementation = new CreateFolderService();

        // Invocar la implementación de la operación
        Throwable applicationException =
            serviceImplementation.executeImpl(this, request, response, inbean, outbean);

        // Si ha ocurrido una excepción, enviarla al cliente
        if (applicationException != null) {
          // Traza
          // new es.tid.frawa.common.TdiFrawaTraceListener().trace(applicationException);
          new es.tid.frawa.common.TdiFrawaTraceListener().trace(applicationException);
          output = response.getWriter();
          if (applicationException instanceof TdiServiceException) {
            sendError(output, (TdiServiceException) applicationException);
          } else {
            String inputBean = tdi.text.StringUtil.escapeXML(inbean.toString(), false);
            String rc = "\n";
            sendError(
                output,
                new TdiServiceException(
                    1,
                    "." + rc + "[Operation: CreateFolder]" + rc + inputBean + rc + ".",
                    applicationException.getClass().getName()
                        + ":"
                        + applicationException.getMessage()));
          }
          return;
        }

        // Invocar el método afterService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].afterService(request, response, outbean, "QualiPSoStorage", action);
        }

        // Respuesta
        output = response.getWriter();

        // Bean de salida
        String output_str = outbean.toJSON(false);

        // Invocar el método afterParse() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].afterParse(request, response, output_str.toString());
        }

        // Enviar la respuesta
        output.println(output_str);

        // Invocar el método endService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].endService(request, response);
        }

      } else if (action.equals("http://www.qualipso.org/advdoc/ws/storage/GetFiles")) {

        // SERVICIO: GetFiles

        // Parámetro de entrada al servicio
        GetFiles_req inbean = new GetFiles_req();
        inbean.fromJSON(input.toString());

        // Invocar el método beforeService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].beforeService(request, response, inbean, "QualiPSoStorage", action);
        }

        // Parámetro de salida del servicio
        GetFiles_resp outbean = new GetFiles_resp();

        // Crear un objeto que implementa la operación
        GetFilesService serviceImplementation = new GetFilesService();

        // Invocar la implementación de la operación
        Throwable applicationException =
            serviceImplementation.executeImpl(this, request, response, inbean, outbean);

        // Si ha ocurrido una excepción, enviarla al cliente
        if (applicationException != null) {
          // Traza
          // new es.tid.frawa.common.TdiFrawaTraceListener().trace(applicationException);
          new es.tid.frawa.common.TdiFrawaTraceListener().trace(applicationException);
          output = response.getWriter();
          if (applicationException instanceof TdiServiceException) {
            sendError(output, (TdiServiceException) applicationException);
          } else {
            String inputBean = tdi.text.StringUtil.escapeXML(inbean.toString(), false);
            String rc = "\n";
            sendError(
                output,
                new TdiServiceException(
                    1,
                    "." + rc + "[Operation: GetFiles]" + rc + inputBean + rc + ".",
                    applicationException.getClass().getName()
                        + ":"
                        + applicationException.getMessage()));
          }
          return;
        }

        // Invocar el método afterService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].afterService(request, response, outbean, "QualiPSoStorage", action);
        }

        // Respuesta
        output = response.getWriter();

        // Bean de salida
        String output_str = outbean.toJSON(false);

        // Invocar el método afterParse() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].afterParse(request, response, output_str.toString());
        }

        // Enviar la respuesta
        output.println(output_str);

        // Invocar el método endService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].endService(request, response);
        }

      } else if (action.equals("http://www.qualipso.org/advdoc/ws/storage/GetSubFolders")) {

        // SERVICIO: GetSubFolders

        // Parámetro de entrada al servicio
        GetSubFolders_req inbean = new GetSubFolders_req();
        inbean.fromJSON(input.toString());

        // Invocar el método beforeService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].beforeService(request, response, inbean, "QualiPSoStorage", action);
        }

        // Parámetro de salida del servicio
        GetSubFolders_resp outbean = new GetSubFolders_resp();

        // Crear un objeto que implementa la operación
        GetSubFoldersService serviceImplementation = new GetSubFoldersService();

        // Invocar la implementación de la operación
        Throwable applicationException =
            serviceImplementation.executeImpl(this, request, response, inbean, outbean);

        // Si ha ocurrido una excepción, enviarla al cliente
        if (applicationException != null) {
          // Traza
          // new es.tid.frawa.common.TdiFrawaTraceListener().trace(applicationException);
          new es.tid.frawa.common.TdiFrawaTraceListener().trace(applicationException);
          output = response.getWriter();
          if (applicationException instanceof TdiServiceException) {
            sendError(output, (TdiServiceException) applicationException);
          } else {
            String inputBean = tdi.text.StringUtil.escapeXML(inbean.toString(), false);
            String rc = "\n";
            sendError(
                output,
                new TdiServiceException(
                    1,
                    "." + rc + "[Operation: GetSubFolders]" + rc + inputBean + rc + ".",
                    applicationException.getClass().getName()
                        + ":"
                        + applicationException.getMessage()));
          }
          return;
        }

        // Invocar el método afterService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].afterService(request, response, outbean, "QualiPSoStorage", action);
        }

        // Respuesta
        output = response.getWriter();

        // Bean de salida
        String output_str = outbean.toJSON(false);

        // Invocar el método afterParse() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].afterParse(request, response, output_str.toString());
        }

        // Enviar la respuesta
        output.println(output_str);

        // Invocar el método endService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].endService(request, response);
        }

      } else if (action.equals("http://www.qualipso.org/advdoc/ws/storage/LoadBinaryFile")) {

        // SERVICIO: LoadBinaryFile

        // Parámetro de entrada al servicio
        LoadBinaryFile_req inbean = new LoadBinaryFile_req();
        inbean.fromJSON(input.toString());

        // Invocar el método beforeService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].beforeService(request, response, inbean, "QualiPSoStorage", action);
        }

        // Parámetro de salida del servicio
        LoadBinaryFile_resp outbean = new LoadBinaryFile_resp();

        // Crear un objeto que implementa la operación
        LoadBinaryFileService serviceImplementation = new LoadBinaryFileService();

        // Invocar la implementación de la operación
        Throwable applicationException =
            serviceImplementation.executeImpl(this, request, response, inbean, outbean);

        // Si ha ocurrido una excepción, enviarla al cliente
        if (applicationException != null) {
          // Traza
          // new es.tid.frawa.common.TdiFrawaTraceListener().trace(applicationException);
          new es.tid.frawa.common.TdiFrawaTraceListener().trace(applicationException);
          output = response.getWriter();
          if (applicationException instanceof TdiServiceException) {
            sendError(output, (TdiServiceException) applicationException);
          } else {
            String inputBean = tdi.text.StringUtil.escapeXML(inbean.toString(), false);
            String rc = "\n";
            sendError(
                output,
                new TdiServiceException(
                    1,
                    "." + rc + "[Operation: LoadBinaryFile]" + rc + inputBean + rc + ".",
                    applicationException.getClass().getName()
                        + ":"
                        + applicationException.getMessage()));
          }
          return;
        }

        // Invocar el método afterService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].afterService(request, response, outbean, "QualiPSoStorage", action);
        }

        // Respuesta
        output = response.getWriter();

        // Bean de salida
        String output_str = outbean.toJSON(false);

        // Invocar el método afterParse() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].afterParse(request, response, output_str.toString());
        }

        // Enviar la respuesta
        output.println(output_str);

        // Invocar el método endService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].endService(request, response);
        }

      } else if (action.equals("http://www.qualipso.org/advdoc/ws/storage/LoadFile")) {

        // SERVICIO: LoadFile

        // Parámetro de entrada al servicio
        LoadFile_req inbean = new LoadFile_req();
        inbean.fromJSON(input.toString());

        // Invocar el método beforeService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].beforeService(request, response, inbean, "QualiPSoStorage", action);
        }

        // Parámetro de salida del servicio
        LoadFile_resp outbean = new LoadFile_resp();

        // Crear un objeto que implementa la operación
        LoadFileService serviceImplementation = new LoadFileService();

        // Invocar la implementación de la operación
        Throwable applicationException =
            serviceImplementation.executeImpl(this, request, response, inbean, outbean);

        // Si ha ocurrido una excepción, enviarla al cliente
        if (applicationException != null) {
          // Traza
          // new es.tid.frawa.common.TdiFrawaTraceListener().trace(applicationException);
          new es.tid.frawa.common.TdiFrawaTraceListener().trace(applicationException);
          output = response.getWriter();
          if (applicationException instanceof TdiServiceException) {
            sendError(output, (TdiServiceException) applicationException);
          } else {
            String inputBean = tdi.text.StringUtil.escapeXML(inbean.toString(), false);
            String rc = "\n";
            sendError(
                output,
                new TdiServiceException(
                    1,
                    "." + rc + "[Operation: LoadFile]" + rc + inputBean + rc + ".",
                    applicationException.getClass().getName()
                        + ":"
                        + applicationException.getMessage()));
          }
          return;
        }

        // Invocar el método afterService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].afterService(request, response, outbean, "QualiPSoStorage", action);
        }

        // Respuesta
        output = response.getWriter();

        // Bean de salida
        String output_str = outbean.toJSON(false);

        // Invocar el método afterParse() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].afterParse(request, response, output_str.toString());
        }

        // Enviar la respuesta
        output.println(output_str);

        // Invocar el método endService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].endService(request, response);
        }

      } else if (action.equals("http://www.qualipso.org/advdoc/ws/storage/RemoveFile")) {

        // SERVICIO: RemoveFile

        // Parámetro de entrada al servicio
        RemoveFile_req inbean = new RemoveFile_req();
        inbean.fromJSON(input.toString());

        // Invocar el método beforeService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].beforeService(request, response, inbean, "QualiPSoStorage", action);
        }

        // Parámetro de salida del servicio
        RemoveFile_resp outbean = new RemoveFile_resp();

        // Crear un objeto que implementa la operación
        RemoveFileService serviceImplementation = new RemoveFileService();

        // Invocar la implementación de la operación
        Throwable applicationException =
            serviceImplementation.executeImpl(this, request, response, inbean, outbean);

        // Si ha ocurrido una excepción, enviarla al cliente
        if (applicationException != null) {
          // Traza
          // new es.tid.frawa.common.TdiFrawaTraceListener().trace(applicationException);
          new es.tid.frawa.common.TdiFrawaTraceListener().trace(applicationException);
          output = response.getWriter();
          if (applicationException instanceof TdiServiceException) {
            sendError(output, (TdiServiceException) applicationException);
          } else {
            String inputBean = tdi.text.StringUtil.escapeXML(inbean.toString(), false);
            String rc = "\n";
            sendError(
                output,
                new TdiServiceException(
                    1,
                    "." + rc + "[Operation: RemoveFile]" + rc + inputBean + rc + ".",
                    applicationException.getClass().getName()
                        + ":"
                        + applicationException.getMessage()));
          }
          return;
        }

        // Invocar el método afterService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].afterService(request, response, outbean, "QualiPSoStorage", action);
        }

        // Respuesta
        output = response.getWriter();

        // Bean de salida
        String output_str = outbean.toJSON(false);

        // Invocar el método afterParse() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].afterParse(request, response, output_str.toString());
        }

        // Enviar la respuesta
        output.println(output_str);

        // Invocar el método endService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].endService(request, response);
        }

      } else if (action.equals("http://www.qualipso.org/advdoc/ws/storage/RemoveFolder")) {

        // SERVICIO: RemoveFolder

        // Parámetro de entrada al servicio
        RemoveFolder_req inbean = new RemoveFolder_req();
        inbean.fromJSON(input.toString());

        // Invocar el método beforeService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].beforeService(request, response, inbean, "QualiPSoStorage", action);
        }

        // Parámetro de salida del servicio
        RemoveFolder_resp outbean = new RemoveFolder_resp();

        // Crear un objeto que implementa la operación
        RemoveFolderService serviceImplementation = new RemoveFolderService();

        // Invocar la implementación de la operación
        Throwable applicationException =
            serviceImplementation.executeImpl(this, request, response, inbean, outbean);

        // Si ha ocurrido una excepción, enviarla al cliente
        if (applicationException != null) {
          // Traza
          // new es.tid.frawa.common.TdiFrawaTraceListener().trace(applicationException);
          new es.tid.frawa.common.TdiFrawaTraceListener().trace(applicationException);
          output = response.getWriter();
          if (applicationException instanceof TdiServiceException) {
            sendError(output, (TdiServiceException) applicationException);
          } else {
            String inputBean = tdi.text.StringUtil.escapeXML(inbean.toString(), false);
            String rc = "\n";
            sendError(
                output,
                new TdiServiceException(
                    1,
                    "." + rc + "[Operation: RemoveFolder]" + rc + inputBean + rc + ".",
                    applicationException.getClass().getName()
                        + ":"
                        + applicationException.getMessage()));
          }
          return;
        }

        // Invocar el método afterService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].afterService(request, response, outbean, "QualiPSoStorage", action);
        }

        // Respuesta
        output = response.getWriter();

        // Bean de salida
        String output_str = outbean.toJSON(false);

        // Invocar el método afterParse() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].afterParse(request, response, output_str.toString());
        }

        // Enviar la respuesta
        output.println(output_str);

        // Invocar el método endService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].endService(request, response);
        }

      } else if (action.equals("http://www.qualipso.org/advdoc/ws/storage/StoreBinaryFile")) {

        // SERVICIO: StoreBinaryFile

        // Parámetro de entrada al servicio
        StoreBinaryFile_req inbean = new StoreBinaryFile_req();
        inbean.fromJSON(input.toString());

        // Invocar el método beforeService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].beforeService(request, response, inbean, "QualiPSoStorage", action);
        }

        // Parámetro de salida del servicio
        StoreBinaryFile_resp outbean = new StoreBinaryFile_resp();

        // Crear un objeto que implementa la operación
        StoreBinaryFileService serviceImplementation = new StoreBinaryFileService();

        // Invocar la implementación de la operación
        Throwable applicationException =
            serviceImplementation.executeImpl(this, request, response, inbean, outbean);

        // Si ha ocurrido una excepción, enviarla al cliente
        if (applicationException != null) {
          // Traza
          // new es.tid.frawa.common.TdiFrawaTraceListener().trace(applicationException);
          new es.tid.frawa.common.TdiFrawaTraceListener().trace(applicationException);
          output = response.getWriter();
          if (applicationException instanceof TdiServiceException) {
            sendError(output, (TdiServiceException) applicationException);
          } else {
            String inputBean = tdi.text.StringUtil.escapeXML(inbean.toString(), false);
            String rc = "\n";
            sendError(
                output,
                new TdiServiceException(
                    1,
                    "." + rc + "[Operation: StoreBinaryFile]" + rc + inputBean + rc + ".",
                    applicationException.getClass().getName()
                        + ":"
                        + applicationException.getMessage()));
          }
          return;
        }

        // Invocar el método afterService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].afterService(request, response, outbean, "QualiPSoStorage", action);
        }

        // Respuesta
        output = response.getWriter();

        // Bean de salida
        String output_str = outbean.toJSON(false);

        // Invocar el método afterParse() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].afterParse(request, response, output_str.toString());
        }

        // Enviar la respuesta
        output.println(output_str);

        // Invocar el método endService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].endService(request, response);
        }

      } else if (action.equals("http://www.qualipso.org/advdoc/ws/storage/StoreFile")) {

        // SERVICIO: StoreFile

        // Parámetro de entrada al servicio
        StoreFile_req inbean = new StoreFile_req();
        inbean.fromJSON(input.toString());

        // Invocar el método beforeService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].beforeService(request, response, inbean, "QualiPSoStorage", action);
        }

        // Parámetro de salida del servicio
        StoreFile_resp outbean = new StoreFile_resp();

        // Crear un objeto que implementa la operación
        StoreFileService serviceImplementation = new StoreFileService();

        // Invocar la implementación de la operación
        Throwable applicationException =
            serviceImplementation.executeImpl(this, request, response, inbean, outbean);

        // Si ha ocurrido una excepción, enviarla al cliente
        if (applicationException != null) {
          // Traza
          // new es.tid.frawa.common.TdiFrawaTraceListener().trace(applicationException);
          new es.tid.frawa.common.TdiFrawaTraceListener().trace(applicationException);
          output = response.getWriter();
          if (applicationException instanceof TdiServiceException) {
            sendError(output, (TdiServiceException) applicationException);
          } else {
            String inputBean = tdi.text.StringUtil.escapeXML(inbean.toString(), false);
            String rc = "\n";
            sendError(
                output,
                new TdiServiceException(
                    1,
                    "." + rc + "[Operation: StoreFile]" + rc + inputBean + rc + ".",
                    applicationException.getClass().getName()
                        + ":"
                        + applicationException.getMessage()));
          }
          return;
        }

        // Invocar el método afterService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].afterService(request, response, outbean, "QualiPSoStorage", action);
        }

        // Respuesta
        output = response.getWriter();

        // Bean de salida
        String output_str = outbean.toJSON(false);

        // Invocar el método afterParse() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].afterParse(request, response, output_str.toString());
        }

        // Enviar la respuesta
        output.println(output_str);

        // Invocar el método endService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].endService(request, response);
        }

      } else if (action.equals("http://www.qualipso.org/advdoc/ws/storage/TestLoopback")) {

        // SERVICIO: TestLoopback

        // Parámetro de entrada al servicio
        org.qualipso.advdoc.ws.client.storage.beans.TestLoopback inbean =
            new org.qualipso.advdoc.ws.client.storage.beans.TestLoopback();
        inbean.fromJSON(input.toString());

        // Invocar el método beforeService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].beforeService(request, response, inbean, "QualiPSoStorage", action);
        }

        // Parámetro de salida del servicio
        org.qualipso.advdoc.ws.client.storage.beans.TestLoopback outbean =
            new org.qualipso.advdoc.ws.client.storage.beans.TestLoopback();

        // Crear un objeto que implementa la operación
        TestLoopbackService serviceImplementation = new TestLoopbackService();

        // Invocar la implementación de la operación
        Throwable applicationException =
            serviceImplementation.executeImpl(this, request, response, inbean, outbean);

        // Si ha ocurrido una excepción, enviarla al cliente
        if (applicationException != null) {
          // Traza
          // new es.tid.frawa.common.TdiFrawaTraceListener().trace(applicationException);
          new es.tid.frawa.common.TdiFrawaTraceListener().trace(applicationException);
          output = response.getWriter();
          if (applicationException instanceof TdiServiceException) {
            sendError(output, (TdiServiceException) applicationException);
          } else {
            String inputBean = tdi.text.StringUtil.escapeXML(inbean.toString(), false);
            String rc = "\n";
            sendError(
                output,
                new TdiServiceException(
                    1,
                    "." + rc + "[Operation: TestLoopback]" + rc + inputBean + rc + ".",
                    applicationException.getClass().getName()
                        + ":"
                        + applicationException.getMessage()));
          }
          return;
        }

        // Invocar el método afterService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].afterService(request, response, outbean, "QualiPSoStorage", action);
        }

        // Respuesta
        output = response.getWriter();

        // Bean de salida
        String output_str = outbean.toJSON(false);

        // Invocar el método afterParse() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].afterParse(request, response, output_str.toString());
        }

        // Enviar la respuesta
        output.println(output_str);

        // Invocar el método endService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].endService(request, response);
        }

      } else if (action.equals("http://www.qualipso.org/advdoc/ws/storage/TestParser")) {

        // SERVICIO: TestParser

        // Parámetro de entrada al servicio
        org.qualipso.advdoc.ws.client.storage.beans.TestParser inbean =
            new org.qualipso.advdoc.ws.client.storage.beans.TestParser();
        inbean.fromJSON(input.toString());

        // Invocar el método beforeService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].beforeService(request, response, inbean, "QualiPSoStorage", action);
        }

        // Parámetro de salida del servicio
        org.qualipso.advdoc.ws.client.storage.beans.TestParser outbean =
            new org.qualipso.advdoc.ws.client.storage.beans.TestParser();

        // Crear un objeto que implementa la operación
        TestParserService serviceImplementation = new TestParserService();

        // Invocar la implementación de la operación
        Throwable applicationException =
            serviceImplementation.executeImpl(this, request, response, inbean, outbean);

        // Si ha ocurrido una excepción, enviarla al cliente
        if (applicationException != null) {
          // Traza
          // new es.tid.frawa.common.TdiFrawaTraceListener().trace(applicationException);
          new es.tid.frawa.common.TdiFrawaTraceListener().trace(applicationException);
          output = response.getWriter();
          if (applicationException instanceof TdiServiceException) {
            sendError(output, (TdiServiceException) applicationException);
          } else {
            String inputBean = tdi.text.StringUtil.escapeXML(inbean.toString(), false);
            String rc = "\n";
            sendError(
                output,
                new TdiServiceException(
                    1,
                    "." + rc + "[Operation: TestParser]" + rc + inputBean + rc + ".",
                    applicationException.getClass().getName()
                        + ":"
                        + applicationException.getMessage()));
          }
          return;
        }

        // Invocar el método afterService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].afterService(request, response, outbean, "QualiPSoStorage", action);
        }

        // Respuesta
        output = response.getWriter();

        // Bean de salida
        String output_str = outbean.toJSON(false);

        // Invocar el método afterParse() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].afterParse(request, response, output_str.toString());
        }

        // Enviar la respuesta
        output.println(output_str);

        // Invocar el método endService() de los filtros
        for (int i = 0; i < filters.length; i++) {
          filters[i].endService(request, response);
        }

      } else {

        throw new Exception(getClass().getName() + ".service() Operación " + action + " no válida");
      }

    } catch (ServletException e) {

      // Ha ocurrido un error en los filtros

      // Traza
      // new es.tid.frawa.common.TdiFrawaTraceListener().trace(e);
      new es.tid.frawa.common.TdiFrawaTraceListener().trace(e);

      // Enviar <Fault> al cliente
      if (output == null) {
        output = response.getWriter();
      }
      TdiServiceException se = new TdiServiceException(-1, "Filter exception", e.getMessage());
      sendError(output, se);

    } catch (Throwable t) {

      // Invocar el método onException() de los filtros
      for (int i = 0; i < filters.length; i++) {
        filters[i].onException(request, response, t, "QualiPSoStorage", action);
      }

      // Traza
      // new es.tid.frawa.common.TdiFrawaTraceListener().trace(t);
      new es.tid.frawa.common.TdiFrawaTraceListener().trace(t);

      // Elevar una ServletException
      throw new ServletException(
          getClass().getName()
              + ".service() Server Exception: "
              + t.getClass().getName()
              + " -> "
              + t.getMessage());
      // if (output == null) {
      //	output = response.getWriter();
      // }
      // TdiServiceException se = new TdiServiceException(-2,t.getClass().getName(),t.getMessage());
      // sendError(output,se);

    } finally {

      // Invocar el método onFinally() de los filtros
      for (int i = 0; i < filters.length; i++) {
        filters[i].onFinally(request, response, "QualiPSoStorage", action);
      }
    }
  }
Example #4
0
  /**
   * Redirects the HTTP request to the Authentication module. It gets the authentication url from
   * <code>SystemProperties</code>.
   *
   * @param request an HttpServletRequest object that contains the request the client has made of
   *     the servlet.
   * @param response an HttpServletResponse object that contains the response the servlet sends to
   *     the client.
   * @exception IOException If an input or output exception occurs
   */
  private void redirectForAuthentication(
      HttpServletRequest request,
      HttpServletResponse response,
      String policyAdviceList,
      String requestParams)
      throws IOException {
    if (debug.messageEnabled()) {
      debug.message(
          "CDCClientServlet.redirectForAuthentication: " + "requestURL=" + request.getRequestURL());
    }
    StringBuilder redirectURL = new StringBuilder(100);
    StringBuilder gotoURL = new StringBuilder(100);

    // Check if user has authenticated to another OpenAM
    // instance
    String authURL = null;
    Cookie authCookie = CookieUtils.getCookieFromReq(request, authURLCookieName);
    if (authCookie != null) {
      authURL = CookieUtils.getCookieValue(authCookie);
      if (debug.messageEnabled()) {
        debug.message(
            "CDCClientServlet.redirectForAuthentication: "
                + "got an authenticated URL= "
                + authURL);
      }
    }
    try {
      if (authURL == null
          || authURL.length() == 0
          || !authURL.toLowerCase().startsWith("http")
          || policyAdviceList != null) {
        String finalURL = request.getParameter(GOTO_PARAMETER);

        if (finalURL == null || finalURL.equals("")) {
          finalURL = request.getParameter(TARGET_PARAMETER);
        }

        if (finalURL == null || finalURL.equals("")) {
          if (debug.messageEnabled()) {
            debug.message(
                "CDCClientServlet.redirectForAuthentication: "
                    + "goto or target parameter is missing in the request.");
          }

          showError(response, SERVER_ERROR_STR_MATCH);
          return;
        }

        gotoURL
            .append(deployDescriptor)
            .append(CDCURI)
            .append(QUESTION_MARK)
            .append(TARGET_PARAMETER)
            .append(EQUAL_TO)
            .append(URLEncDec.encode(finalURL))
            .append(AMPERSAND)
            .append(requestParams);

        // Construct the login URL
        String loginURI = request.getParameter(LOGIN_URI);
        String cdcUri;

        if (loginURI != null && !loginURI.isEmpty() && isValidCDCURI(loginURI)) {
          if (debug.messageEnabled()) {
            debug.message(
                "CDCClientServlet.redirectForAuthentication:found " + LOGIN_URI + "=" + loginURI);
          }

          cdcUri = loginURI;
        } else {
          cdcUri = cdcAuthURI;
        }

        if (debug.messageEnabled()) {
          debug.message(
              "CDCClientServlet.redirectForAuthentication: Login URI is set to = " + cdcUri);
        }

        if (cdcUri.indexOf(QUESTION_MARK) == -1) {
          redirectURL.append(cdcUri).append(QUESTION_MARK);
        } else {
          redirectURL.append(cdcUri).append(AMPERSAND);
        }

        if (policyAdviceList != null) {
          redirectURL.append(policyAdviceList).append(AMPERSAND);
        }
        redirectURL
            .append(GOTO_PARAMETER)
            .append(EQUAL_TO)
            .append(URLEncDec.encode(gotoURL.toString()));

        if (debug.messageEnabled()) {
          debug.message(
              "CDCClientServlet.redirectForAuthentication"
                  + ":redirectURL before dispatching is="
                  + redirectURL);
        }
        RequestDispatcher dispatcher = request.getRequestDispatcher(redirectURL.toString());
        dispatcher.forward(request, response);
      } else {
        // Redirect the user to the authenticated URL
        redirectURL
            .append(authURL)
            .append(deployDescriptor)
            .append(CDCURI)
            .append(QUESTION_MARK)
            .append(request.getQueryString());
        // Reset the cookie value to null, to avoid continuous loop
        // when a load balancer is used
        if (authCookie != null) {
          authCookie.setValue("");
          response.addCookie(authCookie);
        }
        response.sendRedirect(redirectURL.toString());
      }

      if (debug.messageEnabled()) {
        debug.message(
            "CDCClientServlet.redirectForAuthentication:"
                + "Forwarding for authentication to= "
                + redirectURL);
      }
    } catch (IOException ex) {
      debug.error(
          "CDCClientServlet.redirectForAuthentication: Failed "
              + "in forwarding to Authentication service. IOException",
          ex);
      showError(response, "Could for forward to authentication service:" + ex.getMessage());
    } catch (ServletException se) {
      debug.error(
          "CDCClientServlet.redirectForAuthentication : Failed "
              + "in forwarding to Authentication service. ServletException",
          se);
      showError(response, "Could for forward to authentication service:" + se.getMessage());
    } catch (IllegalStateException ie) {
      debug.error(
          "CDCClientServlet.redirectForAuthentication : Failed "
              + "in forwarding to Authentication service. Illegal state",
          ie);
      showError(response, "Could for forward to authentication service:" + ie.getMessage());
    }
  }
Example #5
0
  /**
   * Redirects the HTTP request to the Authentication module. It gets the authentication url from
   * <code>SystemProperties</code>.
   *
   * @param request an HttpServletRequest object that contains the request the client has made of
   *     the servlet.
   * @param response an HttpServletResponse object that contains the response the servlet sends to
   *     the client.
   * @exception IOException If an input or output exception occurs
   */
  private void redirectForAuthentication(HttpServletRequest request, HttpServletResponse response)
      throws IOException {
    if (debug.messageEnabled()) {
      debug.message(
          "CDCClientServlet.redirectForAuthentication: " + "requestURL=" + request.getRequestURL());
    }
    StringBuffer redirectURL = new StringBuffer(100);
    StringBuffer gotoURL = new StringBuffer(100);

    // Check if user has authenticated to another OpenSSO
    // instance
    String authURL = null;
    Cookie authCookie = CookieUtils.getCookieFromReq(request, authURLCookieName);
    if (authCookie != null) {
      authURL = CookieUtils.getCookieValue(authCookie);
      if (debug.messageEnabled()) {
        debug.message(
            "CDCClientServlet.redirectForAuthentication: "
                + "got an authenticated URL= "
                + authURL);
      }
    }
    try {
      if (authURL == null
          || authURL.length() == 0
          || !authURL.toLowerCase().startsWith("http")
          || policyAdviceList != null) {
        String finalURL = request.getParameter(GOTO_PARAMETER);

        if (finalURL == null || finalURL.equals("")) {
          finalURL = request.getParameter(TARGET_PARAMETER);
        }

        if (finalURL == null || finalURL.equals("")) {
          showError(response, "GOTO or TARGET parameter is missing" + " in the request");
          return;
        }

        gotoURL
            .append(deployDescriptor)
            .append(CDCURI)
            .append(QUESTION_MARK)
            .append(TARGET_PARAMETER)
            .append(EQUAL_TO)
            .append(URLEncDec.encode(finalURL))
            .append(AMPERSAND)
            .append(requestParams);

        // Construct the login URL
        String cdcurl = SystemProperties.get(Constants.CDCSERVLET_LOGIN_URL);
        if (cdcurl != null && cdcurl.length() > 0) {
          if (cdcurl.indexOf("?") == -1) {
            redirectURLStr = cdcurl + QUESTION_MARK;
          } else {
            redirectURLStr = cdcurl + AMPERSAND;
          }
        } else {
          redirectURLStr = AUTHURI + QUESTION_MARK;
        }
        if (debug.messageEnabled()) {
          debug.message("CDCClientServlet init redirect URL is" + "set to= " + redirectURLStr);
        }

        redirectURL.append(redirectURLStr);
        if (policyAdviceList != null) {
          redirectURL.append(policyAdviceList).append(AMPERSAND);
        }
        redirectURL
            .append(GOTO_PARAMETER)
            .append(EQUAL_TO)
            .append(URLEncDec.encode(gotoURL.toString()));

        // Check for policy advices
        if (policyAdviceList != null) {
          redirectURL.append(AMPERSAND).append(policyAdviceList);
        }
        if (debug.messageEnabled()) {
          debug.message(
              "CDCClientServlet.redirectForAuthentication"
                  + ":redirectURL before dispatching is="
                  + redirectURL);
        }
        RequestDispatcher dispatcher = request.getRequestDispatcher(redirectURL.toString());
        dispatcher.forward(request, response);
      } else {
        // Redirect the user to the authenticated URL
        redirectURL
            .append(authURL)
            .append(deployDescriptor)
            .append(CDCURI)
            .append(QUESTION_MARK)
            .append(request.getQueryString());
        // Reset the cookie value to null, to avoid continous loop
        // when a load balancer is used
        if (authCookie != null) {
          authCookie.setValue("");
          response.addCookie(authCookie);
        }
        response.sendRedirect(redirectURL.toString());
      }

      if (debug.messageEnabled()) {
        debug.message(
            "CDCClientServlet.redirectForAuthentication:"
                + "Forwarding for authentication to= "
                + redirectURL);
      }
    } catch (IOException ex) {
      debug.error(
          "CDCClientServlet.redirectForAuthentication: Failed "
              + "in forwarding to Authentication service. IOException",
          ex);
      showError(response, "Could for forward to authentication service:" + ex.getMessage());
    } catch (ServletException se) {
      debug.error(
          "CDCClientServlet.redirectForAuthentication : Failed "
              + "in forwarding to Authentication service. ServletException",
          se);
      showError(response, "Could for forward to authentication service:" + se.getMessage());
    } catch (IllegalStateException ie) {
      debug.error(
          "CDCClientServlet.redirectForAuthentication : Failed "
              + "in forwarding to Authentication service. Illegal state",
          ie);
      showError(response, "Could for forward to authentication service:" + ie.getMessage());
    }
  }
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {
    TableSQLData tableSQL = null;
    VariablesSecureApp vars = new VariablesSecureApp(request);
    Boolean saveRequest = (Boolean) request.getAttribute("autosave");

    if (saveRequest != null && saveRequest) {
      String currentOrg = vars.getStringParameter("inpadOrgId");
      String currentClient = vars.getStringParameter("inpadClientId");
      boolean editableTab =
          (!org.openbravo.erpCommon.utility.WindowAccessData.hasReadOnlyAccess(
                  this, vars.getRole(), tabId)
              && (currentOrg.equals("")
                  || Utility.isElementInList(
                      Utility.getContext(this, vars, "#User_Org", windowId, accesslevel),
                      currentOrg))
              && (currentClient.equals("")
                  || Utility.isElementInList(
                      Utility.getContext(this, vars, "#User_Client", windowId, accesslevel),
                      currentClient)));

      OBError myError = new OBError();
      String commandType = request.getParameter("inpCommandType");
      String strcBpGroupId = request.getParameter("inpcBpGroupId");

      if (editableTab) {
        int total = 0;

        if (commandType.equalsIgnoreCase("EDIT") && !strcBpGroupId.equals(""))
          total = saveRecord(vars, myError, 'U');
        else total = saveRecord(vars, myError, 'I');

        if (!myError.isEmpty() && total == 0) throw new OBException(myError.getMessage());
      }
      vars.setSessionValue(request.getParameter("mappingName") + "|hash", vars.getPostDataHash());
      vars.setSessionValue(tabId + "|Header.view", "EDIT");

      return;
    }

    try {
      tableSQL =
          new TableSQLData(
              vars,
              this,
              tabId,
              Utility.getContext(this, vars, "#AccessibleOrgTree", windowId, accesslevel),
              Utility.getContext(this, vars, "#User_Client", windowId),
              Utility.getContext(this, vars, "ShowAudit", windowId).equals("Y"));
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    String strOrderBy = vars.getSessionValue(tabId + "|orderby");
    if (!strOrderBy.equals("")) {
      vars.setSessionValue(tabId + "|newOrder", "1");
    }

    if (vars.commandIn("DEFAULT")) {

      String strC_BP_Group_ID =
          vars.getGlobalVariable("inpcBpGroupId", windowId + "|C_BP_Group_ID", "");

      String strView = vars.getSessionValue(tabId + "|BusinessPartnerCategory.view");
      if (strView.equals("")) {
        strView = defaultTabView;

        if (strView.equals("EDIT")) {
          if (strC_BP_Group_ID.equals("")) strC_BP_Group_ID = firstElement(vars, tableSQL);
          if (strC_BP_Group_ID.equals("")) strView = "RELATION";
        }
      }
      if (strView.equals("EDIT"))
        printPageEdit(response, request, vars, false, strC_BP_Group_ID, tableSQL);
      else printPageDataSheet(response, vars, strC_BP_Group_ID, tableSQL);
    } else if (vars.commandIn("DIRECT")) {
      String strC_BP_Group_ID = vars.getStringParameter("inpDirectKey");

      if (strC_BP_Group_ID.equals(""))
        strC_BP_Group_ID =
            vars.getRequiredGlobalVariable("inpcBpGroupId", windowId + "|C_BP_Group_ID");
      else vars.setSessionValue(windowId + "|C_BP_Group_ID", strC_BP_Group_ID);

      vars.setSessionValue(tabId + "|BusinessPartnerCategory.view", "EDIT");

      printPageEdit(response, request, vars, false, strC_BP_Group_ID, tableSQL);

    } else if (vars.commandIn("TAB")) {

      String strView = vars.getSessionValue(tabId + "|BusinessPartnerCategory.view");
      String strC_BP_Group_ID = "";
      if (strView.equals("")) {
        strView = defaultTabView;
        if (strView.equals("EDIT")) {
          strC_BP_Group_ID = firstElement(vars, tableSQL);
          if (strC_BP_Group_ID.equals("")) strView = "RELATION";
        }
      }
      if (strView.equals("EDIT")) {

        if (strC_BP_Group_ID.equals("")) strC_BP_Group_ID = firstElement(vars, tableSQL);
        printPageEdit(response, request, vars, false, strC_BP_Group_ID, tableSQL);

      } else printPageDataSheet(response, vars, "", tableSQL);
    } else if (vars.commandIn("SEARCH")) {
      vars.getRequestGlobalVariable("inpParamName", tabId + "|paramName");

      vars.getRequestGlobalVariable("inpParamUpdated", tabId + "|paramUpdated");
      vars.getRequestGlobalVariable("inpParamUpdatedBy", tabId + "|paramUpdatedBy");
      vars.getRequestGlobalVariable("inpParamCreated", tabId + "|paramCreated");
      vars.getRequestGlobalVariable("inpparamCreatedBy", tabId + "|paramCreatedBy");

      vars.removeSessionValue(windowId + "|C_BP_Group_ID");
      String strC_BP_Group_ID = "";

      String strView = vars.getSessionValue(tabId + "|BusinessPartnerCategory.view");
      if (strView.equals("")) strView = defaultTabView;

      if (strView.equals("EDIT")) {
        strC_BP_Group_ID = firstElement(vars, tableSQL);
        if (strC_BP_Group_ID.equals("")) {
          // filter returns empty set
          strView = "RELATION";
          // switch to grid permanently until the user changes the view again
          vars.setSessionValue(tabId + "|BusinessPartnerCategory.view", strView);
        }
      }

      if (strView.equals("EDIT"))
        printPageEdit(response, request, vars, false, strC_BP_Group_ID, tableSQL);
      else printPageDataSheet(response, vars, strC_BP_Group_ID, tableSQL);
    } else if (vars.commandIn("RELATION")) {

      String strC_BP_Group_ID =
          vars.getGlobalVariable("inpcBpGroupId", windowId + "|C_BP_Group_ID", "");
      vars.setSessionValue(tabId + "|BusinessPartnerCategory.view", "RELATION");
      printPageDataSheet(response, vars, strC_BP_Group_ID, tableSQL);
    } else if (vars.commandIn("NEW")) {

      printPageEdit(response, request, vars, true, "", tableSQL);

    } else if (vars.commandIn("EDIT")) {

      @SuppressWarnings("unused") // In Expense Invoice tab this variable is not used, to be fixed
      String strC_BP_Group_ID =
          vars.getGlobalVariable("inpcBpGroupId", windowId + "|C_BP_Group_ID", "");
      vars.setSessionValue(tabId + "|BusinessPartnerCategory.view", "EDIT");

      setHistoryCommand(request, "EDIT");
      printPageEdit(response, request, vars, false, strC_BP_Group_ID, tableSQL);

    } else if (vars.commandIn("NEXT")) {

      String strC_BP_Group_ID = vars.getRequiredStringParameter("inpcBpGroupId");

      String strNext = nextElement(vars, strC_BP_Group_ID, tableSQL);

      printPageEdit(response, request, vars, false, strNext, tableSQL);
    } else if (vars.commandIn("PREVIOUS")) {

      String strC_BP_Group_ID = vars.getRequiredStringParameter("inpcBpGroupId");

      String strPrevious = previousElement(vars, strC_BP_Group_ID, tableSQL);

      printPageEdit(response, request, vars, false, strPrevious, tableSQL);
    } else if (vars.commandIn("FIRST_RELATION")) {

      vars.setSessionValue(tabId + "|BusinessPartnerCategory.initRecordNumber", "0");
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("PREVIOUS_RELATION")) {

      String strInitRecord =
          vars.getSessionValue(tabId + "|BusinessPartnerCategory.initRecordNumber");
      String strRecordRange = Utility.getContext(this, vars, "#RecordRange", windowId);
      int intRecordRange = strRecordRange.equals("") ? 0 : Integer.parseInt(strRecordRange);
      if (strInitRecord.equals("") || strInitRecord.equals("0")) {
        vars.setSessionValue(tabId + "|BusinessPartnerCategory.initRecordNumber", "0");
      } else {
        int initRecord = (strInitRecord.equals("") ? 0 : Integer.parseInt(strInitRecord));
        initRecord -= intRecordRange;
        strInitRecord = ((initRecord < 0) ? "0" : Integer.toString(initRecord));
        vars.setSessionValue(tabId + "|BusinessPartnerCategory.initRecordNumber", strInitRecord);
      }
      vars.removeSessionValue(windowId + "|C_BP_Group_ID");

      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("NEXT_RELATION")) {

      String strInitRecord =
          vars.getSessionValue(tabId + "|BusinessPartnerCategory.initRecordNumber");
      String strRecordRange = Utility.getContext(this, vars, "#RecordRange", windowId);
      int intRecordRange = strRecordRange.equals("") ? 0 : Integer.parseInt(strRecordRange);
      int initRecord = (strInitRecord.equals("") ? 0 : Integer.parseInt(strInitRecord));
      if (initRecord == 0) initRecord = 1;
      initRecord += intRecordRange;
      strInitRecord = ((initRecord < 0) ? "0" : Integer.toString(initRecord));
      vars.setSessionValue(tabId + "|BusinessPartnerCategory.initRecordNumber", strInitRecord);
      vars.removeSessionValue(windowId + "|C_BP_Group_ID");

      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("FIRST")) {

      String strFirst = firstElement(vars, tableSQL);

      printPageEdit(response, request, vars, false, strFirst, tableSQL);
    } else if (vars.commandIn("LAST_RELATION")) {

      String strLast = lastElement(vars, tableSQL);
      printPageDataSheet(response, vars, strLast, tableSQL);
    } else if (vars.commandIn("LAST")) {

      String strLast = lastElement(vars, tableSQL);

      printPageEdit(response, request, vars, false, strLast, tableSQL);
    } else if (vars.commandIn("SAVE_NEW_RELATION", "SAVE_NEW_NEW", "SAVE_NEW_EDIT")) {

      OBError myError = new OBError();
      int total = saveRecord(vars, myError, 'I');
      if (!myError.isEmpty()) {
        response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
      } else {
        if (myError.isEmpty()) {
          myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=RowsInserted");
          myError.setMessage(total + " " + myError.getMessage());
          vars.setMessage(tabId, myError);
        }
        if (vars.commandIn("SAVE_NEW_NEW"))
          response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
        else if (vars.commandIn("SAVE_NEW_EDIT"))
          response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
        else response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
      }
    } else if (vars.commandIn(
        "SAVE_EDIT_RELATION", "SAVE_EDIT_NEW", "SAVE_EDIT_EDIT", "SAVE_EDIT_NEXT")) {

      String strC_BP_Group_ID =
          vars.getRequiredGlobalVariable("inpcBpGroupId", windowId + "|C_BP_Group_ID");
      OBError myError = new OBError();
      int total = saveRecord(vars, myError, 'U');
      if (!myError.isEmpty()) {
        response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
      } else {
        if (myError.isEmpty()) {
          myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=RowsUpdated");
          myError.setMessage(total + " " + myError.getMessage());
          vars.setMessage(tabId, myError);
        }
        if (vars.commandIn("SAVE_EDIT_NEW"))
          response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
        else if (vars.commandIn("SAVE_EDIT_EDIT"))
          response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
        else if (vars.commandIn("SAVE_EDIT_NEXT")) {
          String strNext = nextElement(vars, strC_BP_Group_ID, tableSQL);
          vars.setSessionValue(windowId + "|C_BP_Group_ID", strNext);
          response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
        } else response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
      }
    } else if (vars.commandIn("DELETE")) {

      String strC_BP_Group_ID = vars.getRequiredStringParameter("inpcBpGroupId");
      // BusinessPartnerCategoryData data = getEditVariables(vars);
      int total = 0;
      OBError myError = null;
      if (org.openbravo.erpCommon.utility.WindowAccessData.hasNotDeleteAccess(
          this, vars.getRole(), tabId)) {
        myError =
            Utility.translateError(
                this,
                vars,
                vars.getLanguage(),
                Utility.messageBD(this, "NoWriteAccess", vars.getLanguage()));
        vars.setMessage(tabId, myError);
      } else {
        try {
          total =
              BusinessPartnerCategoryData.delete(
                  this,
                  strC_BP_Group_ID,
                  Utility.getContext(this, vars, "#User_Client", windowId, accesslevel),
                  Utility.getContext(this, vars, "#User_Org", windowId, accesslevel));
        } catch (ServletException ex) {
          myError = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage());
          if (!myError.isConnectionAvailable()) {
            bdErrorConnection(response);
            return;
          } else vars.setMessage(tabId, myError);
        }
        if (myError == null && total == 0) {
          myError =
              Utility.translateError(
                  this,
                  vars,
                  vars.getLanguage(),
                  Utility.messageBD(this, "NoWriteAccess", vars.getLanguage()));
          vars.setMessage(tabId, myError);
        }
        vars.removeSessionValue(windowId + "|cBpGroupId");
        vars.setSessionValue(tabId + "|BusinessPartnerCategory.view", "RELATION");
      }
      if (myError == null) {
        myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=RowsDeleted");
        myError.setMessage(total + " " + myError.getMessage());
        vars.setMessage(tabId, myError);
      }
      response.sendRedirect(strDireccion + request.getServletPath());

    } else if (vars.commandIn("SAVE_XHR")) {

      OBError myError = new OBError();
      JSONObject result = new JSONObject();
      String commandType = vars.getStringParameter("inpCommandType");
      char saveType = "NEW".equals(commandType) ? 'I' : 'U';
      try {
        int total = saveRecord(vars, myError, saveType);
        if (myError.isEmpty()) {
          myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=RowsUpdated");
          myError.setMessage(total + " " + myError.getMessage());
          myError.setType("Success");
        }
        result.put("oberror", myError.toMap());
        result.put("tabid", vars.getStringParameter("tabID"));
        result.put("redirect", strDireccion + request.getServletPath() + "?Command=" + commandType);
      } catch (Exception e) {
        log4j.error("Error saving record (XHR request): " + e.getMessage(), e);
        myError.setType("Error");
        myError.setMessage(e.getMessage());
      }

      response.setContentType("application/json");
      PrintWriter out = response.getWriter();
      out.print(result.toString());
      out.flush();
      out.close();
    } else if (vars.getCommand().toUpperCase().startsWith("BUTTON")
        || vars.getCommand().toUpperCase().startsWith("SAVE_BUTTON")) {
      pageErrorPopUp(response);
    } else pageError(response);
  }