Commit 7918d928 by Percy Quispe

correcciones

parent de2ba4b5
package demojsoncrud.servlets;
import demojsoncrud.utilities.GeneralUtils;
import demojsoncrud.utilities.PostRequest;
import java.io.IOException;
import java.io.PrintWriter;
......@@ -72,7 +73,7 @@ public class RequestFilter implements Filter, ServletContextListener {
JSONArray views = new JSONArray(menu.get("vistas").toString());//Obtiene las vistas disponibles del usuario
List<Object> salida=views.toList();
String ruta = request.getRequestURI();
int indice = obtenerIndex(ruta);
int indice = GeneralUtils.obtenerIndex(ruta);
String rutaJsp = ruta.substring(indice, ruta.length());
if(url.contains(".jsp")){
boolean acceso = false;
......@@ -85,8 +86,7 @@ public class RequestFilter implements Filter, ServletContextListener {
}
if(!acceso){
Response.ResponseBuilder builder = null;
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.sendError(401);
sendError(response);
builder = Response.status(Response.Status.UNAUTHORIZED).entity(response);
throw new WebApplicationException(builder.build());
}
......@@ -94,28 +94,17 @@ public class RequestFilter implements Filter, ServletContextListener {
// List<String> views = (List<String>) ;
chain.doFilter(request, response);
} else {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.sendError(401);
sendError(response);
}
}
} else {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.sendError(401);
}
}
private int obtenerIndex(String ruta){
char[] c = ruta.toCharArray();
int salida = 0;
for (int i = c.length-1; i >= 0; i--) {
String help = c[i]+"";
if(!help.equals("/")){
salida = i;
}else{
break;
sendError(response);
}
}
return salida;
private void sendError (HttpServletResponse response) throws IOException{
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.sendError(401);
}
@Override
public void destroy() {
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package demojsoncrud.utilities;
/**
*
* @author sistem08user
*/
public class GeneralUtils {
public static int obtenerIndex(String ruta){
char[] c = ruta.toCharArray();
int salida = 0;
for (int i = c.length-1; i >= 0; i--) {
String help = c[i]+"";
if(!help.equals("/")){
salida = i;
}else{
break;
}
}
return salida;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment