Call the BYD webservice from the eclipse(JAVA).
Hi experts,
Two days ago, I want to call the BYD webservice from eclipse(JAVA), so I try it in my test system, it is OK. Now I share the experience,I would appreciate your comments.
1.Get ready the webservice in BYD system, for example, I choose the webservice “querysupplierin1”, create the Communication Scenarios and the Communication Arrangements.
2.Test the webservice in soapUI, maybe don’t need to do it, but I want to confirm the webservice is working. Using the Raw parameter and the XML parameter, it is OK when running.
3.Call the BYD webservice from the eclipse(JAVA), I using the httpClient, the code as:
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
public class CallBYDQuerysupplier {
public String invokeRemoteFuc() {
//POST 方法,成功
String result = “no result!”;
//XML parameter
String soapRequestData = “”
+ “<soapenv:Envelope xmlns:soapenv=\”http://schemas.xmlsoap.org/soap/envelope/\” xmlns:glob=\”http://sap.com/xi/SAPGlobal20/Global\”>”
+ ” <soapenv:Header/>”
+ ” <soapenv:Body>”
+ ” <glob:SupplierByElementsQuery_sync>”
+ ” <SupplierSelectionByElements>”
+ ” <SelectionByInternalID>”
+ ” <InclusionExclusionCode>I</InclusionExclusionCode>”
+ ” <IntervalBoundaryTypeCode>3</IntervalBoundaryTypeCode>”
+ ” <LowerBoundaryIdentifier>1000171</LowerBoundaryIdentifier>”
+ ” <UpperBoundaryIdentifier>1000171</UpperBoundaryIdentifier>”
+ ” </SelectionByInternalID>”
+ ” </SupplierSelectionByElements>”
+ ” <ProcessingConditions>”
+ ” <QueryHitsMaximumNumberValue>10</QueryHitsMaximumNumberValue>”
+ ” <QueryHitsUnlimitedIndicator>false</QueryHitsUnlimitedIndicator>”
+ ” </ProcessingConditions>”
+ ” </glob:SupplierByElementsQuery_sync>”
+ ” </soapenv:Body>”
+ “</soapenv:Envelope>”;
InputStream is = null;
HttpClient client = new HttpClient();
//Raw parameter
PostMethod method = new PostMethod(“https://my336304.sapbydesign.com/sap/bc/srt/scs/sap/querysupplierin1?sap-vhost=my336304.sapbydesign.com”);
method.setRequestHeader(“Host”, “https://my336304.sapbydesign.com”);
method.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);
method.setRequestHeader(“Authorization”,”Basic X1RFU1Q6UHA4MzAyMDQ=”);
method.setRequestHeader(“Username”, “_TEST”);
method.setRequestHeader(“Password”, “******”);
RequestEntity requestEntity = new StringRequestEntity(soapRequestData);
method.setRequestEntity(requestEntity);
try {
client.executeMethod(method);
is = method.getResponseBodyAsStream();
Document document = Jsoup.parse(is,”UTF-8″,””);
System.err.println(document);
} catch (Exception e) {
e.printStackTrace();
}finally{
method.releaseConnection();
try {
if(is!=null){
is.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return result;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
//System.out.println(“HELLOWORLD”);
CallBYDQuerysupplier t = new CallBYDQuerysupplier();
String result = t.invokeRemoteFuc();
System.out.println(result);
}
}
4.The result is xml file as:
Hello Benny,
Thank you for the solution, it was very helpful!
Dor Alon