我正在使用SAP odata连接为android开发一个小型测试应用程序。我想使用Apache olingo库来支持odata。 目标是使用OData在Android应用程序和SAP系统之间交换数据。
这是一个httpsurlconnection
,带有ssl和基本身份验证
直到现在我可以在后端验证获取输入流。当我将输入流解析为字符串时,我得到如下所示的内容。但我想解析一些olingo数据类型中的输入流,以区分元数据和内容等。
我的问题是,如果可以这样做吗?我尝试仅使用olingo和基本的auth,但没有成功。什么是与odata,实体元等合作的最佳方式。我读了很多关于olingo但没有得到它。 我非常感谢你的帮助。
我的连接的asyncclass:
public class MyODataService extends AsyncTask<String,Void,String>{
private HttpsURLConnection conn;
private URL url;
private SSLContext sc;
private String urlToUse;
private String userpass;
private String basicAuth;
private final String USER_AGENT="Mozilla/5.0";
@Override
protected void onPostExecute(String s) {
}
@Override
protected String doInBackground(String... params){
urlToUse="****";
userpass="****";
String result=null;
try {
url = new URL(urlToUse);
conn = (HttpsURLConnection) url.openConnection();
sc = SSLContext.getInstance("TLS");
sc.init(null, null, new java.security.SecureRandom());
conn.setSSLSocketFactory(sc.getSocketFactory());
basicAuth = "Basic " + Base64.encodeToString(userpass.getBytes(), Base64.DEFAULT);
conn.setRequestProperty("Authorization", basicAuth);
conn.setRequestProperty("User-Agent", USER_AGENT);
conn.setDoInput(true);
conn.setRequestMethod("GET");
conn.connect();
InputStream is=conn.getInputStream();
conn.disconnect();
}catch (Exception e){e.printStackTrace();}
return result;
}
输入流中的内容(如果解析为字符串):
<feed
xmlns="http://www.w3.org/2005/Atom"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xml:base="***link***">
<id>***link***</id>
<title type="text">TestSet</title>
<updated>2017-03-16T12:36:01Z</updated>
<author>
<name/>
</author>
<link href="TestSet" rel="self" title="TestSet"/>
<entry>
<id>***link***</id>
<title type="text">TestSet(1)</title>
<updated>2017-03-16T12:36:01Z</updated>
<category term="***.Test" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<link href="TestSet(1)" rel="self" title="Test"/>
<content type="application/xml">
<m:properties xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
<d:Lfdnr>1</d:Lfdnr>
<d:Text>Hello World</d:Text>
</m:properties></content>
</entry>
<entry>
<id>***link***</id>
<title type="text">TestSet(2)</title>
<updated>2017-03-16T12:36:01Z</updated>
<category term="***.Test" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<link href="TestSet(2)" rel="self" title="Test"/>
<content type="application/xml">
<m:properties xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
<d:Lfdnr>2</d:Lfdnr>
<d:Text>Hello World</d:Text>
</m:properties>
</content>
</entry>