Package com.hybris.ymkt.common.odata
Class ODataService
java.lang.Object
com.hybris.ymkt.common.odata.ODataService
This bean shall be instantiated for each OData service as separate $metadata are used by OData services.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.apache.olingo.odata2.core.edm.provider.EdmxProviderprotected HttpURLConnectionServiceprotected ODataConvertEdmServiceprotected Stringprotected Proxyprotected Stringprotected Stringprotected ODataService.TokenCacheprotected Stringprotected static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]bufferStream(InputStream stream) ReadInputStreamand return a byte array.protected voidcheckStatus(HttpURLConnectionResponse response) protected com.google.gson.JsonObjectconvertMapToJSON(org.apache.olingo.odata2.api.edm.EdmEntityType entityType, Map<?, ?> data) byte[]convertMapToJSONPayload(String entitySetName, Map<String, Object> data) Convert an entity map into a JSON payload reading to be transfered.convertMapToJSONString(org.apache.olingo.odata2.api.edm.EdmEntityType entityType, Map<String, Object> data) Convert an entity map into a JSON String.convertMapToURIParameters(String functionImportName, Map<String, Object> data) Build properly formated String value arguments for OData Function Import.protected com.google.gson.JsonElementconvertObjectToJsonElement(Object value, org.apache.olingo.odata2.api.edm.EdmElement element) protected com.google.gson.JsonElementconvertObjectToJsonElement(Object value, org.apache.olingo.odata2.api.edm.EdmNavigationProperty navigation) protected StringconvertObjectToString(Object value, org.apache.olingo.odata2.api.edm.EdmLiteralKind literalKind, org.apache.olingo.odata2.api.edm.EdmElement element) createResourcePath(String entitySetName, Map<String, Object> data) Create $batch part URL accessing entity by keys for Addressing Entries.Create an absolute URL accessing the OData service at the resource path provided.Create an absolute URL accessing the OData service at the resourcePath provided using OData query options.Create an absolute URL accessing the OData service at the resourcePath provided using OData query options.protected byte[]decompressIfGZIP(byte[] payload) protected HttpURLConnectionResponseExecute the request with Authorization : "Basic BASE64user:pass".
Using this method will create a new http session (unnecessary cost) on the yMKT side.
It is preferable to useexecuteWithRetry(HttpURLConnectionRequest)for most execution scenarios.executeWithRetry(HttpURLConnectionRequest request) Execute the request with "cookie" & "x-csrf-token".
If the existing session and/or token expired, those are refreshed and the request is re-tried.Create anODataFilterBuilderstarting on the entitySetName provided.protected StringBuilderorg.apache.olingo.odata2.api.edm.EdmgetEdm()Provide buffered olingo'sEdmof the OData service.org.apache.olingo.odata2.api.edm.EdmEntitySetgetEntitySet(String entitySetName) Simple wrapping with improved error handling of :
this.getEdm().getDefaultEntityContainer().getEntitySet(entitySetName);protected ODataService.TokenCachegetUser()protected ODataService.TokenCachevoidsetHttpURLConnectionService(HttpURLConnectionService httpURLConnectionService) voidsetODataConvertEdmService(ODataConvertEdmService oDataConvertEdmService) voidsetPassword(String password) voidvoidsetRootUrl(String rootUrl) voidsetSapClient(String sapClient) void
-
Field Details
-
X_CSRF_TOKEN
- See Also:
-
edmxProvider
protected volatile org.apache.olingo.odata2.core.edm.provider.EdmxProvider edmxProvider -
httpURLConnectionService
-
oDataConvertEdmService
-
proxy
-
sapClient
-
token
-
password
-
rootUrl
-
user
-
-
Constructor Details
-
ODataService
public ODataService()
-
-
Method Details
-
bufferStream
ReadInputStreamand return a byte array.- Parameters:
stream-InputStreamto read.- Returns:
- All bytes that could be read from the
InputStream - Throws:
IOException- fromInputStream.read(byte[])- See Also:
-
checkStatus
- Throws:
IOException
-
convertMapToJSON
@Nonnull protected com.google.gson.JsonObject convertMapToJSON(org.apache.olingo.odata2.api.edm.EdmEntityType entityType, Map<?, ?> data) throws IOException, org.apache.olingo.odata2.api.edm.EdmException- Throws:
IOExceptionorg.apache.olingo.odata2.api.edm.EdmException
-
convertMapToJSONPayload
@Nonnull public byte[] convertMapToJSONPayload(String entitySetName, Map<String, Object> data) throws IOExceptionConvert an entity map into a JSON payload reading to be transfered.- Parameters:
entitySetName- <EntitySet Name> value found in the DefaultEntityContainer of the OData service.data-Mapcontaining the <Property/NavigationProperty Name> and value to be converted.- Returns:
- byte array of the JSON payload.
- Throws:
IOException- if an I/O error occurs.- See Also:
-
EdmLiteralKind.JSON
-
convertMapToJSONString
@Nonnull public String convertMapToJSONString(org.apache.olingo.odata2.api.edm.EdmEntityType entityType, Map<String, Object> data) throws IOExceptionConvert an entity map into a JSON String.- Parameters:
entityType-EdmEntityTypeof the OData entity to be converted.data-Mapcontaining the <Parameter> Name and value to be converted.- Returns:
- String of the JSON payload.
- Throws:
IOException- if an I/O error occurs.- See Also:
-
EdmLiteralKind.JSON
-
convertMapToURIParameters
public Map<String,String> convertMapToURIParameters(String functionImportName, Map<String, Object> data) throws IOExceptionBuild properly formated String value arguments for OData Function Import.- Parameters:
functionImportName- Attribute Name value found in the <FunctionImport> of the OData service.data-Mapcontaining the <Parameter> Name and value to be converted.- Returns:
Mapcontaining the <Parameter> Name and converted value.- Throws:
IOException- if an I/O error occurs.- See Also:
-
EdmLiteralKind.URI
-
convertObjectToJsonElement
@Nonnull protected com.google.gson.JsonElement convertObjectToJsonElement(Object value, org.apache.olingo.odata2.api.edm.EdmElement element) throws org.apache.olingo.odata2.api.edm.EdmException - Throws:
org.apache.olingo.odata2.api.edm.EdmException
-
convertObjectToString
@Nullable protected String convertObjectToString(Object value, org.apache.olingo.odata2.api.edm.EdmLiteralKind literalKind, org.apache.olingo.odata2.api.edm.EdmElement element) throws org.apache.olingo.odata2.api.edm.EdmException - Throws:
org.apache.olingo.odata2.api.edm.EdmException
-
createResourcePath
Create $batch part URL accessing entity by keys for Addressing Entries.- Parameters:
entitySetName- <EntitySet Name> value found in the DefaultEntityContainer of the OData service.data-Mapcontaining the <Property/NavigationProperty Name> and value to be converted.- Returns:
- resource path
- Throws:
IOException- if an I/O error occurs.
-
createURL
Create an absolute URL accessing the OData service at the resource path provided.- Parameters:
resourcePath- Resource path of the OData service.- Returns:
URL
-
createURL
Create an absolute URL accessing the OData service at the resourcePath provided using OData query options.- Parameters:
resourcePath- Resource path of the OData service.queryOptions- OData Query String Options.- Returns:
URL
-
createURL
Create an absolute URL accessing the OData service at the resourcePath provided using OData query options.- Parameters:
resourcePath- Resource path of the OData service.queryOptions- OData Query String Options.- Returns:
URL
-
decompressIfGZIP
- Throws:
IOException
-
executeWithBasicAuth
@Nonnull protected HttpURLConnectionResponse executeWithBasicAuth(HttpURLConnectionRequest request) throws IOException Execute the request with Authorization : "Basic BASE64user:pass".
Using this method will create a new http session (unnecessary cost) on the yMKT side.
It is preferable to useexecuteWithRetry(HttpURLConnectionRequest)for most execution scenarios.- Parameters:
request-HttpURLConnectionRequestto execute.- Returns:
HttpURLConnectionResponseexecuted.- Throws:
IOException- If the HTTP request was not successful.- See Also:
-
executeWithRetry
@Nonnull public HttpURLConnectionResponse executeWithRetry(HttpURLConnectionRequest request) throws IOException Execute the request with "cookie" & "x-csrf-token".
If the existing session and/or token expired, those are refreshed and the request is re-tried.- Parameters:
request-HttpURLConnectionRequestto execute.- Returns:
HttpURLConnectionResponseexecuted.- Throws:
IOException- If the HTTP request was not successful.
-
filter
Create anODataFilterBuilderstarting on the entitySetName provided.- Parameters:
entitySetName- <EntitySet Name> value found in the DefaultEntityContainer of the OData service.- Returns:
ODataFilterBuilder- Throws:
IOException- if an I/O error occurs.
-
getCustomQueryOptions
-
getEdm
Provide buffered olingo'sEdmof the OData service.- Returns:
- And instance of
Edm$metadatafor the service end point set bysetRootUrl(String).
This resource is requested once for the entire lifecycle of the bean. This resource is also synchronized.
Each Thread has its own instance of Edm. - Throws:
IOException- If Edm could not be returned.
-
getEntitySet
public org.apache.olingo.odata2.api.edm.EdmEntitySet getEntitySet(String entitySetName) throws IOException Simple wrapping with improved error handling of :
this.getEdm().getDefaultEntityContainer().getEntitySet(entitySetName);- Parameters:
entitySetName- <EntitySet Name> value found in the DefaultEntityContainer of the OData service.- Returns:
EdmEntitySet- Throws:
IOException- In case of communication errors.
-
getTokenCache
- Throws:
IOException
-
refreshToken
@Nonnull protected ODataService.TokenCache refreshToken(ODataService.TokenCache token) throws IOException - Throws:
IOException
-
getPassword
- Parameters:
password- Password used to login withsetUser(String)at thesetRootUrl(String)address.
-
getRootUrl
- Parameters:
rootUrl- OData service root URL.
-
getUser
- Parameters:
user- Username used to login at thesetRootUrl(String)address.
-
setHttpURLConnectionService
-
setODataConvertEdmService
-
setPassword
- Parameters:
password- Password used to login withsetUser(String)at thesetRootUrl(String)address.
-
setProxy
- Throws:
MalformedURLException
-
setRootUrl
- Parameters:
rootUrl- OData service root URL.
Sample :https://localhost:50100/sap/opu/odata/sap/PROD_RECO_RUNTIME_SRV/
localhostshould be replaced with the proper SAP Marketing server host name.
-
setSapClient
- Parameters:
sapClient- the sapClient to set
-
setUser
- Parameters:
user- Username used to login at thesetRootUrl(String)address.
-