wergeld
Posts: 171
Joined: Thu Sep 01, 2011 4:23 pm

New PhantomJS Export Module Config Question [SOLVED]

I am running this locally on my Win7 box.
I followed the instructions here:
https://github.com/highslide-software/h ... erver/java

Maven successfully built the project and I am running it via:

Code: Select all

 mvn jetty:run
When I have my HighCharts test site up and I click to export it failed with jetty 404 for URL:
http://localhost:8080/highcharts-export

Turns out the dev.properties file is using url=http://localhost:8080/export/. So I changed the URL in the HighCharts export to point to the one in dev.properties. I know get a neat little Highcharts Export Server page with items to test. However, when I click on "Generate Image" button I get the following:

Code: Select all

Oops..,

Cannot run program "/phantomjs": CreateProcess error=2, The system cannot find the file specified
Reading the documentation at the guide link above I have placed the phantomjs directory in a path accessible to the webserver. Is this not correct?
My setup is:
IIS 7 running a .NET 4 web site
jetty running the export-server

So, where do I put the phantomjs folder and its contents?


UPDATE:
So upon further reading and my not-so good inference of what was meant by this text:
Specify the location of PhantomJS and the highcharts-convert script in the SVGCreator.java file. This is found here: highcharts-export/src/main/java/com/highcharts/export/util/SVGCreator.java change these lines:

private final String PHANTOM_EXEC = "/usr/local/bin/phantomjs"; private String PHANTOM_SCRIPT = "highcharts-convert.js";

-You can change the name of the script, but it's expected to be in this folder: highcharts-export/src/main/webapp/WEB-INF/phantomjs/
I changed the lines to:

Code: Select all

	private final String PHANTOM_EXEC = "highcharts-export/src/main/webapp/WEB-INF/phantomjs";
	private String PHANTOM_SCRIPT = "highcharts-convert.js";
Still no joy.
So, do I need to put the phantomjs directory on the webserver (if so, which one: IIS or the Jetty server)?
It is already in the WAR package - is this not sufficient?
Last edited by wergeld on Tue Jan 08, 2013 8:06 pm, edited 1 time in total.
wergeld
Posts: 171
Joined: Thu Sep 01, 2011 4:23 pm

Re: New PhantomJS Export Module Config Question

So, after much digging I getting further down the rabbit hole.
In SVGCreator.java we have these lines:

Code: Select all

	private final String PHANTOM_EXEC = ".";
	private String PHANTOM_SCRIPT = "highcharts-convert.js";
Then in the buildCommand() function we do this:

Code: Select all

		StringBuilder sb = new StringBuilder(PHANTOM_EXEC);
		sb.append(" " + location + "/phantomjs/" + PHANTOM_SCRIPT);
		sb.append(" -infile " + inFilename);
		sb.append(" -outfile " + outFilename);
So, what is location?

That is defined in ExportController.java:

Code: Select all

String location = servletContext.getRealPath("/") + "/WEB-INF";
So, since the WEB-INF directory is included in the WAR wouldn't we set PHANTOM_EXEC to "nothing" so that sb becomes:
sb = /WEB-INF/phantomjs/highcharts-convert.js
What is the purpose of PHANTOM_EXEC? I do not have a java parser/debugger other than maven and I have never used it before today.
What should PHANTOM_EXEC's value be?
wergeld
Posts: 171
Joined: Thu Sep 01, 2011 4:23 pm

Re: New PhantomJS Export Module Config Question

So, I see now that a new file is needed called phantomjs (missed that in the download section). I have downloaded the latest 1.8.1.
I have placed this on my jetty server under:

Code: Select all

ROOT\Scripts\phantomjs\
The file is called phantomjs.exe as our servers are in the Windows environment.
The question still remains -
What should the PHANTOM_EXEC value be.

My full Windows path to the phantomjs.exe file is

Code: Select all

C:\jetty-distribution-9.0.0.M3\webapps\ROOT\Scripts
My webapp is in:

Code: Select all

C:\jetty-distribution-9.0.0.M3\webapps
wergeld
Posts: 171
Joined: Thu Sep 01, 2011 4:23 pm

Re: New PhantomJS Export Module Config Question

Solved:

Code: Select all

private final String PHANTOM_EXEC = "C:\\jetty-distribution-9.0.0.M3\\webapps\\ROOT\\Scripts\\phantomjs\\phantomjs.exe";
Now to find a way to remove the fact that choosing an export opens a new page with demo data....
Gert Vaartjes
Posts: 217
Joined: Thu Apr 14, 2011 6:03 am

Re: New PhantomJS Export Module Config Question [SOLVED]

Hi,

When each export results in opening the demo page is that probally, because you are triggering a GET request. Ensure the webapp.url ends on a forwardslash like this

Code: Select all

webapp.url=http://localhost:8080/export/
or remove the demo() method in the exportcontroller.java, here https://github.com/highslide-software/h ... .java#L110

Good luck

Gert Vaartjes
CTO
Highsoft
wergeld
Posts: 171
Joined: Thu Sep 01, 2011 4:23 pm

Re: New PhantomJS Export Module Config Question [SOLVED]

grtvrt wrote:Hi,

When each export results in opening the demo page is that probally, because you are triggering a GET request. Ensure the webapp.url ends on a forwardslash like this

Code: Select all

webapp.url=http://localhost:8080/export/
or remove the demo() method in the exportcontroller.java, here https://github.com/highslide-software/h ... .java#L110

Good luck

Gert Vaartjes
My webapp.url already ended in "/".
Removing the demo code below from exportcontroller.java:

Code: Select all

	@RequestMapping(value = "/demo", method = RequestMethod.GET)
	public String demo() {
		return "demo";
	}

	/* catch all GET requests and redirect those */
	@RequestMapping(method = RequestMethod.GET)
	public String getAll() {
		return "redirect:demo";
	}
This resulted in 404 errors.
What fixed it was to add an ending "/" on the highcharts url string:

Code: Select all

url: "http://localhost:8080/highcharts-export/"
Thanks!
vinayhkskit
Posts: 1
Joined: Fri Jul 26, 2013 8:33 am

Re: New PhantomJS Export Module Config Question [SOLVED]

Please update the document for exporting url with forwardslash at the end in http://docs.highcharts.com/#export-server-setup.
exporting:{
url:'http://new.server.com/highcharts-export/'
}

Return to “Highcharts Usage”