Unkown error when calling Java applet from JavaScript - java

Here's the JavaScript (on an aspx page):
function WriteDocument(clientRef, system, branch, category, pdfXML)
{
AppletReturnValue = document.DocApplet.WriteDocument(clientRef, apmBROOMS, branch, category, pdfXML);
if (AppletReturnValue.length > 0) {
document.getElementById('pdfData').value = "";
CallServer(AppletReturnValue,'');
}
PostBackAndDisplayPDF()
}
pdfXML is got from pdfData which is a hidden field on the page containing the XML that contains base64 encoded pdf data which is passed to the java applet. All the other values being passed have within range sensible values.
The XML is like this
<Documents>
<FileName>AFileName</FileName>
<PDF>JVBERiDAzOTY1NzMwIDAwMDAwIG4NCjAwMDM5NjU4NDcgMDAwMDAgbg0KMDAwMzk2NTk2</PDF>
</Documents>
The contents of the element PDF is a lot bigger than displayed here
The signature of the Java method is:
public String WriteDocument(String clientPolicyReference,
int systemType,
int branch,
String category,
String PDFData) throws Exception
It seems that when the size of the PDF data gets large the applet fails to be called and the error 'Unknown Error' is thrown in the JS.
The PDF doc the data of which is producing this error is about 4Mb in size.
Many thanks in advance for any help.

Thanks for responding chaps but I've sorted the problem.
How? I took JRE 1.6 update 12 off and stuck update 7 (which is the version we reccomend to those who use our website) on my machine.
Why update 12 stopped working I don't know. Why update 7 is stable I don't know. [sigh]
It's things like this that make me glad I work mostly with a 'long time between releases' framework like .net.

Related

Document.select("a[href]") not getting all the href

I am using JSOUP to fetch the documents from a website.
Below is my code
webPageUrl = https://mwcc.ms.gov/#/electronicDataInterchange
Document doc = Jsoup.connect(webPageUrl).get();
Elements links = doc.getElementsByAttribute("a[href]");
Below line of code is not working. It is supposed to return an element but doesn't:
doc.getElementsByAttribute("a[href]")
Can someone please point out the mistake in my code?
That page seems to be an Angular application, which means it loads some (probably all or most) of its content via JavaScript scripts.
The fact that the URL contains the fragment separator # is already a strong indicator of that fact, because if you do a HTTP request, then everything after that indicator is cut off (i.e. not sent to the server), so the actual request will just be of https://mwcc.ms.gov/.
As far as I know JSoup does not support running JavaScript, so you might need to look into a more involved scraping tool (possibly running a full browser engine).

CommandExecuteIn Background throws a "Not an (encodable) value" error

I am currently trying to implement file exports in background so that the user can do some actions while the file is downloading.
I used the apache isis CommandExexuteIn:Background action attribute. However, I got an error
"Not an (encodable) value", this is an error thrown by the ScalarValueRenderer class.
This is how my method looks like:
#Action(semantics = SemanticsOf.SAFE,
command = CommandReification.ENABLED)
commandExecuteIn = CommandExecuteIn.BACKGROUND)
public Blob exportViewAsPdf() {
final Contact contact = this;
final String filename = this.businessName + " Contact Details";
final Map<String, Object> parameters = new HashMap<>();
parameters.put("contact", contact);
final String template = templateLoader.buildFromTemplate(Contact.class, "ContactViewTemplate", parameters);
return pdfExporter.exportAsPdf(filename, template);
}
I think the error has something to do with the command not actually invoking the action but returns the persisted background command.
This implementation actually worked on the method where there is no return type. Did I miss something? Or is there a way to implement background command and get the expected results?
interesting use case, but it's not one I anticipated when that part of the framework was implemented, so I'm not surprised it doesn't work. Obviously the error message you are getting here is pretty obscure, so I've raised a
JIRA ticket to see if we could at least improve that.
I'm interested to know in what user experience you think the framework should provide here?
In the Estatio application that we work on (that has driven out many of the features added to the framework over the last few years) we have a somewhat similar requirement to obtain PDFs from a reporting server (which takes 5 to 10 seconds) and then download them. This is for all the tenants in a shopping centre, so there could be 5 to 50 of these to generate in a single go. The design we went with was to move the rendering into a background command (similar to the templateLoader.buildFromTemplate(...) and pdfExporter.exportAsPdf(...) method calls in your code fragment, and to capture the output as a Document, via the document module. We then use the pdfbox addon to stitch all the document PDFs together as a single downloadable PDF for printing.
Hopefully that gives you some ideas of a different way to support your use case
Thx
Dan

Size of the parameter in applet call is too big

I have problem in passing some data from JavaScript to an applet. I think size of data is too big (18M characters in string) to pass it through LiveConnect.
I put code samples below:
JavaScript:
var bigData = generateSomeBigData(18000000); // string contaning 18 000 000 characters
applet.Execute(bigData); // no error
Applet:
public void Execute(String data) {
this.doSomethingWithData(data); // data is null
}
I didn't get any error or exceptions in java console or in javascript code.
I've tried running applet with bigger heap, but it didn't help.
... <param name="java_arguments" value="-Xmx128m" /> ...
The only problem is I get null instead of string contaning data, it doesn't depend on browser (FF, Chrome).
I solved this problem. I moved data generation to server site and I'm passing data to applet using one time self destructing link. Applet can download information, which is no more available, and return result.
Here you have an example:
Server:
String bigData = this.generateBigData(18000000);
String linkToData = this.getOneTimeLink(bigData);
JavaScript:
applet.Execute(linkToBigData);
Applet:
public void Execute(String link) {
String data = this.downloadData(link);
this.doSomethingWithData(data); // data is not null ;)
}
EDIT 11 May 2015:
Maybe you need a small explanation to one time destructing link. I used it because it was another requirement to my project but it is not necessary to achieve solution.

Does Delphi XE2 correctly import WSDL from Java/Axis2 when function has no return value?

I'm importing a service into Delphi so I can test my front end (delphi) with my back end (java) and when I go to test a server function I get the following error:
XML document must have a top level element.
Line: 0
What I have noticed is that my function does not have a a return value (public void functionName) but if I switch it to say Boolean and just return true, the error no longer comes up.
The function appears to execute regardless of the error message being there or not however.
Here's the function being called (Java):
public void addNewUser(String facility, String username, String password, String status) {
serviceHelper.addNewUser(facility, username, password, status);
}
And the corresponding call in Delphi:
procedure TForm1.btnAddUserClick(Sender: TObject);
begin
GetServicePortType.addNewUser(lbledtFacility.Text,
lbledtUsername.Text,
lbledtPassword.Text,
cbb1.Text);
end;
I'm not very comfortable with answering by saying 'Try googling this' but if you're still stuck, try it anyway.
delphi babet "XML document must have a top level element."
Babet was the nom de plume of someone who was (and may still be, for all I know) closely involved in the development of Delphi's SOAP parser and import code and used to appear regularly in EMB's newgroups until about a year ago to help out with SOAP problems. I remember that he (despite using the moniker "Jean-Marie" on the forums) replied to several queries about this error.
The messages usally comes from the underlying MS-XML Parser. It seems that your XML isn't valid.

Same Jsoup code behaving differently on Android and desktop

I've got 5-line, simple Jsoup code parsing some strings, it smoothly runs and returns an array list with values that i want, however on android emulator and phone, it just returns nothing without even giving an error.
Thats the whole code :
Document doc = Jsoup.connect(myURL).get();
Elements els = doc.select("div font a");
for (int i = 3; i < els.size(); i++) {
latestNews.add(els.get(i).text());
}
On desktop, it adds elements into array list, however on device, nothing occurs. Could anyone help about it ?
Are you sure you are receiving the same HTML from the site? you should debug and check your doc variable to make sure it contains the same HTML as you'd expect on the site. Possible case of grabbing the mobile site when you are parsing the full site? (not sure if Jsoup prevents getting the mobile site or not). You likely need to set the user agent so that you receive the full desktop variant of the website.
ex.
Document doc = Jsoup.connect(myURL).userAgent("Mozilla").get();

Categories

Resources