├── .gitignore ├── .idea └── codeStyles │ └── Project.xml ├── CHANGELOG ├── LICENSE ├── README.md ├── RELEASE.md ├── bintray_upload_v1.gradle ├── build.gradle ├── cloudsdk ├── .gitignore ├── build.gradle ├── consumer-proguard-rules.pro ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── io │ │ └── particle │ │ └── android │ │ └── sdk │ │ └── cloud │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ ├── io │ │ └── particle │ │ │ └── android │ │ │ └── sdk │ │ │ ├── cloud │ │ │ ├── ApiDefs.java │ │ │ ├── ApiFactory.java │ │ │ ├── BroadcastContract.java │ │ │ ├── DeviceState.java │ │ │ ├── EventsDelegate.java │ │ │ ├── FunctionArgs.java │ │ │ ├── ParallelDeviceFetcher.java │ │ │ ├── ParticleAccessToken.java │ │ │ ├── ParticleCloud.java │ │ │ ├── ParticleCloudSDK.java │ │ │ ├── ParticleDevice.java │ │ │ ├── ParticleEvent.java │ │ │ ├── ParticleEventHandler.java │ │ │ ├── ParticleEventVisibility.java │ │ │ ├── ParticleUser.java │ │ │ ├── Responses.java │ │ │ ├── SDKGlobals.java │ │ │ ├── SDKProvider.java │ │ │ ├── SimpleParticleEventHandler.java │ │ │ ├── exceptions │ │ │ │ ├── PartialDeviceListResultException.java │ │ │ │ ├── ParticleCloudException.java │ │ │ │ └── ParticleLoginException.java │ │ │ └── models │ │ │ │ ├── AccountInfo.java │ │ │ │ ├── DeviceStateChange.java │ │ │ │ └── SignUpInfo.java │ │ │ ├── persistance │ │ │ ├── AppDataStorage.java │ │ │ └── SensitiveDataStorage.java │ │ │ └── utils │ │ │ ├── Async.java │ │ │ ├── EZ.java │ │ │ ├── Funcy.java │ │ │ ├── Parcelables.java │ │ │ ├── ParticleInternalStringUtils.java │ │ │ ├── Preconditions.java │ │ │ ├── Py.java │ │ │ ├── TLog.java │ │ │ └── Toaster.java │ └── org │ │ └── kaazing │ │ ├── gateway │ │ ├── bridge │ │ │ └── ValidateOrigin.java │ │ └── client │ │ │ ├── impl │ │ │ ├── Channel.java │ │ │ ├── CommandMessage.java │ │ │ ├── DecoderInput.java │ │ │ ├── DecoderListener.java │ │ │ ├── EncoderOutput.java │ │ │ ├── Handler.java │ │ │ ├── WebSocketChannel.java │ │ │ ├── WebSocketHandler.java │ │ │ ├── WebSocketHandlerAdapter.java │ │ │ ├── WebSocketHandlerFactory.java │ │ │ ├── WebSocketHandlerListener.java │ │ │ ├── auth │ │ │ │ └── AuthenticationUtil.java │ │ │ ├── bridge │ │ │ │ ├── BridgeUtil.java │ │ │ │ ├── ClassLoaderFactory.java │ │ │ │ ├── HttpRequestBridgeHandler.java │ │ │ │ ├── Proxy.java │ │ │ │ ├── ProxyListener.java │ │ │ │ ├── WebSocketNativeBridgeHandler.java │ │ │ │ └── XoaEvent.java │ │ │ ├── http │ │ │ │ ├── HttpRequest.java │ │ │ │ ├── HttpRequestAuthenticationHandler.java │ │ │ │ ├── HttpRequestDelegateHandler.java │ │ │ │ ├── HttpRequestEvent.java │ │ │ │ ├── HttpRequestFactory.java │ │ │ │ ├── HttpRequestHandler.java │ │ │ │ ├── HttpRequestHandlerAdapter.java │ │ │ │ ├── HttpRequestHandlerFactory.java │ │ │ │ ├── HttpRequestListener.java │ │ │ │ ├── HttpRequestLoggingHandler.java │ │ │ │ ├── HttpRequestRedirectHandler.java │ │ │ │ ├── HttpRequestTransportHandler.java │ │ │ │ ├── HttpRequestUtil.java │ │ │ │ └── HttpResponse.java │ │ │ ├── util │ │ │ │ ├── WSCompositeURI.java │ │ │ │ ├── WSURI.java │ │ │ │ └── WebSocketUtil.java │ │ │ ├── ws │ │ │ │ ├── CloseCommandMessage.java │ │ │ │ ├── ReadyState.java │ │ │ │ ├── WebSocketCompositeChannel.java │ │ │ │ ├── WebSocketCompositeHandler.java │ │ │ │ ├── WebSocketHandshakeObject.java │ │ │ │ ├── WebSocketLoggingHandler.java │ │ │ │ ├── WebSocketReAuthenticateHandler.java │ │ │ │ ├── WebSocketSelectedChannel.java │ │ │ │ ├── WebSocketSelectedHandler.java │ │ │ │ ├── WebSocketSelectedHandlerImpl.java │ │ │ │ └── WebSocketTransportHandler.java │ │ │ ├── wseb │ │ │ │ ├── CreateChannel.java │ │ │ │ ├── CreateHandler.java │ │ │ │ ├── CreateHandlerFactory.java │ │ │ │ ├── CreateHandlerImpl.java │ │ │ │ ├── CreateHandlerListener.java │ │ │ │ ├── DownstreamChannel.java │ │ │ │ ├── DownstreamHandler.java │ │ │ │ ├── DownstreamHandlerFactory.java │ │ │ │ ├── DownstreamHandlerImpl.java │ │ │ │ ├── DownstreamHandlerListener.java │ │ │ │ ├── UpstreamChannel.java │ │ │ │ ├── UpstreamHandler.java │ │ │ │ ├── UpstreamHandlerFactory.java │ │ │ │ ├── UpstreamHandlerImpl.java │ │ │ │ ├── UpstreamHandlerListener.java │ │ │ │ ├── WebSocketEmulatedChannel.java │ │ │ │ ├── WebSocketEmulatedDecoder.java │ │ │ │ ├── WebSocketEmulatedDecoderImpl.java │ │ │ │ ├── WebSocketEmulatedDecoderListener.java │ │ │ │ ├── WebSocketEmulatedEncoder.java │ │ │ │ ├── WebSocketEmulatedEncoderImpl.java │ │ │ │ └── WebSocketEmulatedHandler.java │ │ │ └── wsn │ │ │ │ ├── WebSocketNativeAuthenticationHandler.java │ │ │ │ ├── WebSocketNativeBalancingHandler.java │ │ │ │ ├── WebSocketNativeChannel.java │ │ │ │ ├── WebSocketNativeCodec.java │ │ │ │ ├── WebSocketNativeDelegateHandler.java │ │ │ │ ├── WebSocketNativeEncoder.java │ │ │ │ ├── WebSocketNativeEncoderImpl.java │ │ │ │ ├── WebSocketNativeHandler.java │ │ │ │ └── WebSocketNativeHandshakeHandler.java │ │ │ ├── transport │ │ │ ├── AuthenticateEvent.java │ │ │ ├── BridgeDelegate.java │ │ │ ├── CloseEvent.java │ │ │ ├── ErrorEvent.java │ │ │ ├── Event.java │ │ │ ├── IoBufferUtil.java │ │ │ ├── LoadEvent.java │ │ │ ├── MessageEvent.java │ │ │ ├── OpenEvent.java │ │ │ ├── ProgressEvent.java │ │ │ ├── ReadyStateChangedEvent.java │ │ │ ├── RedirectEvent.java │ │ │ ├── http │ │ │ │ ├── HttpRequestDelegate.java │ │ │ │ ├── HttpRequestDelegateFactory.java │ │ │ │ ├── HttpRequestDelegateImpl.java │ │ │ │ ├── HttpRequestDelegateListener.java │ │ │ │ └── HttpRequestUtil.java │ │ │ └── ws │ │ │ │ ├── Base64Util.java │ │ │ │ ├── BridgeSocket.java │ │ │ │ ├── BridgeSocketFactory.java │ │ │ │ ├── BridgeSocketImpl.java │ │ │ │ ├── FrameProcessor.java │ │ │ │ ├── FrameProcessorListener.java │ │ │ │ ├── WebSocketDelegate.java │ │ │ │ ├── WebSocketDelegateFactory.java │ │ │ │ ├── WebSocketDelegateImpl.java │ │ │ │ ├── WebSocketDelegateListener.java │ │ │ │ ├── WsFrameEncodingSupport.java │ │ │ │ └── WsMessage.java │ │ │ └── util │ │ │ ├── Base64Util.java │ │ │ ├── GenericURI.java │ │ │ ├── HexUtil.java │ │ │ ├── HttpURI.java │ │ │ ├── StringUtils.java │ │ │ ├── URIUtils.java │ │ │ ├── WrappedByteBuffer.java │ │ │ └── auth │ │ │ └── LoginHandlerProvider.java │ │ └── net │ │ ├── URLFactory.java │ │ ├── URLStreamHandlerFactorySpi.java │ │ ├── auth │ │ ├── BasicChallengeHandler.java │ │ ├── ChallengeHandler.java │ │ ├── ChallengeRequest.java │ │ ├── ChallengeResponse.java │ │ ├── DispatchChallengeHandler.java │ │ ├── LoginHandler.java │ │ ├── NegotiableChallengeHandler.java │ │ └── NegotiateChallengeHandler.java │ │ ├── http │ │ └── HttpRedirectPolicy.java │ │ ├── impl │ │ ├── auth │ │ │ ├── BasicChallengeResponseFactory.java │ │ │ ├── DefaultBasicChallengeHandler.java │ │ │ ├── DefaultDispatchChallengeHandler.java │ │ │ └── RealmUtils.java │ │ └── util │ │ │ ├── BlockingQueueImpl.java │ │ │ └── ResumableTimer.java │ │ ├── sse │ │ ├── SseEventReader.java │ │ ├── SseEventSource.java │ │ ├── SseEventSourceFactory.java │ │ ├── SseEventType.java │ │ ├── SseException.java │ │ └── impl │ │ │ ├── AuthenticatedEventSourceFactory.java │ │ │ ├── AuthenticatedSseEventSourceImpl.java │ │ │ ├── AuthenticatedSseEventStream.java │ │ │ ├── DefaultEventSourceFactory.java │ │ │ ├── SseEventReaderImpl.java │ │ │ ├── SseEventSourceImpl.java │ │ │ ├── SseEventStream.java │ │ │ ├── SseEventStreamListener.java │ │ │ ├── SsePayload.java │ │ │ ├── SseURLConnection.java │ │ │ ├── SseURLConnectionImpl.java │ │ │ ├── legacy │ │ │ ├── EventSource.java │ │ │ ├── EventSourceAdapter.java │ │ │ ├── EventSourceEvent.java │ │ │ ├── EventSourceImpl.java │ │ │ └── EventSourceListener.java │ │ │ └── url │ │ │ ├── SseURLStreamHandlerFactorySpiImpl.java │ │ │ └── SseURLStreamHandlerImpl.java │ │ └── ws │ │ ├── WebSocket.java │ │ ├── WebSocketException.java │ │ ├── WebSocketExtension.java │ │ ├── WebSocketFactory.java │ │ ├── WebSocketMessageReader.java │ │ ├── WebSocketMessageType.java │ │ ├── WebSocketMessageWriter.java │ │ ├── WsURLConnection.java │ │ └── impl │ │ ├── DefaultWebSocketFactory.java │ │ ├── WebSocketImpl.java │ │ ├── WsExtensionParameterValuesSpiImpl.java │ │ ├── WsURLConnectionImpl.java │ │ ├── io │ │ ├── WsInputStreamImpl.java │ │ ├── WsMessagePullParser.java │ │ ├── WsMessageReaderAdapter.java │ │ ├── WsMessageReaderImpl.java │ │ ├── WsMessageWriterImpl.java │ │ ├── WsOutputStreamImpl.java │ │ ├── WsReaderImpl.java │ │ └── WsWriterImpl.java │ │ ├── spi │ │ ├── WebSocketExtensionFactorySpi.java │ │ ├── WebSocketExtensionHandlerSpi.java │ │ ├── WebSocketExtensionParameterValuesSpi.java │ │ └── WebSocketExtensionSpi.java │ │ └── url │ │ ├── WsURLStreamHandlerFactorySpiImpl.java │ │ ├── WsURLStreamHandlerImpl.java │ │ ├── WssURLStreamHandlerFactorySpiImpl.java │ │ └── WssURLStreamHandlerImpl.java │ ├── res │ └── values │ │ ├── config.xml │ │ └── oauth_client_creds.xml │ └── resources │ └── META-INF │ └── services │ ├── org.kaazing.net.URLStreamHandlerFactorySpi │ ├── org.kaazing.net.auth.BasicChallengeHandler │ ├── org.kaazing.net.auth.DispatchChallengeHandler │ ├── org.kaazing.net.sse.SseEventSourceFactory │ └── org.kaazing.net.ws.WebSocketFactory ├── example_app ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── io │ │ └── particle │ │ └── cloudsdk │ │ └── example_app │ │ ├── DeviceInfoActivity.java │ │ ├── LoginActivity.java │ │ ├── SplashActivity.java │ │ └── ValueActivity.java │ └── res │ ├── layout │ ├── activity_device_info.xml │ ├── activity_login.xml │ ├── activity_splash.xml │ └── activity_value.xml │ ├── menu │ ├── menu_splash.xml │ └── menu_value.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── pom_generator_v1.gradle └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # OS X noise 6 | # Intellij 7 | .DS_Store 8 | 9 | # Files for the Dalvik VM 10 | *.dex 11 | 12 | # Java class files 13 | *.class 14 | 15 | # Generated files 16 | bin/ 17 | gen/ 18 | 19 | # Gradle files 20 | .gradle/ 21 | build/ 22 | /*/build/ 23 | 24 | 25 | # Local configuration file (sdk path, etc) 26 | local.properties 27 | # no longer used, but we don't want this file to leak(!) 28 | bintray.properties 29 | # not used either, but better safe than sorry, in case of copy/paste accidents, etc. 30 | bintray_user_auth_secrets.properties 31 | 32 | 33 | # Proguard folder generated by Eclipse 34 | proguard/ 35 | 36 | # Log Files 37 | *.log 38 | 39 | 40 | # IDEA/Android Studio 41 | # We want to IGNORE most of .idea 42 | *.iml 43 | /.idea/* 44 | 45 | # IDEA/Android Studio exceptions 46 | # And these are the files we explicitly want to *KEEP*, 47 | !/.idea/codeStyles/ 48 | !/.idea/copyright/ 49 | !/.idea/fileTemplates/ 50 | !/.idea/inspectionProfiles/ 51 | !/.idea/scopes/ 52 | !/.idea/codeStyleSettings.xml 53 | !/.idea/encodings.xml 54 | !/.idea/.name 55 | 56 | # Keystore files 57 | *.jks 58 | 59 | # External native build folder generated in Android Studio 2.2 and later 60 | .externalNativeBuild 61 | 62 | # Google Services (e.g. APIs or Firebase) 63 | google-services.json 64 | 65 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | 0.5.1 2 | ===== 3 | * New features - Two factor authentication. 4 | 5 | 6 | 0.5.0 7 | ===== 8 | * Exposing list of devices beyond package within PartialDeviceListResultException. 9 | 10 | 11 | 0.4.9 12 | ===== 13 | * Android libraries update, refactoring. 14 | 15 | 16 | 0.4.8 17 | ===== 18 | * Android libraries update, refactoring. 19 | * Reset password bug fix. 20 | 21 | 22 | 0.4.7 23 | ===== 24 | * Android libraries update, catching async task RejectedExecutionException. 25 | 26 | 27 | 0.4.6 28 | ===== 29 | * Adding refresh and inject session token methods. 30 | 31 | 32 | 0.4.5 33 | ===== 34 | * Exposing iccid and data usage for electron. 35 | 36 | 37 | 0.4.4 38 | ===== 39 | * Adding back organization endpoints as deprecated. 40 | 41 | 42 | 0.4.3 43 | ===== 44 | * Adding back email field for organization sign up 45 | 46 | 47 | 0.4.2 48 | ===== 49 | * Support for all device types/names by platform id 50 | * Global listener in ParticleCloud for system events 51 | * resetFlashingState - works with global system events instead of flashing timer 52 | * Fix for eventName emitting "message" most of the time 53 | * Org endpoints changed to product id 54 | * Password reset url changed to match url used in iOS. 55 | * Workaround/fix for sign up not throwing exception on error. 56 | 57 | 58 | 0.4.1 59 | ===== 60 | * Optional account information included in sign up api calls 61 | * Exposed new device fields 62 | 63 | 64 | 0.4.0 65 | ===== 66 | * Retrolambda support + some lambdafying of the code 67 | * Change target to API 25 68 | * Bug fixes: "Unsubscribing from events not working", "type bug in Funcy" 69 | 70 | 71 | 0.3.4 72 | ===== 73 | * fix an uncommon crasher bug 74 | * Use a much smarter config for building internal executor 75 | * Add (non-public, "preview") API for fetching ParticleDevices in parallel 76 | 77 | 78 | 0.3.3 79 | ===== 80 | * Fix for #7 to make subscribing to events for individual devices work again; thanks 81 | to reddigfabian for the PR. 82 | 83 | 84 | 0.3.2 85 | ===== 86 | * Electron support! 87 | * Use SharedPreferences.apply() instead of .commit() for an easy perf boost 88 | * Code cleanups, including switching to @ParametersAreNonnullByDefault 89 | 90 | 91 | 0.3.1 92 | ===== 93 | * Workaround for lame 3rd party packaging problems 94 | * Update GSON dependency 95 | 96 | 97 | 0.3.0 98 | ====== 99 | * At last, event pub/sub support! 100 | 101 | 102 | 0.2.2 103 | ====== 104 | * Fix `getVariable()` call by adding type-safe methods for getting variables of each supported type 105 | * Expose the "last heard" info for `ParticleDevice`s 106 | 107 | 108 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Particle Android Cloud SDK 2 | 3 | ## MOVED! 4 | 5 | The Cloud SDK has moved to [the new Particle Android repository!](https://github.com/particle-iot/particle-android) This repository is now deprecated and will not be updated. 6 | 7 | -------------------------------------------------------------------------------- /RELEASE.md: -------------------------------------------------------------------------------- 1 | # Making official releases 2 | 3 | These are the steps for releasing an updated version of the Particle SDK. 4 | For example, if you were releasing version `2.4.2`, you'd do the following: 5 | 6 | 1. Make sure the CHANGELOG is current 7 | 2. Pull from origin to ensure you have the latest upstream changes 8 | 3. Update the `version` field in `cloudsdk/build.gradle` to `'2.4.2'` 9 | 4. Build a release and publish it to JCenter. From the `cloudsdk` dir, 10 | do: `../gradlew clean build install bintrayUpload` 11 | 5. Submit a PR to the docs site updating the version code in `android.md` to `2.4.2` 12 | 6. Update the example app to pull the new version from JCenter, clean its build, and 13 | then build & run the example app as a final smoke test. 14 | 7. Commit and push the previous two changes 15 | 8. Tag the release: `git tag v2.4.2` (note the "v" at the beginning) 16 | 9. Push the tag: `git push origin v2.4.2` (again, note the "v") 17 | 10. (if applicable) announce the update via the appropriate channels 18 | -------------------------------------------------------------------------------- /bintray_upload_v1.gradle: -------------------------------------------------------------------------------- 1 | // lifted from https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle 2 | // and copied into the repo for safety/stability 3 | apply plugin: 'com.jfrog.bintray' 4 | 5 | version = libraryVersion 6 | 7 | task sourcesJar(type: Jar) { 8 | from android.sourceSets.main.java.srcDirs 9 | classifier = 'sources' 10 | } 11 | 12 | task javadoc(type: Javadoc) { 13 | source = android.sourceSets.main.java.srcDirs 14 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 15 | } 16 | 17 | task javadocJar(type: Jar, dependsOn: javadoc) { 18 | classifier = 'javadoc' 19 | from javadoc.destinationDir 20 | } 21 | 22 | artifacts { 23 | archives javadocJar 24 | archives sourcesJar 25 | } 26 | 27 | // FIXME: this feels hackish, but it works for now, and it shouldn't 28 | // have any side effects* for anyone building the lib locally, 29 | // so #SHIPIT 30 | // 31 | // * My apologies if this turns out not to be true. Patches welcome! 32 | Properties authDataProps = new Properties() 33 | try { 34 | authDataProps.load(project.rootProject.file('../bintray_user_auth_secrets.properties').newDataInputStream()) 35 | } catch (Exception e) { 36 | // do nothing; this is the default state for everyone who isn't publishing 37 | // the lib. 38 | } 39 | 40 | bintray { 41 | user = authDataProps.getProperty("bintray.user") 42 | key = authDataProps.getProperty("bintray.apikey") 43 | 44 | configurations = ['archives'] 45 | pkg { 46 | userOrg = bintrayOrg 47 | repo = bintrayRepo 48 | name = bintrayName 49 | desc = libraryDescription 50 | websiteUrl = siteUrl 51 | vcsUrl = gitUrl 52 | licenses = allLicenses 53 | publish = true 54 | publicDownloadNumbers = false 55 | version { 56 | // desc = libraryDescription 57 | gpg { 58 | sign = false // Determines whether to GPG sign the files. The default is false 59 | // passphrase = properties.getProperty("bintray.gpg.password") // Optional. The passphrase for GPG signing' 60 | } 61 | } 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | google() 6 | jcenter() 7 | } 8 | 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.1.3' 11 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' 12 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' 13 | } 14 | 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | google() 20 | jcenter() 21 | } 22 | } 23 | 24 | task clean(type: Delete) { 25 | delete rootProject.buildDir 26 | } 27 | -------------------------------------------------------------------------------- /cloudsdk/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /cloudsdk/consumer-proguard-rules.pro: -------------------------------------------------------------------------------- 1 | -dontwarn okio.** 2 | -------------------------------------------------------------------------------- /cloudsdk/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /home/jensck/Library/android-sdk-linux/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /cloudsdk/src/androidTest/java/io/particle/android/sdk/cloud/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package io.particle.android.sdk.cloud; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /cloudsdk/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/io/particle/android/sdk/cloud/BroadcastContract.java: -------------------------------------------------------------------------------- 1 | package io.particle.android.sdk.cloud; 2 | 3 | 4 | public interface BroadcastContract { 5 | 6 | String BROADCAST_DEVICES_UPDATED = "BROADCAST_DEVICES_UPDATED"; 7 | String BROADCAST_SYSTEM_EVENT = "BROADCAST_SYSTEM_EVENT"; 8 | 9 | } 10 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/io/particle/android/sdk/cloud/FunctionArgs.java: -------------------------------------------------------------------------------- 1 | package io.particle.android.sdk.cloud; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | public class FunctionArgs { 6 | 7 | @SerializedName("params") 8 | public final String params; 9 | 10 | public FunctionArgs(String params) { 11 | this.params = params; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/io/particle/android/sdk/cloud/ParticleCloudSDK.java: -------------------------------------------------------------------------------- 1 | package io.particle.android.sdk.cloud; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.Nullable; 5 | 6 | import javax.annotation.ParametersAreNonnullByDefault; 7 | 8 | import io.particle.android.sdk.cloud.ApiFactory.OauthBasicAuthCredentialsProvider; 9 | import io.particle.android.sdk.utils.TLog; 10 | 11 | /** 12 | * Entry point for the Particle Cloud SDK. 13 | */ 14 | @ParametersAreNonnullByDefault 15 | public class ParticleCloudSDK { 16 | // NOTE: pay attention to the interface, try to ignore the implementation, it's going to change. 17 | 18 | /** 19 | * Initialize the cloud SDK. Must be called somewhere in your Application.onCreate() 20 | * 21 | * (or anywhere else before your first Activity.onCreate() is called) 22 | */ 23 | public static void init(Context ctx) { 24 | initWithParams(ctx, null); 25 | } 26 | 27 | public static void initWithOauthCredentialsProvider( 28 | Context ctx, @Nullable OauthBasicAuthCredentialsProvider oauthProvider) { 29 | initWithParams(ctx, oauthProvider); 30 | } 31 | 32 | public static ParticleCloud getCloud() { 33 | verifyInitCalled(); 34 | return instance.sdkProvider.getParticleCloud(); 35 | } 36 | 37 | 38 | // NOTE: This is closer to the interface I'd like to provide eventually 39 | static void initWithParams(Context ctx, 40 | @Nullable OauthBasicAuthCredentialsProvider oauthProvider) { 41 | if (instance != null) { 42 | log.w("Calling ParticleCloudSDK.init() more than once does not re-initialize the SDK."); 43 | return; 44 | } 45 | 46 | Context appContext = ctx.getApplicationContext(); 47 | SDKProvider sdkProvider = new SDKProvider(appContext, oauthProvider); 48 | instance = new ParticleCloudSDK(sdkProvider); 49 | } 50 | 51 | @SuppressWarnings("BooleanMethodIsAlwaysInverted") 52 | static boolean isInitialized() { 53 | return instance != null; 54 | } 55 | 56 | static SDKProvider getSdkProvider() { 57 | verifyInitCalled(); 58 | return instance.sdkProvider; 59 | } 60 | 61 | static void verifyInitCalled() { 62 | if (!isInitialized()) { 63 | throw new IllegalStateException("init not called before using the Particle SDK. " 64 | + "Are you calling ParticleCloudSDK.init() in your Application.onCreate()?"); 65 | } 66 | } 67 | 68 | 69 | private static final TLog log = TLog.get(ParticleCloudSDK.class); 70 | 71 | private static ParticleCloudSDK instance; 72 | 73 | 74 | private final SDKProvider sdkProvider; 75 | 76 | private ParticleCloudSDK(SDKProvider sdkProvider) { 77 | this.sdkProvider = sdkProvider; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/io/particle/android/sdk/cloud/ParticleEvent.java: -------------------------------------------------------------------------------- 1 | package io.particle.android.sdk.cloud; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import java.util.Date; 6 | 7 | import javax.annotation.ParametersAreNonnullByDefault; 8 | 9 | 10 | // Normally it's bad form to use network data models as API data models, but considering that 11 | // for the moment, they'd be a 1:1 mapping, we'll just reuse this data model class. If the 12 | // network API changes, then we can write new classes for the network API models, without 13 | // impacting the public API of the SDK. 14 | @ParametersAreNonnullByDefault 15 | public class ParticleEvent { 16 | 17 | @SerializedName("coreid") 18 | public final String deviceId; 19 | 20 | @SerializedName("data") 21 | public final String dataPayload; 22 | 23 | @SerializedName("published_at") 24 | public final Date publishedAt; 25 | 26 | @SerializedName("ttl") 27 | public final int timeToLive; 28 | 29 | public ParticleEvent(String deviceId, String dataPayload, Date publishedAt, int timeToLive) { 30 | this.deviceId = deviceId; 31 | this.dataPayload = dataPayload; 32 | this.publishedAt = publishedAt; 33 | this.timeToLive = timeToLive; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/io/particle/android/sdk/cloud/ParticleEventHandler.java: -------------------------------------------------------------------------------- 1 | package io.particle.android.sdk.cloud; 2 | 3 | 4 | public interface ParticleEventHandler extends SimpleParticleEventHandler { 5 | 6 | // FIXME: ugh, use a more specific exception here 7 | void onEventError(Exception e); 8 | } 9 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/io/particle/android/sdk/cloud/ParticleEventVisibility.java: -------------------------------------------------------------------------------- 1 | package io.particle.android.sdk.cloud; 2 | 3 | 4 | import android.support.annotation.IntDef; 5 | 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | 9 | 10 | @IntDef({ParticleEventVisibility.PRIVATE, 11 | ParticleEventVisibility.PUBLIC}) 12 | @Retention(RetentionPolicy.SOURCE) 13 | public @interface ParticleEventVisibility { 14 | int PRIVATE = 1; 15 | int PUBLIC = 2; 16 | } 17 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/io/particle/android/sdk/cloud/ParticleUser.java: -------------------------------------------------------------------------------- 1 | package io.particle.android.sdk.cloud; 2 | 3 | 4 | import javax.annotation.ParametersAreNonnullByDefault; 5 | 6 | import io.particle.android.sdk.persistance.SensitiveDataStorage; 7 | import io.particle.android.sdk.utils.Preconditions; 8 | 9 | import static io.particle.android.sdk.utils.Py.truthy; 10 | 11 | 12 | @ParametersAreNonnullByDefault 13 | public class ParticleUser { 14 | 15 | /** 16 | * Initialize ParticleUser class with new credentials and store session in keychain 17 | */ 18 | public static synchronized ParticleUser fromNewCredentials(String user, String password) { 19 | Preconditions.checkArgument(truthy(user), "Username cannot be empty or null"); 20 | Preconditions.checkArgument(truthy(password), "Password cannot be empty or null"); 21 | 22 | SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage(); 23 | sensitiveDataStorage.saveUser(user); 24 | sensitiveDataStorage.savePassword(password); 25 | 26 | return new ParticleUser(user, password); 27 | } 28 | 29 | /** 30 | * Try to initialize a ParticleUser class with stored credentials 31 | * 32 | * @return ParticleUser instance if successfully retrieved session, else null 33 | */ 34 | public static synchronized ParticleUser fromSavedSession() { 35 | SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage(); 36 | String user = sensitiveDataStorage.getUser(); 37 | String password = sensitiveDataStorage.getPassword(); 38 | 39 | if (truthy(user) && truthy(password)) { 40 | return new ParticleUser(user, password); 41 | } else { 42 | return null; 43 | } 44 | } 45 | 46 | public static void removeSession() { 47 | SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage(); 48 | sensitiveDataStorage.resetPassword(); 49 | sensitiveDataStorage.resetUser(); 50 | } 51 | 52 | 53 | private final String user; 54 | private final String password; 55 | 56 | 57 | private ParticleUser(String user, String password) { 58 | this.user = user; 59 | this.password = password; 60 | } 61 | 62 | public String getPassword() { 63 | return password; 64 | } 65 | 66 | public String getUser() { 67 | return user; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/io/particle/android/sdk/cloud/SDKGlobals.java: -------------------------------------------------------------------------------- 1 | package io.particle.android.sdk.cloud; 2 | 3 | 4 | import android.content.Context; 5 | 6 | import javax.annotation.ParametersAreNonnullByDefault; 7 | 8 | import io.particle.android.sdk.persistance.AppDataStorage; 9 | import io.particle.android.sdk.persistance.SensitiveDataStorage; 10 | 11 | 12 | @ParametersAreNonnullByDefault 13 | public class SDKGlobals { 14 | 15 | private static volatile SensitiveDataStorage sensitiveDataStorage; 16 | private static volatile AppDataStorage appDataStorage; 17 | 18 | private static boolean isInitialized = false; 19 | 20 | 21 | public static synchronized void init(Context ctx) { 22 | ctx = ctx.getApplicationContext(); 23 | if (isInitialized) { 24 | return; 25 | } 26 | 27 | sensitiveDataStorage = new SensitiveDataStorage(ctx); 28 | appDataStorage = new AppDataStorage(ctx); 29 | 30 | isInitialized = true; 31 | } 32 | 33 | 34 | public static SensitiveDataStorage getSensitiveDataStorage() { 35 | return sensitiveDataStorage; 36 | } 37 | 38 | public static AppDataStorage getAppDataStorage() { 39 | return appDataStorage; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/io/particle/android/sdk/cloud/SimpleParticleEventHandler.java: -------------------------------------------------------------------------------- 1 | package io.particle.android.sdk.cloud; 2 | 3 | /** 4 | * Created by Julius. 5 | */ 6 | 7 | public interface SimpleParticleEventHandler { 8 | void onEvent(String eventName, ParticleEvent particleEvent); 9 | } 10 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/io/particle/android/sdk/cloud/exceptions/PartialDeviceListResultException.java: -------------------------------------------------------------------------------- 1 | package io.particle.android.sdk.cloud.exceptions; 2 | 3 | import java.util.List; 4 | 5 | import io.particle.android.sdk.cloud.ParticleDevice; 6 | import retrofit.RetrofitError; 7 | 8 | public class PartialDeviceListResultException extends Exception { 9 | 10 | public final List devices; 11 | 12 | public PartialDeviceListResultException(List devices, Exception cause) { 13 | super(cause); 14 | this.devices = devices; 15 | } 16 | 17 | public PartialDeviceListResultException(List devices, RetrofitError error) { 18 | super(error); 19 | this.devices = devices; 20 | } 21 | 22 | public PartialDeviceListResultException(List devices) { 23 | super("Undefined error while fetching devices"); 24 | this.devices = devices; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/io/particle/android/sdk/cloud/exceptions/ParticleLoginException.java: -------------------------------------------------------------------------------- 1 | package io.particle.android.sdk.cloud.exceptions; 2 | 3 | import org.json.JSONException; 4 | import org.json.JSONObject; 5 | 6 | /** 7 | * Created by Julius. 8 | */ 9 | public class ParticleLoginException extends ParticleCloudException { 10 | 11 | public ParticleLoginException(Exception exception) { 12 | super(exception); 13 | } 14 | 15 | /** 16 | * Server-provided multi-factor auth token. May be null. 17 | * 18 | * @return server-provided multi-factor auth token or null 19 | */ 20 | public String getMfaToken() { 21 | if (responseData == null || responseData.getBody() == null) { 22 | return null; 23 | } 24 | try { 25 | JSONObject jsonObject = new JSONObject(responseData.getBody()); 26 | if (jsonObject.has("mfa_token")) { 27 | return jsonObject.getString("mfa_token"); 28 | } 29 | 30 | } catch (JSONException ignore) { 31 | } 32 | return null; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/io/particle/android/sdk/cloud/models/AccountInfo.java: -------------------------------------------------------------------------------- 1 | package io.particle.android.sdk.cloud.models; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import com.google.gson.annotations.SerializedName; 7 | 8 | /** 9 | * Keeps secondary user account information. 10 | */ 11 | public class AccountInfo implements Parcelable { 12 | @SerializedName("first_name") 13 | private String firstName; 14 | @SerializedName("last_name") 15 | private String lastName; 16 | @SerializedName("company_name") 17 | private String companyName; 18 | @SerializedName("business_account") 19 | private boolean businessAccount; 20 | 21 | public AccountInfo() { 22 | } 23 | 24 | public AccountInfo(String firstName, String lastName, String companyName, boolean businessAccount) { 25 | this.firstName = firstName; 26 | this.lastName = lastName; 27 | this.companyName = companyName; 28 | this.businessAccount = businessAccount; 29 | } 30 | 31 | public String getFirstName() { 32 | return firstName; 33 | } 34 | 35 | public void setFirstName(String firstName) { 36 | this.firstName = firstName; 37 | } 38 | 39 | public String getLastName() { 40 | return lastName; 41 | } 42 | 43 | public void setLastName(String lastName) { 44 | this.lastName = lastName; 45 | } 46 | 47 | public String getCompanyName() { 48 | return companyName; 49 | } 50 | 51 | public void setCompanyName(String companyName) { 52 | this.companyName = companyName; 53 | } 54 | 55 | public boolean isBusinessAccount() { 56 | return businessAccount; 57 | } 58 | 59 | public void setBusinessAccount(boolean isBusinessAccount) { 60 | this.businessAccount = isBusinessAccount; 61 | } 62 | 63 | @Override 64 | public int describeContents() { 65 | return 0; 66 | } 67 | 68 | @Override 69 | public void writeToParcel(Parcel dest, int flags) { 70 | dest.writeString(this.firstName); 71 | dest.writeString(this.lastName); 72 | dest.writeString(this.companyName); 73 | dest.writeByte(this.businessAccount ? (byte) 1 : (byte) 0); 74 | } 75 | 76 | protected AccountInfo(Parcel in) { 77 | this.firstName = in.readString(); 78 | this.lastName = in.readString(); 79 | this.companyName = in.readString(); 80 | this.businessAccount = in.readByte() != 0; 81 | } 82 | 83 | public static final Creator CREATOR = new Creator() { 84 | @Override 85 | public AccountInfo createFromParcel(Parcel source) { 86 | return new AccountInfo(source); 87 | } 88 | 89 | @Override 90 | public AccountInfo[] newArray(int size) { 91 | return new AccountInfo[size]; 92 | } 93 | }; 94 | } 95 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/io/particle/android/sdk/cloud/models/DeviceStateChange.java: -------------------------------------------------------------------------------- 1 | package io.particle.android.sdk.cloud.models; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | import android.support.annotation.NonNull; 6 | 7 | import javax.annotation.ParametersAreNonnullByDefault; 8 | 9 | import io.particle.android.sdk.cloud.ParticleDevice; 10 | 11 | @ParametersAreNonnullByDefault 12 | public class DeviceStateChange implements Parcelable { 13 | private final ParticleDevice device; 14 | @NonNull private final ParticleDevice.ParticleDeviceState state; 15 | 16 | public DeviceStateChange(ParticleDevice device, @NonNull ParticleDevice.ParticleDeviceState state) { 17 | this.device = device; 18 | this.state = state; 19 | } 20 | 21 | @Override 22 | public int describeContents() { 23 | return 0; 24 | } 25 | 26 | @Override 27 | public void writeToParcel(Parcel dest, int flags) { 28 | dest.writeParcelable(this.device, flags); 29 | dest.writeInt(this.state == ParticleDevice.ParticleDeviceState.UNKNOWN ? -1 : this.state.ordinal()); 30 | } 31 | 32 | protected DeviceStateChange(Parcel in) { 33 | this.device = in.readParcelable(ParticleDevice.class.getClassLoader()); 34 | int tmpState = in.readInt(); 35 | this.state = tmpState == -1 ? ParticleDevice.ParticleDeviceState.UNKNOWN : 36 | ParticleDevice.ParticleDeviceState.values()[tmpState]; 37 | } 38 | 39 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 40 | @Override 41 | public DeviceStateChange createFromParcel(Parcel source) { 42 | return new DeviceStateChange(source); 43 | } 44 | 45 | @Override 46 | public DeviceStateChange[] newArray(int size) { 47 | return new DeviceStateChange[size]; 48 | } 49 | }; 50 | 51 | public ParticleDevice getDevice() { 52 | return device; 53 | } 54 | 55 | @NonNull 56 | public ParticleDevice.ParticleDeviceState getState() { 57 | return state; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/io/particle/android/sdk/persistance/AppDataStorage.java: -------------------------------------------------------------------------------- 1 | package io.particle.android.sdk.persistance; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | 6 | import javax.annotation.ParametersAreNonnullByDefault; 7 | 8 | /** 9 | * Storage for misc settings to be persisted which aren't related to 10 | * identity, authorization, or any other sensitive data. 11 | */ 12 | @ParametersAreNonnullByDefault 13 | public class AppDataStorage { 14 | 15 | private static final String KEY_USER_HAS_CLAIMED_DEVICES = "KEY_USER_HAS_CLAIMED_DEVICES"; 16 | 17 | private final SharedPreferences sharedPrefs; 18 | 19 | 20 | public AppDataStorage(Context ctx) { 21 | ctx = ctx.getApplicationContext(); 22 | this.sharedPrefs = ctx.getSharedPreferences("spark_sdk_prefs", Context.MODE_PRIVATE); 23 | } 24 | 25 | public void saveUserHasClaimedDevices(boolean value) { 26 | sharedPrefs.edit() 27 | .putBoolean(KEY_USER_HAS_CLAIMED_DEVICES, value) 28 | .apply(); 29 | } 30 | 31 | public boolean getUserHasClaimedDevices() { 32 | return sharedPrefs.getBoolean(KEY_USER_HAS_CLAIMED_DEVICES, false); 33 | } 34 | 35 | public void resetUserHasClaimedDevices() { 36 | sharedPrefs.edit() 37 | .remove(KEY_USER_HAS_CLAIMED_DEVICES) 38 | .apply(); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/io/particle/android/sdk/utils/ParticleInternalStringUtils.java: -------------------------------------------------------------------------------- 1 | // Contents lifted from StringUtils.java in Apache commons-lang 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.particle.android.sdk.utils; 20 | 21 | 22 | import java.util.Iterator; 23 | 24 | 25 | public class ParticleInternalStringUtils { 26 | 27 | 28 | public static String join(final Iterable iterable, final char separator) { 29 | if (iterable == null) { 30 | return null; 31 | } 32 | return join(iterable.iterator(), separator); 33 | } 34 | 35 | 36 | public static String join(final Iterator iterator, final char separator) { 37 | 38 | // handle null, zero and one elements before building a buffer 39 | if (iterator == null) { 40 | return null; 41 | } 42 | if (!iterator.hasNext()) { 43 | return ""; 44 | } 45 | final Object first = iterator.next(); 46 | if (!iterator.hasNext()) { 47 | @SuppressWarnings("deprecation") 48 | // ObjectUtils.toString(Object) has been deprecated in 3.2 49 | final String result = objToString(first); 50 | return result; 51 | } 52 | 53 | // two or more elements 54 | final StringBuilder buf = new StringBuilder(256); // Java default is 16, probably too small 55 | if (first != null) { 56 | buf.append(first); 57 | } 58 | 59 | while (iterator.hasNext()) { 60 | buf.append(separator); 61 | final Object obj = iterator.next(); 62 | if (obj != null) { 63 | buf.append(obj); 64 | } 65 | } 66 | 67 | return buf.toString(); 68 | } 69 | 70 | private static String objToString(Object obj) { 71 | return obj == null ? "" : obj.toString(); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/io/particle/android/sdk/utils/Preconditions.java: -------------------------------------------------------------------------------- 1 | package io.particle.android.sdk.utils; 2 | 3 | import android.support.annotation.Nullable; 4 | 5 | /** 6 | * Like Guava's Preconditions, but without the overwhelming method count cost 7 | */ 8 | public class Preconditions { 9 | 10 | public static void checkArgument(boolean condition, String errorMessage) { 11 | if (!condition) { 12 | throw new IllegalArgumentException(String.valueOf(errorMessage)); 13 | } 14 | } 15 | 16 | 17 | public static T checkNotNull(T reference) { 18 | if (reference == null) { 19 | throw new NullPointerException(); 20 | } 21 | return reference; 22 | } 23 | 24 | 25 | public static T checkNotNull(T reference, @Nullable Object errorMessage) { 26 | if (reference == null) { 27 | throw new NullPointerException(String.valueOf(errorMessage)); 28 | } 29 | return reference; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/io/particle/android/sdk/utils/TLog.java: -------------------------------------------------------------------------------- 1 | package io.particle.android.sdk.utils; 2 | 3 | import android.support.v4.util.ArrayMap; 4 | import android.util.Log; 5 | 6 | /** 7 | * NOTE: this class is likely to be deprecated soon in favor of Jake Wharton's Timber: 8 | * https://goo.gl/xmQYYU 9 | */ 10 | public class TLog { 11 | 12 | private static final ArrayMap, TLog> loggers = new ArrayMap<>(); 13 | 14 | public static TLog get(Class clazz) { 15 | TLog logger = loggers.get(clazz); 16 | if (logger == null) { 17 | logger = new TLog(clazz.getSimpleName()); 18 | loggers.put(clazz, logger); 19 | } 20 | return logger; 21 | } 22 | 23 | private final String tag; 24 | 25 | private TLog(String tag) { 26 | this.tag = tag; 27 | } 28 | 29 | public void e(String msg) { 30 | Log.e(tag, msg); 31 | } 32 | 33 | public void e(String msg, Throwable tr) { 34 | Log.e(tag, msg, tr); 35 | } 36 | 37 | public void w(String msg) { 38 | Log.w(tag, msg); 39 | } 40 | 41 | public void w(String msg, Throwable tr) { 42 | Log.w(tag, msg, tr); 43 | } 44 | 45 | public void i(String msg) { 46 | Log.i(tag, msg); 47 | } 48 | 49 | public void i(String msg, Throwable tr) { 50 | Log.i(tag, msg, tr); 51 | } 52 | 53 | public void d(String msg) { 54 | Log.d(tag, msg); 55 | } 56 | 57 | public void d(String msg, Throwable tr) { 58 | Log.d(tag, msg, tr); 59 | } 60 | 61 | public void v(String msg) { 62 | Log.v(tag, msg); 63 | } 64 | 65 | public void v(String msg, Throwable tr) { 66 | Log.v(tag, msg, tr); 67 | } 68 | 69 | public void wtf(String msg) { 70 | Log.wtf(tag, msg); 71 | } 72 | 73 | public void wtf(String msg, Throwable tr) { 74 | Log.wtf(tag, msg, tr); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/io/particle/android/sdk/utils/Toaster.java: -------------------------------------------------------------------------------- 1 | package io.particle.android.sdk.utils; 2 | 3 | import android.app.Activity; 4 | import android.support.annotation.NonNull; 5 | import android.support.annotation.Nullable; 6 | import android.widget.Toast; 7 | 8 | import javax.annotation.ParametersAreNonnullByDefault; 9 | 10 | 11 | @ParametersAreNonnullByDefault 12 | public class Toaster { 13 | 14 | /** 15 | * Shows a toast message for a short time. 16 | *

17 | * This is safe to call from background/worker threads. 18 | */ 19 | public static void s(@NonNull final Activity activity, @Nullable final String msg) { 20 | showToast(activity, msg, Toast.LENGTH_SHORT); 21 | } 22 | 23 | /** 24 | * Shows a toast message for a longer time than {@link #s(Activity, String)}. 25 | *

26 | * This is safe to call from background/worker threads. 27 | */ 28 | public static void l(@NonNull final Activity activity, @Nullable final String msg) { 29 | showToast(activity, msg, Toast.LENGTH_LONG); 30 | } 31 | 32 | 33 | private static void showToast(@NonNull final Activity activity, @Nullable final String msg, 34 | final int length) { 35 | Runnable toastRunnable = () -> Toast.makeText(activity, msg, length).show(); 36 | 37 | if (EZ.isThisTheMainThread()) { 38 | toastRunnable.run(); 39 | } else { 40 | EZ.runOnMainThread(toastRunnable); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/bridge/ValidateOrigin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.bridge; 23 | 24 | final class ValidateOrigin { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/Channel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl; 23 | 24 | import org.kaazing.net.auth.ChallengeResponse; 25 | 26 | import java.util.concurrent.atomic.AtomicLong; 27 | 28 | public class Channel { 29 | public static final String HEADER_SEQUENCE = "X-Sequence-No"; 30 | 31 | // TODO: This is an abstration violation - authentication should not be exposed on Channel 32 | /** Authentication data */ 33 | public ChallengeResponse challengeResponse = new ChallengeResponse(null, null); 34 | public boolean authenticationReceived = false; 35 | public boolean preventFallback = false; 36 | 37 | private Channel parent; 38 | private final AtomicLong sequence; 39 | 40 | public Channel() { 41 | this(0); 42 | } 43 | 44 | public Channel(long sequence) { 45 | this.sequence = new AtomicLong(sequence); 46 | } 47 | 48 | public void setParent(Channel parent) { 49 | this.parent = parent; 50 | } 51 | 52 | public Channel getParent() { 53 | return parent; 54 | } 55 | 56 | public long nextSequence() { 57 | return this.sequence.getAndIncrement(); 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return "[" + this.getClass().getSimpleName() + "]"; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/CommandMessage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl; 23 | 24 | public interface CommandMessage { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/DecoderInput.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl; 23 | 24 | import org.kaazing.gateway.client.util.WrappedByteBuffer; 25 | 26 | 27 | public interface DecoderInput { 28 | 29 | WrappedByteBuffer read(C channel); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/DecoderListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl; 23 | 24 | import org.kaazing.gateway.client.util.WrappedByteBuffer; 25 | 26 | 27 | public interface DecoderListener { 28 | 29 | void messageDecoded(C channel, WrappedByteBuffer message); 30 | void messageDecoded(C channel, String message); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/EncoderOutput.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl; 23 | 24 | import org.kaazing.gateway.client.util.WrappedByteBuffer; 25 | 26 | 27 | public interface EncoderOutput { 28 | 29 | void write(C channel, WrappedByteBuffer buf); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/Handler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl; 23 | 24 | /** 25 | * Handler marker class 26 | */ 27 | public interface Handler { 28 | 29 | } 30 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/WebSocketHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl; 23 | 24 | import org.kaazing.gateway.client.impl.util.WSURI; 25 | import org.kaazing.gateway.client.util.WrappedByteBuffer; 26 | 27 | public interface WebSocketHandler extends Handler { 28 | 29 | void processConnect(WebSocketChannel channel, WSURI location, String[] protocols); 30 | void processAuthorize(WebSocketChannel channel, String authorizeToken); 31 | void processTextMessage(WebSocketChannel channel, String text); 32 | void processBinaryMessage(WebSocketChannel channel, WrappedByteBuffer buffer); 33 | void processClose(WebSocketChannel channel, int code, String reason); 34 | void setListener(WebSocketHandlerListener listener); 35 | void setIdleTimeout(WebSocketChannel channel, int timeout); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/WebSocketHandlerFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl; 23 | 24 | public interface WebSocketHandlerFactory { 25 | 26 | WebSocketHandler createWebSocketHandler(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/bridge/ClassLoaderFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.bridge; 23 | 24 | import java.net.URL; 25 | import java.net.URLClassLoader; 26 | 27 | public abstract class ClassLoaderFactory { 28 | 29 | private static ClassLoaderFactory sharedInstance; 30 | 31 | static { 32 | sharedInstance = new DefaultClassLoaderFactory(); 33 | } 34 | 35 | public abstract ClassLoader createClassLoader(URL url, ClassLoader parent) throws Exception; 36 | 37 | public abstract String getQueryParameters(); 38 | 39 | public abstract String getCrossOriginProxyClass(); 40 | 41 | public static void setInstance(ClassLoaderFactory factory) { 42 | sharedInstance = factory; 43 | } 44 | 45 | public static ClassLoaderFactory getInstance() { 46 | return sharedInstance; 47 | } 48 | 49 | private static class DefaultClassLoaderFactory extends ClassLoaderFactory{ 50 | 51 | @Override 52 | public ClassLoader createClassLoader(URL url, ClassLoader parent) throws Exception { 53 | URL[] urls = { url }; 54 | return URLClassLoader.newInstance(urls, parent); 55 | } 56 | 57 | @Override 58 | public String getQueryParameters() { 59 | return "?.kr=xsj"; //"?.kv=10.05&.kr=xsj"; 60 | } 61 | 62 | @Override 63 | public String getCrossOriginProxyClass() { 64 | return "org.kaazing.gateway.bridge.CrossOriginProxy"; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/bridge/Proxy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.bridge; 23 | 24 | import org.kaazing.gateway.client.impl.bridge.XoaEvent.XoaEventKind; 25 | 26 | import java.net.URI; 27 | 28 | /** 29 | * This class manages the handler id and URI associated with each proxy for the bridge. 30 | */ 31 | public class Proxy { 32 | private Integer handlerId; 33 | private URI uri; 34 | private Object peer; 35 | private ProxyListener listener; 36 | 37 | public Proxy() { 38 | } 39 | 40 | public URI getUri() { 41 | return uri; 42 | } 43 | 44 | void setUri(URI uri) { 45 | this.uri = uri; 46 | } 47 | 48 | void setListener(ProxyListener listener) { 49 | this.listener = listener; 50 | } 51 | 52 | public void setHandlerId(Integer handlerId) { 53 | this.handlerId = handlerId; 54 | } 55 | 56 | public Integer getHandlerId() { 57 | return handlerId; 58 | } 59 | 60 | public void setPeer(Object peer) { 61 | this.peer = peer; 62 | } 63 | 64 | public Object getPeer() { 65 | return peer; 66 | } 67 | 68 | void processEvent(XoaEventKind kind, Object[] params) { 69 | BridgeUtil.processEvent(new XoaEvent(handlerId, kind, params)); 70 | } 71 | 72 | void eventReceived(Integer handlerId, XoaEventKind name, Object[] params) { 73 | listener.eventReceived(this, name, params); 74 | } 75 | 76 | public String toString() { 77 | return "[Proxy "+handlerId+"]"; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/bridge/ProxyListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.bridge; 23 | 24 | import org.kaazing.gateway.client.impl.bridge.XoaEvent.XoaEventKind; 25 | 26 | public interface ProxyListener { 27 | 28 | void eventReceived(Proxy proxy, XoaEventKind name, Object[] params); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/http/HttpRequestEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.http; 23 | 24 | import org.kaazing.gateway.client.util.WrappedByteBuffer; 25 | 26 | import java.util.logging.Logger; 27 | 28 | public class HttpRequestEvent { 29 | private static final String CLASS_NAME = HttpRequestEvent.class.getName(); 30 | private static final Logger LOG = Logger.getLogger(CLASS_NAME); 31 | 32 | private static final long serialVersionUID = -7922410353957227356L; 33 | 34 | private HttpRequest source; 35 | private final Kind kind; 36 | private final WrappedByteBuffer data; 37 | 38 | /** 39 | * Type of the HttpRequestEvent. 40 | */ 41 | public enum Kind { 42 | OPEN, LOAD, PROGRESS, ERROR, READYSTATECHANGE, ABORT 43 | } 44 | 45 | public HttpRequestEvent(HttpRequest source, Kind kind) { 46 | this(source, kind, null); 47 | } 48 | 49 | public HttpRequestEvent(HttpRequest source, Kind kind, WrappedByteBuffer data) { 50 | this.source = source; 51 | LOG.entering(CLASS_NAME, "", new Object[] { source, kind, data }); 52 | this.kind = kind; 53 | this.data = data; 54 | } 55 | 56 | public HttpRequest getSource() { 57 | return source; 58 | } 59 | 60 | public Kind getKind() { 61 | return kind; 62 | } 63 | 64 | public WrappedByteBuffer getData() { 65 | return data; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/http/HttpRequestFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.http; 23 | 24 | import org.kaazing.gateway.client.impl.http.HttpRequest.Method; 25 | import org.kaazing.gateway.client.util.HttpURI; 26 | 27 | public interface HttpRequestFactory { 28 | 29 | HttpRequest createHttpRequest(Method method, HttpURI uri, boolean async); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/http/HttpRequestHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.http; 23 | 24 | import org.kaazing.gateway.client.util.WrappedByteBuffer; 25 | 26 | public interface HttpRequestHandler { 27 | 28 | void processOpen(HttpRequest request); 29 | void processSend(HttpRequest request, WrappedByteBuffer buffer); 30 | void processAbort(HttpRequest request); 31 | 32 | void setListener(HttpRequestListener listener); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/http/HttpRequestHandlerFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.http; 23 | 24 | 25 | public interface HttpRequestHandlerFactory { 26 | 27 | HttpRequestHandler createHandler(); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/http/HttpRequestListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.http; 23 | 24 | import org.kaazing.gateway.client.util.WrappedByteBuffer; 25 | 26 | public interface HttpRequestListener { 27 | 28 | /** Invoked when the request is ready to send data upstream */ 29 | void requestReady(HttpRequest request); 30 | 31 | /** Invoked when the response status code and headers are available */ 32 | void requestOpened(HttpRequest request); 33 | 34 | /** Invoked when streamed data is received on the response */ 35 | void requestProgressed(HttpRequest request, WrappedByteBuffer payload); 36 | 37 | /** Invoked when the response has completed and all data is available */ 38 | void requestLoaded(HttpRequest request, HttpResponse response); 39 | 40 | /** Invoked when the request has been aborted */ 41 | void requestAborted(HttpRequest request); 42 | 43 | /** Invoked when the request has closed and no longer valid */ 44 | void requestClosed(HttpRequest request); 45 | 46 | /** Invoked when an error has occurred while processing the request or response */ 47 | void errorOccurred(HttpRequest request, Exception exception); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/util/WSURI.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.util; 23 | 24 | import org.kaazing.gateway.client.util.GenericURI; 25 | import org.kaazing.gateway.client.util.URIUtils; 26 | 27 | import java.net.URI; 28 | import java.net.URISyntaxException; 29 | 30 | 31 | /** 32 | * URI with guarantee to be a valid, non-null, ws URI 33 | */ 34 | public class WSURI extends GenericURI { 35 | 36 | @Override 37 | protected boolean isValidScheme(String scheme) { 38 | return "ws".equals(scheme) || "wss".equals(scheme); 39 | } 40 | 41 | public WSURI(String location) throws URISyntaxException { 42 | this(new URI(location)); 43 | } 44 | 45 | public WSURI(URI location) throws URISyntaxException { 46 | super(location); 47 | } 48 | 49 | protected WSURI duplicate(URI uri) { 50 | try { 51 | return new WSURI(uri); 52 | } catch (URISyntaxException e) { 53 | throw new IllegalArgumentException(e); 54 | } 55 | } 56 | 57 | static WSURI replaceScheme(URI uri, String scheme) throws URISyntaxException { 58 | URI wsUri = URIUtils.replaceScheme(uri, scheme); 59 | return new WSURI(wsUri); 60 | } 61 | 62 | public boolean isSecure() { 63 | String scheme = getScheme(); 64 | return "wss".equals(scheme); 65 | } 66 | 67 | public String getHttpEquivalentScheme() { 68 | return (uri.getScheme().equals("ws") ? "http" : "https"); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/ws/CloseCommandMessage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.ws; 23 | 24 | import org.kaazing.gateway.client.impl.CommandMessage; 25 | 26 | import java.util.logging.Logger; 27 | 28 | public class CloseCommandMessage implements CommandMessage { 29 | 30 | private static final String CLASS_NAME = CloseCommandMessage.class.getName(); 31 | private static final Logger LOG = Logger.getLogger(CLASS_NAME); 32 | 33 | public static final int CLOSE_NO_STATUS = 1005; 34 | public static final int CLOSE_ABNORMAL = 1006; 35 | 36 | private int code = 0; 37 | private String reason; 38 | 39 | public CloseCommandMessage(int code, String reason) { 40 | if (code == 0) { 41 | code = CLOSE_NO_STATUS; 42 | } 43 | 44 | this.code = code; 45 | this.reason = reason; 46 | } 47 | 48 | public int getCode() { 49 | return code; 50 | } 51 | 52 | public String getReason() { 53 | return reason; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/ws/ReadyState.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.ws; 23 | 24 | /** 25 | * Values are CONNECTING = 0, OPEN = 1, CLOSING = 2, and CLOSED = 3; 26 | */ 27 | public enum ReadyState { 28 | CONNECTING, OPEN, CLOSING, CLOSED 29 | } -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/ws/WebSocketHandshakeObject.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.ws; 23 | 24 | public class WebSocketHandshakeObject { 25 | 26 | private String name; 27 | private String escape; 28 | private HandshakeStatus status; 29 | 30 | /** 31 | * @return the name 32 | */ 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | /** 38 | * @param name the name to set 39 | */ 40 | public void setName(String name) { 41 | this.name = name; 42 | } 43 | 44 | /** 45 | * @return the escape 46 | */ 47 | public String getEscape() { 48 | return escape; 49 | } 50 | 51 | /** 52 | * @param escape the escape to set 53 | */ 54 | public void setEscape(String escape) { 55 | this.escape = escape; 56 | } 57 | 58 | /** 59 | * @return the status 60 | */ 61 | public HandshakeStatus getStatus() { 62 | return status; 63 | } 64 | 65 | /** 66 | * @param status the status to set 67 | */ 68 | public void setStatus(HandshakeStatus status) { 69 | this.status = status; 70 | } 71 | 72 | public enum HandshakeStatus { 73 | Pending, 74 | Accepted 75 | } 76 | 77 | /* Kaazing default objects */ 78 | public final static String KAAZING_EXTENDED_HANDSHAKE = "x-kaazing-handshake"; 79 | public static final String KAAZING_SEC_EXTENSION_IDLETIMEOUT = "x-kaazing-idle-timeout"; 80 | 81 | } 82 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/ws/WebSocketSelectedChannel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.ws; 23 | 24 | import org.kaazing.gateway.client.impl.WebSocketChannel; 25 | import org.kaazing.gateway.client.impl.util.WSURI; 26 | 27 | public abstract class WebSocketSelectedChannel extends WebSocketChannel { 28 | 29 | WebSocketSelectedHandler handler; 30 | 31 | protected ReadyState readyState = ReadyState.CONNECTING; 32 | 33 | protected String[] requestedProtocols; 34 | 35 | // /** The protocol selected upon the completion of the WebSocket handshake */ 36 | // protected String selectedProtocol; 37 | 38 | public WebSocketSelectedChannel(WSURI location) { 39 | super(location); 40 | } 41 | 42 | public ReadyState getReadyState() { 43 | return readyState; 44 | } 45 | 46 | public String[] getRequestedProtocols() { 47 | return requestedProtocols; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/ws/WebSocketSelectedHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.ws; 23 | 24 | import org.kaazing.gateway.client.impl.WebSocketHandler; 25 | 26 | public interface WebSocketSelectedHandler extends WebSocketHandler { 27 | 28 | public void setNextHandler(WebSocketHandler nextHandler); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/wseb/CreateChannel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.wseb; 23 | 24 | import org.kaazing.gateway.client.impl.Channel; 25 | import org.kaazing.gateway.client.impl.http.HttpRequest; 26 | 27 | import java.util.HashMap; 28 | import java.util.Map; 29 | 30 | class CreateChannel extends Channel { 31 | 32 | protected String cookie = null; 33 | Map controlFrames; 34 | String[] protocols; 35 | private HttpRequest request; 36 | 37 | public CreateChannel() { 38 | super(0); 39 | controlFrames = new HashMap<>(); 40 | } 41 | 42 | public void setProtocols(String[] protocols) { 43 | this.protocols = protocols; 44 | } 45 | public String[] getProtocols() { 46 | return protocols; 47 | } 48 | 49 | public HttpRequest getRequest() { 50 | return request; 51 | } 52 | 53 | public void setRequest(HttpRequest request) { 54 | this.request = request; 55 | } 56 | } -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/wseb/CreateHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.wseb; 23 | 24 | import org.kaazing.gateway.client.impl.http.HttpRequestHandler; 25 | import org.kaazing.gateway.client.util.HttpURI; 26 | 27 | interface CreateHandler { 28 | 29 | void setListener(CreateHandlerListener createHandlerListener); 30 | void processOpen(CreateChannel createChannel, HttpURI createUri); 31 | void processClose(CreateChannel crateChannel); 32 | void setNextHandler(HttpRequestHandler nextHandler); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/wseb/CreateHandlerFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.wseb; 23 | 24 | interface CreateHandlerFactory { 25 | CreateHandler createCreateHandler(); 26 | } 27 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/wseb/CreateHandlerListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.wseb; 23 | 24 | import org.kaazing.gateway.client.util.HttpURI; 25 | 26 | public interface CreateHandlerListener { 27 | 28 | void createCompleted(CreateChannel channel, HttpURI upstreamUri, HttpURI downstreamUri, String protocol); 29 | void createFailed(CreateChannel channel, Exception exception); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/wseb/DownstreamHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.wseb; 23 | 24 | import org.kaazing.gateway.client.impl.http.HttpRequestHandler; 25 | import org.kaazing.gateway.client.util.HttpURI; 26 | 27 | interface DownstreamHandler { 28 | void processConnect(DownstreamChannel downstreamChannel, HttpURI downstreamUri); 29 | void processClose(DownstreamChannel channel); 30 | void setListener(DownstreamHandlerListener downstreamHandlerListener); 31 | void setNextHandler(HttpRequestHandler nextHandler); 32 | } 33 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/wseb/DownstreamHandlerFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.wseb; 23 | 24 | interface DownstreamHandlerFactory { 25 | DownstreamHandler createDownstreamHandler(); 26 | } 27 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/wseb/DownstreamHandlerListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.wseb; 23 | 24 | import org.kaazing.gateway.client.impl.CommandMessage; 25 | import org.kaazing.gateway.client.util.WrappedByteBuffer; 26 | 27 | public interface DownstreamHandlerListener { 28 | 29 | public void downstreamOpened(DownstreamChannel channel); 30 | public void binaryMessageReceived(DownstreamChannel channel, WrappedByteBuffer data); 31 | public void textMessageReceived(DownstreamChannel channel, String text); 32 | public void commandMessageReceived(DownstreamChannel channel, CommandMessage message); 33 | public void downstreamFailed(DownstreamChannel channel, Exception exception); 34 | public void downstreamClosed(DownstreamChannel channel); 35 | public void pingReceived(DownstreamChannel channel); 36 | } 37 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/wseb/UpstreamChannel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.wseb; 23 | 24 | import org.kaazing.gateway.client.impl.Channel; 25 | import org.kaazing.gateway.client.impl.http.HttpRequest; 26 | import org.kaazing.gateway.client.util.HttpURI; 27 | import org.kaazing.gateway.client.util.WrappedByteBuffer; 28 | 29 | import java.util.concurrent.ConcurrentLinkedQueue; 30 | import java.util.concurrent.atomic.AtomicBoolean; 31 | 32 | class UpstreamChannel extends Channel { 33 | HttpURI location; 34 | String cookie; 35 | 36 | ConcurrentLinkedQueue sendQueue = new ConcurrentLinkedQueue<>(); 37 | AtomicBoolean sendInFlight = new AtomicBoolean(false); 38 | HttpRequest request; 39 | 40 | WebSocketEmulatedChannel parent; 41 | 42 | public UpstreamChannel(HttpURI location, String cookie) { 43 | this(location, cookie, 0); 44 | } 45 | 46 | UpstreamChannel(HttpURI location, String cookie, long sequence) { 47 | super(sequence); 48 | this.location = location; 49 | this.cookie = cookie; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/wseb/UpstreamHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.wseb; 23 | 24 | import org.kaazing.gateway.client.impl.http.HttpRequestHandler; 25 | import org.kaazing.gateway.client.util.WrappedByteBuffer; 26 | 27 | interface UpstreamHandler { 28 | 29 | void setListener(UpstreamHandlerListener upstreamHandlerListener); 30 | void processOpen(UpstreamChannel channel); 31 | void processClose(UpstreamChannel upstreamChannel, int code, String reason); 32 | void processTextMessage(UpstreamChannel upstreamChannel, String message); 33 | void processBinaryMessage(UpstreamChannel upstreamChannel, WrappedByteBuffer message); 34 | void setNextHandler(HttpRequestHandler nextHandler); 35 | void processPong(UpstreamChannel upstreamChannel); 36 | } 37 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/wseb/UpstreamHandlerFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.wseb; 23 | 24 | interface UpstreamHandlerFactory { 25 | UpstreamHandler createUpstreamHandler(); 26 | } 27 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/wseb/UpstreamHandlerListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.wseb; 23 | 24 | public interface UpstreamHandlerListener { 25 | 26 | void upstreamFailed(UpstreamChannel channel, Exception exception); 27 | void upstreamCompleted(UpstreamChannel channel); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/wseb/WebSocketEmulatedChannel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.wseb; 23 | 24 | import org.kaazing.gateway.client.impl.util.WSURI; 25 | import org.kaazing.gateway.client.impl.ws.CloseCommandMessage; 26 | import org.kaazing.gateway.client.impl.ws.WebSocketSelectedChannel; 27 | import org.kaazing.gateway.client.util.HttpURI; 28 | 29 | public class WebSocketEmulatedChannel extends WebSocketSelectedChannel { 30 | 31 | public HttpURI redirectUri; 32 | CreateChannel createChannel; 33 | UpstreamChannel upstreamChannel; 34 | DownstreamChannel downstreamChannel; 35 | 36 | protected String cookie = null; 37 | 38 | /* close event */ 39 | boolean wasCleanClose = false; 40 | int closeCode = CloseCommandMessage.CLOSE_ABNORMAL; 41 | String closeReason = ""; 42 | 43 | public WebSocketEmulatedChannel(WSURI location) { 44 | super(location); 45 | } 46 | } -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/wseb/WebSocketEmulatedDecoder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.wseb; 23 | 24 | import org.kaazing.gateway.client.impl.DecoderInput; 25 | 26 | public interface WebSocketEmulatedDecoder { 27 | 28 | void decode(C channel, DecoderInput in, WebSocketEmulatedDecoderListener listener); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/wseb/WebSocketEmulatedDecoderListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.wseb; 23 | 24 | import org.kaazing.gateway.client.impl.DecoderListener; 25 | import org.kaazing.gateway.client.util.WrappedByteBuffer; 26 | 27 | //TODO: Create a Command abstraction instead of passing WrappedByteBuffer 28 | public interface WebSocketEmulatedDecoderListener extends DecoderListener { 29 | 30 | void commandDecoded(C channel, WrappedByteBuffer command); 31 | void pingReceived(C channel); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/wseb/WebSocketEmulatedEncoder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.wseb; 23 | 24 | import org.kaazing.gateway.client.impl.EncoderOutput; 25 | import org.kaazing.gateway.client.util.WrappedByteBuffer; 26 | 27 | public interface WebSocketEmulatedEncoder { 28 | 29 | void encodeTextMessage(C channel, String message, EncoderOutput out); 30 | void encodeBinaryMessage(C channel, WrappedByteBuffer message, EncoderOutput out); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/wsn/WebSocketNativeChannel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.wsn; 23 | 24 | import org.kaazing.gateway.client.impl.bridge.Proxy; 25 | import org.kaazing.gateway.client.impl.util.WSURI; 26 | import org.kaazing.gateway.client.impl.ws.WebSocketSelectedChannel; 27 | import org.kaazing.gateway.client.transport.ws.WebSocketDelegate; 28 | 29 | import java.util.concurrent.atomic.AtomicBoolean; 30 | import java.util.concurrent.atomic.AtomicInteger; 31 | 32 | public class WebSocketNativeChannel extends WebSocketSelectedChannel { 33 | 34 | /* Balancer attributes */ 35 | public WSURI redirectUri; 36 | public final AtomicInteger balanced = new AtomicInteger(0); 37 | public final AtomicBoolean reconnecting = new AtomicBoolean(false); 38 | public final AtomicBoolean reconnected = new AtomicBoolean(false); 39 | 40 | /* Bridge channel */ 41 | private Proxy proxy; 42 | private WebSocketDelegate delegate; 43 | 44 | public void setProxy(Proxy proxy) { 45 | this.proxy = proxy; 46 | } 47 | 48 | public Proxy getProxy() { 49 | return proxy; 50 | } 51 | 52 | public void setDelegate(WebSocketDelegate delegate) { 53 | this.delegate = delegate; 54 | } 55 | 56 | public WebSocketDelegate getDelegate() { 57 | return delegate; 58 | } 59 | 60 | public WebSocketNativeChannel(WSURI location) { 61 | super(location); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/impl/wsn/WebSocketNativeEncoder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.impl.wsn; 23 | 24 | import org.kaazing.gateway.client.impl.EncoderOutput; 25 | import org.kaazing.gateway.client.impl.WebSocketChannel; 26 | import org.kaazing.gateway.client.util.WrappedByteBuffer; 27 | 28 | public interface WebSocketNativeEncoder { 29 | 30 | void encodeTextMessage(WebSocketChannel channel, String message, EncoderOutput out); 31 | void encodeBinaryMessage(WebSocketChannel channel, WrappedByteBuffer message, EncoderOutput out); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/transport/AuthenticateEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.transport; 23 | 24 | import java.util.logging.Logger; 25 | 26 | public class AuthenticateEvent extends Event { 27 | private static final String CLASS_NAME = AuthenticateEvent.class.getName(); 28 | private static final Logger LOG = Logger.getLogger(CLASS_NAME); 29 | 30 | private String challenge; 31 | 32 | /** 33 | * Authenticate Event 34 | * 35 | * @param challenge 36 | */ 37 | public AuthenticateEvent(String challenge) { 38 | super(Event.AUTHENTICATE); 39 | LOG.entering(CLASS_NAME, "", new Object[] { type, challenge }); 40 | this.challenge = challenge; 41 | } 42 | 43 | public String getChallenge() { 44 | LOG.exiting(CLASS_NAME, "getLocation", challenge); 45 | return challenge; 46 | } 47 | 48 | public String toString() { 49 | StringBuilder ret = new StringBuilder("AuthenticateEvent [type=" + type + " challenge=" + challenge + "{"); 50 | for (Object a : params) { 51 | ret.append(a).append(" "); 52 | } 53 | return ret + "}]"; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/transport/BridgeDelegate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.transport; 23 | 24 | public interface BridgeDelegate { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/transport/CloseEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.transport; 23 | 24 | public class CloseEvent extends Event { 25 | 26 | private int code; 27 | private String reason; 28 | private boolean wasClean; 29 | private Exception exception; 30 | 31 | public CloseEvent(int code, boolean wasClean, String reason) { 32 | super(Event.CLOSED); 33 | this.code = code; 34 | this.wasClean = wasClean; 35 | this.reason = reason; 36 | } 37 | 38 | public CloseEvent(Exception exception) { 39 | super(Event.CLOSED); 40 | this.exception = exception; 41 | } 42 | 43 | public int getCode() { 44 | return code; 45 | } 46 | 47 | public boolean wasClean() { 48 | return wasClean; 49 | } 50 | 51 | public String getReason() { 52 | return reason; 53 | } 54 | 55 | public Exception getException() { 56 | return exception; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/transport/ErrorEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.transport; 23 | 24 | public class ErrorEvent extends Event { 25 | private Exception exception; 26 | 27 | public ErrorEvent() { 28 | super(Event.ERROR); 29 | } 30 | 31 | public ErrorEvent(Exception exception) { 32 | super(Event.ERROR); 33 | this.exception = exception; 34 | } 35 | 36 | public void setException(Exception exception) { 37 | this.exception = exception; 38 | } 39 | 40 | public Exception getException() { 41 | return exception; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/transport/Event.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.transport; 23 | 24 | /** 25 | * Class representing the HTML 5 DOM event 26 | */ 27 | public class Event { 28 | /** 29 | * WebSocket and ByteSocket Events 30 | */ 31 | public static final String MESSAGE = "message"; 32 | public static final String OPEN = "open"; 33 | public static final String CLOSED = "closed"; 34 | public static final String REDIRECT = "redirect"; 35 | public static final String AUTHENTICATE = "authenticate"; 36 | 37 | /** 38 | * EventSource Events use MESSAGE, OPEN from the list above 39 | */ 40 | public static final String ERROR = "error"; 41 | 42 | /** 43 | * HttpRequest Events use OPEN and ERROR from the list above 44 | */ 45 | public static final String READY_STATE_CHANGE = "readystatechange"; 46 | public static final String LOAD = "load"; 47 | public static final String ABORT = "abort"; 48 | public static final String PROGRESS = "progress"; 49 | 50 | private static final String[] EMPTY_PARAMS = {}; 51 | Object[] params; 52 | String type; 53 | 54 | public Event(String type) { 55 | this(type, EMPTY_PARAMS); 56 | } 57 | 58 | public Event(String type, Object[] params) { 59 | this.type = type; 60 | this.params = params; 61 | } 62 | 63 | public String getType() { 64 | return type; 65 | } 66 | 67 | public Object[] getParams() { 68 | return params; 69 | } 70 | 71 | public String toString() { 72 | StringBuilder ret = new StringBuilder("Event[type:" + type + "{"); 73 | for (Object a : params) { 74 | ret.append(a).append(" "); 75 | } 76 | return ret + "}]"; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/transport/IoBufferUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.transport; 23 | 24 | import java.nio.ByteBuffer; 25 | 26 | public class IoBufferUtil { 27 | 28 | public static ByteBuffer expandBuffer(ByteBuffer existingBuffer, int additionalRequired) { 29 | int pos = existingBuffer.position(); 30 | if ((pos + additionalRequired) > existingBuffer.limit()) { 31 | if ((pos + additionalRequired) < existingBuffer.capacity()) { 32 | existingBuffer.limit(pos + additionalRequired); 33 | } else { 34 | // reallocate the underlying byte buffer and keep the original buffer 35 | // intact. The resetting of the position is required because, one 36 | // could be in the middle of a read of an existing buffer, when they 37 | // decide to over write only few bytes but still keep the remaining 38 | // part of the buffer unchanged. 39 | int newCapacity = existingBuffer.capacity() + additionalRequired ; 40 | java.nio.ByteBuffer newBuffer = java.nio.ByteBuffer.allocate(newCapacity); 41 | existingBuffer.flip(); 42 | newBuffer.put(existingBuffer); 43 | return newBuffer; 44 | } 45 | } 46 | return existingBuffer; 47 | } 48 | 49 | public static boolean canAccomodate(ByteBuffer existingBuffer, int additionalLength) { 50 | return ((existingBuffer.position() + additionalLength) <= existingBuffer.limit()); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/transport/LoadEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.transport; 23 | 24 | import java.nio.ByteBuffer; 25 | import java.util.logging.Logger; 26 | 27 | public class LoadEvent extends Event { 28 | private static final String CLASS_NAME = LoadEvent.class.getName(); 29 | private static final Logger LOG = Logger.getLogger(CLASS_NAME); 30 | 31 | private ByteBuffer responseBuffer; 32 | 33 | public LoadEvent(ByteBuffer responseBuffer) { 34 | super(Event.LOAD); 35 | LOG.entering(CLASS_NAME, "", new Object[]{responseBuffer}); 36 | this.responseBuffer = responseBuffer; 37 | } 38 | 39 | public ByteBuffer getResponseBuffer() { 40 | return responseBuffer; 41 | } 42 | 43 | public String toString() { 44 | StringBuilder ret = new StringBuilder("LoadEvent [type=" + type + " responseBuffer=" + responseBuffer + "{"); 45 | for(Object a: params) { 46 | ret.append(a).append(" "); 47 | } 48 | return ret + "}]"; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/transport/OpenEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.transport; 23 | 24 | import java.util.logging.Logger; 25 | 26 | public class OpenEvent extends Event { 27 | private static final String CLASS_NAME = OpenEvent.class.getName(); 28 | private static final Logger LOG = Logger.getLogger(CLASS_NAME); 29 | 30 | private String protocol; 31 | 32 | public OpenEvent() { 33 | super(Event.OPEN); 34 | LOG.entering(CLASS_NAME, ""); 35 | } 36 | 37 | public OpenEvent(String protocol) { 38 | super(Event.OPEN); 39 | this.protocol = protocol; 40 | LOG.entering(CLASS_NAME, ""); 41 | } 42 | 43 | public String toString() { 44 | StringBuilder ret = new StringBuilder("OpenEvent [type=" + type + " + {"); 45 | for(Object a: params) { 46 | ret.append(a).append(" "); 47 | } 48 | return ret + "}]"; 49 | } 50 | 51 | /** 52 | * @return the protocol, if more than one protocols are defined, separated by comma 53 | */ 54 | public String getProtocol() { 55 | return protocol; 56 | } 57 | 58 | /** 59 | * @param protocol the protocol to set 60 | */ 61 | public void setProtocol(String protocol) { 62 | this.protocol = protocol; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/transport/ProgressEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.transport; 23 | 24 | import java.nio.ByteBuffer; 25 | import java.util.logging.Logger; 26 | 27 | 28 | public class ProgressEvent extends Event { 29 | private static final String CLASS_NAME = ProgressEvent.class.getName(); 30 | private static final Logger LOG = Logger.getLogger(CLASS_NAME); 31 | 32 | private int bytesTotal; 33 | private int bytesLoaded; 34 | private ByteBuffer payload; 35 | 36 | public ProgressEvent(ByteBuffer payload, int bytesLoaded, int bytesTotal) { 37 | super("progress"); 38 | LOG.entering(CLASS_NAME, "", new Object[]{payload, bytesLoaded, bytesTotal}); 39 | this.payload = payload; 40 | this.bytesLoaded = bytesLoaded; 41 | this.bytesTotal = bytesTotal; 42 | } 43 | 44 | public int getBytesTotal() { 45 | LOG.exiting(CLASS_NAME, "getBytesTotal", bytesTotal); 46 | return bytesTotal; 47 | } 48 | 49 | public int getBytesLoaded() { 50 | LOG.exiting(CLASS_NAME, "getBytesLoaded", bytesLoaded); 51 | return bytesLoaded; 52 | } 53 | 54 | public ByteBuffer getPayload() { 55 | LOG.exiting(CLASS_NAME, "getPayload", payload); 56 | return payload; 57 | } 58 | 59 | public String toString() { 60 | StringBuilder ret = new StringBuilder("ProgressEvent [type=" + type + " payload=" + payload + "{"); 61 | for(Object a: params) { 62 | ret.append(a).append(" "); 63 | } 64 | return ret + "}]"; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/transport/ReadyStateChangedEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.transport; 23 | 24 | public class ReadyStateChangedEvent extends Event { 25 | 26 | public ReadyStateChangedEvent(String[] params) { 27 | super(Event.READY_STATE_CHANGE, params); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/transport/RedirectEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.transport; 23 | 24 | import java.util.logging.Logger; 25 | 26 | public class RedirectEvent extends Event { 27 | private static final String CLASS_NAME = RedirectEvent.class.getName(); 28 | private static final Logger LOG = Logger.getLogger(CLASS_NAME); 29 | 30 | private String location; 31 | 32 | /** 33 | * Redirect Event 34 | * 35 | * @param location 36 | */ 37 | public RedirectEvent(String location) { 38 | super(Event.REDIRECT); 39 | LOG.entering(CLASS_NAME, "", new Object[]{type, location}); 40 | this.location = location; 41 | } 42 | 43 | public String getLocation() { 44 | LOG.exiting(CLASS_NAME, "getLocation", location); 45 | return location; 46 | } 47 | 48 | public String toString() { 49 | StringBuilder ret = new StringBuilder("RedirectEvent [type=" + type + " location=" + location + "{"); 50 | for (Object a : params) { 51 | ret.append(a).append(" "); 52 | } 53 | return ret + "}]"; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/transport/http/HttpRequestDelegate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.transport.http; 23 | 24 | import org.kaazing.gateway.client.transport.BridgeDelegate; 25 | 26 | import java.net.URL; 27 | import java.nio.ByteBuffer; 28 | 29 | public interface HttpRequestDelegate extends BridgeDelegate { 30 | 31 | void setRequestHeader(String header, String value); 32 | 33 | int getStatusCode(); 34 | String getResponseHeader(String headerLocation); 35 | ByteBuffer getResponseText(); 36 | 37 | void processOpen(String method, URL url, String origin, boolean async, long connectTimeout) throws Exception; 38 | void processSend(ByteBuffer content); 39 | void processAbort(); 40 | 41 | void setListener(HttpRequestDelegateListener listener); 42 | 43 | } -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/transport/http/HttpRequestDelegateFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.transport.http; 23 | 24 | public interface HttpRequestDelegateFactory { 25 | 26 | HttpRequestDelegate createHttpRequestDelegate(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/transport/http/HttpRequestDelegateListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.transport.http; 23 | 24 | import org.kaazing.gateway.client.transport.CloseEvent; 25 | import org.kaazing.gateway.client.transport.ErrorEvent; 26 | import org.kaazing.gateway.client.transport.LoadEvent; 27 | import org.kaazing.gateway.client.transport.OpenEvent; 28 | import org.kaazing.gateway.client.transport.ProgressEvent; 29 | import org.kaazing.gateway.client.transport.ReadyStateChangedEvent; 30 | 31 | public interface HttpRequestDelegateListener { 32 | 33 | void opened(OpenEvent event); 34 | void errorOccurred(ErrorEvent event); 35 | void readyStateChanged(ReadyStateChangedEvent event); 36 | void loaded(LoadEvent event); 37 | void progressed(ProgressEvent progressEvent); 38 | void closed(CloseEvent event); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/transport/ws/BridgeSocket.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.transport.ws; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | import java.io.OutputStream; 27 | import java.net.InetSocketAddress; 28 | import java.net.SocketException; 29 | 30 | interface BridgeSocket { 31 | 32 | void connect(InetSocketAddress inetSocketAddress, long timeout) throws IOException; 33 | InputStream getInputStream() throws IOException; 34 | OutputStream getOutputStream() throws IOException; 35 | void close() throws IOException; 36 | 37 | void setSoTimeout(int i) throws SocketException; 38 | void setKeepAlive(boolean b) throws SocketException; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/transport/ws/BridgeSocketFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.transport.ws; 23 | 24 | import java.io.IOException; 25 | 26 | interface BridgeSocketFactory { 27 | 28 | BridgeSocket createSocket(boolean secure) throws IOException; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/transport/ws/BridgeSocketImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.transport.ws; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | import java.io.OutputStream; 27 | import java.net.InetSocketAddress; 28 | import java.net.Socket; 29 | import java.net.SocketException; 30 | 31 | import javax.net.ssl.SSLSocketFactory; 32 | 33 | class BridgeSocketImpl implements BridgeSocket { 34 | 35 | boolean secure; 36 | Socket socket; 37 | 38 | BridgeSocketImpl(boolean secure) { 39 | this.secure = secure; 40 | } 41 | 42 | @Override 43 | public void connect(InetSocketAddress inetSocketAddress, long timeout) throws IOException { 44 | if (secure) { 45 | socket = SSLSocketFactory.getDefault().createSocket(); 46 | } 47 | else { 48 | socket = new Socket(); 49 | } 50 | 51 | 52 | assert(timeout >= 0); 53 | socket.connect(inetSocketAddress, (int)timeout); 54 | } 55 | 56 | @Override 57 | public void close() throws IOException { 58 | socket.close(); 59 | } 60 | 61 | @Override 62 | public InputStream getInputStream() throws IOException { 63 | return socket.getInputStream(); 64 | } 65 | 66 | @Override 67 | public OutputStream getOutputStream() throws IOException { 68 | return socket.getOutputStream(); 69 | } 70 | 71 | @Override 72 | public void setKeepAlive(boolean val) throws SocketException { 73 | socket.setKeepAlive(val); 74 | } 75 | 76 | @Override 77 | public void setSoTimeout(int timeout) throws SocketException { 78 | socket.setSoTimeout(timeout); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/transport/ws/FrameProcessorListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.transport.ws; 23 | 24 | import java.nio.ByteBuffer; 25 | 26 | interface FrameProcessorListener { 27 | 28 | void messageReceived(ByteBuffer buffer, String type); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/transport/ws/WebSocketDelegate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.transport.ws; 23 | 24 | import org.kaazing.gateway.client.transport.BridgeDelegate; 25 | 26 | import java.io.IOException; 27 | import java.nio.ByteBuffer; 28 | 29 | public interface WebSocketDelegate extends BridgeDelegate { 30 | 31 | void processOpen(); 32 | void processAuthorize(String string); 33 | void processDisconnect() throws IOException; 34 | void processDisconnect(short code, String reason) throws IOException; //add code and reason 35 | void processSend(ByteBuffer byteBuffer); 36 | void processSend(String text); //add this method to send text frame message 37 | 38 | void setListener(WebSocketDelegateListener listener); 39 | void setIdleTimeout(int timeout); //set WebSocket idle timeout in miliseconds 40 | } -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/transport/ws/WebSocketDelegateFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.transport.ws; 23 | 24 | import java.net.URI; 25 | 26 | public interface WebSocketDelegateFactory { 27 | 28 | WebSocketDelegate createWebSocketDelegate(URI xoaUrl, URI originUrl, String wsProtocol); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/transport/ws/WebSocketDelegateListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.transport.ws; 23 | 24 | import org.kaazing.gateway.client.transport.AuthenticateEvent; 25 | import org.kaazing.gateway.client.transport.CloseEvent; 26 | import org.kaazing.gateway.client.transport.ErrorEvent; 27 | import org.kaazing.gateway.client.transport.MessageEvent; 28 | import org.kaazing.gateway.client.transport.OpenEvent; 29 | import org.kaazing.gateway.client.transport.RedirectEvent; 30 | 31 | public interface WebSocketDelegateListener { 32 | 33 | void authenticationRequested(AuthenticateEvent authenticateEvent); 34 | void opened(OpenEvent event); 35 | void redirected(RedirectEvent redirectEvent); 36 | void messageReceived(MessageEvent messageEvent); 37 | void closed(CloseEvent event); 38 | void errorOccurred(ErrorEvent event); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/transport/ws/WsMessage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.transport.ws; 23 | 24 | import java.nio.ByteBuffer; 25 | import java.util.Arrays; 26 | 27 | public class WsMessage { 28 | 29 | public enum Kind { 30 | BINARY, TEXT, CLOSE, COMMAND, PING, PONG 31 | } 32 | 33 | private Kind kind; 34 | 35 | public Kind getKind() { 36 | return kind; 37 | } 38 | 39 | private final ByteBuffer buf; 40 | 41 | public WsMessage(ByteBuffer buf, Kind kind) { 42 | this.buf = buf; 43 | this.kind = kind; 44 | } 45 | 46 | public ByteBuffer getBytes() { 47 | return buf; 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return String.valueOf(getKind()) + 53 | ':' + 54 | ' ' + 55 | Arrays.toString(buf.array()); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/util/HttpURI.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.util; 23 | 24 | import java.net.URI; 25 | import java.net.URISyntaxException; 26 | 27 | 28 | /** 29 | * URI with guarantee to be a valid, non-null, http or https URI 30 | */ 31 | public class HttpURI extends GenericURI { 32 | 33 | @Override 34 | protected boolean isValidScheme(String scheme) { 35 | return "http".equals(scheme) || "https".equals(scheme); 36 | } 37 | 38 | public HttpURI(String location) throws URISyntaxException { 39 | this(new URI(location)); 40 | } 41 | 42 | HttpURI(URI uri) throws URISyntaxException { 43 | super(uri); 44 | } 45 | 46 | protected HttpURI duplicate(URI uri) { 47 | try { 48 | return new HttpURI(uri); 49 | } catch (URISyntaxException e) { 50 | throw new IllegalArgumentException(e); 51 | } 52 | } 53 | 54 | public boolean isSecure() { 55 | return "https".equals(uri.getScheme()); 56 | } 57 | 58 | public static HttpURI replaceScheme(GenericURI location, String scheme) throws URISyntaxException { 59 | return HttpURI.replaceScheme(location.getURI(), scheme); 60 | } 61 | 62 | public static HttpURI replaceScheme(URI location, String scheme) throws URISyntaxException { 63 | URI uri = URIUtils.replaceScheme(location, scheme); 64 | return new HttpURI(uri); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/util/URIUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.util; 23 | 24 | import java.net.URI; 25 | import java.net.URISyntaxException; 26 | 27 | public class URIUtils { 28 | 29 | public static URI replaceScheme(String location, String scheme) { 30 | try { 31 | return replaceScheme(new URI(location), scheme); 32 | } catch (URISyntaxException e) { 33 | throw new IllegalArgumentException("Invalid URI/Scheme: replacing scheme with "+scheme+" for "+location); 34 | } 35 | } 36 | 37 | public static URI replaceScheme(URI uri, String scheme) { 38 | try { 39 | String location = uri.toString(); 40 | int index = location.indexOf("://"); 41 | return new URI(scheme + location.substring(index)); 42 | } catch (URISyntaxException e) { 43 | throw new IllegalArgumentException("Invalid URI/Scheme: replacing scheme with "+scheme+" for "+uri); 44 | } 45 | } 46 | 47 | public static URI replacePath(URI uri, String path) { 48 | try { 49 | return new URI(uri.getScheme(), uri.getAuthority(), path, uri.getQuery(), uri.getFragment()); 50 | } catch (URISyntaxException e) { 51 | throw new IllegalArgumentException("Invalid URI/Scheme: replacing path with '"+path+"' for "+uri); 52 | } 53 | } 54 | 55 | public static URI replaceQueryParameters(URI uri, String queryParams) { 56 | try { 57 | return new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), queryParams, uri.getFragment()); 58 | } catch (URISyntaxException e) { 59 | throw new IllegalArgumentException("Invalid URI/Scheme: replacing query parameters with '"+queryParams+"' for "+uri); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/gateway/client/util/auth/LoginHandlerProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.gateway.client.util.auth; 23 | 24 | import org.kaazing.net.auth.LoginHandler; 25 | 26 | /** 27 | * An internal marker interface to mark implementations of challenge handlers 28 | * that may in fact provide access to Login Handlers. 29 | * 30 | */ 31 | public interface LoginHandlerProvider { 32 | 33 | /** 34 | * Get the login handler associated with this challenge handler. 35 | * A login handler is used to assist in obtaining credentials to respond to challenge requests. 36 | * 37 | * @return a login handler to assist in providing credentials, or {@code null} if none has been established yet. 38 | */ 39 | public LoginHandler getLoginHandler(); 40 | } 41 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/net/URLStreamHandlerFactorySpi.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | package org.kaazing.net; 22 | 23 | import java.net.URLStreamHandlerFactory; 24 | import java.util.Collection; 25 | 26 | /** 27 | * This a Service Provider Interface (SPI) class. Implementors 28 | * can create extensions of this class. At runtime, the extensions will be 29 | * instantiated using the {@link ServiceLoader} APIs using the META-INF/services 30 | * mechanism in the {@link URLFactory} implementation. 31 | *

32 | * {@link URLStreamHandlerFactory} is a singleton that is registered using the 33 | * static method 34 | * {@link URL#setURLStreamHandlerFactory(URLStreamHandlerFactory)}. Also, 35 | * the {@link URL} objects can only be created for the following protocols: 36 | * -- http, https, file, ftp, and jar. In order to install protocol handlers 37 | * for other protocols, one has to hijack or override the system's singleton 38 | * {@link URLStreamHandlerFactory} instance with a custom implementation. The 39 | * objective of this class is to make the {@link URLStreamHandler} registration 40 | * for other protocols such as ws, wss, etc. feasible without hijacking the 41 | * system's {@link URLStreamHandlerFactory}. 42 | *

43 | */ 44 | public abstract class URLStreamHandlerFactorySpi implements URLStreamHandlerFactory { 45 | 46 | /** 47 | * Returns a list of supported protocols. This can be used to instantiate 48 | * appropriate {@link URLStreamHandler} objects based on the protocol. 49 | * 50 | * @return list of supported protocols 51 | */ 52 | public abstract Collection getSupportedProtocols(); 53 | } 54 | 55 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/net/auth/LoginHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.net.auth; 23 | 24 | import java.net.PasswordAuthentication; 25 | 26 | /** 27 | * A login handler is responsible for obtaining credentials from an arbitrary 28 | * source. 29 | *

30 | * Login Handlers can be associated with one or more {@link ChallengeHandler} 31 | * objects, to ensure that when a Challenge Handler requires credentials for a {@link ChallengeResponse}, 32 | * the work is delegated to a {@link LoginHandler}. 33 | *

34 | * At client configuration time, a {@link LoginHandler} can be associated with a {@link ChallengeHandler} as follows: 35 | *

36 |  * {@code
37 |  *
38 |  * BasicChallengeHandler basicChallengeHandler = ChallengeHandlerLoader.load(BasicChallengeHandler.class);
39 |  * LoginHandler loginHandler = new LoginHandler() {
40 |  *    public PasswordAuthentication getCredentials() {
41 |  *        // Obtain credentials in an application-specific manner
42 |  *    }
43 |  * }
44 |  * basicChallengeHandler.setLoginHandler(loginHandler);
45 |  *    
46 |  * }
47 |  * 
48 | */ 49 | public abstract class LoginHandler { 50 | 51 | /** 52 | * Default constructor. 53 | */ 54 | protected LoginHandler() { 55 | } 56 | 57 | /** 58 | * Gets the password authentication credentials from an arbitrary source. 59 | * @return the password authentication obtained. 60 | */ 61 | public abstract PasswordAuthentication getCredentials(); 62 | 63 | } -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/net/impl/auth/BasicChallengeResponseFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.net.impl.auth; 23 | 24 | import org.kaazing.gateway.client.util.Base64Util; 25 | import org.kaazing.gateway.client.util.WrappedByteBuffer; 26 | import org.kaazing.net.auth.ChallengeHandler; 27 | import org.kaazing.net.auth.ChallengeResponse; 28 | 29 | import java.net.PasswordAuthentication; 30 | import java.util.Arrays; 31 | 32 | public class BasicChallengeResponseFactory { 33 | 34 | public static ChallengeResponse create(PasswordAuthentication creds, ChallengeHandler nextChallengeHandler) { 35 | String unencoded = String.format("%s:%s", creds.getUserName(), new String(creds.getPassword())); 36 | String response = String.format("Basic %s", Base64Util.encode(WrappedByteBuffer.wrap(unencoded.getBytes()))); 37 | Arrays.fill(creds.getPassword(), (char) 0); 38 | return new ChallengeResponse(response.toCharArray(), nextChallengeHandler); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/net/impl/auth/RealmUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.net.impl.auth; 23 | 24 | import org.kaazing.net.auth.ChallengeRequest; 25 | 26 | import java.util.regex.Matcher; 27 | import java.util.regex.Pattern; 28 | 29 | public final class RealmUtils { 30 | 31 | private RealmUtils() { 32 | // prevent object creation 33 | } 34 | 35 | private static final String REALM_REGEX = "(.*)\\s?(?i:realm=)(\"(.*)\")(.*)"; 36 | private static final Pattern REALM_PATTERN= Pattern.compile(REALM_REGEX); 37 | 38 | /** 39 | * A realm parameter is a valid authentication parameter for all authentication schemes 40 | * according to RFC 2617 Section 2.1". 41 | * 42 | * 43 | * The realm directive (case-insensitive) is required for all 44 | * authentication schemes that issue a challenge. The realm value 45 | * (case-sensitive), in combination with the canonical root URL (the 46 | * absoluteURI for the server whose abs_path is empty) of the server 47 | * being accessed, defines the protection space. 48 | * 49 | * 50 | * @param challengeRequest the challenge request to extract a realm from 51 | * 52 | * @return the unquoted realm parameter value if present, or {@code null} if no such parameter exists. 53 | */ 54 | public static String getRealm(ChallengeRequest challengeRequest) { 55 | String authenticationParameters = challengeRequest.getAuthenticationParameters(); 56 | if ( authenticationParameters == null) { 57 | return null; 58 | } 59 | Matcher m = REALM_PATTERN.matcher(authenticationParameters); 60 | if ( m.matches() && m.groupCount()>=3) { 61 | return m.group(3); 62 | } 63 | return null; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/net/sse/SseEventType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.net.sse; 23 | 24 | public enum SseEventType { 25 | EOS, EMPTY, DATA; 26 | } -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/net/sse/SseException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.net.sse; 23 | 24 | import java.io.IOException; 25 | 26 | public class SseException extends IOException { 27 | 28 | private static final long serialVersionUID = 1L; 29 | 30 | public SseException(String reason) { 31 | super(reason); 32 | } 33 | 34 | public SseException(Exception ex) { 35 | super(ex); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/net/sse/impl/AuthenticatedEventSourceFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Portions of this file copyright (c) 2007-2014 Kaazing Corporation. 3 | * All rights reserved. 4 | * 5 | * Licensed to the Apache Software Foundation (ASF) under one 6 | * or more contributor license agreements. See the NOTICE file 7 | * distributed with this work for additional information 8 | * regarding copyright ownership. The ASF licenses this file 9 | * to you under the Apache License, Version 2.0 (the 10 | * "License"); you may not use this file except in compliance 11 | * with the License. You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, 16 | * software distributed under the License is distributed on an 17 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 | * KIND, either express or implied. See the License for the 19 | * specific language governing permissions and limitations 20 | * under the License. 21 | */ 22 | 23 | package org.kaazing.net.sse.impl; 24 | 25 | import org.kaazing.net.sse.SseEventSource; 26 | 27 | import java.net.URI; 28 | import java.net.URISyntaxException; 29 | 30 | import io.particle.android.sdk.cloud.ParticleCloud; 31 | 32 | 33 | public class AuthenticatedEventSourceFactory extends DefaultEventSourceFactory { 34 | 35 | private final ParticleCloud cloud; 36 | 37 | public AuthenticatedEventSourceFactory(ParticleCloud cloud) { 38 | this.cloud = cloud; 39 | } 40 | 41 | @Override 42 | public SseEventSource createEventSource(URI location) throws URISyntaxException { 43 | 44 | String scheme = location.getScheme(); 45 | if (!scheme.toLowerCase().equals("sse") && 46 | !scheme.toLowerCase().equals("http") && 47 | !scheme.toLowerCase().equals("https")) { 48 | String s = String.format("Incorrect scheme or protocol '%s'", scheme); 49 | throw new URISyntaxException(location.toString(), s); 50 | } 51 | 52 | SseEventSourceImpl eventSource = new AuthenticatedSseEventSourceImpl(location, cloud); 53 | 54 | // Set up the defaults from the factory. 55 | eventSource.setFollowRedirect(getDefaultFollowRedirect()); 56 | eventSource.setRetryTimeout(getDefaultRetryTimeout()); 57 | 58 | return eventSource; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/net/sse/impl/SseEventStreamListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.net.sse.impl; 23 | 24 | public interface SseEventStreamListener { 25 | 26 | void streamOpened(); 27 | void messageReceived(String eventName, String data); 28 | void streamErrored(Exception exception); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/net/sse/impl/SsePayload.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.net.sse.impl; 23 | 24 | public class SsePayload { 25 | 26 | private String _eventName; 27 | private String _data; 28 | 29 | public SsePayload(String eventName, String data) { 30 | _eventName = eventName; 31 | _data = data; 32 | } 33 | 34 | public String getData() { 35 | return _data; 36 | } 37 | 38 | public String getEventName() { 39 | return _eventName; 40 | } 41 | 42 | public void setData(String data) { 43 | _data = data; 44 | } 45 | 46 | public void setEventName(String eventName) { 47 | if ((eventName == null) || (eventName.trim().length() == 0)) { 48 | eventName = "message"; 49 | } 50 | 51 | _eventName = eventName; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/net/sse/impl/legacy/EventSourceAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.net.sse.impl.legacy; 23 | 24 | 25 | /** 26 | * An adapter class for {@link EventSourceListener}. Use this as a base class to 27 | * override selected methods only. 28 | * 29 | */ 30 | public class EventSourceAdapter implements EventSourceListener { 31 | 32 | @Override 33 | public void onError(EventSourceEvent error) { 34 | 35 | } 36 | 37 | @Override 38 | public void onMessage(EventSourceEvent message) { 39 | 40 | } 41 | 42 | @Override 43 | public void onOpen(EventSourceEvent open) { 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/net/sse/impl/legacy/EventSourceEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.net.sse.impl.legacy; 23 | 24 | import java.util.EventObject; 25 | import java.util.logging.Logger; 26 | 27 | /** 28 | * This class represents events generated by the EventSource object 29 | * 30 | */ 31 | public class EventSourceEvent extends EventObject { 32 | private static final String CLASS_NAME = EventSourceEvent.class.getName(); 33 | private static final Logger LOG = Logger.getLogger(CLASS_NAME); 34 | 35 | private static final long serialVersionUID = -3654347840399311101L; 36 | private final Type type; 37 | private final String data; 38 | 39 | /** 40 | * Type of the EventSourceEvent. 41 | */ 42 | public enum Type { 43 | OPEN, MESSAGE, ERROR 44 | } 45 | 46 | /** 47 | * 48 | * @param source 49 | * @param type 50 | */ 51 | public EventSourceEvent(Object source, Type type) { 52 | this(source, type, null); 53 | } 54 | 55 | public EventSourceEvent(Object source, Type type, String message) { 56 | super(source); 57 | LOG.entering(CLASS_NAME, "", new Object[] { source, type, message }); 58 | this.type = type; 59 | this.data = message; 60 | } 61 | 62 | /** 63 | * Get type of the EventSourceEvent OPEN, MESSAGE or ERROR 64 | * 65 | * @return the EventSourceEvent type 66 | */ 67 | public Type getType() { 68 | LOG.exiting(CLASS_NAME, "getType", type); 69 | return type; 70 | } 71 | 72 | /** 73 | * Returns the message data delivered by the event source 74 | * 75 | * @return the message data 76 | */ 77 | public String getData() { 78 | LOG.exiting(CLASS_NAME, "getData", data); 79 | return data; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/net/sse/impl/legacy/EventSourceListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.net.sse.impl.legacy; 23 | 24 | import java.util.EventListener; 25 | 26 | /** 27 | * Interface for the listener listening to events on the EventSource object 28 | * 29 | */ 30 | public interface EventSourceListener extends EventListener{ 31 | 32 | /** 33 | * Called when the EventSource is opened 34 | * 35 | * @param open EventSourceEvent of type OPEN 36 | */ 37 | public void onOpen(EventSourceEvent open); 38 | 39 | /** 40 | * Called on the receipt of a message from the EventSource 41 | * 42 | * @param message EventSourceEvent of type MESSAGE 43 | */ 44 | public void onMessage(EventSourceEvent message); 45 | 46 | /** 47 | * Called on the receipt of an error from the EventSource 48 | * 49 | * @param error EventSourceEvent of type ERROR 50 | */ 51 | public void onError(EventSourceEvent error); 52 | 53 | } 54 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/net/sse/impl/url/SseURLStreamHandlerFactorySpiImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.net.sse.impl.url; 23 | 24 | import org.kaazing.net.URLStreamHandlerFactorySpi; 25 | 26 | import java.net.URLStreamHandler; 27 | import java.util.Collection; 28 | import java.util.Collections; 29 | 30 | import static java.util.Collections.unmodifiableList; 31 | 32 | public class SseURLStreamHandlerFactorySpiImpl extends URLStreamHandlerFactorySpi { 33 | private static final Collection _supportedProtocols = unmodifiableList(Collections.singletonList("sse")); 34 | 35 | @Override 36 | public URLStreamHandler createURLStreamHandler(String protocol) { 37 | if (!_supportedProtocols.contains(protocol)) { 38 | String s = String.format("Protocol not supported '%s'", protocol); 39 | throw new IllegalArgumentException(s); 40 | } 41 | 42 | return new SseURLStreamHandlerImpl(protocol); 43 | } 44 | 45 | @Override 46 | public Collection getSupportedProtocols() { 47 | return _supportedProtocols; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/net/ws/WebSocketMessageType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.net.ws; 23 | 24 | /** 25 | * {@link WebSocketMessageType} represents the types of the messages that are 26 | * received by the {@link WebSocketMessageReader}. WebSocketMessageType.EOS 27 | * represents end-of-stream. 28 | */ 29 | public enum WebSocketMessageType { 30 | EOS, TEXT, BINARY; 31 | } -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/net/ws/WebSocketMessageWriter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.net.ws; 23 | 24 | import java.io.IOException; 25 | import java.nio.ByteBuffer; 26 | 27 | /** 28 | * {@link WebSocketMessageWriter} is used to send binary and text messages. A 29 | * reference to {@link WebSocketMessageWriter} is obtained by invoking either 30 | * {@link WebSocket#getMessageWriter()} or 31 | * {@link WsURLConnection#getMessageWriter() methods after the connection has 32 | * been established. Trying to get a reference to {@link WebSocketMessageWriter} 33 | * before the connection is established will result in an IOException. 34 | *

35 | * Once the connection is closed, a new {@link WebSocketMessageReader} should 36 | * be obtained using the aforementioned methods after the connection has been 37 | * established. Using the old reader will result in IOException. 38 | */ 39 | public abstract class WebSocketMessageWriter { 40 | 41 | /** 42 | * Sends a text message using the specified payload. Trying to write 43 | * after the underlying connection has been closed will result in an 44 | * IOException. 45 | * 46 | * @param src CharSequence payload of the message 47 | * @throws IOException if the connection is not open or if the connection 48 | * has been closed 49 | */ 50 | public abstract void writeText(CharSequence src) throws IOException; 51 | 52 | /** 53 | * Sends a binary message using the specified payload. 54 | * 55 | * @param src ByteBuffer payload of the message 56 | * @throws IOException if the connection is not open or if the connection 57 | * has been closed 58 | */ 59 | public abstract void writeBinary(ByteBuffer src) throws IOException; 60 | } 61 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/net/ws/impl/WsExtensionParameterValuesSpiImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.net.ws.impl; 23 | 24 | import org.kaazing.net.ws.WebSocketExtension.Parameter; 25 | import org.kaazing.net.ws.impl.spi.WebSocketExtensionParameterValuesSpi; 26 | 27 | import java.util.Collection; 28 | import java.util.Collections; 29 | import java.util.HashMap; 30 | import java.util.Map; 31 | import java.util.Set; 32 | 33 | import static java.util.Collections.unmodifiableSet; 34 | 35 | public final class WsExtensionParameterValuesSpiImpl extends WebSocketExtensionParameterValuesSpi { 36 | 37 | private final Map, Object> values; 38 | 39 | WsExtensionParameterValuesSpiImpl() { 40 | values = new HashMap<>(); 41 | } 42 | 43 | @Override 44 | public Collection> getParameters() { 45 | if (values.isEmpty()) { 46 | return unmodifiableSet(Collections.>emptySet()); 47 | } 48 | 49 | Set> keys = values.keySet(); 50 | return unmodifiableSet(keys); 51 | } 52 | 53 | @Override 54 | public T getParameterValue(Parameter parameter) { 55 | return parameter.type().cast(values.get(parameter)); 56 | } 57 | 58 | public void setParameterValue(Parameter parameter, T value) { 59 | values.put(parameter, value); 60 | } 61 | 62 | // This is used to set value of a negotiated parameter. At that time, we 63 | // only have the string representation of the parameter. So, it's important 64 | // that negotiated parameters be of type String. 65 | public void setParameterValue(Parameter parameter, String value) { 66 | values.put(parameter, value); 67 | } 68 | } -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/net/ws/impl/io/WsMessageWriterImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.net.ws.impl.io; 23 | 24 | import org.kaazing.net.ws.WebSocketException; 25 | import org.kaazing.net.ws.WebSocketMessageWriter; 26 | import org.kaazing.net.ws.impl.WebSocketImpl; 27 | 28 | import java.io.IOException; 29 | import java.io.UnsupportedEncodingException; 30 | import java.nio.ByteBuffer; 31 | 32 | public class WsMessageWriterImpl extends WebSocketMessageWriter { 33 | private WebSocketImpl _webSocket; 34 | private boolean _closed = false; 35 | 36 | public WsMessageWriterImpl(WebSocketImpl webSocket) { 37 | _webSocket = webSocket; 38 | } 39 | 40 | @Override 41 | public void writeText(CharSequence src) throws IOException { 42 | if (isClosed()) { 43 | String s = "Cannot write as the MessageWriter is closed"; 44 | throw new WebSocketException(s); 45 | } 46 | try { 47 | src.toString().getBytes("UTF-8"); 48 | } 49 | catch (UnsupportedEncodingException e) { 50 | String s = "The platform must support UTF-8 encoded text per RFC 6455"; 51 | throw new IOException(s); 52 | } 53 | 54 | _webSocket.send(src.toString()); 55 | } 56 | 57 | @Override 58 | public void writeBinary(ByteBuffer src) throws IOException { 59 | if (isClosed()) { 60 | String s = "Cannot write as the MessageWriter is closed"; 61 | throw new WebSocketException(s); 62 | } 63 | 64 | _webSocket.send(src); 65 | } 66 | 67 | // ----------------- Internal Implementation ---------------------------- 68 | public void close() { 69 | _closed = true; 70 | _webSocket = null; 71 | } 72 | 73 | public boolean isClosed() { 74 | return _closed; 75 | } 76 | } -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/net/ws/impl/spi/WebSocketExtensionParameterValuesSpi.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.net.ws.impl.spi; 23 | 24 | import org.kaazing.net.ws.WebSocket; 25 | import org.kaazing.net.ws.WebSocketExtension.Parameter; 26 | import org.kaazing.net.ws.WsURLConnection; 27 | 28 | import java.util.Collection; 29 | 30 | /** 31 | * WsExtensionParameterValues is part of Service Provider Interface 32 | * (SPI) for admins/implementors. 33 | *

34 | * WsExtensionParameterValues is used to cache extension parameters as 35 | * name-value pairs in a very generic type-safe way. The implementations of 36 | * {@link WebSocket#connect()} and {@link WsURLConnection#connect()} invoke 37 | * {@link WebSocketExtensionFactorySpi#createWsExtension(WebSocketExtensionParameterValuesSpi)} 38 | * method and pass in all the extension parameters that have been earlier set 39 | * by the developer for the enabled extensions. 40 | */ 41 | public abstract class WebSocketExtensionParameterValuesSpi { 42 | /** 43 | * Returns the collection of {@link Parameter} objects of a 44 | * {@link WebSocketExtension} that have been set. Returns an empty 45 | * Collection if no parameters belonging to the extension have been set. 46 | * 47 | * @return Collection> 48 | */ 49 | public abstract Collection> getParameters(); 50 | 51 | /** 52 | * Returns the value of type T of the specified parameter. A null is 53 | * returned if value is not set. 54 | * 55 | * @param Generic type T of the parameter's value 56 | * @param parameter extension parameter 57 | * @return value of type T of the specified extension parameter 58 | */ 59 | public abstract T getParameterValue(Parameter parameter); 60 | } 61 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/net/ws/impl/spi/WebSocketExtensionSpi.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.net.ws.impl.spi; 23 | 24 | 25 | /** 26 | * WebSocketExtensionSpi is part of Service Provider Interface (SPI) 27 | * for admins/implementors. 28 | *

29 | * A WebSocket Extension implementation consists of the following: 30 | *

    31 | *
  • a sub-class of WebSocketExtensionFactorySpi 32 | *
  • a sub-class of WebSocketExtensionSpi 33 | *
  • a sub-class of WebSocketExtension with 34 | * {@link Parameter}s defined as constants 35 | *
36 | *

37 | * Every supported extension will require implementing the aforementioned 38 | * classes. A subset of the supported extensions will be enabled by the 39 | * application developer. 40 | *

41 | * The enabled extensions are included on the wire during the handshake for 42 | * the client and the server to negotiate. 43 | *

44 | * The successfully negotiated extensions are then added to the WebSocket 45 | * message processing pipeline. 46 | * 47 | * @see RevalidateExtension 48 | */ 49 | public abstract class WebSocketExtensionSpi { 50 | 51 | public abstract WebSocketExtensionHandlerSpi createHandler(); 52 | } 53 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/net/ws/impl/url/WssURLStreamHandlerFactorySpiImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.net.ws.impl.url; 23 | 24 | import java.net.URLStreamHandler; 25 | import java.util.Collection; 26 | 27 | import static java.util.Arrays.asList; 28 | import static java.util.Collections.unmodifiableList; 29 | 30 | public class WssURLStreamHandlerFactorySpiImpl extends WsURLStreamHandlerFactorySpiImpl { 31 | private static final Collection _supportedProtocols = unmodifiableList(asList("wss", "wse+ssl", "wssn")); 32 | 33 | @Override 34 | public URLStreamHandler createURLStreamHandler(String protocol) { 35 | if (!_supportedProtocols.contains(protocol)) { 36 | throw new IllegalArgumentException(String.format("Protocol not supported '%s'", protocol)); 37 | } 38 | 39 | return new WssURLStreamHandlerImpl(getExtensionFactories()); 40 | } 41 | 42 | @Override 43 | public Collection getSupportedProtocols() { 44 | return _supportedProtocols; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /cloudsdk/src/main/java/org/kaazing/net/ws/impl/url/WssURLStreamHandlerImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.kaazing.net.ws.impl.url; 23 | 24 | import org.kaazing.net.ws.impl.spi.WebSocketExtensionFactorySpi; 25 | 26 | import java.util.Map; 27 | 28 | public class WssURLStreamHandlerImpl extends WsURLStreamHandlerImpl { 29 | 30 | public WssURLStreamHandlerImpl( 31 | Map extensionFactories) { 32 | super(extensionFactories); 33 | } 34 | 35 | @Override 36 | protected int getDefaultPort() { 37 | return 443; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /cloudsdk/src/main/res/values/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | https://api.particle.io 5 | 6 | 12 | NONE 13 | 14 | 15 | -------------------------------------------------------------------------------- /cloudsdk/src/main/res/values/oauth_client_creds.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | spark-android-app-1234 7 | d34db33f164e458fdb8daffe48b4ffe9d34db33f 8 | 9 | -------------------------------------------------------------------------------- /cloudsdk/src/main/resources/META-INF/services/org.kaazing.net.URLStreamHandlerFactorySpi: -------------------------------------------------------------------------------- 1 | org.kaazing.net.ws.impl.url.WsURLStreamHandlerFactorySpiImpl 2 | org.kaazing.net.ws.impl.url.WssURLStreamHandlerFactorySpiImpl 3 | -------------------------------------------------------------------------------- /cloudsdk/src/main/resources/META-INF/services/org.kaazing.net.auth.BasicChallengeHandler: -------------------------------------------------------------------------------- 1 | org.kaazing.net.impl.auth.DefaultBasicChallengeHandler 2 | -------------------------------------------------------------------------------- /cloudsdk/src/main/resources/META-INF/services/org.kaazing.net.auth.DispatchChallengeHandler: -------------------------------------------------------------------------------- 1 | org.kaazing.net.impl.auth.DefaultDispatchChallengeHandler 2 | -------------------------------------------------------------------------------- /cloudsdk/src/main/resources/META-INF/services/org.kaazing.net.sse.SseEventSourceFactory: -------------------------------------------------------------------------------- 1 | org.kaazing.net.sse.impl.DefaultEventSourceFactory -------------------------------------------------------------------------------- /cloudsdk/src/main/resources/META-INF/services/org.kaazing.net.ws.WebSocketFactory: -------------------------------------------------------------------------------- 1 | org.kaazing.net.ws.impl.DefaultWebSocketFactory -------------------------------------------------------------------------------- /example_app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 27 5 | 6 | defaultConfig { 7 | applicationId "io.particle.cloudsdk.example_app" 8 | minSdkVersion 16 9 | targetSdkVersion 27 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | 21 | compileOptions { 22 | sourceCompatibility JavaVersion.VERSION_1_8 23 | targetCompatibility JavaVersion.VERSION_1_8 24 | } 25 | 26 | } 27 | 28 | dependencies { 29 | implementation fileTree(dir: 'libs', include: ['*.jar']) 30 | 31 | // BY DEFAULT, BUILD APP AGAINST THE LOCAL SDK SOURCE 32 | // (i.e.: make modifications to the SDK source in the local repo show up in this app 33 | // just by rebuilding) 34 | implementation project(':cloudsdk') 35 | // 36 | // **OR** 37 | // 38 | // comment out the above, and 39 | // UNCOMMENT THE FOLLOWING TO USE A PUBLISHED VERSION OF THE SDK: 40 | // implementation 'io.particle:cloudsdk:0.3.3' 41 | 42 | implementation 'com.android.support:appcompat-v7:27.1.1' 43 | implementation 'com.android.support:support-fragment:27.1.1' 44 | } 45 | -------------------------------------------------------------------------------- /example_app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/ido/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /example_app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 26 | 27 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /example_app/src/main/java/io/particle/cloudsdk/example_app/SplashActivity.java: -------------------------------------------------------------------------------- 1 | package io.particle.cloudsdk.example_app; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.Menu; 7 | import android.view.MenuItem; 8 | 9 | 10 | public class SplashActivity extends AppCompatActivity { 11 | 12 | @Override 13 | protected void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | setContentView(R.layout.activity_splash); 16 | } 17 | 18 | @Override 19 | public boolean onCreateOptionsMenu(Menu menu) { 20 | // Inflate the menu; this adds items to the action bar if it is present. 21 | getMenuInflater().inflate(R.menu.menu_splash, menu); 22 | return true; 23 | } 24 | 25 | 26 | @Override 27 | public boolean onOptionsItemSelected(MenuItem item) { 28 | // Handle action bar item clicks here. The action bar will 29 | // automatically handle clicks on the Home/Up button, so long 30 | // as you specify a parent activity in AndroidManifest.xml. 31 | int id = item.getItemId(); 32 | 33 | //noinspection SimplifiableIfStatement 34 | if (id == R.id.action_login) { 35 | Intent intent = new Intent(this, LoginActivity.class); 36 | startActivity(intent); 37 | finish(); 38 | 39 | return true; 40 | } 41 | 42 | return super.onOptionsItemSelected(item); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /example_app/src/main/res/layout/activity_login.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 19 | 20 | 23 | 24 | 25 | 26 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 47 | 48 | 54 | 55 | 61 | 62 | 63 | 64 | 65 | 66 |