diff --git a/sample-proxies/JSONtoPLIST/README.md b/sample-proxies/JSONtoPLIST/README.md new file mode 100644 index 00000000..e32c2a64 --- /dev/null +++ b/sample-proxies/JSONtoPLIST/README.md @@ -0,0 +1,45 @@ +# JSON to PLIST conversion Sample + +This sample provides a simple implementation of the JSONtoPLIST . + + +# Set up + +* The username and password that you use to login to enterprise.apigee.com. +* The name of the organization in which you have an account. Login to + enterprise.apigee.com and check account settings. + +# Configure + +Update `/setup/setenv.sh` with your environment details + +# Import and deploy sample project + +To deploy, run `$ sh deploy.sh` + +To test, run `$ sh invoke.sh` + +The input.json contains the json . +It results in a Plist + +#3rd Part Library Information +This uses https://code.google.com/p/j2plist/ library to convert xml to json. +j2plist is licensed under Apache V2 License. + +# Get help + +For assistance, post to the [Apigee Developer Forum](http://support.apigee.com) + +Copyright © 2013 Apigee Corporation + +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy +of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/sample-proxies/JSONtoPLIST/apiproxy/JSONtoPLIST.xml b/sample-proxies/JSONtoPLIST/apiproxy/JSONtoPLIST.xml new file mode 100755 index 00000000..a5c263ed --- /dev/null +++ b/sample-proxies/JSONtoPLIST/apiproxy/JSONtoPLIST.xml @@ -0,0 +1,2 @@ + + diff --git a/sample-proxies/JSONtoPLIST/apiproxy/policies/jsontoplist.xml b/sample-proxies/JSONtoPLIST/apiproxy/policies/jsontoplist.xml new file mode 100755 index 00000000..d8edfa0d --- /dev/null +++ b/sample-proxies/JSONtoPLIST/apiproxy/policies/jsontoplist.xml @@ -0,0 +1,5 @@ + + + com.apigee.utils.jsontoplist.JSONtoPLIST + java://JSONtoPLIST.jar + \ No newline at end of file diff --git a/sample-proxies/JSONtoPLIST/apiproxy/proxies/default.xml b/sample-proxies/JSONtoPLIST/apiproxy/proxies/default.xml new file mode 100755 index 00000000..28f7b55e --- /dev/null +++ b/sample-proxies/JSONtoPLIST/apiproxy/proxies/default.xml @@ -0,0 +1,29 @@ + + + Default Proxy to create flows on an API + + + + + + + + jsontoplist + + + + + + + + + + + + /jsontoplist + + default + + + + diff --git a/sample-proxies/JSONtoPLIST/deploy.sh b/sample-proxies/JSONtoPLIST/deploy.sh new file mode 100755 index 00000000..8d79a9ff --- /dev/null +++ b/sample-proxies/JSONtoPLIST/deploy.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +source ../../setup/setenv.sh + +echo "Enter your password for the Apigee Enterprise organization $org, followed by [ENTER]:" + +read -s password + +echo Deploying $proxy to $env on $url using $username and $org + +cd ./java +javac -d bin -sourcepath src -classpath ../lib/expressions-1.0.0.jar:../lib/message-flow-1.0.0.jar:../lib/j2plist-0.3.jar:../lib/jsonic-1.2.0.jar src/com/apigee/utils/jsontoplist/JSONtoPLIST.java +cd bin +jar -cvf JSONtoPLIST.jar ./com +cp JSONtoPLIST.jar ../../apiproxy/resources/java +cp ../../lib/j2plist-0.3.jar ../../apiproxy/resources/java +cp ../../lib/jsonic-1.2.0.jar ../../apiproxy/resources/java +cd ../.. +rm -fr java/bin/* + +../../tools/deploy.py -n JSONtoPLIST -u $username:$password -o $org -h $url -e $env -p / -d ../JSONtoPLIST +rm -fr apiproxy/resources/java/* + +echo "If 'State: deployed', then your API Proxy is ready to be invoked." + +echo "Run 'invoke.sh'" diff --git a/sample-proxies/JSONtoPLIST/input.json b/sample-proxies/JSONtoPLIST/input.json new file mode 100644 index 00000000..29926530 --- /dev/null +++ b/sample-proxies/JSONtoPLIST/input.json @@ -0,0 +1,41 @@ +{ + "HotelReservations": { + "HotelReservation": { + "-CreateDateTime": "2009-01-24T17:21:16.137-05:00", + "-LastModifyDateTime": "2009-01-24T17:21:16.137-05:00", + "UniqueID": { + "-Type": "14.UIT", + "-ID": "ABCD1234", + "-ID_Context": "Test" + }, + "RoomStays": { + "RoomStay": { + "RoomTypes": { + "RoomType": { "-NumberOfUnits": "1" } + }, + "RoomRates": { + "RoomRate": { + "-RatePlanCode": "BAVA", + "Rates": { + "Rate": { + "-EffectiveDate": "2012-02-19", + "-ExpireDate": "2012-02-20", + "-RateTimeUnit": "Day" + } + } + } + }, + "BasicPropertyInfo": { + "-HotelCode": "NYCMQ", + "-HotelCodeContext": "Marriott" + } + } + }, + "ResGlobalInfo": { + "GuestCounts": { + "GuestCount": { "-Count": "2" } + } + } + } + } +} \ No newline at end of file diff --git a/sample-proxies/JSONtoPLIST/invoke.sh b/sample-proxies/JSONtoPLIST/invoke.sh new file mode 100755 index 00000000..15967957 --- /dev/null +++ b/sample-proxies/JSONtoPLIST/invoke.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +echo Using org and environment configured in /setup/setenv.sh + +source ../../setup/setenv.sh + +curl -X POST -d @input.json "http://$org-$env.apigee.net/jsontoplist" + diff --git a/sample-proxies/JSONtoPLIST/java/src/com/apigee/utils/jsontoplist/JSONtoPLIST.java b/sample-proxies/JSONtoPLIST/java/src/com/apigee/utils/jsontoplist/JSONtoPLIST.java new file mode 100755 index 00000000..99ab8911 --- /dev/null +++ b/sample-proxies/JSONtoPLIST/java/src/com/apigee/utils/jsontoplist/JSONtoPLIST.java @@ -0,0 +1,87 @@ +/** + * Created on November. 20,2011 + * ClassName: JSONtoXML + * + * @author Saravanakumar Rajagopal + */ + +package com.apigee.utils.jsontoplist; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.Map; + +import net.yesiltas.lib.PList; + +import com.apigee.flow.execution.ExecutionContext; +import com.apigee.flow.execution.ExecutionResult; +import com.apigee.flow.execution.spi.Execution; +import com.apigee.flow.message.MessageContext; + +/** + * This class converts incoming JSON message content to PLIST content. + * + * + * @version 1.0 + * @author Saravanakumar Rajagopal + * + */ + +public class JSONtoPLIST implements Execution{ + + + public ExecutionResult execute(MessageContext context, ExecutionContext executionContext) { + + + String plistObject = null; + + try + { + + String jsonContent = context.getMessage().getContent(); + + if(jsonContent != null) + { + PList plist = new PList(); + plistObject = plist.encode(jsonContent); + context.getMessage().setContent(plistObject); + context.getMessage().setHeader("Content-Type", "application/x-plist"); + context.getMessage().setHeader("Content-Length", plistObject.length()); + + } + + } + catch (Exception e) { + return ExecutionResult.ABORT; + } + + return ExecutionResult.SUCCESS; + + } + + + private static String readFile( String file ) throws IOException { + BufferedReader reader = new BufferedReader( new FileReader (file)); + String line = null; + StringBuilder stringBuilder = new StringBuilder(); + String ls = System.getProperty("line.separator"); + while( ( line = reader.readLine() ) != null ) { + stringBuilder.append( line ); + stringBuilder.append( ls ); + } + return stringBuilder.toString(); + } + + + public static void main(String a[])throws Exception{ + String input = " "; + //String jsonStr = "{\"Errors\":[],\"Containers\":[{\"ContainerId\":\"de5708aa-645c-4aea-8d8f-6054af9703be\",\"Name\":\"My Workspace\",\"CreatedBy\":null,\"CreatedOn\":\"\/Date(-62135596800000)\/\",\"ModifiedBy\":null,\"ModifiedOn\":\"\/Date(-62135596800000)\/\"}]}"; + String jsonStr = readFile("/Users/rajesh/projects/presales/api-platform-samples/sample-proxies/JSONtoPLIST/input.json"); + PList plist = new PList(); + System.out.println(plist.encode(jsonStr)); + + + } + +} diff --git a/sample-proxies/JSONtoPLIST/lib/expressions-1.0.0.jar b/sample-proxies/JSONtoPLIST/lib/expressions-1.0.0.jar new file mode 100644 index 00000000..b2979541 Binary files /dev/null and b/sample-proxies/JSONtoPLIST/lib/expressions-1.0.0.jar differ diff --git a/sample-proxies/JSONtoPLIST/lib/j2plist-0.3.jar b/sample-proxies/JSONtoPLIST/lib/j2plist-0.3.jar new file mode 100644 index 00000000..7375d31c Binary files /dev/null and b/sample-proxies/JSONtoPLIST/lib/j2plist-0.3.jar differ diff --git a/sample-proxies/JSONtoPLIST/lib/jsonic-1.2.0.jar b/sample-proxies/JSONtoPLIST/lib/jsonic-1.2.0.jar new file mode 100644 index 00000000..09f9bec1 Binary files /dev/null and b/sample-proxies/JSONtoPLIST/lib/jsonic-1.2.0.jar differ diff --git a/sample-proxies/JSONtoPLIST/lib/message-flow-1.0.0.jar b/sample-proxies/JSONtoPLIST/lib/message-flow-1.0.0.jar new file mode 100644 index 00000000..da516247 Binary files /dev/null and b/sample-proxies/JSONtoPLIST/lib/message-flow-1.0.0.jar differ diff --git a/sample-proxies/JSONtoPLIST/runjava.sh b/sample-proxies/JSONtoPLIST/runjava.sh new file mode 100755 index 00000000..23bc9675 --- /dev/null +++ b/sample-proxies/JSONtoPLIST/runjava.sh @@ -0,0 +1,6 @@ +cd ./java +javac -d bin -sourcepath src -classpath ../lib/expressions-1.0.0.jar:../lib/message-flow-1.0.0.jar:../lib/j2plist-0.3.jar:../lib/jsonic-1.2.0.jar src/com/apigee/utils/jsontoplist/JSONtoPLIST.java +cd bin +java -classpath ../../lib/expressions-1.0.0.jar:../../lib/message-flow-1.0.0.jar:../../lib/j2plist-0.3.jar:../../lib/jsonic-1.2.0.jar:. com.apigee.utils.jsontoplist.JSONtoPLIST +cd ../.. +rm -fr java/bin/*