hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "STEINER Stephan" <Stephan.Stei...@nextiraone.ch>
Subject Trying to create a SearchMethod
Date Wed, 29 Mar 2006 17:33:54 GMT
Hi

When I was all done and ready to test my WebDAV search request using
basic Java HttpURLConnection, I had to find out the bugger doesn't
support HTTP SEARCH. Oh well, I started looking around, found a 2001
client that's supposed to work but that I couldn't even compile without
pages full of errors. Then I had a look at slide but it wouldn't do the
trick either (no examples..), so I figured it can't be that hard and
since I already have everything else, let's write an additional HTTP
Method for the httpclient.

Unfortunately, Exchange consistantly balked at me so I started Ethereal
and found out that my SEARCH request is in fact a POST with Method
SEARCH. Here's how the first few lines form a proper request (C# has no
problem with SEARCH requests... Is Sun listening?)

SEARCH /exchange/stephan.steiner@nextiraone.ch/Kontakte  HTTP/1.1
Authorization: Basic
Content-Type: text/xml. 

My own request, which extends EntityEnclosingMethod (I figured I needed
to start with a request that involves sending data back to the webserver
since a WEBDAV Search is just that.. Send XML to the server, and get an
XML response back). Ethereal shows the following for my Java search
class:

POST /exchange/stephan.steiner@nextiraone.ch/Kontakte HTTP/1.1. 
Method: SEARCH
Content- Length: 552
Content-Type: text/ xml
Authorization: Basic

So that's not going to work. Now I've been looking through a lot of code
but for the life of me can't find where POST is sent over the line so
I'd appreciate your input.

For your reference I'm pasting my class at the end of this message.

Regards
Stephan



package phonenumberlookup;

import java.net.URLEncoder;
import org.apache.commons.httpclient.HttpConnection;
import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.util.EncodingUtil;
import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
/**
 *
 * @author SSTE
 */
public class SearchMethod extends
org.apache.commons.httpclient.methods.EntityEnclosingMethod
{
    private String searchString;
    /** Creates a new instance of SearchMethod */
    public SearchMethod()
    {
        super();
        this.setRequestHeader("Content-Type", "text/xml");
    }
    
    public SearchMethod(String uri)
    {
        super(uri);
        this.setRequestHeader("Content-Type", "text/xml");
    }
    
    public SearchMethod(String uri, String query)
    {
        this(uri);
        this.setSearchString(query);
    }
    
    public String getName()
    {
        return "SEARCH";
    }
    
    protected boolean shouldCloseConnection(HttpConnection conn)
    {
        return true;
    }
    
    protected RequestEntity generateRequestEntity() 
    {
        if (this.searchString != null)
        {            
            try
            {
                String content = URLEncoder.encode(this.searchString,
"UTF-8");
            }
            catch (java.io.UnsupportedEncodingException u)
            {
                return super.generateRequestEntity();
            }
            ByteArrayRequestEntity entity = new
ByteArrayRequestEntity(EncodingUtil.getAsciiBytes(this.searchString),
"text/xml");
            return entity;
        } 
        else 
        {
            return super.generateRequestEntity();
        }
    }

    public String getSearchString()
    {
        return searchString;
    }

    public void setSearchString(String searchString)
    {
        this.searchString = searchString;
    }
    
}

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org


Mime
View raw message