JDeveloper don't find SignerEPES having xades4j.jar - java

Im using #lgoncalves code to sign an XML with XADES4J EPES. But however jdeveloper don't find (SignerEPES) when I have the xades4j.jar on my classpath. I let you the image of my library and the code:
Project Library
private static void signBes(Document doc) throws XadesProfileResolutionException, XAdES4jException,
KeyStoreException {
//Document doc = getTestDocument();
Element elemToSign = doc.getDocumentElement();
SignaturePolicyInfoProvider policyInfoProvider = new SignaturePolicyInfoProvider()
{
#Override
public SignaturePolicyBase getSignaturePolicy()
{
return new SignaturePolicyIdentifierProperty(
new ObjectIdentifier("oid:/1.2.4.0.9.4.5", IdentifierType.OIDAsURI, "Policy description"),
new ByteArrayInputStream("Test policy input stream".getBytes()))
.withLocationUrl(""); //<- I really don't know what to put right here.
}
};
KeyingDataProvider kdp = new FileSystemKeyStoreKeyingDataProvider("pkcs12","C:/****/****.pfx",new FirstCertificateSelector(),new DirectPasswordProvider("****"),new DirectPasswordProvider("****"),true);
SignerEPES signer = (SignerEPES) new XadesEpesSigningProfile(kdp, policyInfoProvider).newSigner();
new Enveloped(signer).sign(elemToSign);
}
Link to the sample code on GitHub: https://github.com/luisgoncalves/xades4j/blob/master/src/test/java/xades4j/production/SignerEPESTest.java
EDIT:
I tried to force the import like (import xades4j.production.SignerEPES) but IDE says "Cannot be accessed from outside package" but really don't know what that means

SignerEPES is a package-private class, so application code won't be able to import it. The tests use it just to be sure that the proper type is being returned.
In your code you can just use XadesSigner as the type of your variable.

Related

Why does Playwright's generated Java code have invalid syntax?

When I use the Playwright's codegen feature it traces my clickpath into a Java file. But the created file has the wrong syntax, so I can't compile it.
I start the codegen with:
mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="codegen wikipedia.org"
And the inspector provides this code:
public class Example {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions()
.setHeadless(false));
BrowserContext context = browser.newContext();
page.navigate("https://en.wikipedia.org/wiki/Main_Page");
page.getByPlaceholder("Search Wikipedia").click();
page.getByPlaceholder("Search Wikipedia").fill("stackoverflow");
page.getByRole("button", new Page.GetByRoleOptions().setName("Go")).click();
assertThat(page).hasURL("https://en.wikipedia.org/wiki/Stack_Overflow");
}
}
}
But there is already the first error. The method getByRole requires an AriaRole as its first parameter, not a String. So it's easy to fix, but I think it's not the idea of the product to generate code and let the developer fix it.
In some YouTube tutorials the inspector generates only fill and click functions with powerful selectors inside.
Is there a way to change the generated output to a specifc "code-style"? Or is there another reason why other people get nice working code and I don't?
My dependency:
<dependency>
<groupId>com.microsoft.playwright</groupId>
<artifactId>playwright</artifactId>
<version>1.27.0</version>
</dependency>
Sorry if I am wrong. But you should get something like this from an inspector which compiles fine
package org.example;
import com.microsoft.playwright.*;
import com.microsoft.playwright.options.*;
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
import java.util.*;
public class Example {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions()
.setHeadless(false));
BrowserContext context = browser.newContext();
// Open new page
Page page = context.newPage();
// Go to https://www.wikipedia.org/
page.navigate("https://www.wikipedia.org/");
// Click input[name="search"]
page.locator("input[name=\"search\"]").click();
// Fill input[name="search"]
page.locator("input[name=\"search\"]").fill("stackoverflow");
// Click button:has-text("Search")
page.locator("button:has-text(\"Search\")").click();
assertThat(page).hasURL("https://en.wikipedia.org/wiki/Stack_Overflow");
}
}
}

How can I add a custom file(built for every created project) in Eclipse?

I want to create a plug-in for Eclipse in which every custom project I create has a specific template and specific files. I managed to create the template(folder1/folder_name1, folder1/folder_name2, folder2/folder_name1, etc), but I am still trying to figure it out on how to make sure that when I create this type of project, some custom files are created(namely in folder_name1 and folder_name2). How would you think is the best way to do it?
I have tried using IFile, but I'm not really sure on how to use it.
This is the function that creates a project:
public static IProject createProject(String projectName, URI location) {
Assert.isNotNull(projectName);
Assert.isTrue(projectName.trim().length() > 0);
IProject project = createBaseProject(projectName, location);
try {
addNature(project);
String[] paths = {
"folder1/folder_name1", //$NON-NLS-1$
"folder1/folder_name2",
"folder2/folder_name1",
"folder2/folder_name2"}; //$NON-NLS-1$
addToProjectStructure(project, paths);
} catch (CoreException e) {
e.printStackTrace();
project = null;
}
return project;
}
I expect that a file(let's name it test.cpp) it's created in folder_name1 and folder_name2 for each folder1/2.
You have project object ie IProject project = createBaseProject(projectName, location);
you can use the following code snippet
.... other code ...
IFile templateFile = project.getFile("/projectPath/folder1/folder_name1/templateFile1.txt");
String fileContents = "Template File Contents";//You can get the contents from source
InputStream source = new ByteArrayInputStream(contents.getBytes());
templateFile .create(source, false, null);
I hope in this you can create file specific to project folder. You can also get answers from others.

Java Code error while Streaming Data into BigQuery

I'm beginner in Java. Can you tell me please why the following code detected an error though I take exactly the same code given as an example in the following URL of google:
https://developers.google.com/bigquery/streaming-data-into-bigquery#streaminginsertexamples
the word bigquery is underlying in red and the error is: bigquery cannot be resolved.
I remember that I want to stream my data into BigQuery one record at a time by using the tabledata().insertAll() method.
This is my code:
import java.io.IOException;
import java.util.*;
import com.google.api.services.bigquery.*;
import com.google.api.services.bigquery.model.*;
public class sdz1 {
public static void main(String[] args) {
TableRow row = new TableRow();
row.set("Average", 7.7);
TableDataInsertAllRequest.Rows rows = new TableDataInsertAllRequest.Rows();
rows.setInsertId(""+System.currentTimeMillis());
rows.setJson(row);
List rowList = new ArrayList();
rowList.add(rows);
TableDataInsertAllRequest content = new TableDataInsertAllRequest().setRows(rowList);
try
{
TableDataInsertAllResponse response = bigquery
.tabledata()
.insertAll("Vigicolis", "wi_vigicolis", "TestTable", content)
.execute();
// TableDataInsertAllResponse response = new TableDataInsertAllResponse();
// response.bigquery.tabledata().insertAll("Vigicolis", "wi_vigicolis", "TestTable", content).execute();
System.out.println("Response: " + response);
}
catch (IOException e)
{
// handle
}
}
}
You are missing jar file of BigQuery which provides the required packages and classes required to run this program. Find the jar and add it to your classpath via command or in IDE.
Maven dependency link for the jar and jar can be downloaded as well from this link.
You need to create the bigquery object.
Ex:
Bigquery bigquery = new Bigquery(new NetHttpTransport(), new JacksonFactory(), new AppIdentityCredential(SQLSERVICE_ADMIN));

How do I get a class from an external .jar from a different computer?

I'm building a video game and I've built a launcher for my video game as well. The launcher downloads .jar files and stores them in the %appdata% folder for each person who buys the game and downloads the launcher and then runs it.
I need to be able to write a few lines of code to tell the launcher to get the .jar file from the user's computer and run a file from there. The .jar is already compiled and everything is okay and whatnot, but I'm not quite sure how to get the .class file to work with.
Something like this might help:
import System.getPropery("user.home") + "/AppData/Roaming/GameNameHere/bin/game.jar" + ".runGame.class"
And then I could possible do something like this:
if (credentials == true) {
runGame game = new runGame();
game.start();
}
How would I do something like this? Thanks in advance.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
So, I looked the ClassLoader.java class and messed around with it for a bit, but nothing really worked well. What am I doing wrong?
private String location = System.getProperty("user.home") + "\\Desktop\\myJar.jar";
URL url = new URL(location);
public Load() throws Exception {
ClassLoader loader = URLClassLoader.newInstance(new URL[]{url}, getClass().getClassLoader());
Class<?> clazz = Class.forName("gumptastic.MyClass", true, loader);
Method method = clazz.getMethod("output");
method.invoke(this);
}
public static void main(String[] args) {
try {
new Load();
} catch (Exception exc) {
exc.printStackTrace();
}
}
Not sure if you're familiar with this but
I think you should look at class loaders.
http://docs.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html
I guess you would need to write a simple one for your particular needs.
Alternatively, it would be even easier if you just use URLClassLoader.
Below is a simple example. This program has no idea of the Gson class
at compile time. But it can successfully load it, create an instance of it,
and use it at runtime. It was tested on Windows 7.
You can download Google Gson from here.
http://code.google.com/p/google-gson/downloads/list
Then place the gson-2.2.4.jar file anywhere you like
on your computer, then point this program to it by
setting arr[0] in the proper way.
Then observe the magic that is taking place :)
import java.lang.reflect.Constructor;
import java.net.URL;
import java.net.URLClassLoader;
public class Test007 {
public static void main(String[] args) throws Exception {
URL[] arr = new URL[1];
arr[0] = new URL("file:///dir1/dir2/dir3/gson-2.2.4.jar");
URLClassLoader loader = new URLClassLoader(arr);
Class cls = loader.loadClass("com.google.gson.Gson");
System.out.println(cls);
Constructor constructor = cls.getConstructor(new Class[0]);
Object obj = constructor.newInstance(new Object[0]);
System.out.println(obj);
if (obj!=null){
System.out.println("OK, so now we have an instance of:");
System.out.println(obj.getClass().getName());
}
}
}

GWT-EXT tree xml Error

i am new to GWT GWT-EXT and i mimic it's demo
the problem is where i should put xml file
final TreePanel treePanel = new TreePanel() {
{
setAnimate(true);
setEnableDD(true);
setContainerScroll(true);
setRootVisible(true);
}
};
final XMLTreeLoader loader = new XMLTreeLoader() {
{
setDataUrl("countries-cb.xml");
setMethod("get");
setRootTag("countries");
setFolderIdMapping("#id");
setLeafIdMapping("#id");
setFolderTitleMapping("#title");
setFolderTag("team");
setLeafTitleMapping("#title");
setLeafTag("country");
setQtipMapping("#qtip");
setDisabledMapping("#disabled");
setCheckedMapping("#checked");
setIconMapping("#icon");
setAttributeMappings(new String[]{"#rank"});
}
};
AsyncTreeNode root = new AsyncTreeNode("Countries", loader);
treePanel.setRootNode(root);
treePanel.render();
root.expand();
treePanel.expandAll();
See: http://gwt-ext.com/docs/2.0.4/com/gwtext/client/widgets/tree/TreeLoader.html#setDataUrl%28java.lang.String%29
setDataUrl takes a URL parameter for the XML data source.
Perhaps you're stuck on "how can I serve an XML file"?
i put it under projectName/war/projectName/xmlfile.xml and it works well.

Categories

Resources