I added a new method to my REST resource (Jersey). When I'm trying to test it I fails with:
ClientAbortException: java.io.IOException: An established connection was aborted by the software in your host machine.
When I'm debugging it, I can see that my code gets to the return statement, by somewhere afterwards fail.
BTW, I have many other methods that works just fine, all return JSON objects.
This happened when I'm trying to call the new method from Jersey Client or simply from a web browser.
My code:
#GET
#Path("/metrics/samples")
#Produces(MediaType.APPLICATION_JSON)
public MetricSamples getFragmentMetricsSamples(#DefaultValue ("-1") #QueryParam ("from")long from, #DefaultValue ("-1") #QueryParam)
{
//Calling DAO code. Everything is OK here.
//I can even see in debug that that return statement is executed successfully.
return metricSamplesDataObject;
}
What can cause the connection to abort?
EDIT
I just came home and seems like the problem is relevant only while working at office.
So, the issue is that this specific method cause ClientAbortExcpetion at work only.
Could it be something related to the network security? Maybe because that amount of data?
Thanks
Related
So I am trying out a simple full stack project of my own that involves a java backend implementation of a REST API, for which I am using the org.restlet.com framework/package and jetty as the server.
Whilst I was testing my API using Postman I noticed something wierd: Every time I started the server only the first POST/PUT/DELETE HTTP Request would get an answer, while the next ones would not receive one and on the console this error message would appear:
/* Timestamp-not-important */ org.restlet.engine.adapter.ServerAdapter commit
INFO: The connection was broken. It was probably closed by the client.
Reason: Closed
The GET HTTP Requests however do not share that problem.
I said "Fair enough, probably it's postman's fault".. after all the request made it to the server and their effects were applied. However, now that I am building the front-end this problem blocks the server's response: instead of a JSON object I get an undefined (edit: actually I get 204 No Content) on the front-end and the same "INFO" on the back-end for every POST/PUT/DELETE after the first one.
I have no idea what it is or what I am doing wrong. It has to be the backend's problem, right? But what should I look for?
Nevermind, it was the stupidest thing ever. I tried to be "smart" about returning the same Representation object (with only a 'success' JSON field) on multiple occasions by making one instance on a static final field of a class. Turns out a new instance must be returned each time.
I'm writing a POC using vertx, looking for alternatives when we have to migrate Spring Web from 4.x to 5 to be java 9 compliant.
I've written a simple client, just a GET towards a publicly available server just to get something working but it silently fails me.
public List<String> pull() {
Vertx vertx = Vertx.vertx();
HttpClientOptions options = new HttpClientOptions().setLogActivity(true);
HttpClient hc = vertx.createHttpClient(options);
hc.getNow(80, "http://sunet.se", "/",r -> {
System.out.println("\n****** Handler called! ***\n");
});
return new ArrayList<>();
}
This will silently fail and I cannot understand why.
As far as I can tell, I do exactly as in the examples given in the docs.
In desperation I fired up wire shark and according to WS, there is no actual call (when I use the browser WS captures that). So, it seems my call is never actually done. I don't get any exceptions or anything. Setting the log level to debug gives nothing noteworthy other than
Failed to get SOMAXCONN from sysctl and file /proc/sys/net/core/somaxconn. Default: 128
And that should not fail the call.
I've also tried using vertx.io WebClient but that fails also, in the same manner.
UPDATE
I've managed to get it to work but with a caveat.
As #tsegismont states in his answer, the protocol part of the URI shouldn't be there, that was not in the examples, I just missed it myself.
I ran my example as a stand-alone and then it worked.
My original example was run as a junit test (it's an easy way to test code and I usually try to write the test code first) and when it's run as a junit test it still doesn't work. Why that is, I have no idea. I would greatly appreciate if someone could tell me how to get that to work.
The getNow variant you use expects the server host, not a URL. It should be:
hc.getNow(80, "sunet.se", "/",r -> {
System.out.println("\n****** Handler called! ***\n");
}
If you found a snippet like this in the Vert.x docs it's a bug. Would you mind to report it?
Now a few comments.
1/ The HttpClient is a low-level client.
Most users should prefer the Vert.x Web Client
Here's an example for your use case:
WebClient client = WebClient.create(vertx);
client
.get(80, "sunet.se", "/")
.send(ar -> {
if (ar.succeeded()) {
// Obtain response
HttpResponse<Buffer> response = ar.result();
System.out.println("Received response with status code" + response.statusCode());
} else {
System.out.println("Something went wrong " + ar.cause().getMessage());
}
});
2/ Create a single Vert.x and WebClient instance
Do not create a Vert.x and WebClient instance on every method call.
It wastes resources and is inefficient.
I'm making a Spring MVC web app.
The problem is that on single method is called twice and I don't know why.
#RequestMapping(value="/profile/{id}", method = RequestMethod.GET)
public String displayUserProfile( #PathVariable String id) {
System.out.println("asdasddsasd");
return "account/userProfile";
}
I commented many line from this method, but is still not working. Also tried to return other view..no good luck.
In console(ulr requests are written):
/demo/account/profile/f91b3a38-6921-41e0-98b7-58dff5cb1152
asdasddsasd
/demo/account/profile/0
asdasddsasd
After the second call of tihs method, it's going to my view
Any other method work fine.
Does anyone know what's the problem here?
*I also read similar question from here..nothing helped
LE: what I also said in the comments.
What is funny is that, if I set o model to the view, on the second call of the method, my view get's the model from the first call. (on the second call, with id 0, the model is null)
I have also observed one GET request causing the controller method to execute twice. The problem occurred when requesting the service using a Chrome browser (the problem did not occur when using Postman). In my case the culprit was the JSONView Chrome extension.
I determined the cause by using the Network tab of the Chrome developer tools. It showed my GET service being requested two times. The second request was initiated by content.js, which is a JavaScript file bundled with JSONView.
After I disabled the JSONView extension, a GET request through Chrome would cause the controller method to execute only once.
I experienced this called-twice phenomenon because BrowserSync replayed HTTP requests in each open BrowserSync browser window.
I finally got some time to find a solution here.
Tried many things, but it didn't worked.
I replaced #PathVariable with #RequestParam and the URL is not accessed twice :)
Had the same problem.
Eventually I found that I have a null in a background-image url like so:
style="background-image: url(null);"
that caused to send another GET with a path variable null.
I have the same problem and find a lot of solution and finally I found the simple reason. It's in my html template css: background:url() .
This cold will run the same url again. So I just remove it out or put url in the bracket and it works.
Sounds like an issue on client side.
Open up your browser, enter <host/port/whatever_you_need_to access_the_app>/demo/account/profile/f91b3a38-6921-41e0-98b7-58dff5cb1152
and check the logs. The chances are that you'll see only one entry
Now run your client code and check network requests to the service. If you're call the controller from the browser like Chrome F12->Network tab should help.
I know it's a kind of obvious, but I think there is nothing really "unusual" in this controller, so it should be more at the level of general flow. In this case maybe it's the best to trace the HTTP traffic and see how many/when/how does it generate requests to your controller.
This might also occur due to one more reason. Because i found samething and observed following.
1st time its when your request processed and you see println statement in Console.
And if you refresh browser at method request of controller method ( example http://localhost:8080/DemoMVC/add?***) each refresh your tomcat processes request again and you get same println statement in console.
Perhaps this is too late. However, I still face these issues and forget the solution every time.
In case you are using any JS library like Angular or React then in your service call observe the response as well.
Here is a code snippet
return this.http.get<User>(`${this.resourceUrl}/activate`, { params: options, observe: 'response' })
.pipe(
filter((response: HttpResponse<User>) => response.ok),
map((response: HttpResponse<User>) => response.body),
catchError(error => {
return of(error)
})
);
The key area to focus is { params: options, observe: 'response' }
I had a controller which was listening to localhost/ and a get method which matched on a path variable something like this:
#GetMapping("/{foo}")
String get(#PathVariable(required = false) String foo)
{
return "hello world";
}
And the problem was, that after calling localhost/ I got the first call, and after that, I got the second call for the favicon.
The same would be true if you would define a context root.
I am using openid4java library for implementing the 'login with google' functionality in a spring-mvc application.
It works fine on my local tomcat server but on the remote server it has suddenly stopped working. It was working fine before there too.
After doing some logging in catalina.out I found that the verification of the response fails after google redirects to the return url
VerificationResult verification = openIdService.getConsumerManager().verify(
receivingURL.toString(),
response, discovered);
Identifier verified = verification.getVerifiedId(); //Null
The value of verified is null on the remote server. On local server its an uri
I am aware that while handling the response, ConsumerManager needs to be the same
instance used to place the authentication request.
The rest of the code is implemented as follows
There is an OpenIdController in which OpenIdService is Autowired.
The OpenIdServiceImpl implements OpenIdService and has the getConsumerManager method which returns the consumerManager instance.
In the construct of the OpenIdServiceImpl, an instance of ConsumerManager is created.
The actions that create the form for submission and handle the response are written in the
OpenIdController and access the consumerManager instance using the getConsumerManager method.
Edit:
I tried logging the Discovery information before the form submission and in the call back here it the output
Debugging OpenId: Discovered (before) OpenID2
OP-endpoint:https://www.google.com/accounts/o8/ud
ClaimedID:null
Delegate:null
Debugging OpenId: Discovered (after) OpenID2
OP-endpoint:https://www.google.com/accounts/o8/ud
ClaimedID:null
Delegate:nul
Am I doing anything wrong here ? But it works on local server!
Or something to do with tomcat configuration on the remote server ?
Any help is appreciated. I can post code if required.
Thanks.
I could resolve this problem by adding the following lines after creating an instance of ConsumerManager.
consumerManager.setAssociations(new InMemoryConsumerAssociationStore());
consumerManager.setNonceVerifier(new InMemoryNonceVerifier(5000));
consumerManager.setMinAssocSessEnc(AssociationSessionType.DH_SHA256);
I found it mentioned it in one of the comments to the SampleConsumer example here - http://code.google.com/p/openid4java/wiki/SampleConsumer
see response #3 from the bottom.
Haven't yet tried to figure out what it does, but hope its the right way to solve it :)
Ok so I'm making a "simple" web app using the technologies from the topic, recently I found http://www.adobe.com/devnet/flex/articles/flex_hibernate.html so I'm following it and I try to apply it to my app, the only difference being I'm working on a Mac and I'm using MAMP for the database (so no command line for me).
The thing is I'm having some trouble with retrieving/connecting to the database.
I have the remoting-config.xml, persistance.xml, a News.java class (my Entity), a NewsService.java class, a News.as class - all just like in the tutorial. I have of course this line in one of my .mxmls:
<mx:RemoteObject id="loaderService" destination="newsService" result="handleLoadResult(event)" fault="handleFault(event)" showBusyCursor="true" />
And my remoting-config.xml looks like this (well part of it):
<destination id="newsService">
<properties><source>com.gamelist.news.NewsService</source></properties>
</destination>
NewsService has a method:
public List<News> getLatestNews() {
EntityManagerFactory emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT);
EntityManager em = emf.createEntityManager();
Query findLatestQuery = em.createNamedQuery("news.findLatest");
List<News> news = findLatestQuery.getResultList();
return news;
}
And the named query is in the News class:
#Entity
#Table(name="GLT_NEWS")
#NamedQueries({
#NamedQuery(name="news.findLatest", query="from GLT_NEWS order by new_date_added limit 5 ")
})
The handledLoadResult looks like this:
private function handleLoadResult(ev:ResultEvent):void {
newsList = ev.result as ArrayCollection;
newsRecords = newsList.length;
}
Where:
[Bindable]
private var newsList:ArrayCollection = new ArrayCollection();
But when I try to trigger:
loaderService.getLatestNews();
nothing happens, newsList is empty.
Few things I need to point out:
1) as I said I didn't install mysql manually, but I'm using MAMP (yes, the server's running), could this cause some trouble?
2) I already have a "gladm" database and I have a "GLT_NEWS" table with all the fields, is this bad?
Basically the question is how am I suppose to debug this thing so I can find the mistake I'm making? I know that loadData() is executed (did a trace()), but I have no idea what happens with loaderService.getLatestNews()...
#EDIT: ok so I see I'm getting an error in the "fault handler" which says
"Error: Client.Error.MessageSend - Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Status 404: url: 'http://localhost:8080/WebContent/messagebroker/amf' - "
#EDIT2: Ok i solved the problem, as it turns out my ContextRoot was incorrect, the funny thing is I couldn't edit it by going to Project properties->Flex Server as it was uneditable! I had to find the .flexProject file and edit it (obviously my Flex Navigator didn't show it and by accident I noticed it was being filtered).
To answer your question as to, in general, debug this monster...here is what I do.
Set break points in my Java code
Start up the Java application server with the appropriate debug JVM properties set (e.g. -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n)
From Eclipse, I attach a remote debugger to the app server on the default port 8000. The Java Debugger will open up when a break point is hit.
Set breakpoints in my Flex application (or one of its modules).
From Eclipse (with Flash Builder) I launch a debug configuration for my Flex app. The Flex Debugger will open up when a break point is hit.
At this point I have two debuggers open and everything work great. Two other things I do:
a) extend the transaction system timeout, so it doesn't get trigger while I am sitting there think for a few minutes
b) use Charles Proxy (in reverse proxy mode) inbetween the client and server to watch the AMF traffic and view payloads, etc.
Hope this helps.
your error means you are not calling the server on the right way. Something is wrong there, the url the web.config file or other BlazeDS config files.