Skip to Content
0

How can I call the BYD Webservice using java?

Dec 19, 2016 at 07:59 AM

216

avatar image

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.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Benny Huang Dec 21, 2016 at 01:55 AM
1

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 = ""
+ " 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.com 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":

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.

Share
10 |10000 characters needed characters left characters exceeded
Horst Schaude
Dec 20, 2016 at 12:27 PM
0

Hello Bin,

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

Sorry,
Horst

Share
10 |10000 characters needed characters left characters exceeded
Benny Huang Dec 21, 2016 at 12:41 AM
0

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?

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Mar 21, 2017 at 02:50 PM
0

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.

Share
10 |10000 characters needed characters left characters exceeded