Thursday, December 24, 2009

Tally ERP 9 Http XML communication

Hello while i was integrating my java/j2ee application with tally i taught of sharing my information with many developers who may get help in integrating there applications with Tally(which is widely used for accounting in India)

----------------------------CODE--------------------------------------------------------
package com.XXXX.hmis.utils;
/**
* KUMAR GAURAV SRIVASTAVA
*/


/**
*THIS IS A SAMPLE TO CREATE VOUCHER IN TALLY.ERP 9
*FOR TESTING SAVE IT AS test.xml, and CHANGE THE Url & xmlFile VALUES
*
*
*


*/




import java.io.*;
import java.net.*;

public class SOAPClient{
public static void main(String[] args) throws Exception {

String Url = "http://192.168.10.44:9999/";
String xmlFile = "/home/gaurav/Desktop/test.xml";

String SOAPAction = "";

// Create the connection where we're going to send the file.
URL url = new URL(Url);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;


FileInputStream fin = new FileInputStream(xmlFile2Send);

ByteArrayOutputStream bout = new ByteArrayOutputStream();

// Copy the SOAP file to the open connection.
copy(fin,bout);
fin.close();

byte[] b = bout.toByteArray();

// Set the appropriate HTTP parameters.
httpConn.setRequestProperty( "Content-Length",
String.valueOf( b.length ) );
httpConn.setRequestProperty("Content-Type","text/xml; charset=utf-8");
httpConn.setRequestProperty("SOAPAction",SOAPAction);
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);

// Everything's set up; send the XML that was read in to b.
OutputStream out = httpConn.getOutputStream();
out.write( b );
out.close();

// Read the response and write it to standard out.

InputStreamReader isr =
new InputStreamReader(httpConn.getInputStream());
BufferedReader in = new BufferedReader(isr);

String inputLine;

while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);

in.close();
}

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[256];
while (true) {
int bytesRead = in.read(buffer);
if (bytesRead == -1) break;
out.write(buffer, 0, bytesRead);
}
}
}
}
}

9 comments:

  1. Hi
    Im in currently integrating tally for a client, but i cant seem to find the documentation for the SOAP API anywhere. You seem to have accomplished this, where did u find the documentation?

    ReplyDelete
  2. i am also want to integrate tally with my web application. kindly help me i don't know how to start it

    ReplyDelete
  3. Hi I need to test a feature where I need to import xml from my web application to tally.erp 9.
    As I am a QA, I need to know about what basic thngs I need to setup in tally....as I am getting an error that ledger reservation is not found...This may be because Only company is setup but rest of the setup is not done.

    Expecting a help..please send me gautam.chakraborty30@gmail.com

    ReplyDelete
  4. I want to intergrate Tally ERP 9 with java is it possible

    ReplyDelete
    Replies
    1. It is very urgent to implement Tally ERP 9 with java ,please help me my email id is sdantey@gmail.com

      Delete
  5. please reply me how to write the xml for stock balance

    ReplyDelete
  6. pls help me how to create accounting vochers in tally using java

    ReplyDelete
  7. pls help me how to create accounting vochers in tally using java

    ReplyDelete
  8. This is very helpful site for tally user. Just visiting here on my site.

    Tally Sales

    ReplyDelete