opensaml 2.6 to 3.2 SamlSchema and X509Credential - java

Hi i am currently porting an app to OpenSAML 3.2 and getting Problems with following:
1- SAMLSchemaBuilder has no getSAMLSchema methods:
Schema schema = SAMLSchemaBuilder.getSAML11Schema();
parserPoolManager.setSchema(schema)
2- The new org.opensaml.xmlsec.signature.support.SignatureValidator only accepts org.opensaml.security.credential.Credential not org.opensaml.xml.security.x509.X509Credential
BasicX509Credential publicCredential = new BasicX509Credential();
SignatureValidator.validate(signature, publicCredential);
Can someone help me?

Quick look on the JavaDoc, it looks like som difference in the constructor and then call getSAMLSchema instead of getSAML11Schema.
For your last question, try using the CredentialSupport class. It has a method for creating a Credential from a X509Certificate. getSimpleCredential

Related

How to implement the Google Distance Matrix API in Java without using the HTTP request method

I am aware of the fact that I am able to use a HTTP request to use the distance matrix API (i.e. https://maps.googleapis.com/maps/api/distancematrix/json?origins=42.11622,78.10112&destinations=40.82231,72.224166&key=YOUR_API_KEY)
But I would like to simply use the Java API instead. From my understanding the first step is to create a GeoApiContext and this seems to be where I am failing. I have tried the following code:
private static GeoApiContext context = new GeoApiContext.Builder().apiKey("MyKey").queryRateLimit(500).build();
However I am just met with the following compile error:
java.land.NoClassDefFoundError: com/google/common/util/concurrent/RateLimiter
Any help on the matter would be appreciated. The plan is to use this to create a DistanceMatrix API request if that helps.
check out this link you may find it useful... there are code examples
https://www.programcreek.com/java-api-examples/index.php?api=com.google.maps.model.DistanceMatrix

Searchanalytics Query JAVA API v3 (Google WebMaster Tools)

I am trying to implement Google Webmasters Searchanalytics Query using using the Java API but i did not found any Java sample to use , in Google website here there is only Python samples for Searchanalytics Query , and they did not say that it's not available in Java API.
I found this class Webmasters.Searchanalytics.Query in the Java API which I assume that is equivalent to the Python function searchanalytics.query() but i did not found any implementation of it.
My question if it is possible to query data from Google Search Console using the Java API??
if yes i wounder if there is someone who can provide a Java sample, something like the Python sample provided by Google here.
Thank you in advance.
I succeded to implement Webmasters.Searchanalytics.Query
as follow
first you need to create your QueryRequest using the SearchAnalyticsQueryRequest class example:
private static SearchAnalyticsQueryRequest createSearchAnalyticsQueryRequest() {
SearchAnalyticsQueryRequest searQueryRequest = new SearchAnalyticsQueryRequest();
searQueryRequest.setStartDate("2016-04-10");
searQueryRequest.setEndDate("2016-04-20");
List<String> dimensions = new ArrayList<String>();
dimensions.add("page");
dimensions.add("query");
dimensions.add("country");
dimensions.add("device");
dimensions.add("date");
searQueryRequest.setDimensions(dimensions);
return searQueryRequest;
}
then executing the query as follow :
public static String Query(String site,
SearchAnalyticsQueryRequest searQueryRequest) throws Exception {
Webmasters.Searchanalytics.Query query = service.searchanalytics()
.query(site, searQueryRequest);
SearchAnalyticsQueryResponse queryResponse = query.execute();
return queryResponse.toPrettyString();
}
I think You missed it. here. Actually all you need to do is to click the Java link on the left.

Play framework 2.4 form fill does not work

In Play Framework 2.4 Java, I need to fill a form using the following code, but it does not work. The output value of usereditform.field("email").value() is null. Anyone know why?
SignupClz signupobj = new SignupClz();
signupobj.email="abcd#efgh.com";
signupobj.name="abcd";
signupobj.password = "eoijf";
Form<SignupClz> usereditform = Form.form(SignupClz.class).fill(signupobj);
System.out.println(usereditform.field("email").value());
This code is correct. Please look at other points - maybe you did not recognize "abcd#efgh.com" output in the console.
For example I have the similar code and it works:
EditForm rawEditForm = new EditForm();
rawEditForm.title = boxModel.title;
rawEditForm.body = boxModel.body;
rawEditForm.id = id;
Form<EditForm> editForm = Form.form(EditForm.class).fill(rawEditForm);
Logger.info("Title: " + editForm.field("title").value());
I am learning PlayFramework and stumbled upon this question.
For PlayFramework 2.8 form field values cannot be directly accessed, be it reading or filling(writing) information. You have to explicity tell it when building the form, like this :
#Inject
FormFactory formFactory;
Form<SignupClz> usereditform = FormFactory.form(SignupClz.class) //
.withDirectFieldAccess(true)
.fill(signupobj);
System.out.println(usereditform.field("email").value());
Note that in this version forms are built using FormFactory, make sure you inject it or add it to your code otherwise.
Details in their official documentation https://www.playframework.com/documentation/2.8.x/JavaForms#Defining-a-form:~:text=Instead%20of%20enabling%20%E2%80%9Cdirect%20field%20access%E2%80%9D%20for%20all%20forms%2C%20you%20can%20enable%20it%20only%20for%20specific%20ones%3A

Restlet- Beginner Stuff for Client Side - Path, Accept Header, QueryParam

Before I started with Restlet I already wrote a Jersey client. It was very intutiv - it seems like Restlet isnt. There is not much documentation and I can't solve the easiest problems.
Where I am:
service = new ClientResource("http://localhost:8080/com-project-core/rest");
service.setChallengeResponse(ChallengeScheme.HTTP_BASIC, "admin", "geheima");
What I get from documentation:
String myString = service.get(String.class);
or wrapping up a Resource:
ConnectedResourceIF connectedResource = service.wrap(ConnectedResourceIF.class);
Thats working. But what about:
A. When I want to change my service path? In Jersey it was intuitiv like
service.path("foo").path("bar")
for
http://localhost:8080/com-project-core/rest/foo/bar
B. I want to set a acceptHeader. In jersey it was like
service.accept(MediaType.TEXT_PLAIN)
C. I want to set query parameters. In jersey:
service.queryParam("1","foo").queryParam("2","bar")
Sorry, hope someone can solve this beginner problems. I cant find somethign in the restlet documentation.
For A:
service.getChild("/foo/bar", ConnectedResourceIF.class);
For B (need a recent 2.1 RCx version):
service.accept(MediaType.TEXT_PLAIN);
For C (need a recent 2.1 RCx version):
service.setQueryValue("1","foo");
service.setQueryValue("2","bar");
The best place to look for such things is the Javadocs, because those API changes are pretty recent:
http://www.restlet.org/documentation/snapshot/jee/api/org/restlet/resource/ClientResource.html
We are working on a new in-depth tutorial for next 2.2 version. First finishing "Restlet in Action" book :)

PHP Call from Java Using Quercus

I have a sample PHP class which I would like to Utilize in my Java Application.
We have decided to use Quercus as a Libary for doing the Integration.
Can some one let me know How can I call a PHP class from Java Code using Quercus.
For Example.
PHP class name is calculator.php and it has one method say sum() which expects 2 numbers to be passed and It will do the summation of those number.
Please let me know the sample code which can be coded to achive the same.
Thanks,
You should look at QuercusEngine
import com.caucho.quercus.QuercusEngine;
QuercusEngine engine = new QuercusEngine();
engine.setOutputStream(System.out);
engine.executeFile("src/test.php");
Other examples
The only needed jars are resin.jar and servlet-api.jar.
It seems that you can't usefully instantiate a QuercusEngine these days. Instead:
import javax.script.ScriptEngine;
import com.caucho.quercus.script.QuercusScriptEngineFactory;
QuercusScriptEngineFactory factory = new QuercusScriptEngineFactory();
ScriptEngine engine = factory.getScriptEngine();
You then probably want engine.eval(reader);

Categories