Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

java code to call Business connnector service

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

Former Member
Not what you were looking for? View more on this topic or Ask a question