to give a brief about my situation:
Earlier I was using chart.js for creating charts in my dashboard. Then I came across Quicksight a couple of days back. So I thought of switching to it as it provides better handling without any hassle.
Before Quicksight I was using jsp for my page, js(jquery) for my frontend and Java as my backend (spring-boot) with MongoDB as my database.
Keeping my structure same I just defined a jsp so that the user can be directed to the particular page after hitting on the chats.
Then, in my js file, I have written a (my own defined) ajaxRequest that will direct it to the Java controller:
$(document).ready(
function(){
ajaxRequest("/myService/char/getQuickSight", "GET", "", function(response){
})
}
);
Now I am not able to understand how to go on with my controller class. I have written something like this:
private static AmazonQuickSight getClient() {
final AWSCredentialsProvider credsProvider = new AWSCredentialsProvider() {
#Override
public AWSCredentials getCredentials() {
// provide actual IAM access key and secret key here
return new BasicAWSCredentials("access-key", "secret-key");
}
#Override
public void refresh() {
}
};
return AmazonQuickSightClientBuilder.standard().withRegion(Regions.SA_EAST_1.getName())
.withCredentials(credsProvider).build();
}
For he above code I refered to this
It is also throughing an error:
ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: com.amazonaws.client.AwsSyncClientParams.getAdvancedConfig()Lcom/amazonaws/client/builder/AdvancedConfig;] with root cause
java.lang.NoSuchMethodError: com.amazonaws.client.AwsSyncClientParams.getAdvancedConfig()Lcom/amazonaws/client/builder/AdvancedConfig;
(I can also provide the full stacktrace..)
But I am not able to understand how to move forward and what to do with the code. So if anyone can help me out I'll really appreciate it.
P.S. I have also added the following dependency in my POM
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-quicksight</artifactId>
<version>1.11.457</version>
</dependency>
Related
I am new to this so could anyone point me to the right direction?
I have a JavaScript file by which i want to take the value of a span from a website. Now the website dynamically refreshes the span every 1 second. I am using Java (Eclipse) to fetch this data. When i try to take the span value from website, it gives me no values because the span uses JavaScript to store these values. I already asked this question and i will drop a link below. So all i want to know is, how to take this data dynamically using JSoup. Someone commented on my last post saying the JavaScript might be querying a web service and to find that code. But i could not find the code and i don't know what to do next.
Here is the link to my last question: Fetching Dynamic Website Data Using Java
Here is the link to the website which stores data i want in a span named "id=spot" (Basically numeric numbers of stock): https://www.binary.com/trading?l=EN
And finally here is the link to the JavaScript file of the website which have all the functions: https://static.binary.com/js/binary.min.js?13b386b
Please help me as i am very new to this and i have spent more than 2 days trying to find the answer with no luck.
Thank you in advance
--------------------------------------------------------------------------------.---------------------------------------------------
Okay so the first part of the question is solved but i am having another issue now. I copied this code but i am getting this error now. Here is my code:
import java.net.URI;
import java.io.IOException;
import java.lang.InterruptedException;
import javax.websocket.*;
#ClientEndpoint
public class WSClient {
#OnOpen
public void onOpen(Session session) throws java.io.IOException
{
session.getBasicRemote().sendText("{\"ticks\": \"R_100\"}");
}
#OnMessage
public void onMessage(String message)
{
System.out.println("ticks update: " + message);
}
public static void main(String[] args)
throws IOException, DeploymentException, InterruptedException
{
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
URI apiUri = URI.create("wss://ws.binaryws.com/websockets/v3");
Session session = container.connectToServer(WSClient.class, apiUri);
Thread.sleep(10000);
}
}
And here is the error on console:
Exception in thread "main" java.lang.RuntimeException: Could not find an implementation class.
at javax.websocket.ContainerProvider.getWebSocketContainer(ContainerProvider.java:73)
at WSClient.main(WSClient.java:24)
This site is using WebSockets to retrieve the data from server to show in the client:
var onLoad = function(){
trading_page = 1;
if(sessionStorage.getItem('currencies')){
displayCurrencies();
}
BinarySocket.init({
onmessage: function(msg){
Message.process(msg); //this function is updating that sppan
},
onclose: function(){
processMarketUnderlying();
}
});
Price.clearFormId();
TradingEvents.init();
Content.populate();
So you can not see the data in downloaded HTML with JSOUP. You need a UI-less Browser in java like HTML-UNIT.
But the preferred and more reasonable way is to use the API of the site.
I was wondering if there were any good techniques in keeping your WebAPI controller routes in sync with the client side.
For instance, you have a WebAPI controller BooksController. On the client you could invoke a method by calling the endpoint:
$.get('books/1');
Then one day you decide to rename the controller, or add a RoutePrefix. This breaks the client side code, as the endpoint has changed.
I came across the library WebApiProxy, which looks interesting. Does anyone have a good approach to solving this problem? Is there a reason to use string literals on the client that I may be overlooking?
I created a blog bost on te subject. Take a look :)
http://blog.walden.dk/post/2017/02/02/export-all-your-asp-net-webapi-endpoints-to-json
Im working on a post consuming it in javascript.. Anyway, this code exports the endpoints runtime, and will work on refactorings and route changes. It exports uri parameters as well, they can be used to be parsed in javascript and replaced with values from the client.
The simplest way to achieve waht you want, is to use the built-in ApiExplorer in ASP.NET WEBAPI. It searches for all "ApiController" implementations, and reads the route-attribute metadata.
public class EndpointManager
{
public IEnumerable<ApiMethodModel> Export()
{
//Use the build-in apiexplorer to find webapi endpoints
IApiExplorer apiExplorer = GlobalConfiguration.Configuration.Services.GetApiExplorer();
//exclude endpoints without the attribute
var apiMethods = apiExplorer.ApiDescriptions.Select(ad => new ApiMethodModel(ad)).ToList();
return apiMethods;
}
}
You can create an endpoint that returns that generated data.
[RoutePrefix("api/endpoint")]
public class EndpointApiController : ApiController {
[HttpGet]
[Route("all")]
public IEnumerable<ApiMethodModel> All()
{
var endpoints = new EndpointManager().Export();
return endpoints;
}
}
Now all the endpoints can be reached at "/api/endpoint/all"
Here is an sample I was talking about in my comment to your question:
function getUrl(uri) {
var bookRoute = /books(.*?)/i;
var otherRoute = /something(.*?)/i;
if(uri.match(bookRoute)) {
return uri.replace(bookRoute, "http://localhost/webapi/books$1")
}
if(uri.match(otherRoute)) {
return uri.replace(otherRoute, "http://mydomain/api/something$1")
}
return uri;
}
alert(getUrl("books/1"));
alert(getUrl("something/realy/different/1"));
All you need is to define the routes in the body of your function.
this is a follow-up to my previous question here..
MVC - trouble linking to another Controller/Action
as you can see, i eventually did get my view from another controller to display in a new tab so it was working. that is until i installed SignalR. the simple version using this tutorial as a guide..
http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr-and-mvc
the tutorial worked fine after following the steps to create a project. the only thing i had to do to make it work was change the version of the jquery signalr javascript file to the latest (it was one i didn't have because the tutorial was written in older VS 2012).
in any case, after following the same steps for my site, i now get an error when i click the link for /SignalR/SRStart (new tab)..
Protocol error: Unknown transport
playing around i found that this only happens after calling app.MapSignalR() in the startup.cs file. can't understand why since the tutorial i followed worked fine unless it has something to do with crossing over into another controller on that link. it's in the SRStart view that i placed all the signalr connection code and callback function but i don't think it's ever reached since the page doesn't even load.
this is my code..
startup.cs
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
app.MapSignalR();
}
}
hub
public class SRHub : Hub
{
public void Send(string message)
{
// Call the addNewMessageToPage method to update clients.
var conn = GlobalHost.ConnectionManager.GetHubContext<SRHub>();
conn.Clients.All.addNewMessageToPage(message);
//Clients.All.addNewMessageToPage(message);
}
}
javascript in SRStart.cshtml
$(function () {
// Reference the auto-generated proxy for the hub.
var conn = $.connection.sRHub;
// Create a function that the hub can call back to display messages.
conn.client.addNewMessageToPage = function (message) {
if (!message.contains('[EOF]')) {
populateStreamDialog(message);
}
};
$.connection.hub.start()
.done(function () {
});
});
any help would be appreciated..
I was able to replicate error. Problem is that /SignalR is route used by SignalR itself.
By using MVC controller named SignalRController there is now conflict between SignalR and MVC causing the error.
Just rename you MVC controller SignalRController (and folder containing its views) to something else...
I have written a java script function in the skin file of the visual web Gui application which returns some value too. Now i am invoking the java script method from code behind.
public void XYZ( string message)
{
this.InvokeMethodWithId("testCall", message);
}
And javascript function is:--
function testCall(strGuid, txt) {
alert("hai Java script fired..");
return txt+ 'returned from JavaScript';
}
I want the value returned from JavaScript in the application. how can i achieve it. Is there in other method to invoke the methods of JavaScript?
I want something like this:--
public void Conect( string message)
{
string returnedvalue = this.InvokeMethodWithId("testCall", message);
}
Javascript is executed on the client so the return won't make it to the server.
A solution could be to use AJAX to send that value to the server. Stack Overflow is full of answers about AJAX.
Here's a good example.
#Amish Kumar,
As noted by other replies already, the client-side and server-side are not directly connected in web programming. The client is always the initiator of every request, and the server-side's "purpose" is to render a response, which will then be returned to the client for processing, in Visual WebGui this is usually some UI update processing. This basically means that your client script will not execute until the server-side has finished rendering the response, and the only way the client can get some message back to the server is to issue another request.
Think about how you need to use the MessageBox in Visual WebGui for instance. In order to receive the "response" from the MessageBox, you need to supply a callback handler in your server-side code, and then your server-side code will have completed creating the response, which is returned to the client. The client updates its UI and on some action to the MessageBox dialog, it sends a new request to the server, which interpretes the action and invokes your callback handler. In the callback handler you use Form.DialogResult to get the user action.
A very basic way to make this work in custom Visual WebGui code could be like the following code on a Form:
private void button1_Click(object sender, EventArgs e)
{
SendClientMessage("This is a test");
}
public void SendClientMessage(string strMessage)
{
System.Text.StringBuilder sb = new StringBuilder();
sb.AppendLine("var objEvent = mobjApp.Events_CreateEvent('{0}', 'MessageEvent');");
sb.AppendLine("mobjApp.Events_SetEventAttribute(objEvent, 'Msg', '{1}');");
sb.AppendLine("mobjApp.Events_RaiseEvents();");
this.InvokeScript(string.Format(sb.ToString(), this.ID, strMessage));
}
protected override void FireEvent(Gizmox.WebGUI.Common.Interfaces.IEvent objEvent)
{
if (objEvent.Type == "MessageEvent")
MessageBox.Show(objEvent["Msg"]);
else
base.FireEvent(objEvent);
}
This code will not work unless you set your Visual WebGui applicaton for no Obscuring. In order for this code to work on an obscured application, you would need to add the JavaScript as an obscured JavaScript resource and it would work fine.
Palli
enter code here
My question is if there is a way to simply post process wicket HTML response?
What I want to do is to apply some DOM transformations to the generated HTML using Rhino (http://www.mozilla.org/rhino/) and jQuery.
Anyone ever thought about it? Any suggestions where to start?
Best,
Maciej Wrzalik
OK, I've got this:
public class MyRequestCycle extends WebRequestCycle {
public MyRequestCycle(WebApplication application, WebRequest request, WebResponse response) {
super(application, request, response);
}
#Override
protected void onEndRequest() {
String responseString = response.toString();
//String newResponseString = process(responseString);
//replace old response content with the newResponseString
super.onEndRequest();
}
}
In method onEndRequest the string responseString contains HTML code that I'm going to alter some way using Rhino, Envjs and jQuery but the question is how can I replace the old response content with the new one?
Envjs emulates the browser environment under Rhino, and specifically allows you to do DOM manipulation server-side using jQuery. I have used it before in my projects, and have had good success. Relevant resources:
http://www.envjs.com/
http://ejohn.org/blog/bringing-the-browser-to-the-server/
If you want the post-processing done on the server, your best bet is likely to implement a Servlet Filter which modifies the response before it goes to the client.
As you're working on the rendered HTML, this has nothing particular to do with Wicket, and could be applied to html generated by any Java framework.
As suggested, a normal Java EE filter would work fine, if there's nothing Wicket-specific that you need for the processing.
But if you want to do it inside Wicket, for some reason or other, I suppose you could create your own RequestCycle implementation (MyRequestCycle extends WebRequestCycle) and do the processing there (perhaps by overriding onEndRequest and/or getWebResponse).
To use a custom RequestCycle, override newRequestCycle in your Application class:
#Override
public RequestCycle newRequestCycle(Request request, Response response) {
return new MyRequestCycle(this, (WebRequest) request, response);
}
I'm using custom a RequestCycle for a couple of things (e.g. this) myself—it's simple and straightforward—but I'm not 100% sure if it fits your needs here. (My Wicket experience is still somewhat limited.)