I am new to GWT and trying to build a sample application. Here is my EntryPoint class.
package com.google.gwt.sample.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
public class TalkToServer implements EntryPoint {
public TalkToServer() {}
public void onModuleLoad() {
HTTPRequest.asyncGet
(GWT.getHostPageBaseURL() + "person.xml",
new ResponseTextHandler() {
public void onCompletion(String responseText) {
GWT.log("some log message");
}
});
}
}
The error here is -
log(java.lang.String,java.lang.Throwable) in com.google.gwt.core.client.GWT cannot be applied to (java.lang.String)
I have checked gwt's javadoc and found that log can take string as argument. I am not able to figure out why log is throwing this error. Please let me know if I am missing something.
Try using
GWT.log("some log message", new Throwable())
Related
This is a simple Java code as a Spark job, mentioned in Spark job-server github repo
package com.sample.wordcount;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import org.apache.spark.api.java.JavaSparkContext;
import spark.jobserver.japi.JSparkJob;
import spark.jobserver.api.JobEnvironment;
public class SparkJavaJob implements JSparkJob {
#Override
public Object run(Object sc, JobEnvironment runtime, Config data) {
return "OK";
}
#Override
public Config verify(Object sc, JobEnvironment runtime, Config config) {
return ConfigFactory.empty();
}
}
While submitting it to Spark Jobserver, it shows Job loading failed.
{
"status": "JOB LOADING FAILED",
"result": {
"message": "com.sample.wordcount.SparkJavaJob cannot be cast to spark.jobserver.api.SparkJobBase",
"errorClass": "java.lang.ClassCastException"
}
Can anyone help me out with this?
I was able to solve this issue. Basically I had to change the context type, while creating it.
curl -d '' localhost:8090/contexts/jcontext?context-factory=spark.jobserver.context.JavaSparkContextFactory&num-cpu-cores=2&memory-per-node=1g
We have to use "spark.jobserver.context.JavaSparkContextFactory"
after some work on a spigot plugin IntelliJ itself doesn't give an error, however upon the jar build (when loaded into the server) the console prints an unirest callback error.
The project uses the spigot dependency for 1.13.2.
Code:
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.async.Callback;
import com.mashape.unirest.http.exceptions.UnirestException;
import org.bukkit.plugin.java.JavaPlugin;
public class Weather extends JavaPlugin {
#Override
public void onEnable() {
// Plugin startup logic
getServer().getScheduler().runTaskTimer(this, () -> Unirest.get("https://data.buienradar.nl/2.0/feed/json").asJsonAsync(new Callback<JsonNode>() {
#Override
public void completed(HttpResponse<JsonNode> response) {
getServer().broadcastMessage(response.getBody().toString());
getLogger().info(response.getBody().toString());
}
#Override
public void failed(UnirestException e) {
e.printStackTrace();
}
#Override
public void cancelled() {
}
}), 0, 20 * 30);
}
}
org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError - Unirest means, that the class Unirest is not found at runtime. A common mistake is, that you have added the library containing the class Unirest as dependency, but the library does not get exported with your plugin. So, make sure, that when you export your plugin, the library containg the class Unirest is also included in the resulting jar file.
I have the following webservice :
package testSmart;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
#WebService(name="AddHM", portName="prtNameHM", serviceName="srvNameHM", targetNamespace="hm.com")
#SOAPBinding(style=Style.RPC)
public class add {
AddBusinessLogic add=new AddBusinessLogic();
#WebMethod(action="GoAdd", operationName="Go_AddNumber")
public int addNum(int i, int j) {
return add.addNum(i, j);
}
}
which works perfectly fine with glassfish.
then I stopped glassfish and use the following code to make my server :
import javax.xml.ws.Endpoint;
public class publisher {
public static void main(String[] args) {
// TODO Auto-generated method stub
Endpoint.publish("http://localhost:1234/add", new add());
}
}
Now when I try this link:
http://localhost:1234/add
Nothing happens and the browser says no data received.
Even after trying different port the same problem exist.
Can anyone help me how to fix it?
Call to http://localhost:1234/add will not get you anything because there is no specific document with that URI that browser can get. But if you type
http://localhost:1234/add?wsdl
you should get the generated wsdl document.
Anyone with experience using Java-Sandbox, I have implemented one of the basic examples found in the documentation but i cant get it working.
Code:
SandPlayground.java
import java.util.concurrent.TimeUnit;
import net.datenwerke.sandbox.*;
import net.datenwerke.sandbox.SandboxContext.AccessType;
import net.datenwerke.sandbox.SandboxContext.RuntimeMode;
import net.datenwerke.sandbox.SandboxedEnvironment;
public class SandPlayground {
/**
* #param args
*/
public static void main(String[] args) {
System.out.println("Running...");
SandboxService sandboxService = SandboxServiceImpl.initLocalSandboxService();
// configure context
SandboxContext context = new SandboxContext();
//context.setRunRemote(true);
context.setRunInThread(true);
context.setMaximumRunTime(2, TimeUnit.SECONDS, RuntimeMode.ABSOLUTE_TIME);
context.addClassPermission(AccessType.PERMIT, "java.lang.System");
context.addClassPermission(AccessType.PERMIT, "java.io.PrintStream");
//run code in sandbox
SandboxedCallResult<String> result = sandboxService.runSandboxed(MyEnvironment.class, context, "This is some value");
// output result
System.out.println(result.get());
}
}
MyEnvironment.java
import net.datenwerke.sandbox.SandboxedEnvironment;
public class MyEnvironment implements SandboxedEnvironment<String> {
private final String myValue;
public MyEnvironment(String myValue){
this.myValue = myValue;
}
#Override
public String execute() throws Exception {
/* run untrusted code */
System.out.println(myValue);
/* return some value */
return "This is a different value";
}
}
And I'm getting the error:
EDIT: I've included the dependencies, but I'm still getting some errors:
With the code above I get:
Exception in thread "main" net.datenwerke.sandbox.exception.SandboxedTaskKilledException: killed task as maxmimum runtime was exceeded
at net.datenwerke.sandbox.SandboxMonitorDaemon.testRuntime(SandboxMonitorDaemon.java:82)
at net.datenwerke.sandbox.SandboxMonitorDaemon.run(SandboxMonitorDaemon.java:57)
at java.lang.Thread.run(Thread.java:724)
and when i remove the context.setMaximumRunTime() call, I get:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections/map/IdentityMap ...
Any help is much appreciated.
most likely you are missing the javassist library (see the documentatio of the sandbox for dependencies: http://blog.datenwerke.net/p/the-java-sandbox.html). You'll find the javassist library on sourceforge at: https://sourceforge.net/projects/jboss/files/Javassist/
The javaassist library is used to remove finalizers in loaded code. This can be turned off in the sandbox context:
contex.setRemoveFinalizers(false)
Hope this helps.
I've been using the onStart method for a while and it works no problem, but when I try to override onBadRequest, I get an error:
Here's the class:
import models.User;
import play.Application;
import play.GlobalSettings;
import play.Logger;
import play.mvc.Result;
import views.html.error_page;
import static play.mvc.Results.badRequest;
public class Global extends GlobalSettings {
#Override
public void onStart(Application app){
Logger.info("Application started!");
// Check if the database is empty
if(User.find.findRowCount()==0){
Ebean.save((List) Yaml.load("initial-data.yml"));
}
}
#Override
public void onStop(Application app){
Logger.info("Application stopped!");
}
#Override
public Result onBadRequest(String uri, String error) {
Logger.info("Bad Request");
return badRequest(error_page.render());
}
}
The first two work no problem, but the third one causes the error.
Here's the API entry:
You used the old API.
Here's the API for Play 2.1.1:
http://www.playframework.com/documentation/api/2.1.1/java/play/GlobalSettings.html
Called when an action has been found, but the request parsing has failed.
Result onBadRequest(Http.RequestHeader request, java.lang.String error)
Called when an exception occurred.
Result onError(Http.RequestHeader request, java.lang.Throwable t)
This works:
#Override
public Result onError(Http.RequestHeader request, Throwable t){
Logger.error("Error thrown: " + t.getMessage());
return internalServerError(error_page.render());
}
This page was useful. I'm still confused why the API is wrong.
I hope this helps out somebody with a similar problem.