This question to readers who have used Highcharts Export Server:
I am trying to run Highcharts-3.0.2 as an export server in Java. I set it up with tomcat-7.0.41 and tried to use the example supplied (/demo). While the /demo page loaded successfully, on sending the request to generate image the log shows:
[ERROR] [http-bio-8080-exec-6 07:00:08] (SVGConverter.java:requestServer:109) POOL EXHAUSTED!!
I get the same message on every subsequent request.
On studying the code I found that when the application starts among others the following steps are executed:
AbstractPool calls on the objectfactory to create a new Server object and adds it to the blocking queue.
T object = objectFactory.create();
queue.add(object);
poolSize.getAndIncrement();
The Server object is a new java.lang.Process object. After it is created it listens on the inputstream stream.
process = new ProcessBuilder(commands).start();
final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String readLine = bufferedReader.readLine();
if (readLine == null || !readLine.contains("ready")) {
throw new RuntimeException("Error, PhantomJS couldnot start");
}
The readLine() blocks and the control is not returned and the Server instance is never added to the queue. Hence, the pool exhausted error.
So, there must be something on the inputstream to be read so that the control can proceed. My question is what is it that I have missed here?
RESOLVED: The problem was in app.properties. The parameter script in app.properties when left empty does not work in tomcat either contrary to the documentation. It is the convertor script highcharts-convertor.js which when executed in the process (see code above) returns a string on the inputstream.
Edit Jumped the gun too soon! The parameter script when left empty works as described in the documentation. I can see in the log:
[DEBUG] [pool-1-thread-1 01:46:35] (ServerObjectFactory.java:create:33) in makeObject,
C:\Users\...\webapp\phantomjs,
C:/Users/.../workspaces/.../.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/...highcharts-convert.js, 127.0.0.1
I do not understand what goes wrong when the command is constructed correctly with all the required parameters?
Explicitly giving the complete path to the highcharts-convertor.js for the parameter script in the app.properties works.
Is anybody experiencing this behavior?
I'm working in eclipse juno service release 2, buildid:20130225-0426, Highcharts-3.0.2, tomcat-7.0.41, win7 64bit
For us using jetty or tomcat we had to explicitly give the location of both the files and, this is the kicker, make sure that all the files in the target directories listed in your app.properties files are not Read Only.
exec = C:/jetty-distribution-9.0.3.v20130506/webapps/Scripts/phantomjs/phantomjs.exe
script = C:/jetty-distribution-9.0.3.v20130506/webapps/Scripts/phantomjs/highcharts-convert.js
The C:/jetty-distribution-9.0.3.v20130506/webapps/Scripts/phantomjs directory and all contents were not flagged as Read Only. This, for some reason, allowed the scripts and phatomjs.exe to be executable by the WAR.
The export-server for java is updated lately. We noticed many people had problems with the location of the phantomJS javascripts. All javascript files necessary for phantomjs are now unzipped to a temporary location and picked up from them for later use by the application.
With this you don't have to specify any longer the filelocation of the scripts.
Related
I have a server where I work with a database and files using a java app.
When I start my app I give a report regarding file access to the server using:
public static boolean folderExists(String folderPath) {
File folderToCheck = new File(folderPath);
return folderToCheck.exists();
}
Every time I start my app (after a fresh restart of my computer)
I get a false response, even though the server is on.
The reason is because I must give an authentication as another user.
What I do is access the server through Windows
where I am being asked for username/password,
and after that I get a true response regarding file access to the server.
Is there a way to give the authentication username/password through Java,
and not through Windows?
Thank you
On Windows 'native' Java IO (e.g. java.io.File) always inherits the security context of the user running the JVM process. For example, you could run the Java app as a Windows service with the correct credentials.
The JCIFS project implements CIFS (the Windows SMB file server protocol) and allows you to directly specify the username/password.
See the API for examples.
I am pretty sure, that there is no way to grant fileaccess by java, without a Windows-Call.
You can call cacls file.log /e /t /p Everyone:f but this will be language-dependent.
I had a similar problem: How to change the file ACL in windows, if I only know the SID?
With Java7 there may be a way to do this.
I am getting "Non HTTP response code: java.net.SocketException
Response message: Non HTTP response message: Connection reset" this type of error after running jmeter script
I bet that you're experiencing the problem described in Connection Reset since JMeter 2.10 ? wiki page
So I would recommend to take the next steps:
Switch "Implementation" of all your HTTP Request Samplers to "HttpClient4". The best way to do this is using HTTP Request Defaults so you will have to change the value in just one place.
As per the wiki page add the next 2 lines to user.properties file (lives under /bin folder of your JMeter installation)
httpclient4.retrycount=1
hc.parameters.file=hc.parameters
Add the next line to hc.parameters file (same location, /lib folder)
http.connection.stalecheck$Boolean=true
Remember to restart JMeter after making these changes, properties change is not dynamic, they're being picked up upon JMeter startup.
Hope this helps.
I have my middle layer jar file running on the linux server. I want that jar file running in background non-stop.
nohup java -jar RushMiddleLayer.jar &
But when i re-run this command, another new instance of the jar created and running.
I have searched through google. They suggested some options.
"Bind a ServerSocket". But which is not working for me. Process killed after press enter or Ctrl+C.
I want to have two benefits from the jar. One is always running with fail. Another if restart the jar using the same command (nohup java -jar RushMiddleLayer.jar &).
It should replace the existing jar, not create the new instance.
Just to make sure I understand what you want, you want a jar file that runs in the background and it is only able to be launched once and once only?
If this is what you want, there is two ways to achieve this:
Use a port as a semaphore (as you suggested)
Use a file as a semaphore.
For option 1,
The code should be as simple as something like:
try {
serverSocket = new ServerSocket(port);
} catch (IOException e) {
System.out.println("Could not listen on port: " + port);
// ...
}
An IOException will be thrown, if you cannot open server socket on this port. However, this could also occur if some other application is using this port. So be careful what port number you choose.
For option 2,
You simply use a FileWriter and create a dummy file and keep this file open until the jar/program is finished (or closed). When a second instance of the jar attempts to open, an exception will be thrown and it won't be able to start due to the fact that it will try to open the file for writing which produces an IOException because only one process can have a write handle to a file at the same time.
So I'm running the Google App Engine development server (Java) on localhost. I'm trying to retrieve a URL using Python 2.7 urllib.urlopen. The initial retrieve works, but then when I try to call read() or readlines() I get:
Traceback (most recent call last):
File "./getMap.py", line 6, in <module>
lst = f.readlines()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 513, in readlines
line = self.readline()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 445, in readline
data = self._sock.recv(self._rbufsize)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 552, in read
s = self.fp.read(amt)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 378, in read
data = self._sock.recv(left)
socket.error: [Errno 54] Connection reset by peer
The browser works, wget works. Problem occurs with both urllib and urllib2. Here's the code:
import urllib2
f = urllib2.urlopen("http://localhost:8080/default.jsp")
lst = f.readlines()
for a in lst:
print a
Strangely, I can print out the first line of the file using readline() -- I just can't get the whole file. I get the sense that maybe Python is "lazily" not requesting the entire contents of the URL until I request it via readlines(), and by then the app engine dev server has overzealously closed the connection. But I could be totally wrong about that.
I tried researching this problem but I didn't see anything applicable. Most of the Google hits I'm seeing surround random, intermittant timing issues (this isn't an intermittant problem, it's reliable) or proxy/firewall issues (nothing like that going on here).
Assuming my theory is correct -- is there a way to tell urlopen to get the whole response right away, as wget and the browser seem to be doing? Or is there a way to tell the GAE dev server to chill out and not close the connection so quickly? I'd rather not dive into lower-level python socket stuff if I don't have to.
thanks
p.s. clarification: the python script is just running from the command line and trying to make a connection to the GAE dev server, which is running on the same box. I'm NOT trying to connect to the GAE dev server from itself or something weird like that, the GAE server is running Java, not Python. What I'm actually trying to do here is this: my GAE web app has some web services and I'm writing a batch script to get/post to those webservices, so that when I need to reset/clear the data store (example: data gets corrupted) I can use this python script to back up the data first, then I erase the data store, and then use the script again to load that data back in.
UPDATE: so I tried a few more tests. Python has no trouble reading any HTML file served by the GAE dev server. However any JSP, even the simplest "hello world" JSP, fails to read with the same "connection reset by peer" error. I'll try updating to the 1.6.1 version of the GAE SDK, I have to do that anyway at some point, might as well be now. Hopefully it will fix this.
While I cannot see anything wrong with your python code and have no idea what might be wrong with your Java GAE setup I instead propose a different take on the problem.
You mention that you basically want to send GET/POST requests to your server and save/later read the content and that command line tools like wget works. I suggest you use a bash script and curl and python for the cases when you need to do more advanced text editing.
curl http://localhost:8080/default.jsp > default.bak
... wipe db ...
data = $(cat default.bak)
curl -X "POST" -d "backup=$data" http://localhost:8080/default_restore.jsp
If you need to edit the data before sending it you can use python to either read from default.bak or by piping it to stdin
data = $(cat default.bak)
python your_script.py $data
curl http://localhost:8080/default.jsp | python yourscript.py > default.bak
Obviously a bit late to the party, but I had exactly the same issue, and I solved it by swapping out urllib for httplib:
import httplib
conn = httplib.HTTPConnection('localhost:8080')
# get the current image and save to file
url = 'default.jsp'
conn.request("GET", url)
response = conn.getresponse()
if response.status == 404:
return None
img_file = open("out.jpg",'wb')
img_file.write(response.read())
img_file.close()
response.close()
conn.close()
I don't know why this works, I can only assume that httplib is slightly better behaved than urllib
I have a server where I work with a database and files using a java app.
When I start my app I give a report regarding file access to the server using:
public static boolean folderExists(String folderPath) {
File folderToCheck = new File(folderPath);
return folderToCheck.exists();
}
Every time I start my app (after a fresh restart of my computer)
I get a false response, even though the server is on.
The reason is because I must give an authentication as another user.
What I do is access the server through Windows
where I am being asked for username/password,
and after that I get a true response regarding file access to the server.
Is there a way to give the authentication username/password through Java,
and not through Windows?
Thank you
On Windows 'native' Java IO (e.g. java.io.File) always inherits the security context of the user running the JVM process. For example, you could run the Java app as a Windows service with the correct credentials.
The JCIFS project implements CIFS (the Windows SMB file server protocol) and allows you to directly specify the username/password.
See the API for examples.
I am pretty sure, that there is no way to grant fileaccess by java, without a Windows-Call.
You can call cacls file.log /e /t /p Everyone:f but this will be language-dependent.
I had a similar problem: How to change the file ACL in windows, if I only know the SID?
With Java7 there may be a way to do this.