[oXygen-user] HttpUrlConnection and HTTP method in a Saxon extension

Dan Caprioara
Mon Jan 5 03:05:51 CST 2009


Oxygen uses the Apache  http client to read/write from WebDAV HTTP 
servers.  For this,  a new implementation of the HTTPURLConnection wraps 
the Apache http client. Normally, the PUT method is used for storing 
data on the servers  and GET to retrieve it, but the POST method is also 

This is how I tried to reproduce your problem, but without success:

First of all, I have enabled the http logging. For this, I have created 
a log4j.properties file in the oXygen installation directory, with the 
following content:

log4j.rootCategory= info, R
# R is the standard output
log4j.appender.R.layout.ConversionPattern=%r %p [ %t ] %c - %m%n

I have then started oXygen using the startup scripts available in the 
installation directory.

I have compiled the following java class, and added it as an extension 
to the transformation scenario. I have then tested with both Saxon B and 
Saxon 6.5:

import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class SaxonExtension {

  public static String post() {
    try {
      URL url = new URL("http://www.sync.ro/");
      HttpURLConnection conn = (HttpURLConnection)url.openConnection();
      OutputStream os = conn.getOutputStream();
      InputStream is = conn.getInputStream();
      int r = is.read();
      StringBuffer buf = new StringBuffer();
      while(r != -1) {
        r = is.read();
      return buf.toString();
    } catch (Exception e) {
      return e.toString();

The following lines were written in the log:

  - >> "POST http://www.sync.ro/ HTTP/1.1[\r][\n]"
  - >> "User-Agent: Jakarta Commons-HttpClient/3.1[\r][\n]"
  - >> "Host: www.sync.ro[\r][\n]"
  - >> "Proxy-Connection: Keep-Alive[\r][\n]"
  - >> "Content-Length: 6[\r][\n]"
  - >> "[\r][\n]"
  - >> "some_parameter"

Please send to support the log you obtain and eventually a Java sample 
showing the problem.
As a workaround, you could create directly a 
sun.net.www.protocol.http.HttpURLConnection object.

Happy New Year!
Dan Caprioara

Florent Georges wrote:
>   Hi,
>   Best wishes to the oXygen team and users.
>   I have a Saxon extension in Java, that opens an HTTP connection from
> a URL and set the HTTP method on it to POST:
>     URL url  = ...;
>     HttpURLConnection conn = (HttpURLConnection) url.openConnection();
>     conn.setRequestMethod("POST");
>   Unfortunately, the method is always GET, and there is no exception
> raised in that code.  I must admit it took a while to find the cause.
> The code works well outside oXygen, and the object 'conn' is actually
> of type ro.sync.net.protocol.http.WebdavHttpURLConnection when the
> transform is launched from within oXygen.
>   Is it because of a bug in this class?  Is there any way to work
> around this one?  Outside of oXygen, in a standalone Sun JVM, the
> class is sun.net.www.protocol.http.HttpURLConnection, for what is
> worth noting...
>   Un an nou fericit!

More information about the oXygen-user mailing list