blackberry+ +how+to+guide
TRANSCRIPT
-
8/3/2019 Blackberry+ +How+to+Guide
1/30
Consuming SAP NetWeaver Gateway
Services from Blackberry Applications
-
8/3/2019 Blackberry+ +How+to+Guide
2/30
Copyright/Trademark
Copyright
Copyright 2011 SAP AG. All rights reserved.
SAP Library document classification: PUBLIC
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission
of SAP AG. The information contained herein may be changed without prior notice.
Some software products marketed by SAP AG and its distributors contain proprietary software components of othersoftware vendors.
Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.
IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, Systemz9, z10, z9, iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390Parallel Enterprise Server, PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER,OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF,Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix aretrademarks or registered trademarks of IBM Corporation.
Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.
Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe SystemsIncorporated in the United States and/or other countries.
Oracle is a registered trademark of Oracle Corporation.
UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.
Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registeredtrademarks of Citrix Systems, Inc.
HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide Web Consortium,
Massachusetts Institute of Technology.
Java is a registered trademark of Sun Microsystems, Inc.
JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented andimplemented by Netscape.
SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP BusinessObjects Explorer, StreamWork, and other SAPproducts and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAPAG in Germany and other countries.
Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence,Xcelsius, and other Business Objects products and services mentioned herein as well as their respective logos aretrademarks or registered trademarks of Business Objects Software Ltd. Business Objects is an SAP company.
Sybase and Adaptive Server, iAnywhere, Sybase 365, SQL Anywhere, and other Sybase products and services mentionedherein as well as their respective logos are trademarks or registered trademarks of Sybase, Inc. Sybase is an SAPcompany.
All other product and service names mentioned are the trademarks of their respective companies. Data contained in thisdocument serves informational purposes only. National product specifications may vary.
These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not beliable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services arethose that are set forth in the express warranty statements accompanying such products and services, if any. Nothingherein should be construed as constituting an additional warranty.
-
8/3/2019 Blackberry+ +How+to+Guide
3/30
Copyright/Trademark
Table of Contents
Consuming SAP NetWeaver Gateway Services from Blackberry Applications......................... 4
Prerequisites.................................................................................................................................................... 5Building a Blackberry Application ................................................................................................................. 6
Function Import Example ........................................................................................................................... 6
Read Example............................................................................................................................................ 10
Create Example ......................................................................................................................................... 12
Authentication Using X.509 Certificate ...................................................................................................... 16
Prerequisites .............................................................................................................................................. 16
Blackberry Project Configuration............................................................................................................. 17
Read Example............................................................................................................................................ 18
Appendix 1 - RMTSAMPLEFLIGHT Service Metadata Description............................................ 19
Appendix 2 Code Snippets .......................................................................................................... 25
Read - Get Carrier by Carrier ID................................................................................................................. 25
Function Import ............................................................................................................................................. 26
Create - Booking a Flight............................................................................................................................. 28
-
8/3/2019 Blackberry+ +How+to+Guide
4/30
Copyright/Trademark
CONSUMING SAP NETWEAVER GATEWAY SERVICES
FROM BLACKBERRY APPLICATIONS
SAP NetWeaver Gateway technology provides a simple way to interact with SAP applications through
variety of devices, environments and platforms based on market standards. The framework enables
development of innovative, people-centric solutions that bring the power of SAP business software into
new experiences, such as: social networking and collaboration environments; mobile and tablet devices;
and rich internet applications. The framework supports rapid innovation while ensuring security, integrity,
management and optimized maintenance of the core SAP systems. Completely flexible, the software offers
connectivity to SAP applications using any programming language or model without the need for SAP
knowledge by taking advantage of REST services and OData/ATOM protocols.
Note: There is added value in using the SAP OData Mobile SDK (which comes with the usage of SUP).This added value is not included when using the code snippets.
This guide provides information on how to consume SAP NetWeaver Gateway services from Blackberry
applications based on the following scenario:
The user wants to fly from New York to San Francisco.
He goes online and searches for the different flights available. He enters his search parameters: city of
origin, destination city, departure date, and arrival date (Function Import).
From the SAP NetWeaver Gateway, he receives the information for the option(s) that meet(s) his searchparameters (Get Function).
He can now select the one that suits him the most and book his flight (Create Function).
The links to access the service document and metadata document are provided the in table below.
Service
Document
http://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/
Metadata
Document
http://:< Gateway_Port>/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/
$metadata?$format=xml
Each service URL should contain the following information:
Gateway host
Port
SAP Client no need to specify client if connecting to the default client.
Example:
http://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT?sap-client=100
To obtain information on the selected service (its properties, function imports, associations, etc.), refer to
Appendix 1, were we show the Metadata description of the RMTSAMPLEFLIGHT service.
To view the code snippets in a format that can be copied into new code, refer toAppendix 2.
-
8/3/2019 Blackberry+ +How+to+Guide
5/30
Copyright/Trademark
The Flight service contains the following collections:
Collection URL
FlightCollection (list of flights) http://:/sap/opu/sdata/
iwfnd/RMTSAMPLEFLIGHT/FlightCollection
CarrierCollection (list of carriers http://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection
BookingsCollection (list of Bookings) http://:/sap/opu/sdata/
iwfnd/RMTSAMPLEFLIGHT/BookingCollection
The operation GetAvailableFlights on FlightCollection is used to get a list of flights. The following is the URL
for the same:
http://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?Each collection supports some or all of the operations listed below. The table below provides the list of
operations supported and the methods that each of this operations map to respectively:
Operation Method
Create HTTP POST
Read GET
Update PUT
Delete DELETE
Prerequisites
The following tools are required for developing a Blackberry application:
Software Version
SAP NetWeaver Gateway 2.0
Eclipse 3.5
OS Blackberry 5.0
Contact your system administrator for landscape details to connect to the SAP NetWeaver Gateway system.
-
8/3/2019 Blackberry+ +How+to+Guide
6/30
Copyright/Trademark
Building a Blackberry Application
Function Import Example
To get a list of the available flights, based on filter criteria, trigger the GetAvailableFlights function import
with cityFrom, cityTo, fromDate, and toDate parameters. The response will contain a list of flights that
meet the criteria.
Note: For more information on Function Import (also called Service Operation), refer to OData
documentation at http://www.odata.org/developers/protocols/uri-conventionsunder the Addressing
Service Operations section.
Refer to the code snippet below for details on how to do it from a Blackberry application:
1. Use the following method for executing a Function Import that returns a collection of flights.
/**
* Get available flights - provide source, destination city and date as* input.
* @param from
* @param to
* @param date
* @return* @throws IOException
*/
public String getFlightList(String cityFrom, String cityTo, String fromdate, String todate)
throws IOException
{
2. Create the URL request that will be sent.
String requestUrl = "https://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfro
m=" + cityFrom + "&cityto=" + cityTo + "&fromdate=" + fromdate + "&todate=" + todate;
HttpConnection httpConnection = (HttpConnection) Connector.open(requestUrl);
httpConnection.setRequestProperty( "Content-Type", "text/xml");
httpConnection.setRequestMethod(HttpConnection. GET);
3. Add the basic authentication header.
httpConnection.setRequestProperty( "Authorization", "Basic " +
Base64OutputStream.encodeAsString(userpassword.getBytes(), 0, userpassword.getBytes().length,false, false));
4. Execute the request.
Note: If there is a failure in the service, throw an exception:
int status = httpConnection.getResponseCode();
if (status != HttpConnection.HTTP_OK)
{
thrownew RuntimeException("Error code: " + status);
}
-
8/3/2019 Blackberry+ +How+to+Guide
7/30
Copyright/Trademark
5. Read the input stream.
InputStream inputStream = httpConnection.openInputStream();
httpConnection.close();
6.
Convert the input stream into a String
String resultAsString = new String(IOUtilities.streamToBytes(inputStream), "UTF-8");
return resultAsString;
}
To parse the properties for each entry from the feed, follow the example below:
publicvoid parsePropertiesFromFeed(String xml)
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
String propertyValue = null;
String propertyName = null;
try
{
DocumentBuilder builder = factory.newDocumentBuilder();
Document dom = builder.parse(new ByteArrayInputStream(xml.getBytes()));
Element root = dom.getDocumentElement();
NodeList entries = root.getElementsByTagName("atom:entry");
// iterate over entries
for (int i = 0; i < entries.getLength(); i++)
{
add(new LabelField("entry number: " + i));
Node atomContentNode = entries.item(i).getChildNodes().item(1);
If (atomContentNode.getNodeName().equalsIgnoreCase("atom:content"))
{
Node mpropertiesNode = atomContentNode.getChildNodes().item(0);
if (mpropertiesNode.getNodeName().equalsIgnoreCase("m:properties"))
{
NodeList mpropertiesList = mpropertiesNode.getChildNodes();
// iterate over entry properties
for (int j = 0; j < mpropertiesList.getLength(); j++)
{
propertyName = mpropertiesList.item(j).getNodeName();
-
8/3/2019 Blackberry+ +How+to+Guide
8/30
Copyright/Trademark
propertyValue = mpropertiesList.item(j).getFirstChild().getNodeValue();
add(new LabelField(propertyName + ": " + propertyValue));
}
}
}
}
}
catch (Exception e)
{
thrownew RuntimeException(e.getMessage());
}
}
Response
-http://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/FlightCollectionFlightCollection2011-09-27T06:32:42Z
-
--
AA
00172011-01-05T00:00:00889.00USD747-400385367185742.7331222121
-
USnew yorkJFK
USSAN FRANCISCOSFO361PT11H00M00SPT14H01M00S2574.0000SMI0
http://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/FlightCollection(carrid='AA',connid='0017',fldate='20110105')
http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728 -
8/3/2019 Blackberry+ +How+to+Guide
9/30
Copyright/Trademark
Flight2011-09-27T06:32:42Z
-
-
-
AA0017
2011-03-16T00:00:00422.94USD747-400385
371192129.2231302120
-USnew yorkJFK
USSAN FRANCISCOSFO361PT11H00M00SPT14H01M00S2574.0000SMI0
http://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/FlightCollection(carrid='AA',conn
id='0017',fldate='20110316')
Flight2011-09-27T06:32:42Z
http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728 -
8/3/2019 Blackberry+ +How+to+Guide
10/30
Copyright/Trademark
Read Example
To read the carrier details, you must call the CarrierCollection using the Carrier ID parameter.
Refer to the code snippet below for details on how to do it from a Blackberry application:
1. Create a Get Specific carrier query string and execute it, the result returned in the response is an XML
containing the Carrier entry.
/*** Returns carrier entry xml by carrier id.
*
* @param carrid
* @return
* @throws IOException
*/public String getCarrier(String carrid) throws IOException
{
2. Create the URL request that will be sent.
String requestUrl = "https://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(carrid='" + carrid + "')";
httpConnection httpConnection = (HttpConnection) Connector.open(requestUrl);
httpConnection.setRequestProperty( "Content-Type", "text/xml");
httpConnection.setRequestMethod(HttpConnection. GET);
3. Add the basic authentication header.
httpConnection.setRequestProperty( "Authorization", "Basic " +Base64OutputStream.encodeAsString(userpassword.getBytes(), 0, userpassword.getBytes().length,
false, false));
4. Execute the request.
Note: If there is a failure in the service, throw an exception:
int status = httpConnection.getResponseCode();
if (status != HttpConnection.HTTP_OK)
{
thrownew RuntimeException("Error code: " + status);
}
5. Read the input stream.
InputStream inputStream = httpConnection.openInputStream();
httpConnection.close();
6. Convert the input stream into a String.
String resultAsString = new String(IOUtilities.streamToBytes(inputStream), "UTF-8");
return resultAsString;
-
8/3/2019 Blackberry+ +How+to+Guide
11/30
Copyright/Trademark
}
To parse the properties from the entry xml, follow the example below:
publicvoidparsePropertiesFromEntry(String xml)
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
String propertyValue = null;
String propertyName = null;
try
{
DocumentBuilder builder = factory.newDocumentBuilder();
Document dom = builder.parse(new ByteArrayInputStream(xml.getBytes()));
Element root = dom.getDocumentElement();
NodeList properties = root.getElementsByTagName("m:properties").item(0).getChildNodes();
// iterate over the entry properties
for (int i = 0; i < properties.getLength(); i++)
{
propertyName = properties.item(i).getNodeName();
propertyValue = properties.item(i).getFirstChild().getNodeValue();
add(new LabelField(propertyName + ": " + propertyValue));
}
}
catch (Exception e)
{
thrownew RuntimeException(e.getMessage());
}
}
Response
-
-
AAAmerican AirlinesUSDhttp://www.aa.com
:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(carrid='AA')
Carrier2011-09-27T10:00:38Z
http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(carrid='AA')http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(carrid='AA')http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(carrid='AA')http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(carrid='AA')http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(carrid='AA')http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(carrid='AA') -
8/3/2019 Blackberry+ +How+to+Guide
12/30
Copyright/Trademark
Create Example
To book a flight, trigger the HTTP POST method on the Booking Collection (with the Booking details in the
request body). Check for the HTTP response code. If the response code is 201, then the HTTP-POST is
successful. The response contains the newly created Booking ID in the bookidfield, as well as the entire
information that was part of the request body.
Refer to the code snippet below for details on how to invoke a create request from a Blackberry
application:
1. Create the entry body.
String content = "" +
"" +
"AA" +
"0017" +
"2011-07-27T00:00:00" +
"" +
"00004617" +
"P" +
"" +
"KG" +
"14.4000" +
"Y" +
"879.82" +
"USD" +
"803.58" +
"USD" +
"2011-05-22T00:00:00" +
"00000000" +
"00000325" +
"" +
"Joe Smith" +
"1234567" +
"1990-10-10" +
"";
-
8/3/2019 Blackberry+ +How+to+Guide
13/30
Copyright/Trademark
2. Use the XML string to execute the method as shown below:
/**
* Books a flight according to the details provided in the body of the
* request.
*
* @param content
* the booking entry payload* @return the booking entry payload
*/
public String createBooking(String content)
{
3. Create the URL request that will be sent.
String bookingUrl = "https://:/sap/opu/sdata/IWFND/RMTSAMPLEFLIGHT/BookingCollection";
4. Create the HTTP Post request:
String result = null;
HttpConnection connection;
try
{
connection = (HttpConnection) Connector.open(bookingUrl);
5. Add the basic authentication header.
connection.setRequestProperty( "Authorization", "Basic " +
Base64OutputStream.encodeAsString(userpassword.getBytes(), 0, userpassword.getBytes().length,
false, false));
connection.setRequestMethod(HttpConnection.POST);
connection.setRequestProperty( "Content-Type", "text/xml");
connection.setRequestProperty( "Content-Length", content == null ? "0" :
Integer.toString(content
.getBytes("UTF-8").length));
Note: Make sure to add this header to post requests:
connection.setRequestProperty( "X-Requested-With", "XMLHttpRequest");
6. Add the body of the HTTP post.
if (content != null)
{
OutputStream outputStream = connection.openOutputStream();
outputStream.write(content.getBytes( "UTF-8"));
outputStream.close();
}
-
8/3/2019 Blackberry+ +How+to+Guide
14/30
Copyright/Trademark
7. Get the response.
InputStream inputStream = null;
try
{
inputStream = connection.openInputStream();
}
catch (IOException e)
{
e.printStackTrace();
}
int resCode = connection.getResponseCode();
if (resCode != HttpConnection.HTTP_CREATED)
{
Note: If there is a failure in the service, throw an exception:
System.err.println("Server error code " + resCode);
thrownew RuntimeException("Server error code " + resCode);
}
result = new String(IOUtilities.streamToBytes(inputStream), "UTF-8");
}
catch (IOException e)
{
e.printStackTrace();
thrownew RuntimeException(e.getMessage);
}
return result;
}
-
8/3/2019 Blackberry+ +How+to+Guide
15/30
Copyright/Trademark
Creation of Request Body for Create Method
The request body can be easily created by looking at the tags in the collections metadata. For example, the
metadata for Booking Collection provides information about the various fields (tags) that are needed for
creating a booking.
-
8/3/2019 Blackberry+ +How+to+Guide
16/30
Copyright/Trademark
Authentication Using X.509 Certificate
The procedure above describes requests sent to the service using Basic Authentication.
If X.509 Certificate Authentication is needed, the X.509 Client Certificate should be attached to any request
sent to the service. In addition, a CA Certificate of the SAP NetWeaver Gateway server should be used for
server authentication, as part of the SSL Handshake process.
Note:OData generated proxies do not support X.509 Certificate Authentication. Therefore, the servicerequests should be sent using Java libraries which support SSL and X.509 Certificates. In addition, the
developer is responsible for parsing the service response according to the OData/SAP Data Protocols.
Prerequisites
The following tools are required for developing a Java application for Blackberry using X.509 Certificate
Authentication.
Software Version
Portecle-1.7 1.7
Make sure you have performed the following procedures:
Download Portecle.
On a Windows operating system, this can be done by downloading the Portecle-1.7.zip file and
extracting it to a selected folder.
Export the root CA Certificate of the SAP NetWeaver Gateway server into a local file. You may use anybrowser program for that. Make sure the certificate is saved in Base64-encoded format.
Store the X.509 Client Certificate (which should be attached to each request sent to the service) in a
local file. Make sure the certificate is saved in PEM format. If the certificate is saved in a different
format, you may convert it to PEM format using a converter tool, such asOpenSSL.
For example, to convert a PKCS#12 file (pfx.p12) containing a private key and certificates to PEM
format, execute the following command:
openssl pkcs12 -in .pfx -out .pem nodes
You may need to install a patch to your JRE, and set the encryption to unlimited strength depending on
your key strength. For this, you must copy the jar files fromJCE 6.0 unlimited strength Jurisdiction Policy
Filesand override those in your JRE (for example, C:\Program Files\Java\jre6\lib\security)
http://sourceforge.net/projects/portecle/files/portecle/1.7/portecle-1.7.zip/downloadhttp://sourceforge.net/projects/portecle/files/portecle/1.7/portecle-1.7.zip/downloadhttp://www.openssl.org/http://www.openssl.org/http://www.openssl.org/http://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.htmlhttp://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.htmlhttp://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.htmlhttp://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.htmlhttp://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.htmlhttp://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.htmlhttp://www.openssl.org/http://sourceforge.net/projects/portecle/files/portecle/1.7/portecle-1.7.zip/download -
8/3/2019 Blackberry+ +How+to+Guide
17/30
Copyright/Trademark
Blackberry Project Configuration
To allow the code to use a CA Certificate and an X.509 Client Certificate:
1. Using the Portecle tool, import a CA Certificate to the key store of your MDS JRE.
For instructions on how to import a CA Certificate to a trust store, refer to the Blackberrydocumentation at
http://docs.blackberry.com/en/admin/deliverables/20839/Configuring_how_apps_trusted_conn_to_web
_servers_268738_11.jsp,under the "Add a retrieved certificate for a web server to the key store"
section.
For instructions on how to import a CA Certificate to a trust store refer to Portrcle documentation at
http://portecle.sourceforge.net/import-trusted-cert.html.
2. Configure the simulator to use the X.509 certificate.
a. Configure the simulator to use a computer file system as a microSD card as described in the
Blackberry documentation at:
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800792/801083/H
ow_To_-_Use_a_computer_file_system_as_a_microSD_card.html?nodeid=1417343&vernum=0,
under the "How To - Use a computer file system as a microSD card Article Number: DB-00654"
section.
b. Save the X.509 Client Certificate in the simulators SD Card library.
c. Run the simulator.
d. From the simulator, browse for the X.509 Client Certificate located in the SD card library and click
it. The simulator prompts you to install it.
e. Install the X.509 Client Certificate.
http://docs.blackberry.com/en/admin/deliverables/20839/Configuring_how_apps_trusted_conn_to_web_servers_268738_11.jsphttp://docs.blackberry.com/en/admin/deliverables/20839/Configuring_how_apps_trusted_conn_to_web_servers_268738_11.jsphttp://docs.blackberry.com/en/admin/deliverables/20839/Configuring_how_apps_trusted_conn_to_web_servers_268738_11.jsphttp://portecle.sourceforge.net/import-trusted-cert.htmlhttp://portecle.sourceforge.net/import-trusted-cert.htmlhttp://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800792/801083/How_To_-_Use_a_computer_file_system_as_a_microSD_card.html?nodeid=1417343&vernum=0http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800792/801083/How_To_-_Use_a_computer_file_system_as_a_microSD_card.html?nodeid=1417343&vernum=0http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800792/801083/How_To_-_Use_a_computer_file_system_as_a_microSD_card.html?nodeid=1417343&vernum=0http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800792/801083/How_To_-_Use_a_computer_file_system_as_a_microSD_card.html?nodeid=1417343&vernum=0http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800792/801083/How_To_-_Use_a_computer_file_system_as_a_microSD_card.html?nodeid=1417343&vernum=0http://portecle.sourceforge.net/import-trusted-cert.htmlhttp://docs.blackberry.com/en/admin/deliverables/20839/Configuring_how_apps_trusted_conn_to_web_servers_268738_11.jsphttp://docs.blackberry.com/en/admin/deliverables/20839/Configuring_how_apps_trusted_conn_to_web_servers_268738_11.jsp -
8/3/2019 Blackberry+ +How+to+Guide
18/30
Copyright/Trademark
Read Example
Refer to the code snippet below for details on how to send a request to a Java Blackberry application using
X.509 Certificate Authentication:
1. Open https connection.
HttpsConnection sc = (HttpsConnection) Connector.open(url,
Connector.READ_WRITE);
InputStream in = sc.openInputStream();
2. Read the response.
while ((inChar = in.read()) != -1) {//append incoming characters to the bufferinBuffer.append((char)inChar);
response = inBuffer.toString();}
3. Close the inputStream.
in.close();
4. Close the HTTP Connection.
sc.close();
-
8/3/2019 Blackberry+ +How+to+Guide
19/30
Copyright/Trademark
Appendix 1 - RMTSAMPLEFLIGHT Service Metadata
Description
-
8/3/2019 Blackberry+ +How+to+Guide
20/30
Copyright/Trademark
-
8/3/2019 Blackberry+ +How+to+Guide
21/30
Copyright/Trademark
-
8/3/2019 Blackberry+ +How+to+Guide
22/30
Copyright/Trademark
-
8/3/2019 Blackberry+ +How+to+Guide
23/30
Copyright/Trademark
Airline
Flight Number
Date
-
8/3/2019 Blackberry+ +How+to+Guide
24/30
Copyright/Trademark
Date
Date
Depart.city
Arrival city
-
8/3/2019 Blackberry+ +How+to+Guide
25/30
Copyright/Trademark
APPENDIX 2 CODE SNIPPETS
Read - Get Carrier by Carrier ID
/**
* Returns carrier entry xml by carrier id.*
* @param carrid* @return
* @throws IOException
*/public String getCarrier(String carrid) throws IOException
{
// create the request URL
String requestUrl = "https://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollecti
on(carrid='" + carrid + "')";
HttpConnection httpConnection = (HttpConnection) Connector.open(requestUrl);
httpConnection.setRequestProperty("Content-Type", "text/xml");
httpConnection.setRequestMethod(HttpConnection.GET);
// Add the basic authentication headerhttpConnection.setRequestProperty("Authorization", "Basic " +Base64OutputStream.encodeAsString(userpassword.getBytes(), 0,
userpassword.getBytes().length, false, false));
// get the responseint status = httpConnection.getResponseCode();
// throw an exception to handle request failure
if (status != HttpConnection.HTTP_OK){
thrownew RuntimeException("Error code: " + status);
}
// need to read input streamInputStream inputStream = httpConnection.openInputStream();
httpConnection.close();
// converting to String
String resultAsString = new String(IOUtilities.streamToBytes(inputStream), "UTF-8");
return resultAsString;}
// an example of how to parse the properties from the entry xml
publicvoidparsePropertiesFromEntry(String xml){
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
String propertyValue = null;
-
8/3/2019 Blackberry+ +How+to+Guide
26/30
Copyright/Trademark
String propertyName = null;
try
{DocumentBuilder builder = factory.newDocumentBuilder();
Document dom = builder.parse(new ByteArrayInputStream(xml.getBytes()));Element root = dom.getDocumentElement();
NodeList properties =
root.getElementsByTagName("m:properties").item(0).getChildNodes();// iterate over the entry properties
for (int i = 0; i < properties.getLength(); i++){
propertyName = properties.item(i).getNodeName();propertyValue = properties.item(i).getFirstChild().getNodeValue();
add(new LabelField(propertyName + ": " + propertyValue));
}
}catch (Exception e)
{thrownew RuntimeException(e.getMessage());
}}
Function Import
/**
* Get available flights - provide source, destination city and date as* input.
* @param from
* @param to
* @param date
* @return* @throws IOException
*/public String getFlightList(String cityFrom, String cityTo, String date) throws
IOException{
// create the request URL
String requestUrl = "https://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFli
ghts?cityfrom=" + cityFrom + "&cityto=" + cityTo + "&fromdate=" + date +"&todate=" + date;
HttpConnection httpConnection = (HttpConnection) Connector.open(requestUrl);
httpConnection.setRequestProperty("Content-Type", "text/xml");httpConnection.setRequestMethod(HttpConnection.GET);
// Add the basic authentication headerhttpConnection.setRequestProperty("Authorization", "Basic " +Base64OutputStream.encodeAsString(userpassword.getBytes(), 0,
userpassword.getBytes().length, false, false));
// get the responseint status = httpConnection.getResponseCode();
-
8/3/2019 Blackberry+ +How+to+Guide
27/30
Copyright/Trademark
// throw an exception to handle request failure
if (status != HttpConnection.HTTP_OK){
thrownew RuntimeException("Error code: " + status);}
// need to read input streamInputStream inputStream = httpConnection.openInputStream();
httpConnection.close();
// converting to StringString resultAsString = new String(IOUtilities.streamToBytes(inputStream), "UTF-8");
return resultAsString;
}
// an example of how to parse the properties for each entry from the feed // xml
publicvoid parsePropertiesFromFeed(String xml){
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
String propertyValue = null;String propertyName = null;
try
{DocumentBuilder builder = factory.newDocumentBuilder();
Document dom = builder.parse(new ByteArrayInputStream(xml.getBytes()));Element root = dom.getDocumentElement();
NodeList entries = root.getElementsByTagName("atom:entry");
// iterate over entriesfor (int i = 0; i < entries.getLength(); i++){
add(new LabelField("entry number: " + i));Node atomContentNode = entries.item(i).getChildNodes().item(1);
If (atomContentNode.getNodeName().equalsIgnoreCase("atom:content"))
{
Node mpropertiesNode =
atomContentNode.getChildNodes().item(0);if
(mpropertiesNode.getNodeName().equalsIgnoreCase("m:properties"))
{
NodeList mpropertiesList =
mpropertiesNode.getChildNodes();
// iterate over entry properties
for (int j = 0; j < mpropertiesList.getLength(); j++){
propertyName =
mpropertiesList.item(j).getNodeName();
-
8/3/2019 Blackberry+ +How+to+Guide
28/30
Copyright/Trademark
propertyValue =
mpropertiesList.item(j).getFirstChild().getNodeV
alue();
add(new LabelField(propertyName + ": " +propertyValue));
}
}}
}}
catch (Exception e){
thrownew RuntimeException(e.getMessage());
}
}
Create - Booking a Flight
// create the entry payload
String content = "" +
"" +
"AA" +
"0017" +"2011-07-27T00:00:00" +
"" +"00004617" +
"P" +
"" +
"KG" +
"14.4000" +"Y" +
"879.82" +"USD" +
"803.58" +
"USD" +
"2011-05-22T00:00:00" +"00000000" +"00000325" +
"" +"Joe Smith" +
"1234567" +
"1990-10-10" +
"";
/**
-
8/3/2019 Blackberry+ +How+to+Guide
29/30
Copyright/Trademark
* Books a flight according to the details provided in the body of the
* request.
** @param content
* the booking entry payload* @return the booking entry payload
*/
public String createBooking(String content){
// create the request URLString bookingUrl = "https://
:/sap/opu/sdata/IWFND/RMTSAMPLEFLIGHT/BookingCollection";
String result = null;
HttpConnection connection;try
{connection = (HttpConnection) Connector.open(bookingUrl);
// Add the basic authentication header
connection.setRequestProperty("Authorization", "Basic " +
Base64OutputStream.encodeAsString(userpassword.getBytes(), 0,
userpassword.getBytes().length, false, false));
connection.setRequestMethod(HttpConnection.POST);
connection.setRequestProperty("Content-Type", "text/xml");
connection.setRequestProperty("Content-Length", content == null ? "0" :
Integer.toString(content.getBytes("UTF-8").length));
// you must add this header to post requests
connection.setRequestProperty("X-Requested-With", "XMLHttpRequest");
// adding the payloadif (content != null)
{OutputStream outputStream = connection.openOutputStream();
outputStream.write(content.getBytes("UTF-8"));
outputStream.close();}
InputStream inputStream = null;
try{
inputStream = connection.openInputStream();
}catch (IOException e)
{
e.printStackTrace();
}
-
8/3/2019 Blackberry+ +How+to+Guide
30/30
Copyright/Trademark
int resCode = connection.getResponseCode();
if (resCode != HttpConnection.HTTP_CREATED)
{System.err.println("Server error code " + resCode);
thrownew RuntimeException("Server error code " + resCode);}
result = new String(IOUtilities.streamToBytes(inputStream), "UTF-8");
}
catch (IOException e){
e.printStackTrace();
thrownew RuntimeException(e.getMessage);}
return result;}