Well although I have never tested my client for SMS but for Push Proxy, one difference that I see with my code (using Sockets but the principle is the same) is the "Content-Type" parameter.
Try setting it to "application/xml" instead of "text/xml"
 
One more problem that I had is that all new lines have to end with \r\n and not just \n or \r
 
If all else fails you will need to use Ethereal (it is open source and you can get it from http://www.ethereal.com/) to make sure that the Content-Length of your post request is absolutely correct.  Kannel is very sensitive to wrong content lengths.
 
Here is some code  that succesfully sends a POST request to kannel WAP Push. I think that if you change the code to your needs you should make it work for SMS as well (sorry is in sockets not HttpClient - can't seem to find any old code with HttpClient :(
 
===========================================================================================================
import java.net.*;
import java.io.*;
/*
 * PushMeSocket.java
 *
 */
 
public class PushMeSocket {
    URL PPGurl;
    String PPG_URL;
    String charen = "UTF-8";
    String hostName = "is-3052";
    int port = 39898;
    String path = "/wappush";
    InetAddress inetAddress;
    Socket socket;
    String data;
   
    /** Creates a new instance of PushMeSocket */
    public PushMeSocket() {
       this.PPG_URL = "http://is-3052:39898/wappush";
       try {
       
           inetAddress = InetAddress.getByName(hostName);
           socket = new Socket(inetAddress,port);
          
       } catch (Exception e) {
           e.printStackTrace();
       }
    }
   
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       
        PushMeSocket push = new PushMeSocket();
        StringBuffer xmlBuffer = new StringBuffer();
       
        char tmp;
        int readTmp;
        try {
            BufferedReader xmlFile = new BufferedReader(new FileReader(args[0]));
            while ((readTmp=(char)xmlFile.read())!=65535){
               tmp = (char) readTmp;
       
               if (readTmp == 10) {
                   xmlBuffer.append('\r');
               }
               xmlBuffer.append(tmp);
              
            }
            xmlFile.close();
       
            push.data = "">        } catch (Exception e) {
            e.printStackTrace();
        }
       
            System.out.println(push.PushMessage(push.data, "multipartboundary"));
    }
   
   
    public String PushMessage(String XMLDoc, String MultiPartSeperator) {
       
       
        StringBuffer replyString = new StringBuffer();
        StringBuffer headerString = new StringBuffer();
        try {
           
            BufferedWriter sendXMLStream = new BufferedWriter (new OutputStreamWriter(socket.getOutputStream(),this.charen));
            BufferedReader ppgReply = new BufferedReader(new InputStreamReader(socket.getInputStream(),this.charen));
            headerString.append("POST " + this.path + " HTTP/1.1\r\n");
            headerString.append("Host: " + this.hostName + ":"+this.port+"\r\n");
            headerString.append("Content-Type: multipart/related; boundary="+MultiPartSeperator+"; type=\"application/xml\"\r\n");
           
            headerString.append("Content-Length: " + (XMLDoc.getBytes().length) +"\r\n\r\n");
            sendXMLStream.write(headerString.toString());
            sendXMLStream.write(XMLDoc);
            System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
            System.out.println(headerString.toString());
            System.out.println(XMLDoc);
            System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
           
            sendXMLStream.flush();
            
           
 
           
           
            char[] tmp = new char[5000];
            System.out.println("Ready to receive reply ");
           
               ppgReply.read(tmp);
               replyString.append(tmp);
              
 
            ppgReply.close();
            sendXMLStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
       
        return replyString.toString();
    }
   
}
=============================================================================================================================
 
Hope it helps,
 
Spyros

 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Gelvis Sequera
Sent: Thursday, September 22, 2005 6:21 PM
To: users@kannel.org
Subject: Re: Sending post request in java

I used the HttpCLient, and i couldn't resolve the problem
 
here is a piece of code:

case Request.POST:
     
     methodP = new PostMethod(url);
     methodP.setRequestHeader("Content-type", "text/xml");
     methodP.setRequestBody(request.getRequest());
      client.executeMethod(methodP);
     response = methodP.getResponseBodyAsString();
     break;
 
do i have to set some attribute on the PostMethod???? is there any tip?
 
Thanks ..
 
On 9/22/05, Spyros Sakellariou <[EMAIL PROTECTED]> wrote:
I had the same problems trying to send Push Mesages from Java using the HttpUrlConnection.
Checking with Ethereal I found out that the HttpUrlConnection object breaks the request into two packets and that probably confuses Kannel.
I tried using sockets (more work of course) and everything worked well.
Also the HttpClient library from Apache Commons works well with kannel and is much easier to use than HttpUrlConnection.
Just don't use the HttpUrlConnection object.
 
Good luck!

Spyros Sakellariou
 

 -----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Gelvis Sequera
Sent: Tuesday, September 20, 2005 10:56 PM
To: users@kannel.org
Subject: Sending post request in java

Hi.
 
I'm triying to send to consecutive messages from kannel using the Java HttpUrlConnection, but after I send the first, the smsbox dies (but the bearebox keeps up).
 
My conf file is
 
group = smsc
smsc = at
modemtype = wavecom
device = /dev/ttyS1
pin = 1286
sim-buffering = true
speed = 115200
my-number = +58412*******
 
group = smsbox
bearerbox-host = localhost
sendsms-port = 13013
log-file = "/var/log/kannel/smsbox.log"
log-level = 0
access-log = "/var/log/kannel/access.log"
immediate-sendsms-reply = true
 
group = modems
id = wavecom
name = Wavecom
detect-string = "WAVECOM MODEM"
#broken = true
message-storage = SM
enable-mms = true
init-string = "AT S7=45 S0=0 L1 V1 X4 &c1 E1 Q0"
need-sleep = true
 
 
And my log is
 
2005-09-20 11:05:18 [11434] [3] INFO: sendsms sender:<test:+58412*********> (192.168.1.86) to:<multi-cast> msg:<Se les notifica que los pasantes estan probando el proy SML.. jajaja>
2005-09-20 11:05:18 [11434] [3] DEBUG: message length 68, sending 1 messages
2005-09-20 11:05:18 [11434] [3] DEBUG: Status: 202 Answer: <Sent.>
2005-09-20 11:05:18 [11434] [3] DEBUG: HTTP: Resetting HTTPClient for `192.168.1.86'.
2005-09-20 11:05:18 [11434] [3] PANIC: gwlib/octstr.c:2355: seems_valid_real: Assertion `ostr->data != NULL' failed. (Called from gwlib/octstr.c:317:octstr_destroy.)
2005-09-20 11:05:18 [11434] [3] PANIC: /usr/local/sbin/smsbox(gw_panic+0x19a) [0x808015b]
2005-09-20 11:05:18 [11434] [3] PANIC: /usr/local/sbin/smsbox [0x8086fa2]
2005-09-20 11:05:18 [11434] [3] PANIC: /usr/local/sbin/smsbox(octstr_destroy+0x2f) [0x8081641]
2005-09-20 11:05:18 [11434] [3] PANIC: /usr/local/sbin/smsbox [0x805af7d]
2005-09-20 11:05:18 [11434] [3] PANIC: /usr/local/sbin/smsbox [0x8075dae]
2005-09-20 11:05:18 [11434] [3] PANIC: /lib/libpthread.so.0 [0xb7f0b2fe]
2005-09-20 11:05:18 [11434] [3] PANIC: /lib/libc.so.6(__clone+0x5a) [0xb7cb4ada]
 
My post request is something like this:
<message>
<submit>
<da><number>+5841**********</number></da>
<ud>MESSAGE </ud>
<from>
<user>*****</user>
<pass>*****</pass>
</from>
</submit>
</message>
 
Any Ideas???????????
 
 

Reply via email to