Ir al contenido principal

[GWT] XMLHttpRequest cannot load. Origin is not allowed by Access-Control-Allow-Origin

I am developing an app front end  with GWT and this connect to other app that publish AppEngine Endpoints services. 
(Estoy desarrollando una aplicación  front end con GWT que se conecta a otra app que publica servicios rest en AppEngine usando Google Cloud EndPoints).

But, I is generating some problems (is not allowed by Access-Control-Allow-Origin.): 
(Pero, esto  me esta generando  algunos problemas).

The app GWT  call endpoint using  RequestBuilder. and the Endpoint app is other app with other domain. and both was deployed in https://appengine.google.com
(La app GWT llama a los servicios rest' endpoints' usando RequestBuilder. y la app endpoint es otra app con otro dominio. Ambas fueron deployadas en https://appengine.google.com).

Domains of the Apps:
-xappgwtx.appspot.com (GWT).
-xappendpointsx.appspot.com (Google Cloud Endpoints).

GWT Code:

public String getDevice(String id) {
String url = URL_SERVICE_BASE + "deviceendpoint/v1/device/get/" + id;
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
logger.info("::::::::::::sendRequest:::::::");
try {
builder.sendRequest(null, new RequestCallback() {
public void onResponseReceived(Request request, Response response) {
logger.info("response=" + response.getText() + " request:" + request);
resp = response.getText();
if (response.getStatusCode() == 200) {
System.out.println("response=" + response.getText());
logger.info("response=" + response.getText());
}
}

public void onError(Request request, Throwable exception) {
logger.info("onError response=" + exception.getMessage());
resp = exception.getMessage();
exception.printStackTrace();
}
});
} catch (RequestException e) {
logger.info("exception=" + e.getMessage());
e.printStackTrace();

}
return resp;
}

Chrome Console:

After much research in lists, stackoverflow and other forum, solve the problem
(Luego  de mucha investigación en listas y stackoverflow llegue a solucionar el  problema)

Solution: to solve this issue simply assign a variable to your json string into the eval

* Before:

  public static native JavaScriptObject fromJson(String json) /*-{

    return eval("(" + json + ")");

  }-*/;
  
  public final String toJson() {
    return new JSONObject(this).toString();
  }
  
  protected BaseJso() {
  }

* After: 

public class BaseJso extends JavaScriptObject {



public static native JavaScriptObject fromJson(String json) /*-{
eval('var res = ' + json);
return res;
}-*/;

public final String toJson() {
return new JSONObject(this).toString();
}

protected BaseJso() {
}

}

References:


Comentarios

Entradas populares de este blog

Debugging Remoto con Eclipse + WebSphere 7 + Maven

Tienes proyectos java en Maven y no puedes ubicar bugs fácilmente a falta de junit. Sin embargo, existe la alternativa de debugear la aplicación web a través de Java Debugger (jdb). Aquí les muestro una guía de como hacer un debug remoto de la aplicación web en Eclipse y WebSphere 7 a través de Java Debugger (JDB). Eclipse <----> Java Debugger (jdb) <----> WebSphere 7 1. Habilitar el WebSphere en modo Debug. Para esto seguir los siguientes pasos:  1. Servers –> Server Types –> WebSphere application servers 2. Under Server Infrastructure section –> expandir Java and Process Management –> Process definition 3. dentro de la seccion Additional Properties –> click Java Virtual Machine 4. clic en el check “Debug Mode” 5. En texbox Debug arguments, poner este valor:  -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8888 6. Reiniciar el servidor WebSphere. Ahora, WebSphere se inicia en modo debug, y escuchando en el pu

Java POI HSSFCell : añadir comentario en una celda

POI HSSFComment: Una manera simple de añadir un comentario en una celda de excel usando el metodo cell.setCellComment(). public class ExcelTools { public static void main(String[] args){ //escribirExcel(); //leerExcel(); validarValoresDuplicadosLista(); System.out.println("Ejemplo Finalizado."); } public static void escribirExcel(){ try{ //Se crea el libro Excel HSSFWorkbook wb = new HSSFWorkbook(); //Se crea una nueva hoja dentro del libro HSSFSheet sheet = wb.createSheet("HojaEjemplo"); //Se crea una fila dentro de la hoja HSSFRow row = sheet.createRow((short)0); HSSFPatriarch patr = sheet.createDrawingPatriarch(); //Creamos celdas de varios tipos row.createCell((short)0).setCellValue(1); row.createCell((short)1).setCellValue(1.2); row.createCell((short)2).setCellValue("ejemplo&

DB2 Error SQL20054N

Ejecutando un alter table me da el  siguiente error: db2 "ALTER TABLE PRG_REC.ESTIMADO_OBJETIVO DROP COLUMN VTA_OBJ_CAMP_FALTA_EXTRANJERA"; Error:  [db2inst1@ibmdb2test]:/home/db2inst1/1223/REQ1223/rollback$ db2 "ALTER TABLE PRG_REC.ESTIMADO_OBJETIVO DROP COLUMN VTA_OBJ_CAMP_FALTA_EXTRANJERA"; DB21034E  The command was processed as an SQL statement because it was not a valid Command Line Processor command.  During SQL processing it returned: SQL20054N  The table "PRG_REC.ESTIMADO_OBJETIVO" is in an invalid state for the operation.  Reason code="23" .  SQLSTATE=55019 Segun IBM la descripcion del error: SQL20054N:  La tabla   nombre-tabla   está en un estado no válido para la operación. Código de razón= código-razón . 23 Se ha realizado el número máximo de modificaciones recomendadas de REORG. Se permite un máximo de tres modificaciones recomendadas de REORG en una tabla antes de que se deba realizar reorg, para actualizar las fila