I am looking to use OAuth2 in my Play application, and I've been having trouble looking for an entry point in coding for it. SecureSocial seems like a good library to use, but there seems to be a disconnect between SecureSocial's Getting Started guide and the classes that are actually available in their library. Specifically, the guide (here) says to stick this class in as a starting UserService. However, it refers to two classes (securesocial.core.Identity and securesocial.core.IdentityId) that are supposedly in SecureSocial's jar are inexplicably missing.
Does anyone know where I can find these classes (or find some kind of up-to-date guide or really any kind of basic, barebones way to learn OAuth with Play)?
I can't post more than two links so I did not link to the jar's page in the maven repository, but search for securesocial_2.11.
What is published -as of this writing - in Maven for Scala 2.11 is SecureSocial 3.0-M1. The published docs are for the 2.1.x version. Identity was removed and is not needed any more. The idea is that you can specify the type you want to represent users without being forced to inherit or implement any other type.
You can read the online docs to understand some concepts and then use the samples which are updated to use the new API here: https://github.com/jaliss/securesocial/tree/3.0-M1/samples.
Related
XMLHttpRequest is an alternative for HTTP calls from GWT client side and allows the control over all aspects of requests/responses. But how to use it?
javadoc address: http://www.gwtproject.org/javadoc/latest/com/google/gwt/xhr/client/class-use/XMLHttpRequest.html
You haven't mentioned what GWT version you use, so I assume the latest one. It means 2.8.2 or newer.
Elemental2 is the way to go
As it is mentioned in comments above, Elemental2 is the right way. I will explain it a bit.
If you think about future-proof implementation (being aware of GWT3/J2CL new approach), please do not use legacy GWT stuff. It means please use elemental2.dom.XMLHttpRequest instead of com.google.gwt.xhr.client.XMLHttpRequest (the one mentioned by you). Please do not use gwt-user dependency if possible, as it will be deprecated (if it is not already).
The Elemental2 is an opensource project available here: https://github.com/google/elemental2. It is kind of a base library for the "new GWT". For easier migration of existing GWT2.x projects to GWT3.x, a part of the "old" gwt-user is currently being ported to the new approach using JsInterop technique and mentioned Elemental2. So definitely Elemental2 is the way to go.
Elemental2 and JsInterop in general
The specification is not yet that rich if about the new JsInterop approach, but at the moment you will find some introduction at least: http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJsInterop.html
Examples
Please find an example for XMLHttpRequest in this article:
http://www.g-widgets.com/2016/09/09/gwt-http-requests-alternatives/
If you look for examples, also a good way is to search this on the Github site this way: https://github.com/search?q=elemental2.dom.XMLHttpRequest&type=Code.
(To use Github search you need to be logged in, in other case you will see "Whoa there! You have triggered an abuse blah blah..." )
One of the results will lead you to the very interesting project (you have the preview of the future GWT now):
https://github.com/gwtproject/gwt-http. It is
a future-proof port of the legacy com.google.gwt.http.HTTP GWT module. It will help to migrate GWT2.x projects to GWT3.x.
When you look to the test package, you will find some examples: https://github.com/gwtproject/gwt-http/tree/master/src/test/java/org/gwtproject/http/client .
So this is finally the answer to your question: "how to use it?" :-)
An additional examples source for XMLHttpRequest (using Elemental2) from Gist: https://gist.github.com/search?utf8=%E2%9C%93&q=elemental2.dom.XMLHttpRequest. This is probably even better for start, as they are short and clear.
What Elemental2 is?
The Elemental2 gives you a type checked access to native browser's API. So if you are familiar with browser's API, you should be able to implement your stuff, even based on some native JavaScript example. Please think about the new GWT like about type safe JavaScript (in addition very performant and well optimized). With JsInterop you create bindings, so it is something similar to bindings for TypeScript. So in fact you have a possibility to deal directly with browser's API, without anything GWT specific.
Libraries? More examples...?
Dealing with XMLHttpRequest is a bit low level.
You have also a possibility to use the library. One of Github search results will lead you to this repository: https://github.com/ibaca/autorest-streaming-example which is an example for interesting REST library: https://github.com/intendia-oss/autorest. A modern and reactive one, works with Observables, RxJava and so on.
This library uses JsInterop and is also migrated to Elemental2 what makes it GWT3/J2CL ready, please see the change: https://github.com/intendia-oss/autorest/commit/58516802cd42134544e6e3787207b5431fae94b5 .
With the Github search query I provided you, now you are able to find even more code examples for XMLHttpRequest. So please just have a look and find the best one for your needs.
An alternative approach would be to use a framework, for instance Errai from RedHat: http://erraiframework.org/. It helps you to deal with many problems at a different abstraction level.
I think now you have some references to study.
On the other hand it's 2018, so why not the Fetch API?
When think about the modern web application, I would rather think about the Fetch API instead of XMLHttpRequest. All modern browsers now implement the fetch() function natively. Isn't it the best way for solving your issue then?
The fetch() is a Promise-based mechanism that allows you to make network requests similar to XMLHttpRequest. Promises and Fetch are handled by Elemental2. Then you can use it from your Java code more or less in similar way like in Mozilla's examples.
Read more about the Fetch API here:
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
https://developers.google.com/web/updates/2015/03/introduction-to-fetch
https://codepen.io/aderaaij/post/fetching-data-with-fetch
https://fetch.spec.whatwg.org/
What more, this is nothing new as you see.
If about the older browsers a polyfill will emulate the missing function: https://github.com/github/fetch.
If about examples, I don't see that much on Github:
https://github.com/search?utf8=%E2%9C%93&q=elemental2.dom.DomGlobal+fetch&type=Code, but at least something.
The Fetch API seems to be the most current solution to the problem.
Please find a very simple fetch() example using Elemental2.
The imports section:
import static elemental2.dom.DomGlobal.fetch;
import static elemental2.dom.DomGlobal.console;
import elemental2.dom.Response;
Then use in your code:
fetch("https://randomuser.me/api/?gender=female&results=1")
.then(Response::json)
.then(data -> {
console.log(Global.JSON.stringify(data));
return null;
}).
catch_(error -> {
console.log(error);
return null;
});
As a result you should be able to see something like this:
{"results":[{"gender":"female","name":{"title":"mrs","first":"caroline","last":"coleman"},"location":{"street":"3703 new road","city":"swansea","state":"leicestershire","postcode":"ZH67 0YS","coordinates":{"latitude":"14.7870","longitude":"-107.8990"},"timezone":{"offset":"-6:00","description":"Central Time (US & Canada), Mexico City"}},"email":"caroline.coleman#example.com","login":{"uuid":"25357d90-cce4-4fe6-a3db-8ab77c0272ba","username":"smallpeacock582","password":"citizen","salt":"VX3s05Ah","md5":"84649cce1db8c6f2cbe33098221aa570","sha1":"005abf7d2ca0ff5b1a0bfd6dcee6d4860ef6e75d","sha256":"caadff0a16e27b0d9893aea483aedc7cf7c4707096c33a58acf44336bb2b54be"},"dob":{"date":"1978-03-14T15:47:16Z","age":40},"registered":{"date":"2013-08-10T19:09:41Z","age":5},"phone":"015396 74385","cell":"0726-723-103","id":{"name":"NINO","value":"JA 32 24 22 P"},"picture":{"large":"https://randomuser.me/api/portraits/women/45.jpg","medium":"https://randomuser.me/api/portraits/med/women/45.jpg","thumbnail":"https://randomuser.me/api/portraits/thumb/women/45.jpg"},"nat":"GB"}],"info":{"seed":"98f4f4a344470fbd","results":1,"page":1,"version":"1.2"}}
You can further convert the result to Java object using a technique called JsInterop DTOs. If you are interested, please find some information here: https://stackoverflow.com/a/50565283/5394086 .
Not recommended approach
If you sadly prefer to use the old GWT, so <= 2.7, then I think you can search for some examples on Github using similar search query, but for this legacy com.google.gwt.xhr.client.XMLHttpRequest. I this case I would also suggest you to not do stuff so low level, but use a library like https://github.com/reinert/requestor (which is unfortunately discontinued and development has stopped on GWT 2.7, but for this GWT version it is probably the best choice). But again please do not go this way and use GWT >= 2.8.2 with Elemental2/JsInterop approach instead.
First timer here and just starting with (the latest) SonarQube. Are there client libraries to download through the web-api already written and available? And is there a set of JAVA classes established that map to the structure of the JSON that will be returned that already exist? I was able to write my own test JAVA code to connect and to parse using the web api provided for one call I wanted, by building my own classes. But it seems like a lot of work to do this for all the data I hoped to pull and wondered if someone had done it already and/or Sonar provided it. And the web-api is a bit cryptic. Had to hover over values to figure out the exact call. I didn't see what I was looking for in the documentation or here. Or is there a better way to dump the data efficiently out of the GUI? Thank you!
Concerning, JAVA client library to request the SonarQube web services, we do not provide such library. There are lot of great tools to do a HTTP request and parse the JSON (see for instance OkHTTP and GSON).
Concerning "the web-api is a bit cryptic", I would be very interested to hear all your feedbacks about this, please share these feedbacks on the Google Group in order to discuss them and improve SonarQube web services.
the OpenSMPP homepage does not contain the documentation of OpenSMPP itself, only the protocol references. Could somebody give me some advice where on Earth can I find documentation and code examples on how to use the OpenSMPP API itself, especially regarding what classes can be used for receiving asynchronously?
Thank you!
If you want to get the API (Javadoc)
- this will be resolved by your IDE if you include the library in your project follwing the instructions here http://opensmpp.org/downloads.html
- if you want to download the API manually start to have a look here https://oss.sonatype.org/content/groups/public/org/opensmpp/
For examples you could have a look in the unit tests, clone (or download) the project https://github.com/OpenSmpp/opensmpp.git and have a look for sources in the 'client/', 'sim/' or '*/test/' folders.
For testing purpose this tutorial might be also of interest: http://mobiforge.com/design-development/sending-sms-with-smpp-kannel-and-java
I'm looking for some documentation or examples on how to use the GWT 2.1 Editor framework. Google's documentation is uh, somewhat lacking.
From the limited documentation available, I've been able to glean that editors will (in theory) allow you to more easily bind GUI elements to data models. This will alleviate the very common task of copying data into a TextArea/ListBox/CheckBox, and then replicating the user's changes back to the underlying model (and ultimately the DB).
If it does indeed deliver on this, it will be very welcome. For now, I'm left scratching my head as to how to implement any of it. Any pointers to documentation or examples would be highly appreciated.
A little while ago, when I was in the same situation (not only did the snippets from the Google documentation not work, but they also left out the most basic glue code to make them work), I attempted to write the most basic Editors example project for myself. I learned the editor basics from the DynaTableRf example (which is way too complex to get started with Editors IMO), and put something together.
Let me warn you: It's simple, but it's raw and unpolished, it's just a proof of concept. It's just a zip of my Eclipse project: http://www.mediafire.com/file/nwsohz7ov3cx173/playGwtEditors-02.zip (note: This is the old version for GWT 2.1)
Update
I just updated the project to use GWT 2.3. The old GWT 2.1 bug which I had mentioned in my project is gone now. Here's the new version: http://www.mediafire.com/file/u1yffwuxi441dip/playGwtEditors-03.zip
I've been in the same place for a while, trying to figure out how Editors hook up with the RequestFactory stuff. The DynaTableRF sample in the GWT 2.1.1 release is what finally started making things come together - it's complex, but I think you need a complex app to start seeing the benefits. The code in each step is wonderfully simple - but there are a lot of steps!
Here is another example using Editor Framework with Request Factory hope it helps too.
https://github.com/mgenov/injecting-request-factory
There are few open source projects/APIs/libraries that we use in our project (Spring, Struts, iBatis etc.) and I want to understand their design and how they work internally.
What is the best way to understand these projects? Note that I am already using these libraries in my project. And I know the input-output interaction/configurations for these libraries. What I don't understand is how these APIs/libraries work internally.
The problems I face is:
Finding the entry class of the library. Is there any way I can know the entry class for the library - something which is kicking the whole API?
Tools/Plugins to use in Eclipse to get an overview of the design of the library. Going through each and every class of the library, can be a very daunting task. Is there any tool you would like to recommend which can generate the class diagrams of the API in Eclipse.
Thanks in advance!!
UPDATE: I need some inputs on eclipse plugins which can help me in getting an overview/class diagram of the library
I always use the same strategy for this: I never try to "understand" the code base as a whole, and I usually try to follow the request flow. I read enough of the documentation to determine what is necessary to use the application, and I read that code (Keep all source code loaded in your IDE).
For example, in struts you'll be installing a servlet filter in web.xml. Start reading the filter and follow the path a single request takes through your stack.
Likewise for spring, there are two main entry points, the filter and "getBean", both of which are mentioned real early in the documentation. Read those two.
For both of these cases you'll find one or two classes that represent the "core" of the framework real quickly. Read those really well and let actual use cases & needs drive your further exploration.
Approaching "understanding" of an open source library (or any other code base for that matter) by trying to find all the pieces is usually not a very good way of approaching these things, it will usually just lead nowhere because a lot of these things contain too much code. When following the request flow I find making diagrams can also be quite distracting, it tends to draw attention/focus away from understanding (and since my understanding increases rapidly most of them are out-of-date even before they reach the printer).
Nice question!!!, what I've done, specially in the case of Spring, apart from consulting the Documentation and their API's is to attach the sources of the project to my project on Eclipse, that way I'm able to navigate through the source code, not just the API. Its been quite helpful specially in the case of the Spring-Security project, there were some concepts that I just couldn't understand until I inspected the source code.
That's one of the advantages of using Open Source libraries.
Regards.
Tools like Structure101 (http://www.headwaysoftware.com/products/structure101/index.php), and Lattix (http://www.lattix.com/) let you analyze code and produce architecture diagrams / dependency matrices.
This is not exactly class diagram - the main focus is on layering. So the entry point is usually the topmost layer.
But then again, as I specified above, you will notice that some libs are just a mess, and these tools will not be helpful enough.
See the S101 online demo: http://www.structure101.com/java/
This for example is the Sonar project architecture: http://www.structure101.com/java/tracker/sonar/1.11.1/arch.html
Your best bet for those three would be to consult the official documentation (make sure you are looking at the version you are using) or to get a book on the technology.
Most APIs don't have a class with a main method; they're running in the webserver called by the server itself. Unless they're running as their own server, they won't have a main method.