Enumeration in helma

// Enumeration
for (var e = req.servletRequest.getHeaderNames(); e.hasMoreElements() ; ) {
var obj = e.nextElement();
app.log(“—“);
app.log(“—header name: “+obj);
app.log(“—header value: “+req.servletRequest.getHeader(obj));
}

HTTP POST in JAVA

geschrieben für helma (siehe http://helma.org ), nicht getestet für PHP

folgende funktion sendet ein file als ByteStream zu einer URL:


import java.net.URL;
import java.io.File;
import java.io.InputStream;
import java.net.URLConnection;
import java.io.FileInputStream;
import java.io.OutputStream;

// class definition

/**
* send file via HTTP POST to uri
*/
public static void sendfile() {
// some text that does not appear in the file
// use an evan number of “-”
String CONTENT_BOUNDARY = “–abc”;
FileInputStream fis1 = null;
OutputStream os1 = null;
InputStream is1 = null;
try {
// the URL of your upload application
URL testPost = new URL(“http://myurl/myaction?userid=a&password=a”);
URLConnection conn = testPost.openConnection();
// conn.setAllowUserInteraction(true);
conn.setDoOutput(true); // turns it into a post
conn.setRequestProperty(“Content-Type”,
“multipart/form-data; boundary=” + CONTENT_BOUNDARY);
// conn.setRequestProperty(“User-Agent”, “Mozilla/4.7 [en] (WinNT; U)”);
// conn.setRequestProperty(“Accept-Language”, “en-us”);
// conn.setRequestProperty(“Accept-Encoding”, “gzip, deflate”);
// conn.setRequestProperty(“Accept”, “image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, application/pdf, application/x-comet, */*”);
// conn.setRequestProperty(“CACHE-CONTROL”, “no-cache”);
os1 = conn.getOutputStream();
// the file, name is “rawfile”
// whatever file you care to upload
String uploadFileName = “C:\\myfile”;

File file1 = new File(uploadFileName);
fis1 = new FileInputStream(file1);

os1.write( (“-” + CONTENT_BOUNDARY + “\r\n” +
“Content-Disposition: form-data; name=\”rawfile\”; filename=\”” +
uploadFileName
+ “\”\r\nContent-Type: text/plain\r\n\r\n”).getBytes());

byte[] fileStuff = new byte[512];
int howMany = -1;
int totMany = 0;
howMany = fis1.read(fileStuff, 0, 512);
while (howMany != -1) {
totMany += howMany;
os1.write(fileStuff, 0, howMany);
howMany = fis1.read(fileStuff, 0, 512);
}
System.err.println(“read ” + totMany +
” bytes from file, wrote to outputstream.”);
fis1.close();
fis1 = null;
os1.write( (“\r\n–” + CONTENT_BOUNDARY + “–\r\n”).getBytes());

is1 = conn.getInputStream();
byte[] urlStuff = new byte[512];
howMany = is1.read(urlStuff, 0, 512);
while (howMany != -1) {
System.out.write(urlStuff, 0, howMany);
howMany = is1.read(urlStuff, 0, 512);
}
System.err.println(“that was your output.”);
is1.close();
is1 = null;
os1.close();
os1 = null;
}
catch (Exception ex) {
System.err.println(“Exception: ” + ex);
ex.printStackTrace();
}
finally {
if (fis1 != null)
try {
fis1.close();
}
catch (Exception ok_to_eat) {
// ok to ignore this
}
if (is1 != null)
try {
is1.close();
}
catch (Exception ok_to_eat) {
// ok to ignore this
}
if (os1 != null)
try {
os1.close();
}
catch (Exception ok_to_eat) {
// ok to ignore this
}
}
}

xml-rpc aufruf auf helma

hop.bat:
set XMLRPC_PORT=8082

app.properties:
XmlRpcAccess = MemberMgr.createAccount
XmlRpcHandlerName = *

MemberMgr/functions.js:
function createAccount(usr, masterAccountID) {
..
}

Root/type.properties:
members = mountpoint(MemberMgr)

JAVA CODE

import java.util.Vector;
import helma.xmlrpc.*;

public class JavaClient {
// The location of our server.
private final static String server_url = “localhost”;
public static void main(String[] args) {
try {
// Create an object to represent our server.
XmlRpcClient server = new XmlRpcClient(server_url, 8082);
// Build our parameter list.
Vector params = new Vector();
params.addElement(new Integer(5));
params.addElement(new Integer(3));

// Call the server, and get our result.
// this only works with Root mountpoints
Object o = server.execute(“members.createAccount”, params);
System.out.println(“result: ” + o);
}
catch (XmlRpcException exception) {
System.err.println(“JavaClient: XML-RPC Fault #” +
Integer.toString(exception.code) + “: ” +
exception.toString());
}
catch (Exception e) {
e.printStackTrace();
}
}
}

servlet in jbuilder

– HttpServlet servlet schreiben

– neues webmodule in JBuilder, libs einbinden

– ins web.xml Klasse (hier ‘NtlmHttpAuthExample’) und mapping

<servlet>
<servlet-name>ntlm</servlet-name>
<servlet-class>NtlmHttpAuthExample</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ntlm</servlet-name>
<url-pattern>/ntlm</url-pattern>
</servlet-mapping>

– web.xml auf schreibgeschützt setzen

– runtimeconfig für server: services/JSP launch uri setzen

z.b. auf http://localhost:8083/ntlm_test/ntlm setzen

module howto

code
– /code/global/constants.js:INITMODULESONSETUP
– /Site/objectFunctions.js:constructor::prefs.sidebar01

web-backend
– in [twoday]/modules gelistet? notfalls [twoday]/modules/import
– in [twoday]/[site]/modules/sidebar gelistet? aktivieren über [twoday]/modules
– in sidebar dargestellt? in [twoday]/[site]/modules/order zur sidebar hinzufügen