Error 404 when consuming Genexus REST service from Javascript

0

I have a Java application made in Genexus 15 U1 (java-mysql-tomcat8), where I have created a procedure with REST protocol property in true, whose parameters in rule are (the output is a sdt): parm (in: & DtCatCSec, in: & TdaCod, in: & page, in: & TdaCatCod, out: & SDTC_CatProducts);

I have tried to call this service from javascript in the following way:

$.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);
  }

But it returns the error in browser console: Failed to load resource: the server responded with a status of 404 (Not Found)

My configuration in the tomcat web.xml is as follows:

 <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>
It is the first time I do this type of integrations, I thank you in advance for your help !!!     
asked by Wen AP 12.05.2017 в 17:52
source

1 answer

0

I solved my mistake myself hehe, this is the correct way to call a rest service of Genexus from JS, there should be more, but this worked for me:

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);
});
    
answered by 16.05.2017 в 19:29