cancel
Showing results for 
Search instead for 
Did you mean: 

How can I call the BYD Webservice using java?

former_member200995
Contributor
0 Kudos

Hi experts,
My current requirement is to call the BYD Webservice using java.
Could you please give me detailed step by step solution to set up this connection and success it ??

Now I can call the BYD Webservice using SoapUI.
Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

former_member200995
Contributor

Hi Horst,

Thanks. I got it, it is success 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!";

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

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","");
// Document document = Jsoup.parse(is,"GB2312","");

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

}

,

Hi Horst,

For example, in soapUI, there is some parameter:

"Raw parameter":

POST https://my336304.sapbydesign.com/sap/bc/srt/scs/sap/querysupplierin1?sap-vhost=my336304.sapbydesign.... HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "http://sap.com/xi/A1S/Global/QuerySupplierIn/FindByElementsRequest"
Content-Length: 1223
Host: my336304.sapbydesign.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Cookie: sap-usercontext=sap-client=057
Cookie2: $Version=1
Authorization: Basic X1RFU1Q6UHA4MzAyMDQ=

"XML parameter":

<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>
<!--Optional:-->
<SupplierSelectionByElements>
<!--Zero or more repetitions:-->
<SelectionByInternalID>
<!--Optional:-->
<InclusionExclusionCode>I</InclusionExclusionCode>
<IntervalBoundaryTypeCode>3</IntervalBoundaryTypeCode>
<!--Optional:-->
<LowerBoundaryIdentifier>1000171</LowerBoundaryIdentifier>
<!--Optional:-->
<UpperBoundaryIdentifier>1000171</UpperBoundaryIdentifier>
</SelectionByInternalID>

</SupplierSelectionByElements>
<!--Optional:-->
<ProcessingConditions>
<!--Optional:-->
<QueryHitsMaximumNumberValue>10</QueryHitsMaximumNumberValue>
<QueryHitsUnlimitedIndicator>false</QueryHitsUnlimitedIndicator>

</ProcessingConditions>

</glob:SupplierByElementsQuery_sync>
</soapenv:Body>
</soapenv:Envelope>

In eclipse, I using the HttpClient, the Raw parameter I can use as:

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", "******");

But I don't know how to using the XML parameter, Could you help me?

Thanks.

Answers (3)

Answers (3)

Former Member
0 Kudos

Hello Everyone,

Instead of invoking direct XML to the Byd Web Service, i tried to create client for the Byd service in java and wanted to invoke the service. For this i have downloaded the Query Accounts wsdl and created java classes out of this wsdl file. Then i created a client application in java and using the methods already created i set the authentication soap headers, user name, password etc. and invoked the method CustomerSelectionByElements. My request is reaching Byd but i am getting error as

The detailed error description may not be available in logon language: Error while parsing an XML stream: ''=' expected'.

I am unable to understand where went wrong and proceed further. If anyone has already worked on similar integration and got success in connecting, please help me in resolving the issue.

Appreciate your help in advance.

Thank You.

former_member200995
Contributor
0 Kudos

Hi Horst,

Thanks, I'm sorry that I didn't make it clear.

There is a Webservice in BYD system.I want to call from the third. Now I can call it using SoapUI, it is success.

My objective is call the Webservice in eclipse(JAVA), but I don't know how can assign the parameter, could you help me?

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Bin,

There is no use of Java inside the SAP Cloud Applications Studio.
I guess you need another tag.

Sorry,
Horst