GetUsersList from scalix server from java soapclient

Discuss Scalix Management Services ( formerly Scalix Admin Console )

Moderator: ScalixSupport

sekharpns

GetUsersList from scalix server from java soapclient

Postby sekharpns » Tue Apr 07, 2009 10:42 am

Dear all ,

this is sekhar. i m trying to get the users of scalix server with GetUsersList using the soap java client giving an xml input containing scalix username and password,and the function name .i m expecting an output of xml response file which contains the user of scalix.

The following is the java file i m using
-------------------------------------------

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
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.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.PutMethod;

//--
import org.apache.commons.httpclient.auth.CredentialsNotAvailableException;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.auth.MalformedChallengeException;
import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
import org.apache.commons.httpclient.params.HostParams;
import org.apache.commons.httpclient.params.HttpClientParams;
import org.apache.commons.httpclient.params.HttpConnectionParams;
//--
import com.sun.xml.internal.ws.wsdl.writer.document.Fault;

/**
*
* This is a sample application that demonstrates
* how to use the Jakarta HttpClient API.
*
* This application sends an XML document
* to a remote web server using HTTP POST
*/
public class SoapTest {

/**
*
* Usage:
* java PostXML http://mywebserver:80/ c:\foo.xml
*
* @param args command line arguments
* Argument 0 is a URL to a web server
* Argument 1 is a local filename
*
*/
public static void main(String[] args) throws Exception {
/*
if (args.length != 2) {
System.out.println(
"Usage: java -classpath <classpath> [-Dorg.apache.commons."+
"logging.simplelog.defaultlog=<loglevel>]" +
" PostXML <url> <filename>]");

System.out.println("<classpath> - must contain the "+
"commons-httpclient.jar and commons-logging.jar");

System.out.println("<loglevel> - one of error, "+
"warn, info, debug, trace");

System.out.println("<url> - the URL to post the file to");
System.out.println("<filename> - file to post to the URL");
System.out.println();
System.exit(1);
}
*/

// Get target URL
//String strURL = args[0];
String strURL ="http://172.16.1.84//webmail";

// Get file to be posted
//String strXMLFilename = args[1];
String strXMLFilename = "D://MyEclipseSampleWorkSpace//SCALIX//input.xml";
File input = new File(strXMLFilename);


//-- 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]);
}

System.out.println("input xml "+sb12.toString());

System.out.println("sb12.toString().length()"+sb12.toString().length());


//---- Convert xml to byte stream end

// Prepare HTTP post
PostMethod post = new PostMethod(strURL);
//PutMethod post=new PutMethod(strURL);
//GetMethod get=new GetMethod(strURL);

// Request content will be retrieved directly
// from the input stream
// Per default, the request content needs to be buffered
// in order to determine its length.
// Request body buffering can be avoided when
// content length is explicitly specified
// post.setRequestEntity(new InputStreamRequestEntity(
// new FileInputStream(input), sb12.toString().length()));

new InputStreamRequestEntity(new ByteArrayInputStream(sb12.toString().getBytes()));

// Specify content type and encoding
// If content encoding is not explicitly specified
// ISO-8859-1 is assumed



post.setRequestHeader("POST","/GetUsersList HTTP/1.1");
post.setRequestHeader("HOST","http://172.16.1.84//webmail");
post.setRequestHeader(
"Content-Type","text/xml; charset=utf-8");
//post.setRequestHeader("Content-Length",String.valueOf(sb12.toString().length()));
post.setRequestHeader("Content-Length",String.valueOf(b));
//post.setRequestHeader("Content-Length", "999");

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);

if (post.getStatusCode() == HttpStatus.SC_OK) {

//Fault fault ;
System.out.println(post.getResponseBodyAsString());
} else {
System.out.println(
"Unexpected failure: "
+ post.getStatusLine().toString());
}
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 Input i m using is
---------------------------------

<SOAP-ENV:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Header>
</soap:Header>
<SOAP-ENV:Body>
<!--
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:MustUnderstand</faultcode>
<faultstring>Failed to locate method (ValidateCreditCard) in class (examplesCreditCard) at /usr/local/ActivePerl-5.6/lib/ site_perl/5.6.0/SOAP/Lite.pm line 1555.</faultstring>
<detail>erro1</detail>

<faultcode>SOAP-ENV:Server</faultcode>
<faultstring>Server OS Internal failure-Reboot Server</faultstring>
<detail>erro2</detail>

<faultcode>Client</faultcode>
<faultstring>Invalid Request</faultstring>
<detail>erro3</detail>
</SOAP-ENV:Fault>
-->
<scalix-caa:CAARequestMessage xmlns:scalix-caa="172.16.1.84:25">
<ServiceType>scalix.res</ServiceType>
<Credentials id="12345">
<Identity name="venkatakrishnan.s@zslindia.co.in" passwd="Test123" />
</Credentials>
<FunctionName>GetUsersList</FunctionName>
<ScalixServers>
<Host>mail.scalix.local</Host>
<Host>172.16.1.84:25.scalix.local</Host>
</ScalixServers>
<FunctionNameParameters></FunctionNameParameters>
<GetUsersListParameters maxRecords="2"></GetUsersListParameters>
</scalix-caa:CAARequestMessage>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>


And the Reponse text i m getting is
-------------------------------------------


sb12.toString().length()1364
XML File Size: 1364
post.isRequestSent()-1 false
Unexpected failure: HTTP/1.1 413 Request Entity Too Large
post.isRequestSent()-2 true
Response status code: 413
Response body:
org.apache.commons.httpclient.AutoCloseInputStream@128e20a
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 172.16.1.84 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



i have tried my level best and still i m struggling to get the out put.

can any one help me to solve this issue .


Thanks

sekhar.

Valerion
Scalix Star
Scalix Star
Posts: 2730
Joined: Thu Feb 26, 2004 7:40 am
Location: Johannesburg, South Africa
Contact:

Re: GetUsersList from scalix server from java soapclient

Postby Valerion » Tue Apr 07, 2009 11:22 am

You should send the request to /caa, not to /webmail. However, this interface is not documented, so you are mostly on your own here, seeing what the requests and responses are. The easiest is to see what /sac generates (the source is on the Scalix website) and compare it with your xml files.


Return to “Scalix Management Services”



Who is online

Users browsing this forum: No registered users and 1 guest