logo
down
shadow

GWT RPC serialization for Dynamic Host Page


GWT RPC serialization for Dynamic Host Page

Content Index :

GWT RPC serialization for Dynamic Host Page
Tag : java , By : MJRider
Date : November 23 2020, 01:01 AM

it should still fix some issue So thx you @xi-chen and @richard-wallis
Part of the solution were discussed on gwt-storage github repo (https://github.com/seanchenxi/gwt-storage/issues/8#issuecomment-68443910)
<%@page import="com.google.gson.Gson"%>
<%@page import="com.learnkeeper.server.ServiceImpl"%>
<%@page import="com.google.gwt.user.server.rpc.RPC"%>
<%@page import="com.learnkeeper.shared.entities.User"%>
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<%
  Object user = request.getSession().getAttribute("user");
  String serialized_user = new Gson().toJson(RPC.encodeResponseForSuccess(ServiceImpl.class.getMethod("getUser"), user).substring("//OK".length()));
%>
<script type="text/javascript">var serialized_user=<%=serialized_user%>;</script>
</head>
<body>
public class User implements IsSerializable {
}
public class HostPageUtils {
  private static final native String getSerializedUser() /*-{
        return $wnd.serialized_user;
  }-*/;

  public static User getUser() {
    final String serializedUser = getSerializedUser();
    StorageSerializer storageSerializer = GWT.create(StorageSerializer.class);
    try {
      return storageSerializer.deserialize(User.class, serializedUser);
    } catch (Exception e) {
      throw new RuntimeException();
    }
  }
}

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

How to know strong name of GWT serialization policy at the time of host page generation?


Tag : gwt , By : Munir
Date : March 29 2020, 07:55 AM
it should still fix some issue I have integrated GWT with spring with a custom SerializationPolicyProvider where I always had to rename .gwt.rpc file and hard code the name in my custom SerializationPolicyProvider class. I got work around by looking at GWT docs. Strong Name is MD5 hash with length of 32. Each time RPC call is made to Spring based Controller's method: public String processCall(String payload), I parse the payload using following code to get strong name:
String strongName = null;
     if(payload!=null){
         StringTokenizer tokens = new StringTokenizer(payload,String.valueOf(AbstractSerializationStream.RPC_SEPARATOR_CHAR));
         while(tokens.hasMoreTokens()){
             String s = tokens.nextToken();
             if(s.length() == 32){
                 strongName = s;
                break;
             }
         }
     }
return SerializationPolicyLoader.loadFromStream(servletContext.getResourceAsStream(moduleBaseURL+"/"+strongName+"gwt.rpc");

Java REST Client still connects to old host after the dynamic address of the host was moved to another host


Tag : java , By : qba73
Date : March 29 2020, 07:55 AM
help you fix your problem I managed to find more time to dig into this issue.
I made more searches on the references made by some about a socket pool being used by the HttpUrlConnection instances.
System.setProperty("http.keepAlive", "false");

Web page works fine in local host but not when i host it in google drive


Tag : ajax , By : Lathentar
Date : March 29 2020, 07:55 AM
it should still fix some issue You can't send AJAX request to another domain/IP per default in all browsers. Those restrictions are turned off when browsing in the localhost/127.0.0.1 context.
If you want to sent a request to another domain/IP you have to enable cross-origin resource sharing or you have to use JSONP.

Create an embedded JavaScript in a Cross Domain Host Page which is not affected by the Host Page CSS?


Tag : javascript , By : Juice
Date : March 29 2020, 07:55 AM
I hope this helps you . I don't know GWT, but you can easily achieve this in plain JavaScript.
Let's assume you're creating an online-count widget. At first, create an iframe:
<script id="your-widget">
  // Select the script tag used to load the widget.
  var scriptElement = document.querySelector("your-widget");
  // Create an iframe.
  var iframe = document.createElement("iframe");
  // Insert iframe before script's next sibling, i.e. after the script.
  scriptElement.parentNode.insertBefore(iframe, scriptElement.nextSibling);
  // rest of the code
</script>
// The URL of your API, without JSONP callback parameter.
var url = "your-api-url";
// Callback function used for JSONP.
// Executed as soon as server response is received.
function callback(count) {
  // rest of code
}
// Create a script.
var script = document.createElement("script");
// Set script's src attribute to API URL + JSONP callback parameter.
// It makes browser send HTTP request to the API.
script.src = url + "?callback=callback";
// Create a div element
var div = document.createElement("div");
// Insert online count to this element.
// I assume that server response is plain-text number, for example 5.
div.innerHTML = count;
// Append div to iframe's body.
iframe.contentWindow.document.body.appendChild(div);
<script type="text/javascript">
(function(d){
    var f = d.getElementsByTagName('SCRIPT')[0], p = d.createElement('SCRIPT');
    window.WidgetId = "1234";   
    p.type = 'text/javascript';
    p.setAttribute('charset','utf-8');
    p.async = true;
    p.id = "your-widget";
    p.src = "//www.example.com/assets/clientwidget/chatwidget.nocache.js";     
    f.parentNode.insertBefore(p, f);
}(document));
</script>    
// Select the script tag used to load the widget.
var scriptElement = document.querySelector("#your-widget");
// Create an iframe.
var iframe = document.createElement("iframe");
// Insert iframe before script's next sibling, i.e. after the script.
scriptElement.parentNode.insertBefore(iframe, scriptElement.nextSibling);

// The URL of your API, without JSONP callback parameter.
var url = "your-api-url";
// Callback function used for JSONP.
// Executed as soon as server response is received.
function callback(count) {
  // Create a div element
  var div = document.createElement("div");
  // Insert online count to this element.
  // I assume that server response is plain-text number, for example 5.
  div.innerHTML = count;
  // Append div to iframe's body.
  iframe.contentWindow.document.body.appendChild(div);
}
// Create a script.
var script = document.createElement("script");
// Set script's src attribute to API URL + JSONP callback parameter.
// It makes browser send HTTP request to the API.
script.src = url + "?callback=callback";

Apache dynamic wildcard host rewrite with dynamic subdomains


Tag : apache , By : ┬Áilad
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • Class file name must end with .class exception in Java Search
  • Java + SQL Server - a viable solution?
  • JUnit vs TestNG
  • Are there any decent free Java data plotting libraries out there?
  • Java Time Zone is messed up
  • Eclipse on win64
  • Automate builds for Java RCP for deployment with JNLP
  • Is there a real benefit of using J#?
  • Why can't I use a try block around my super() call?
  • Accessing post variables using Java Servlets
  • Is this really widening vs autoboxing?
  • How can I Java webstart multiple, dependent, native libraries?
  • Why doesn't Java autoboxing extend to method invocations of methods of the autoboxed types?
  • How do I use Java to read from a file that is actively being written to?
  • What code analysis tools do you use for your Java projects?
  • IllegalArgumentException or NullPointerException for a null parameter?
  • How do I configure and communicate with a serial port?
  • What are the different methods to parse strings in Java?
  • Android Broadcastreceiver for other apps install/delete not working
  • Android Studio onClick not working in BindViewHolder
  • How to use Spring Converter for some controllers only?
  • How verify that 3 numbers in sequence are equals?
  • When using .compareTo to compare dates, why doesn't it take Months into account?
  • Does the perfomance of "filter then map" and "map then filter" differ in a Stream?
  • How can I set the initial Delay after pressing the start Button to a specific time (HH:mm:ss) format
  • How to switch between Android devices during the tests
  • How to configure java.util.logging via properties to use standard output?
  • How to iterate through array in order
  • Is there better way of iteration to find the evenly divisible number?
  • How do I avoid using if statements with a large amount of variables in java
  • Writing JUnit test cases for a Spring Boot Service Application with autowired components
  • Cors for GET with Postman not showing headers
  • Printing values in different column same row using APACHE POI
  • Fully decompile java6 web application
  • Passing keycloak configuration parameters in the code rather than reading from application.properties
  • setDataSource() IO exception
  • Unexpected Output while retrieving Data from mongodb and displaying in a csv file?
  • Algorithm for searching a value in two arrays
  • How to avoid casting with generic return values?
  • Java/RegEx - Negation of pattern not working
  • How to split a string to non empty words if it might include a separator like tab on first place
  • Supplier<Sequence<String>> cannot be iterated more than once
  • Why there is only one thread can actually started in @PostConstruct method?
  • Manage CompletionStage inside of Netty handler
  • Url Problem while Developing on Localhost and deploy on Remote Virtual Server
  • How to identify the missing type id in Jackson error?
  • android data binding error: cannot find symbol
  • Spring Boot application with a jar dependency does not run after maven build
  • Spring Data JPA query , filter ? search engine ? JPQL?
  • Why LiveData returns null in ViewModel?
  • what this line of code mean....new URLClassLoader(new URL[0],getClass().getClassLoader());
  • Why do need to use new Random() instead of just Random Randomnum?
  • I want to access zk components from the java file
  • How do I cast FieldValue.serverTimestamp() to Kotlin/Java Date Class
  • Insertion Sort Double Array with User Input - JAVA
  • Creating 2 dimesional array with user input and find sum of specific columns
  • can not get Advertising ID Provider in android
  • Convert list of Objects to map of properties
  • How to represent an undirected weighted graph in java
  • Return values as array from collection
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com