pl.mbdev.openstage.push
Class Push

java.lang.Object
  extended by pl.mbdev.openstage.push.HttpRequest
      extended by pl.mbdev.openstage.push.PostRequest
          extended by pl.mbdev.openstage.push.Push

public class Push
extends PostRequest

Push capability of the OpenStage phone can be utilised with use of this class. Push enables remote launching of the application that was previously defined in the XML Applications list of a given OpenStage phone.

 Copyright 2011 Mateusz Bysiek,
     mb@mbdev.pl, http://mbdev.pl/
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 
     http://www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 

Author:
Mateusz Bysiek

Nested Class Summary
static class Push.RequestType
          Type of the push request that will be sent to the OpenStage phone.
 
Field Summary
private  java.net.URL appAddr
          Full URL to the application at the remote server.
static java.lang.String PHONE_PORT
          Default port at which the OpenStage phone listens for push requests.
static java.lang.String PHONE_PUSH_SCRIPT
          Default location at which the push-response application can be found in the OpenStage device.
 
Fields inherited from class pl.mbdev.openstage.push.HttpRequest
out
 
Constructor Summary
Push(java.lang.String serverAddress, int serverPort, java.lang.String programName, Push.RequestType requestType, java.lang.String midletName, java.lang.String serverProtocol, java.lang.String serverContextKey, java.lang.String serverContextValue)
          Constructs new definition of push, in which all parameters are set directly.
Push(java.lang.String applicationAddress, java.lang.String midletName, Push.RequestType requestType, java.lang.String serverContextKey, java.lang.String serverContextValue)
          Creates a new push request, with quite convenient way of passing the arguments.
Push(java.net.URL appAddr, java.lang.String midletName, Push.RequestType requestType, java.lang.String serverContextKey, java.lang.String serverContextValue)
          Creates a new push request, with the most convenient way of passing the arguments.
 
Method Summary
 java.net.URL getAppAddr()
          Returns the full address to the application at the remote server.
protected  java.lang.String getResponse(java.lang.String phoneIP)
          Sends the push request to the given OpenStage phone and reads the response.
 boolean sendTo(java.lang.String phoneIP)
          Sends the push request to the given OpenStage phone.
 
Methods inherited from class pl.mbdev.openstage.push.PostRequest
getResponse, sendTo
 
Methods inherited from class pl.mbdev.openstage.push.HttpRequest
connectTo, disconnect, endInput, endOutput, getParameters, startInput, startOutput
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PHONE_PORT

public static final java.lang.String PHONE_PORT
Default port at which the OpenStage phone listens for push requests.

See Also:
Constant Field Values

PHONE_PUSH_SCRIPT

public static final java.lang.String PHONE_PUSH_SCRIPT
Default location at which the push-response application can be found in the OpenStage device.

See Also:
Constant Field Values

appAddr

private final java.net.URL appAddr
Full URL to the application at the remote server.

Constructor Detail

Push

public Push(java.lang.String serverAddress,
            int serverPort,
            java.lang.String programName,
            Push.RequestType requestType,
            java.lang.String midletName,
            java.lang.String serverProtocol,
            java.lang.String serverContextKey,
            java.lang.String serverContextValue)
     throws java.net.MalformedURLException
Constructs new definition of push, in which all parameters are set directly.

Parameters:
serverAddress - IP address or domain, without port number
serverPort - port number
programName - path on the server that leads to the XML application
requestType - type of the request, value from Push.RequestType
midletName - program name, as defined in the OpenStage device
serverProtocol - protocol used by the serever, usually 'http' or 'https'
serverContextKey - key from key-value pair, which is sent back from the phone to the application in the response to the push request
serverContextValue - value from key-value pair, which is sent back from the phone to the application in the response to the push request
Throws:
java.net.MalformedURLException - when given parameters do not describe a correct URL

Push

public Push(java.lang.String applicationAddress,
            java.lang.String midletName,
            Push.RequestType requestType,
            java.lang.String serverContextKey,
            java.lang.String serverContextValue)
     throws java.net.MalformedURLException
Creates a new push request, with quite convenient way of passing the arguments.

Parameters:
applicationAddress - full address of the application on the remote server
midletName - program name, as defined in the OpenStage device
requestType - type of the request, value from Push.RequestType
serverContextKey - key from key-value pair, which is sent back from the phone to the application in the response to the push request
serverContextValue - value from key-value pair, which is sent back from the phone to the application in the response to the push request
Throws:
java.net.MalformedURLException - when given address does not describe a correct URL

Push

public Push(java.net.URL appAddr,
            java.lang.String midletName,
            Push.RequestType requestType,
            java.lang.String serverContextKey,
            java.lang.String serverContextValue)
Creates a new push request, with the most convenient way of passing the arguments.

Parameters:
appAddr - full URL of the application on the remote server
midletName - program name, as defined in the OpenStage device
requestType - type of the request, value from Push.RequestType
serverContextKey - key from key-value pair, which is sent back from the phone to the application in the response to the push request
serverContextValue - value from key-value pair, which is sent back from the phone to the application in the response to the push request
Method Detail

getAppAddr

public java.net.URL getAppAddr()
Returns the full address to the application at the remote server.

Returns:
full address to the application at the remote server

getResponse

protected java.lang.String getResponse(java.lang.String phoneIP)
                                throws java.net.MalformedURLException,
                                       java.io.IOException
Sends the push request to the given OpenStage phone and reads the response.

Parameters:
phoneIP - IP address of the OpenStage phone that will be pushed
Returns:
response of the phone
Throws:
java.io.IOException - thrown when the given URL caused a connection error, there was a protocol exception or data transfer was interrupted
java.net.MalformedURLException - when the provided phone IP is not a valid IP

sendTo

public boolean sendTo(java.lang.String phoneIP)
Sends the push request to the given OpenStage phone.

Parameters:
phoneIP - IP address of the OpenStage phone that will be pushed
Returns:
true if the push request was sent successfully