I am writing a java application using Vertx. I am trying to deploy one of my modules using the following code. But I am facing IllegalArgumentException, which I am not able to solve.
Part of my main class:
System.out.println(System.getProperty("user.dir")
+ File.separator + "modules" + File.separator
+ "agents-0.0.1-SNAPSHOT-mod.zip");
InputStream agf = new FileInputStream(System.getProperty("user.dir")
+ File.separator + "conf" + File.separator
+ "dbproperties1.json");
String json = IOUtils.toString( agf );
LOGGER.debug("db json:::"+json);
JsonObject configprop = new JsonObject(json);
pm.deployModuleFromZip(System.getProperty("user.dir")
+ File.separator + "modules" + File.separator
+ "agents-0.0.1-SNAPSHOT-mod.zip", configprop, 1,
new AsyncResultHandler<String>() {
public void handle(AsyncResult<String> asyncResult) {
LOGGER.debug("Deployment agnet ID dddd");
if (asyncResult.succeeded()) {
LOGGER.debug("Deployment agnet ID is "
+ asyncResult.result());
} else {
LOGGER.debug("Deployment agnet ID is null "
+ asyncResult.result());
asyncResult.cause().printStackTrace();
}
}
});
agf.close();
The error in the console is as follows:
java.lang.IllegalArgumentException: 'other' has different root
at sun.nio.fs.WindowsPath.relativize(WindowsPath.java:392)
at sun.nio.fs.WindowsPath.relativize(WindowsPath.java:44)
at org.vertx.java.platform.impl.DefaultPlatformManager.setPathResolver(DefaultPlatformManager.java:1128)
at org.vertx.java.platform.impl.DefaultPlatformManager.access$2000(DefaultPlatformManager.java:55)
at org.vertx.java.platform.impl.DefaultPlatformManager$18.run(DefaultPlatformManager.java:1276)
at org.vertx.java.core.impl.DefaultContext$3.run(DefaultContext.java:171)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:353)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:366)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
at java.lang.Thread.run(Thread.java:745)
Any help in this regard will be appreciated.
I found the solution for my case.
For a vertx project, there will be mod.json file in the project. It should have the following json.
{
"main": "com.company.agent.Manager",
"preserve-cwd": true
}
"preserve-cwd": true does the help.
Related
Is there a way to get the name of the class that the script was started from inside the #BeforeSuite annotation when not executed via xml file?
Doing this:
reportName = new Exception().getStackTrace()[0].getClassName();
returns the class itself that contains the #BeforeSuite annotation and this:
reportName = new Exception().getStackTrace()[1].getClassName();
returns sun.reflect.NativeMethodAccessorlmpl
If I execute a script directly from a separate class, I want to get that info because I am using it to name my Extent Report file name.
In case you are wondering what the code inside the #BeforeSuite annotation looks like:
// Set Extent Report file name from the global properties file
String reportName = ctx.getCurrentXmlTest().getSuite().getName();
if (reportName.equals("Default suite"))
{
reportName = new Exception().getStackTrace()[0].getClassName();
}
String timeStamp = new SimpleDateFormat("HH.mm.ss").format(new Date());
// Initialize Extent Reports and modify the looks/output
String extentReportPath = "";
if (extent == null) {
if (os.equals("Mac"))
{
extentReportPath = reportPath + "/" + project + "-" + reportName + "-" + environment + "-" + browser + "-" + timeStamp + ".html";
}
else if (os.equals("Windows"))
{
extentReportPath = reportPath + "\\" + project + "-" + reportName + "-" + environment + "-" + browser + "-" + timeStamp + ".html";
}
// Start new report
extent = new ExtentReports(extentReportPath, true);
}
There's more to it, but this is the part pertinent to my question.
---UPDATE---
This was my solution:
// Set Extent Report file name from the global properties file
String reportName = ctx.getCurrentXmlTest().getSuite().getName();
if (reportName.equals("Default suite"))
{
List<ITestNGMethod> allMethods = ctx.getSuite().getAllMethods();
for (ITestNGMethod method : allMethods)
{
String fullMethod = method.toString();
int indexOf = fullMethod.indexOf(".");
reportName = fullMethod.replace(fullMethod.substring(indexOf), ""); }
}
You can pass argument ITestContext to the beforesuite method. testNG will auto-inject it. This should have the information you looking for.
context.getSuite().getAllMethods -> List of TestNGMethods.getRealClass() or getTestClass().
I am java developer.I need to get file information from dropbox using java api.
I tried with metadata class.Here i am getting only id,name,path,size of the file.
But i need to get other information like owner name,mimetype,Createddate
ListFolderResult result = client.files().listFolderBuilder("")
.withIncludeDeleted(false)
.withRecursive(true)
.withIncludeMediaInfo(true)
.start();
while (true) {
List<Metadata> entries = result.getEntries();
int idx = 0;
for (Metadata metadata : entries) {
if (metadata instanceof FolderMetadata) {
System.out.println("" + ++idx + ": FOLDER [" + metadata.getPathDisplay() + "], [" + metadata.getName() + "]");
} else if (metadata instanceof FileMetadata) {
System.out.println("" + ++idx + ": File [" + metadata.getPathDisplay() + "], [" + metadata.getName() + "]");
String filePath = metadata.getPathLower().replace(metadata.getName().toLowerCase(), "");
System.out.println(metadata.getPathLower());
System.out.println("FILE PATH"+filePath);
System.out.println("Dropbox"+((FileMetadata) metadata).getRev());
System.out.println("Dropbox"+((FileMetadata) metadata).getClientModified());
System.out.println("Dropbox"+((FileMetadata) metadata).getMediaInfo());
System.out.println("Dropbox"+((FileMetadata) metadata).getMediaInfo().getMetadataValue());
System.out.println("Dropbox"+((FileMetadata) metadata).getSharingInfo());
..
Thanks advance
The FileMetadata object that you get back is documented here:
https://dropbox.github.io/dropbox-sdk-java/api-docs/v2.0.x/com/dropbox/core/v2/files/FileMetadata.html
It doesn't offer the additional information you're looking for, and there isn't another way to get it via the API, but we'll consider this a feature request.
You can keep your own file extension to mime type mapping if you'd like though. For example, you can find our groupings for some file types permission here:
https://www.dropbox.com/developers-v1/reference/devguide
I am using the Java library Metadata-extractor and cannot extract the tag
description correctly using the getUserCommentDescription method code below,
although the tag.getDescription does work:
String exif = "File: " + file;
File jpgFile = new File(file);
Metadata metadata = ImageMetadataReader.readMetadata(jpgFile);
for (Directory directory : metadata.getDirectories()) {
String directoryName = directory.getName();
for (Tag tag : directory.getTags()) {
String tagName = tag.getTagName();
String description = tag.getDescription();
if (tagName.toLowerCase().contains("comment")) {
Log.d("DEBUG", description);
}
exif += "\n " + tagName + ": " + description; //Returns the correct values.
Log.d("DEBUG", directoryName + " " + tagName + " " + description);
}
if (directoryName.equals("Exif IFD0")) {
// create a descriptor
ExifSubIFDDirectory exifDirectory = metadata.getDirectory(ExifSubIFDDirectory.class);
ExifSubIFDDescriptor descriptor = new ExifSubIFDDescriptor(exifDirectory);
Log.d("DEBUG","Comments: " + descriptor.getUserCommentDescription()); //Always null.
}
Am I missing something here?
You are checking for the directory name Exif IFD0 and then accessing the ExifSubIFDDirectory.
Try this code outside the loop:
Metadata metadata = ImageMetadataReader.readMetadata(jpgFile);
ExifSubIFDDirectory exifDirectory = metadata.getDirectory(ExifSubIFDDirectory.class);
ExifSubIFDDescriptor descriptor = new ExifSubIFDDescriptor(exifDirectory);
String comment = descriptor.getUserCommentDescription();
If this returns null then it may be an encoding issue or bug. If you run this code:
byte[] commentBytes =
exifDirectory.getByteArray(ExifSubIFDDirectory.TAG_USER_COMMENT);
Do you have bytes in the array?
If so then please open an issue in the issue tracker and include a sample image that can be used to reproduce the problem. You must authorise any image you provide for use in the public domain.
{
"lastUpdated":1404620562,
"invasions":{
"Vibrant Valley":{
"asOf":1404620562,
"type":"Penny Pincher",
"progress":"959/1000"
}
},
"error":null
}
I'm new to using Json & Gson so be patient.
So I am attempting to make an application for myself that allows me to view the information from this json file. The only problem is that it is constantly changing and sometimes there will be more then one object under invasions or sometimes there will be none. How would I parse this with gson? Thanks. Note I am grabbing values from here.
https://www.toontownrewritten.com/api/invasions
Thanks!
Use the JsonParser class
String myJson = "{" +
" \"lastUpdated\":1404620562," +
" \"invasions\":{" +
" \"Vibrant Valley\":{" +
" \"asOf\":1404620562," +
" \"type\":\"Penny Pincher\"," +
" \"progress\":\"959/1000\"" +
" }" +
" }," +
" \"error\":null" +
"}"
JsonElement jelement = new JsonParser().parse(myJson);
JsonObject jobject = jelement.getAsJsonObject();
long lastUpdated = jobject.get("lastUpdated").getAsLong();
I am trying to use getValidFileName (String, String, list, boolean) method of DefaultValidator class from ESAPI provided jar (esapi-2.0_rc11) to validate file name. But on run time getting No such method exception.
This is my code:
public static String getValidFileName(String input,String[] strFileExtns, Boolean isNullable) throws Exception
{
List <String> fileExtnsList = new ArrayList <String>();
if (strFileExtns != null && strFileExtns.length > 0)
for(int i=0; i<strFileExtns.length; i++)
fileExtnsList.add(strFileExtns[i]);
return new DefaultValidator().getValidFileName("FileNameValidation", input, fileExtnsList, isNullable);
}
I am getting
java.lang.NoSuchMethodError:org/owasp/esapi/reference/DefaultValidator.getValidFileName(Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Z)Ljava/lang/String;
Code present in the jar:
public String getValidFileName(String context, String input, List<String> allowedExtensions, boolean allowNull)
throws ValidationException, IntrusionException
{
if ((allowedExtensions == null) || (allowedExtensions.isEmpty())) {
throw new ValidationException("Internal Error", "getValidFileName called with an empty or null list of allowed Extensions, therefore no files can be uploaded");
}
String canonical = "";
try
{
if (isEmpty(input)) {
if (allowNull) return null;
throw new ValidationException(context + ": Input file name required", "Input required: context=" + context + ", input=" + input, context);
}
canonical = new File(input).getCanonicalFile().getName();
getValidInput(context, input, "FileName", 255, true);
File f = new File(canonical);
String c = f.getCanonicalPath();
String cpath = c.substring(c.lastIndexOf(File.separator) + 1);
if (!(input.equals(cpath)))
throw new ValidationException(context + ": Invalid file name", "Invalid directory name does not match the canonical path: context=" + context + ", input=" + input + ", canonical=" + canonical, context);
}
catch (IOException e)
{
throw new ValidationException(context + ": Invalid file name", "Invalid file name does not exist: context=" + context + ", canonical=" + canonical, e, context);
}
Iterator i = allowedExtensions.iterator();
while (i.hasNext()) {
String ext = (String)i.next();
if (input.toLowerCase().endsWith(ext.toLowerCase()))
return canonical;
}
throw new ValidationException(context + ": Invalid file name does not have valid extension ( " + allowedExtensions + ")", "Invalid file name does not have valid extension ( " + allowedExtensions + "): context=" + context + ", input=" + input, context);
}
Someone please help me on this.
java.lang.NoSuchMethodError errors are often caused by a dependency issue. If you are using maven (I assume you may be, as this error often occurs with it), troubleshoot the error as follows:
Try issuing "mvn dependency:tree -Dverbose" on the command line and check that the library containing org/owasp/esapi/reference/DefaultValidator is the version you intended. If not, you can use the exclusions tag to exclude the incorrect version from the dependency that is including the incorrect version.
Also check that your resulting classpath lists the dependencies in the correct order.