Java org.osgi Bundle.getEntry undefined - java

I have the following code.
import org.osgi.framework.Bundle;
class Sample {
public static void main(String[] args) {
Bundle bundle = Platform.getBundle("abc.abc");
URL packageBundleUrl = bundle.getEntry("/");
}
}
But I am getting a compilation error for bundle.getEntry(). It says "The method getEntry(String) is undefined for the type Bundle".
I cannot understand what is the problem. Somebody please help me.

Related

Syntax error with creator method in Twilio in Java

I'm using Twilio in Java to send or receive text messages. I added twilio-7.47.1-jar-with-dependencies.jar to the project Java library and executed the following syntax based on an example in Twilio's website.
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;
public class Example {
public static final String ACCOUNT_SID = "AC41b4ea83f681353d261d5d0997d73b30";
public static final String AUTH_TOKEN = "my_auth";
public static void main(String[] args) {
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
Message message = Message.creator(
new com.twilio.type.PhoneNumber("+15558675310"),
new com.twilio.type.PhoneNumber("+15017122661"),
"This is the ship that made the Kessel Run in fourteen parsecs?")
.create();
System.out.println(message.getSid());
}
}
I have a syntax error with the creator method and it is: The method creator(String) in the type Message is not applicable for the arguments (PhoneNumber, PhoneNumber, String)
I looked at many websites related to this subject and all of them use the same syntax for this task.
Does anyone have any idea how to fix it?
Many thanks!

Getting error: Route() in Route cannot be applied to String

I'm designing a Java based MongoDB app and I've ran into a snag when working with Spark.
package com.tengen;
import spark.Request;
import spark.Response;
import spark.Route;
import spark.Spark;
public class HelloWorldSparkStyle {
public static void main(String[] args) {
Spark.get(new Route("/") {
#Override
public Object handle(Request request, Response response) {
return "Hello World From Spark";
}
});
}
}
On new Route("/") I get the error Route() in route cannot be applied to java.lang.string.
I'm confused as to why this doesn't work as I've followed their code exactly.
This should probably be posted on the MongoDB class forum, but I ran into a similar issue. Looks like the get method changed from when the course material was produced. The get now requires a path and a Route
get(path, Route)
import spark.Request;
import spark.Response;
import spark.Route;
import spark.Spark;
public class HelloWorldSparkStyle {
public static void main(String[] args){
Spark.get("/", new Route() {
public Object handle(final Request request, final Response response){
return "Hello World from Spark";
}
});
}
}
Actually I used spark-core-1.1.1.jar it worked fine for me, may be the newer versions of Spark(version 2.0.0) support some different syntax.So if you are using the latest version then you can follow the example given by Mike or just add spark-core-1.1.1.jar to your classpath your example will work fine
That would work in Spark 1. In Spark 2 is recommended by Spark the following (source: http://sparkjava.com/news.html):
import static spark.Spark.*;
public class HelloWorld {
public static void main(String[] args) {
get("/", (req, res) -> "Hello World From Spark");
}
}
Currently, Implementation of Spark Java framework needs to use directory out of Route. So you have to correct your code as follow:
public static void main(String[] args) {
spark.Spark.port(PortNumber);
Spark.get("/", new Route() {
public Object handle(Request request, Response response) throws Exception {
return "This is a sample page";
}
});
}
actually, "/" is the resource to your program. And if you want to change the default spark.Spark.port(PortNumber).
Change the version of Spark in the POM file from the exercise files you download from handout. That fixed issue for me.

GWT.log throwing error

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())

Java-Sandbox example throwing java.lang.NoClassDefFoundError

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.

Java and iMacros

I'm trying to follow this tutorial, regarding using Java with iMacros, but it isn't working. I'm getting an error saying "Could not find or load the main class" even though there is clearly a main class in the sample code on the website. Does anyone know why this might be happening? Thanks!
Update: Code sample
import com.jacob.activeX.*;
public class iMacroJACOBtest {
public static void main(String[] args) {
// Connect to iMacros Scripting Interface
System.out.println("Started.");
ActiveXComponent iim = new ActiveXComponent("imacros");
System.out.println("Calling iimInit");
// call iimInit()
iim.invoke("iimInit");
// call iimPlay()
System.out.println("Calling iimPlay");
iim.invoke("iimPlay", "CODE:URL GOTO=google.de");
}
}

Categories

Resources