Jasper reports Server and GWT integration - gwt

I ve installed Jasper Reports Server and i want to develop a GWT application to call the jasper server web services as : Login , Running a report in the server, listing reports, View User .... I 've implemented web services in java through the Jasper Soft web services guide for example for authentitcation :
public static void connect(String URL,HttpClient httpclient)
{
serverURL = URL;
//report path
HttpClient client = httpclient;
// Setting Login URL in a POST method
String loginURL = serverURL+"rest/login";
PostMethod postMethod = new PostMethod(loginURL);
// Set authentication parameters
postMethod.addParameter("j_username", "jasperadmin");
postMethod.addParameter("j_password", "jasperadmin");
int statusCodeL;
try {
statusCodeL=client.executeMethod(postMethod);
if (statusCodeL != HttpStatus.SC_OK) {
System.out.println("Login failed: " + postMethod.getStatusLine());
return;
}
}catch (HttpException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
But i can t explore those web services when developing with GWT framework Which is no compatible with HTTPClient, even when using the Request Builder the authentication failed.
My question is HOW TO INTEGRATE JASPER REPORTS SERVER INTO GWT APPLICATION ?

I also had to implement the Jasper Report integration at my company. And yes, I also had difficulties. We ended up only using the Jasper Report Library to generate our report and we did the rest ourselves (listing reports, storing generated reports, etc...).

It is possible to use GWT. In the HttpServlet, have that call the Jasper APIs. Then the HttpServlet can return the results of the Jasper call to GWT. I put a comment that links to where the answer is.

Related

Facebook OAuth stopped working suddenly

I noticed yesterday that my Facebook login for my website has stopped working.
This has been working great for the last 2 months, as far as I am aware I have not changed anything. I have tried everything I can on links such as: - as well as many more...
ASP.NET MVC5 OWIN Facebook authentication suddenly not working
I have noticed that the Stack Overflow Facebook auth has also stopped working.
Has anyone else noticed this and found any solution? It's worth noting I am using azure app services to host. But this issue is also found when I am using localhost.
My current setup looks like this...
in Startup.Auth.cs
var facebookOptions = new Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions()
{
AppId = "xxxxxxxxxxxxx",
AppSecret = "xxxxxxxxxxxx"
};
facebookOptions.Scope.Add("email");
app.UseFacebookAuthentication(facebookOptions);
In the following method, loginInfo is null every time.
[AllowAnonymous]
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
return RedirectToAction("Login");
}
I also added a session "WAKEUP" from a different post suggestion, fb auth failed once before and this fixed the issue this time, but it has come back.
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult ExternalLogin(string provider, string returnUrl)
{
Session["WAKEUP"] = "NOW!";
// Request a redirect to the external login provider
return new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl }));
}
As RockSheep explained. Facebook dropped the support vor API v2.2. You need to update your OWIN nuget packages.
You can find the issue on github (from the Katanaproject).
Ensure to activate pre releases in your nuget manager, than you are able to update the nuget packages to version v3.1.0-rc1. But beware: After the update, you need to test your login carefully (maybe you also have other authentication providers like Microsoft or Google, you should test them as well).
Technical
The Api changed the version number to v2.8 and the return value from the API is now in JSON-Format and no longer escaped in the URI. The 'old' OWIN packages can not handle this changes.
[Oauth Access Token] Format - The response format of
https://www.facebook.com/v2.3/oauth/access_token returned when you
exchange a code for an access_token now return valid JSON instead of
being URL encoded. The new format of this response is {"access_token":
{TOKEN}, "token_type":{TYPE}, "expires_in":{TIME}}. We made this
update to be compliant with section 5.1 of RFC 6749.
Here you can find the code-changes on GitHub for further informations and better understanding.
A lot of people started having trouble after yesterday. This is due to Facebook dropping support for v2.2 of their API. For some reason their system still redirects auth calls that don't use a version number to the 2.2 API. A quickfix is to ensure that the API version gets sent with the API call.
Starting at v2.3 Facebook also started returning JSON objects. So make sure to change that in the code as well.
I had the same issue, found solution here Fix facebook oauth 2017
Basically, you need to extend HttpClientHandler and decode JSON response instead of body
Here is a solution for those who are using scribe java.
public Token extract(String response)
{
Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string");
JSONObject obj = new JSONObject(response);
return new Token(obj.get("access_token").toString(), EMPTY_SECRET, response);
}
Create a new class and set the extractor to JSON.
import org.scribe.builder.api.DefaultApi20;
import org.scribe.extractors.AccessTokenExtractor;
import org.scribe.extractors.JsonTokenExtractor;
import org.scribe.model.OAuthConfig;
public class FaceFmApi extends DefaultApi20 {
#Override
public String getAccessTokenEndpoint()
{
return "https://graph.facebook.com/oauth/access_token";
}
#Override
public AccessTokenExtractor getAccessTokenExtractor()
{
return new JsonTokenExtractor();
}
#Override
public String getAuthorizationUrl(OAuthConfig config) {
return null;
}
}
and inject your newly created class as below. Then getAccessToken() will work as expected.
public OAuthService getService() {
return new ServiceBuilder().provider(FaceFmApi.class)
.apiKey(config.getApiKey()).apiSecret(config.getApiSecret())
.callback(config.getCallback()).build();
}

implementation of chat Client in uwp app

The example given on this website working properly following is the link https://blogs.msdn.microsoft.com/brunoterkaly/2012/02/28/node-js-a-chat-server-written-in-node-and-a-client-app-written-in-c/#comment-12985
but when i am trying to implement this client app in uwp template .
issues are coming in Tcpclient , NetworkStream and some other classes which are not available in uwp.
The chat client in the blog you posted here is a WPF project, not a uwp app project. Classes like TcpClient and NetworkStream under System.Net.Sockets namespace are not supported in uwp.
In uwp we use classes under Windows.Networking.Sockets namespace instead, E.g.StreamSocket, StreamSocketListener and so on. More details please refence the sockets official documents in uwp. And the uwp official sample about sockets is here.
I also helped you transferred the chat client in the blog from wpf to uwp, you can directly download it from GitHub for further testing.
Parts of the code for uwp chat client:
private async void cmdConnect_Click(object sender, RoutedEventArgs e)
{
AddPrompt();
Windows.Networking.HostName serverHost = new Windows.Networking.HostName("127.0.0.1");
await tcpClient.ConnectAsync(serverHost, "8000");
serverStream = tcpClient.OutputStream.AsStreamForWrite();
StreamWriter writer = new StreamWriter(serverStream);
string request = txtChatName.Text.Trim() + " is joining";
await writer.WriteLineAsync(request);
await writer.FlushAsync();
Stream streamIn = tcpClient.InputStream.AsStreamForRead();
StreamReader reader = new StreamReader(streamIn);
string response = await reader.ReadLineAsync();
}

Facebook C# SDK Canvas Authorization

I have an iFrame Facebook application. I am using the Facebook C# SDK (version 6.0.10.0), Facebook and Facebook.Web (version 5.4.1.0') libraries.
As i get some help from stackoverflow and some other sites
Facebook C# SDK Authorization Problem
http://forum.ngnrs.com/index.php/topic,199.0.html
i coded as
protected void Page_Load(object sender, EventArgs e)
{
fbApp = new FacebookApp();
authorizer = new CanvasAuthorizer(fbApp);
authorizer.Perms = requiredAppPermissions;
if (authorizer.Authorize())
{
//user authorized
}
else
{
//user not authorized
}
}
but in the line "authorizer = new CanvasAuthorizer(fbApp);" it gives ma a syntax error
as Error 14 The best overloaded method match for 'Facebook.Web.CanvasAuthorizer.CanvasAuthorizer(Facebook.Web.FacebookWebContext)' has some invalid arguments.
In Facebook C# SDK there is no clue about the syntax change;
Please help ?
For a Canvas app, Facebook does a post request to your Canvas Url that you specified in your Application settings. In the post request, you get the signed_request parameter. All you have to do is parse that parameter using the Facebook API method and it will give you the access token which is used to make further calls.
Here is a brief tutorial about the same. This was written with ASP.NET MVC 3.0 in mind. However you can use most of the code for classic ASP.NET too.
http://theocdcoder.com/tutorialcreate-a-facebook-canvas-app-using-asp-net-mvc-3/

GWT + Phonegap Cross domain Requests not working

I'm having trouble with making HTTP Requests using GWT 2.4 (and JQueryMobile jquery.mobile-1.0rc1.min.js, but not for anything related with the calls) on Phonegap 1.1.0. What I want to do is to use the POST method on another server in order to receive content and display it.
On the desktop it's working fine (thanks to a reverse proxy configuration). On Phonegap, I read that "the cross-domain security policy does not affect PhoneGap applications. Since the html files are called by webkit with the file:// protocol, the security policy does not apply.". However, it seems that the request is never made on the phone, as the response is empty and the status code 0 - a similar behavior that I experienced before I solved the cross domain issue on the desktop.
I'm using the regular RequestBuilder on GWT to send my requests. Any ideas on why this is happening? All the permissions on Phonegap are active.
edit: Here is my Java code that sends the request, from which I omitted my soap envelope:
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,url);
rb.setHeader("SOAPAction", "assertIdentityWithSimpleAuthentication");
rb.setHeader("Content-type", "application/x-www-form-urlencoded");
String envelope = "etc"; //this is my soap envelope,
try{
rb.sendRequest(envelope, new RequestCallback() {
public void onError(Request request, Throwable exception) {
requestFailed(exception);
}
public void onResponseReceived(Request request, Response response) {
if(response.getStatusCode() == 200){
String aid = Tools.parseMessage(response.getText(),"assertionId"); //this just parses the response in order to get the string I need
Window.alert("Sucess: "+ aid);
sendAssertionID(aid); //and sends it to another function
}
else setError(response);
}
});
}
catch (RequestException ex) {
requestFailed(ex);
}
Check your url. Your code works fine on my android devices, but fails with an invalid url with code 0.
It needs to start with http:// or https://

Download html page source code using GWT

I am trying to use GWT to download the source code of web pages, but i do not know where to start, can anyone gives me some key word that i can search on google, or gives me some links from tutorials.
Thanks!!
In JavaScript, this is typically done with an XMLHttpRequest. GWT's analog to XMLHttpRequest is RequestBuilder, which can be used like so:
new RequestBuilder("GET", "http://example.com/page.html").sendRequest("", new RequestCallback() {
#Override
public void onResponseReceived(Request request, Response response) {
String src = response.getText();
// do things with the source
}
#Override
public void onError(Request request, Throwable throwable) {
// handle the error
}
});
Some GWT manual about cross-site scripting
https://developers.google.com/web-toolkit/doc/latest/tutorial/Xsite
And here some discussion about using RequestBuilder and JSNI
GWT RequestBuilder - Cross Site Requests
As alternative you can do a page download on the server-side...