Dear saclix forum,
i m facing a severe problem while retrieving the user from saclix server using GetUsersList from saclix api.
i have wrote a java class to connet to scalix and sending an xml file as input with GetUsersList ,username and password.expcting the response xml containing the userlist of scalix.
i m succesfully connectiong to the server but not able to get the proper response..
Below is the java class i have written
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
public class SoapTest {
public static void main(String[] args) throws Exception {
String strURL ="http://sclaix/webmail";
String strXMLFilename = "path://SCALIX//scalix//src//input.xml";
File input = new File(strXMLFilename);
// Prepare HTTP post
PostMethod post = new PostMethod(strURL);
//GetMethod get=new GetMethod(strURL);
post.setRequestEntity(new InputStreamRequestEntity(
new FileInputStream(input), input.length()));
//-- Convert xml to byte stream start
FileInputStream fin = new FileInputStream(strXMLFilename);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
copy(fin,bout);
fin.close();
byte[] b = bout.toByteArray();
StringBuffer sb12=new StringBuffer();
for(int i=0;i<b.length;i++)
{
sb12.append((char)b[i]);
}
//---- Convert xml to byte stream end
post.setRequestHeader("GET","/GetUsersList HTTP/1.1");
post.setRequestHeader("HOST","http://sclaix/webmail");
post.setRequestHeader(
"Content-Type","text/xml; charset=utf-8");
post.setRequestHeader("Content-Length",String.valueOf(b));
System.out.println("XML File Size: "+b.length);
System.out.println("post.isRequestSent()-1 "+post.isRequestSent());
// Get HTTP client
HttpClient httpclient = new HttpClient();
// Execute request
try {
// httpclient.setConnectionTimeout(1000000000);
int result = httpclient.executeMethod(post);
System.out.println("post.isRequestSent()-2 "+post.isRequestSent());
//System.out.println("httpclient.getHost();httpclient.getPort();httpclient.getParams();"+httpclient.getHost()+"1111"+httpclient.getPort()+"2222"+httpclient.getParams());
// Display status code
System.out.println("Response status code: " + result);
// Display response
System.out.println("Response body: ");
//System.out.println(post.getResponseBodyAsString());
//System.out.println(post.getResponseBody());
System.out.println(post.getResponseBodyAsStream());
//--Convert Stream to String start
InputStream isi=post.getResponseBodyAsStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(isi));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
System.out.println("Response String From Stream"+sb.toString());
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
isi.close();
} catch (IOException e) {
e.printStackTrace();
}
}
//--Convert Stream to String end
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("ERROR:"+e);
}finally {
// Release current connection to the connection pool
// once you are done
post.releaseConnection();
}
}
public static void copy(InputStream in, OutputStream out)
throws IOException {
// do not allow other threads to read from the
// input or write to the output while copying is
// taking place
synchronized (in) {
synchronized (out) {
byte[] buffer = new byte[2048];
while (true) {
int bytesRead = in.read(buffer);
if (bytesRead == -1) break;
out.write(buffer, 0, bytesRead);
}
}
}
}
}
-------------
The XML file i m using is
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/
envelope/">
<SOAP-ENV:Body>
<scalix-caa:CAARequestMessage
xmlns:scalix-caa="http://sclaix/webmail">
<ServiceType>scalix.res</ServiceType>
<Credentials id="12345">
<Identity name="vusername"
passwd="pass" />
</Credentials>
<FunctionName>GetUsersList</FunctionName>
<ScalixServers>
<Host>mail.scalix.local</Host>
<Host>http://172.16.1.84/webmail</Host>
</ScalixServers>
<FunctionNameParameters></FunctionNameParameters>
<GetUsersListParameters maxRecords="2">
<!--
<filters>
<surnamefilter value="v*" />
<givennamefilter value="ven" />
<initialsfilter value="v" />
<usertypefilter value="ALL" />
</filters>
-->
<!-- <organizedBy entity="LAST_NAME" /> -->
</GetUsersListParameters>
</scalix-caa:CAARequestMessage>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
using the above fiel i m able to connect to the scalix server and gettting the following response.
Response from scalix
-----------------------
XML File Size: 999
post.isRequestSent()-1 false
post.isRequestSent()-2 true
Response status code: 413
Response body:
org.apache.commons.httpclient.AutoCloseInputStream@1100d7a
Response String From Stream<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>413 Request Entity Too Large</title>
</head><body>
<h1>Request Entity Too Large</h1>
The requested resource<br />/webmail<br />
does not allow request data with POST requests, or the amount of data provided in
the request exceeds the capacity limit.
<hr>
<address>Apache/2.2.3 (Red Hat) Server at scalix Port 80</address>
</body></html>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>413 Request Entity Too Large</title>
</head><body>
<h1>Request Entity Too Large</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator,
root@localhost and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p>
<hr>
<address>Apache/2.2.3 (Red Hat) Server at 172.16.1.84 Port 80</address>
</body></html>
The jar files i m using are
1:commons-codec-1.3.jar
2:commons-httpclient.jar
3:commons-logging.jar
4:soap-2.3.1.jar
as i have tried my level best and now i m looking for help fro u ppl.
i m eagerly waiting for the solution from .please help me in solving the issue.
Thanks in advance
Sekhar