1

Tengo una aplicación Java hecha en Genexus 15 U1 (java-mysql-tomcat8), donde he creado un procedimiento con propiedad REST protocol en true, cuyos parámetros en rule son (la salida es un sdt): parm(in:&DtCatCSec,in:&TdaCod,in:&pagina,in:&TdaCatCod,out:&SDTC_CatProductos);

He tratado de llamar a este servicio desde javascript de la siguiente manera:

$.ajax({
  url: "http://192.168.2.113:8090/Gx15RingoStoreJavaMySQL/rest/PrC_WSProductos",
  data: JSON.stringify({
  DtCatCSec: 1,
  TDAcOD: "0000000472",
  pagina: 1,
  TdaCatCod: "0000000607"
}),
  type: 'POST',
  dataType: 'JSON',
  headers: {
    "Accept": "application/json",
    "contentType": "application/json",
    "contentType": "charset=UTF-8"
  },
  cache: false,
  success: function (data) {
    //Do stuff with the JSON data
    alert("ok");
    /*
   $.each( data.items, function( i, item ) {
      var texto = "<div><p>"+item.SmoothResMenuData[i].Title+"</p></div>"
      $(texto).appendTo( "#images" );
    });
    */
  },
  error: function ( jqXHR,textStatus,errorThrown ){
    var err = "ERROR:"+jqXHR+"-"+textStatus+"-"+errorThrown;
    alert(err);
  }

Pero me devuelve el error en consola del navegador: Failed to load resource: the server responded with a status of 404 (Not Found)

Mi configuracion en el web.xml del tomcat es la siguiente:

 <filter>
      <filter-name>CorsFilter</filter-name>
      <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
      <init-param>
        <param-name>cors.allowed.origins</param-name>
        <param-value>http://192.168.2.113:8090</param-value>
      </init-param>
      <init-param>
        <param-name>cors.allowed.methods</param-name>
        <param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
      </init-param>
      <init-param>
        <param-name>cors.allowed.headers</param-name>
        <param-value>Access-Control-Allow-OriginContent-Type,X-Requested-With,accept,Content-Type,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
      </init-param>
      <init-param>
        <param-name>cors.exposed.headers</param-name>
        <param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
      </init-param>
      <init-param>
        <param-name>cors.support.credentials</param-name>
        <param-value>false</param-value>
      </init-param>
      <init-param>
        <param-name>cors.preflight.maxage</param-name>
        <param-value>2592000</param-value>
      </init-param>
    </filter>
    <filter-mapping>
      <filter-name>CorsFilter</filter-name>
      <url-pattern>/*</url-pattern>
    </filter-mapping>
    <mime-mapping>
    <extension>html</extension>
    <mime-type>text/html;charset=UTF-8;application/json</mime-type>
</mime-mapping>
Es la primera vez que hago este tipo de integraciones, agradezco de antemano su ayuda!!!

1
  • los errores 404 no se dan por errores de implementación sino por errores de ubicación. 404 quiere decir que el servicio no está donde los estás buscando
    – sebagomez
    el 15 may. 2017 a las 15:10

2 respuestas 2

0

Solucioné yo misma mi error jeje, esta es la manera correcta de llamar un servicio rest de Genexus desde JS, deben haber más, pero esta me funcionó:

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "http://192.168.2.113:8080/Gx15RingoStoreJavaMySQL/rest/PrC_WSProductos",
  "method": "POST",
  "headers": {
    "content-type": "application/json",
    "cache-control": "no-cache"
  },
  "processData": false,
  "data": "{\n\"DtCatCSec\" : 1,\n\"TDAcOD\" : \"0000000472\",\n\"pagina\" : 1,\n\"TdaCatCod\" : \"0000000607\"\n}"
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

0

El Error 404 indica que esta URL

http://192.168.2.113:8090/Gx15RingoStoreJavaMySQL/rest/PrC_WSProductos

a la que le haces el request no es alcanzable; esta documentado aquí:

https://es.wikipedia.org/wiki/HTTP_404

en cuanto al código la manera correcta de llamar a un servicio rest desde genexus es:

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "http://192.168.2.113:8080/Gx15RingoStoreJavaMySQL/rest/PrC_WSProductos",
  "method": "POST",
  "headers": {
    "content-type": "application/json",
    "cache-control": "no-cache"
  },
  "processData": false,
  "data": "{\n\"DtCatCSec\" : 1,\n\"TDAcOD\" : \"0000000472\",\n\"pagina\" : 1,\n\"TdaCatCod\" : \"0000000607\"\n}"
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

o con javascript vanilla: no verificado

xhttp.open("POST", "http://192.168.2.113:8080/Gx15RingoStoreJavaMySQL/rest/PrC_WSProductos", true);
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.setRequestHeader("cache-control", "no-cache");
xhttp.send("{\n\"DtCatCSec\" : 1,\n\"TDAcOD\" : \"0000000472\",\n\"pagina\" : 1,\n\"TdaCatCod\" : \"0000000607\"\n}");

https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.