vertx.router 4.3.5, openjdk 11 is not working - router

I am using the vertx-web, vertx-core 4.3.5 version and open jdk 11.
Without router i could able to start the vertx and access the url without any error.
Below is the working code,
server = vertx.createHttpServer().requestHandler(request -> {
String file = "";
if (request.path().equals("/services")) {
request.response().putHeader("content-type", "text/plain").setStatusCode(200).end("Success");
} else if (!request.path().contains("/services")) {
request.response().putHeader("content-type", "text/plain").setStatusCode(400).end();
}
});
// Now bind the server:
server.listen(7898, res -> {
if (res.succeeded()) {
System.out.println("Success " );
startPromise.complete();
} else {
startPromise.fail(res.cause());
}
});
I have tried to implement the vertx-router, but its not working.
Code:
Router router = Router.router(vertx);
router.get("/").handler(rc -> rc.response().end("OK"));
router.get("/greetings").handler(rc -> rc.response().end("Hello world"));
router.get("/greetings/:name").handler(rc -> rc.response().end("Hello " + rc.pathParam("name")));
server = vertx.createHttpServer().requestHandler(router);
Exception:
Router router = Router.router(vertx);
router.get("/").handler(rc -> rc.response().end("OK"));
router.get("/greetings").handler(rc -> rc.response().end("Hello world"));
router.get("/greetings/:name").handler(rc -> rc.response().end("Hello " + rc.pathParam("name")));
server = vertx.createHttpServer().requestHandler(router);
getting the follow exception,
[vert.x-eventloop-thread-0] ERROR io.vertx.core.impl.ContextBase - Unhandled exception
java.lang.NoClassDefFoundError: io/vertx/core/http/impl/HttpServerRequestWrapper
at io.vertx.ext.web.impl.RoutingContextImpl.(RoutingContextImpl.java:80)
at io.vertx.ext.web.impl.RouterImpl.handle(RouterImpl.java:68)
Can you please give the suggestion to resolve the issue.

Related

Firefox link redirection issue using selenium

I have an automation service I build and before you run the automation you give it a link so when you start the automation you get first redirect to this link.
On my machine you get redirected perfectly, but on a friend machine the Firefox browser is opened and thats it.
does anyone know what might be the issue?
here is the class that responsible for this:
case class csvUploadData(clientUrl: String)
val csvUploadForm = Form(
mapping(
"clientUrl" -> nonEmptyText)(csvUploadData.apply)(csvUploadData.unapply))
def uploadCSV = Action.async(parse.multipartFormData) { implicit request =>
csvUploadForm.bindFromRequest.fold(
formWithErrors => {
Future {
Redirect(routes.Application.index).flashing(
"error" -> formWithErrors.error("clientUrl").get.message)
}
},
userData => {
request.body.file("csvFile").fold(Future {
Redirect(routes.Application.index).flashing(
"error" -> "Missing CSV file").withSession(request.session)
}) { formFile =>
import java.io.File
val filename = formFile.filename
Future {
val file = formFile.ref.file
val purchaseInfos = purchaseDS(file)
val t = Try {
val driver: WebDriver = new FirefoxDriver
val actions: ActionsHMRC = new ActionsHMRC(driver, userData.clientUrl)
val results = actions.insertData(purchaseInfos)
results.filter(_._2.isFailure)
}
t match {
case Success(failures) =>
val failedMsg = if (failures.nonEmpty)
failures.map{case (pi, err) => s"${pi.invoiceNumber} -> ${err}}"}.mkString("The following rows failed: [\n","\n","\n\n\n]")
else ""
Redirect(routes.Application.index).flashing(
"success" -> s"The file '$filename' automation successfuly.\n$failedMsg")
case Failure(e) =>
println(e)
Redirect(routes.Application.index).flashing (
"error" -> s"The file '$filename' automation failed.")
}
}
}
})
}
}
I have ver 42.0 and he have 43.0.4
I think that's happening because the new issue occurs with latest update of Mozilla firefox.
It's happening with me too.
To overcome from this issue you need to setPreference as xpinstall.signatures.required", false to firefox Profile and then pass it to driver object
firefoxProfile.setPreference("xpinstall.signatures.required", false);
Below code is working fine for old selenium jars.
static WebDriver driver=null;
public static void main(String[] args) {
final FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("xpinstall.signatures.required", false);
driver = new FirefoxDriver(firefoxProfile);
driver.get("https://www.google.de/");
Thanks it really helps but one change FirefoxDriver(firefoxProfile) is not valid. instead FirefoxOptions as below:
final FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("xpinstall.signatures.required", false);
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setProfile(firefoxProfile);
driver = new FirefoxDriver(firefoxOptions);

Google Web Toolkit - XSRF Protected Services : Invalid RPC Token

I've implemented XSRF Protected Services in GWT project. I'm using GWT 2.6.0 release. When I try to load my app in a browser I get a very strange exception as follows:
Uncaught com.google.gwt.user.client.rpc.RpcTokenException: Invalid RPC token (Invalid RpcToken type: expected 'com.google.gwt.user.client.rpc.XsrfToken' but got 'class com.google.gwt.user.client.rpc.XsrfToken')
I've searched my classpath and I only have one XsrfToken class provided by gwt-servlet.jar located inside my WAR file. I downloaded 2.6 code from GIT and I see the code that is throwing the exception is provided by ProxyCreator.java in the method generateCheckRpcTokenTypeOverride.
Does anyone have any idea as to why this exception would be thrown. The error indicates to me at least that it should pass given that what is expected is what it has.
I'm pasting the method in for completeness:
protected void generateCheckRpcTokenTypeOverride(SourceWriter srcWriter, TypeOracle typeOracle,
SerializableTypeOracle typesSentFromBrowser) {
JClassType rpcTokenType = typeOracle.findType(RpcToken.class.getName());
JClassType[] rpcTokenSubtypes = rpcTokenType.getSubtypes();
String rpcTokenImplementation = "";
for (JClassType rpcTokenSubtype : rpcTokenSubtypes) {
if (typesSentFromBrowser.isSerializable(rpcTokenSubtype)) {
if (rpcTokenImplementation.length() > 0) {
// >1 implematation of RpcToken, bail
rpcTokenImplementation = "";
break;
} else {
rpcTokenImplementation = rpcTokenSubtype.getQualifiedSourceName();
}
}
}
if (rpcTokenImplementation.length() > 0) {
srcWriter.println("#Override");
srcWriter.println("protected void checkRpcTokenType(RpcToken token) {");
srcWriter.indent();
srcWriter.println("if (!(token instanceof " + rpcTokenImplementation + ")) {");
srcWriter.indent();
srcWriter.println("throw new RpcTokenException(\"Invalid RpcToken type: " + "expected '"
+ rpcTokenImplementation + "' but got '\" + " + "token.getClass() + \"'\");");
srcWriter.outdent();
srcWriter.println("}");
srcWriter.outdent();
srcWriter.println("}");
}
}
Thanks very much in advance.

RMI and 2 machines - two way communication

I've got problem with RMI comunication between 2 machines (win 7 and win xp VM). The exception with I have problem is:
java.rmi.ConnectException: Connection refused to host: 169.254.161.21; nested exception is:
java.net.ConnectException: Connection timed out: connect
It's really weired because during connection I use address 192.168.1.4 (server), but exception somehow show sth different. I disabled firewall on both side. Ping working to both side. I tried telnet to server and use server port:
telnet 192.168.1.4 1099 and it's working... I can't figure out where the problem is.
If I run this on host side (eg server side) everything works fine.
How is it look from SERVER:
public class Server
{
public static void main(String args[])
{
InputStreamReader is = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(is);
String portNum, registryURL;
try{
System.out.println("Enter the RMIregistry port number:");
portNum = (br.readLine()).trim();
int RMIPortNum = Integer.parseInt(portNum);
startRegistry(RMIPortNum); // Registry registry = LocateRegistry.createRegistry(RMIPortNum);
ServerSide_Impl exportedObj = new ServerSide_Impl();
registryURL = "rmi://localhost:" + portNum + "/callback";
//registryURL = "rmi://192.168.1.4:" + portNum + "/callback";
Naming.rebind(registryURL, exportedObj);
System.out.println("Callback Server ready.");
}// end try
catch (Exception re) {
System.out.println(
"Exception in HelloServer.main: " + re);
} // end catch
} // end main
//This method starts a RMI registry on the local host, if
//it does not already exists at the specified port number.
private static void startRegistry(int RMIPortNum) throws RemoteException
{
try
{
Registry registry = LocateRegistry.getRegistry(RMIPortNum);
registry.list( );
// This call will throw an exception
// if the registry does not already exist
}
catch (RemoteException e)
{
Registry registry = LocateRegistry.createRegistry(RMIPortNum);
}
} // end startRegistry
} // end class
Client side is look like:
try
{
this.serverAd = serverAddress.getText();
String path = System.getProperty("user.dir");
String pathAfter = path.replace("\\", "/");
String pathFile = "file:/"+pathAfter + "/wideopen.policy";
System.setProperty("java.security.policy", pathFile);
System.setSecurityManager(new RMISecurityManager());
this.hostName = hostNameTextField.getText();
this.portNum = hostPortNumberTextField.getText();
RMIPort = Integer.parseInt(this.portNum);
this.time = Integer.parseInt(timeTextField.getText());
//this.registryURL = "rmi://localhost:" + this.portNum + "/callback";
String registryURLString = "rmi://"+this.serverAd+":" + this.portNum + "/callback";
this.registryURL = registryURLString;
ConsoleTextField.append("\n"+ this.registryURL + "\n");
// find the remote object and cast it to an
// interface object
obj = (ServerSide_Interface)Naming.lookup(this.registryURL);
boolean test = obj.Connect();
if(test)
{
callbackObj = new ClientSide_Impl();
// register for callback
obj.registerForCallback(callbackObj);
isConnected = true;
ConsoleTextField.append("Nawiązano połaczenie z serwerem\n");
TableModel modelTemp = obj.Server_GenerateStartValues();
myDataTable.setModel(modelTemp);
myDataTable.setEnabled(true);
}
else ConsoleTextField.append("Brak połączenia z serwerem\n");
}
catch (Exception ex ){
ConsoleTextField.append(ex + "\n");
System.out.println(ex);
}
This connection is working fine if I run client on host side. If I use VM and try connect between 2 different machines, I can;t figure out what did I do bad
There is something wrong with your etc/hosts file or your DNS setup. It is providing the wrong IP address to the server as the server's external IP address, so RMI embeds the wrong address into the stub, so the client attempts to connect to the wrong IP address.
If you can't fix that, you can set the system property java.rmi.server.hostname to the correct IP address at the server JVM, before exporting any RMI objects (including Registries). That tells RMI to embed that address in the stub.

Apache Abdera Client giving No credentials available for NTLM <any realm>#proxy.tcs.com:8080

I have seen many forum posts for this and tried several suggestions but still I am not able to solve this. The code works good at my home system, but behind the organization firewall it gives a exception message :
No credentials available for NTLM #proxy.tcs.com:8080
Here is the method which I am using
private static void UseAbdera() throws IOException
{
try
{
Abdera abdera = new Abdera();
AbderaClient client = new AbderaClient(abdera);
client.setProxy("OrgProxyHost", 8080);
NTLMAuthenticatorClass authenticator = new NTLMAuthenticatorClass("username", "password");
Authenticator.setDefault(authenticator);
NTCredentials ntcr = new NTCredentials("username", "password", "greenhouse.lotus.com", "India.TCS.com");
client.addCredentials("https://greenhouse.lotus.com", null, null, ntcr);
ClientResponse resp = client.get("https://greenhouse.lotus.com/forums/atom/service");
org.apache.abdera.model.Document<org.apache.abdera.model.Service> service_doc = resp.getDocument();
service_doc.writeTo(System.out);
System.out.println("\n");
org.apache.abdera.model.Service service = service_doc.getRoot();
org.apache.abdera.model.Collection collection = service.getCollection("Forums Feed Collection", "My Topics");
String coll_uri = collection.getResolvedHref().toASCIIString();
org.apache.abdera.model.Entry entry = abdera.newEntry();
entry.setTitle("TEST REPLY !");
// Mark private
resp = client.post(coll_uri, entry);
switch (resp.getType())
{
case SUCCESS:
String location = resp.getLocation().toASCIIString();
System.out.println("New entry created at: " + location);
break;
default:
System.out.println("Error: " + resp.getStatusText());
}
} catch (URISyntaxException ex)
{
Logger.getLogger(IBMConnectionMessages_ForumPractice.class.getName()).log(Level.SEVERE, null, ex);
}
}
This is the exception log I get
org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme
INFO: ntlm authentication scheme selected
Jul 6, 2012 10:42:03 AM org.apache.commons.httpclient.HttpMethodDirector processProxyAuthChallenge
INFO: No credentials available for NTLM #orgProxyHost:8080
Exception in thread "main" java.lang.IllegalStateException
at org.apache.abdera.protocol.client.CommonsResponse.(CommonsResponse.java:44)
at org.apache.abdera.protocol.client.AbderaClient.execute(AbderaClient.java:692)
at org.apache.abdera.protocol.client.AbderaClient.get(AbderaClient.java:216)
at org.apache.abdera.protocol.client.AbderaClient.get(AbderaClient.java:404)
at IBMConnectionMessages_ForumPractice.UseAbdera(IBMConnectionMessages_ForumPractice.java:231)
at IBMConnectionMessages_ForumPractice.main(IBMConnectionMessages_ForumPractice.java:45)
Please help, I have spent half a day on it.
your proxy may need ntlm authentication, so provide your proxy authentication details as NTCredentials while setting proxy credentials.

Guvnor execution server getting 401 when using AD-configured Guvnor as endpoint

We are using:
• Drools Execution Server that came with Drools 5.0.x
• Drools Guvnor 5.2 configured with active directory
The execution server and guvnor run on the same Tomcat and use the same port.
With the execution server you can have a listener for each package within the configuration file. I have two such files, from-file-system.properties that points to a local directory where a drools binary package is manually deployed. This works fine.
But I try to use with-guvnor.properties which points to a package binary on 5.3 Guvnor. Here is the file:
name=ndipiazza
newInstance=true
# Absolute path of the directory containing pc.drl: placeholder replaced by Ant.
url=http://localhost:9109/drools-guvnor/rest/packages/NDD_Test/binary
poll=10
I get the following error:
RuleAgent(ndipiazza) INFO (Mon Jun 18 18:11:32 EDT 2012): Configuring package provider : URLScanner monitoring URLs: http://localhost:9109/drools-guvnor/rest/packages/NDD_Test/binary
RuleAgent(ndipiazza) WARNING (Mon Jun 18 18:11:34 EDT 2012): Was an error contacting http://localhost:9109/drools-guvnor/rest/packages/NDD_Test/binary. Reponse header: {null=[HTTP/1.1 401 Unauthorized]
Some sort of authorization error very likely related to the active directory configuration within Guvnor 5.2.
This used to work for us just fine with an earlier version of Guvnor.
How can I fix this issue?
So we isolated the problem today. Drools Server 5.0.x cannot support a URL endpoint when it has authentication of any sort.
I reported a bug: https://issues.jboss.org/browse/JBRULES-3554
Without these changes, this will not work.
drools-core's org/drools/agent/HttpClientImpl.java
These two methods need to have authentication added in (marked by START and END NDD), and obviously switched with your username/password.
public LastUpdatedPing checkLastUpdated(URL url) throws IOException {
URLConnection con = url.openConnection();
HttpURLConnection httpCon = (HttpURLConnection) con;
try {
// **** START NDD *****
BASE64Encoder enc = new sun.misc.BASE64Encoder();
String userpassword = "ad-user" + ":" + "ad-password";
String encodedAuthorization = enc.encode( userpassword.getBytes() );
httpCon.setRequestProperty("Authorization", "Basic "+
encodedAuthorization);
// **** END NDD *****
httpCon.setRequestMethod( "HEAD" );
String lm = httpCon.getHeaderField( "lastModified" );
LastUpdatedPing ping = new LastUpdatedPing();
ping.responseMessage = httpCon.getHeaderFields().toString();
if ( lm != null ) {
ping.lastUpdated = Long.parseLong( lm );
} else {
long httpLM = httpCon.getLastModified();
if ( httpLM > 0 ) {
ping.lastUpdated = httpLM;
}
}
return ping;
} finally {
httpCon.disconnect();
}
}
public Package fetchPackage(URL url) throws IOException,
ClassNotFoundException {
URLConnection con = url.openConnection();
HttpURLConnection httpCon = (HttpURLConnection) con;
try {
// **** START NDD *****
BASE64Encoder enc = new sun.misc.BASE64Encoder();
String userpassword = "ad-user" + ":" + "ad-password";
String encodedAuthorization = enc.encode( userpassword.getBytes() );
httpCon.setRequestProperty("Authorization", "Basic "+
encodedAuthorization);
// **** END NDD *****
httpCon.setRequestMethod( "GET" );
Object o = DroolsStreamUtils.streamIn( httpCon.getInputStream() );
if ( o instanceof KnowledgePackageImp ) {
return ((KnowledgePackageImp) o).pkg;
} else {
return (Package) o;
}
} finally {
httpCon.disconnect();
}
}
Mystery solved.