on 04-13-2006 4:07 PM
Guy's
following is the code to call Business connector
service,but it's giving error,i am not that good in java,
pls help me to sort this issue,if possible pls provide
alternate code
import java.util.*;
import java.io.*;
import java.net.*;
<b>import org.pf.util.Base64Converter;</b>
public class orderRequest {
// Verbindungsparameter
private String ServerName = " 123.12.45.44";
private int Port = 5755;
private String Protocol = "http";
// Kundendaten
private String UserName = "xyz";
private String Password = "1234";
// Ein-/Ausgabe Daten
private Vector InputDataStr = null;
private Vector OutputDataStr = null;
private String line;
StringBuffer strBuf = new StringBuffer();
private String sendRequest () {
URLConnection con;
URL server;
PrintWriter bw=null;
BufferedReader br=null;
try {
// Oeffnen der Verbindung
server = new URL(Protocol,ServerName,Port,"/invoke/PITS:SalesOrderCreation");
con = server.openConnection();
con.setDoOutput(true);
System.out.println("server "+ server);
<b> con.setRequestProperty("Authorization","Basic "Base64Converter.encode(UserName":"+Password));</b>
// MODIFIED
con.setRequestProperty("Content-Type","text/plain" );
bw = new PrintWriter( new OutputStreamWriter (new BufferedOutputStream (con.getOutputStream())));
InputDataStr = new Vector();
// Schicken der Input Daten
for (Enumeration e = InputDataStr.elements() ; e.hasMoreElements() ; ) {
line = (String)e.nextElement();
bw.println(line);
}
bw.flush();
bw.close();
// Empfangen der Output Daten
OutputDataStr = new Vector(10,10);
br = new BufferedReader(new InputStreamReader(new BufferedInputStream (con.getInputStream())));
if( true )
{
// read the input stream - character by character
int intChar;
while( true )
{
try
{
intChar = br.read();
if( intChar <=0 ) break;
strBuf.append( "" + (char) intChar );
}
catch(IOException expIO)
{
break;
}
}
}
else
{
// read the input stream - one line at a time
while ((line=br.readLine()) != null) {
strBuf.append(line);
}
}
// ggf. Betrachten der Fehler
/*line = (String)OutputDataStr.elementAt(0);
StringTokenizer st = new StringTokenizer(line,";");
String lineElement = null;
String Version = null;
if (st.countTokens() > 2)
{
if (st.hasMoreTokens()) st.nextToken(); // 1
if (st.hasMoreTokens()) Version = st.nextToken(); // 2
if (st.hasMoreTokens()) Customer = st.nextToken(); // 3
if (st.hasMoreTokens()) ReferenceNumber = st.nextToken(); // 4
if (st.hasMoreTokens()) ErrorCode = st.nextToken(); // 5
}
if(ErrorCode.compareTo("0") != 0) return ErrorText;*/
}
catch (Exception e){
e.printStackTrace();
}
finally {
try{bw.close();}
catch (Exception e){;}
try{br.close();}
catch (Exception e){;}
}
return strBuf.toString();
}
public static void main(String args[]) {
orderRequest or = new orderRequest();
System.out.println(or.sendRequest());
}
}
guy's it's giving error in place where i have made it bold,
<b>note:</b>server name and password is changed for
confidenatlity
Hi,
Please post the java exception trace.
If you're Java code wouldn't work you get always an exception, e.g. a java.lang.NullPointerException or in your case I think it would be an java.io.IOException or java.io.UnsupportedEncodingException.
But to help you really I need the detailed exception message.
Regards,
Dainel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.