Tuesday, November 09, 2010

Very nice SOAP client (java)

Here is link to nice java soap client
I've implement also LS2J approach

here is my example. There are some enhancements need to do, but anywhere this also works fine.

Java library

import java.io.*;
import java.net.*;

public class ECWebservice {
String cResponse;
String wsurl;
String msg;
String contentType;

public ECWebservice(String init_url) throws IOException {
wsurl = init_url;
msg = "";
contentType = "text/xml; charset=utf-8";
cResponse = "";
}

public String GetResponce() {
return cResponse;
}

public void SetContentType(String init_contenttype) {
contentType = init_contenttype;
}

public boolean Send(String init_msg) {
boolean result = true;
try {
msg = init_msg;

// Create the connection where we're going to send the file.
URL url = new URL(wsurl);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;

String SOAPAction = msg;

byte[] b = SOAPAction.getBytes();

// Set the appropriate HTTP parameters.
httpConn.setRequestProperty( "Content-Length", String.valueOf(SOAPAction.length()));
httpConn.setRequestProperty("Content-Type", contentType);
httpConn.setRequestProperty("SOAPAction", SOAPAction);
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);

// Everything's set up; send the XML that was read in to b.
OutputStream out = httpConn.getOutputStream();
out.write(b);
out.close();

// Read the response and write it to standard out.
InputStreamReader isr = new InputStreamReader(httpConn.getInputStream(), "utf-8");
BufferedReader in = new BufferedReader(isr);

String inputLine;
while ((inputLine = in.readLine()) != null) {
cResponse += inputLine;
}
in.close();
} catch(Exception e) {
e.printStackTrace();
cResponse = "Main: Exception occured - check Java Debug Console";
result = false;
}

return result;
}
}


LS2J library

Option Public
Option Declare

Use "webservice.core"
UseLSX "*javacon"
Class ECWebservice
responce As string
connection As string
contentType As string

Sub New(connection_url As string)
connection = connection_url
contentType = "text/xml; charset=utf-8"
End Sub

Public Property Get GetResponce As string
GetResponce = responce
End Property

public Property Set SetConnection
connection = SetConnection
End Property

Public Property Set SetContentType
contentType = SetContentType
End Property

Function SendXMLRequest(xmldata) As Boolean
On Error Goto errorproc

'** everything we'll need to access our Java classes
Dim jSession As New JavaSession
Dim jClass As JavaClass
Dim jObject As JavaObject

'** get the IGWebservice class and instantiate an instance of it
Set jClass = jSession.GetClass("ECWebservice")

'** version of CreateObject and init with path to WSDL)
Set jObject = jClass.CreateObject("(Ljava/lang/String;)V", connection)
jObject.SetContentType(contentType)
'** send message and get result: true/false, if true then we got result
If jObject.send(xmldata) Then
me.responce = jObject.GetResponce()
End If

SendXMLRequest = True

endofsub:
Exit Function
errorproc:
MsgBox "Error #" & Err & " on line " & Erl & " in function " & Lsi_info(2) & " : " & Error, 48, "Runtime error"
Resume endofsub
End Function

End Class

Thursday, October 28, 2010

xPage: Could not load 'imb.xsp.widget.layout.TypeAhead'

Does somenody saw such issue? Got it when added typeAhead to customer control. It works fine when I open new document, but when I go to edit mode always get such message, any ideas?

Monday, October 11, 2010

xPage: date picker does not work in IE8

Just found that standard date picker does not work properly in IE8 (it always refresh page when we click on date/time picker. That's not funny :/ question - why do all another browsers work fine?

Workaround
http://www-10.lotus.com/ldd/nd85forum.nsf/0/579744cf7198e21785257731006c9cea?OpenDocument

Thursday, September 16, 2010

Change encoding attribute after XLST

I've done some transformation my DXL using XSLT. The funny thing was that after transformation using


// Transform
var str = docxml.transformNode(xsl);


I always got 'encoding' as UTF-16, that's not correct, so after some time I found nice solution


here is code I used: http://dotnet.itags.org/dotnet-tech/66097/

var doc = new ActiveXObject("Microsoft.XMLDOM");
doc.load(
"test.xml");

// Print initial encoding
var pi = doc.firstChild;
var eattr = pi.attributes.getNamedItem("encoding");
var encoding = eattr.value;

// Convert to string and reload (this loses the encoding)
var xml = doc.xml;
doc.loadXML(xml);

// Reset the encoding to "ISO-8859-1"
pi = doc.firstChild;
var eattr = pi.attributes.getNamedItem("encoding");
if (eattr == null) {
eattr = doc.createAttribute(
"encoding");
pi.attributes.setNamedItem(eattr);
}
eattr.value =
"ISO-8859-1";

// And save document with new encoding.
doc.save("test2.xml");


It works fine for me (and not, output option in XSL did not help)

Wednesday, September 15, 2010

Date.prototype.addDays

I did not find that method how can I add days to my date, so here is solution:

// add days
Date.prototype.addDays = function(days) {
var secsDay = 86400000; // there are 86400000 secs in 1 day
var time = this.getTime(); // number of milliseconds since midnight of January 1, 1970.
var newdate = new Date(time + (days * secsDay));
this.setDate(newdate.getDate());
}


If anybody has better solution, you are welcome!

Tuesday, September 14, 2010

'wget' as way to download files

Need to download files from our Domino server by this path http://host/myfile.log, using MS DOS command?
You can try to use wget as one of possible way to do that.
here is an exmplae of DOS command:
wget.exe http://host/myfile.log
I've run this DOS command in my JS file (yes ActiveX is required for that), but anywhere it is quite interesting approach.

Friday, September 10, 2010

Need to zip file with password in Lotus Notes?

I've task where we need to compress and protect attachments and some log files. I did not look in Lotus Script area at all (as I'm sure it would be not possible or to difficult to do such thing). So I started to look for free RAR/ZIP Java libraries that will have what I need (compress and password).
I was surprised a bit, RAR does not have such API at all, but ZIP has already built in Domino library that allow us to zip files but... not to set password (at least I did not find).

So after couple minutes in google I've found only one free Java library that could zip files with password: http://code.google.com/p/winzipaes/
There were no problems during implementation, library is well described.
Java, Java and Java :)

Thursday, August 26, 2010

Don't forget that if you have URL http://host/db/yourform?OpenForm

Then you need to have at least Author access with ability to create documents in database or... just check option Available to Public Access users in form settings.


Otherwise you can get message into your browser
"You are not authorized to perform this operation."