javax.microedition.io.ConnectionNotFoundException Java Examples

The following examples show how to use javax.microedition.io.ConnectionNotFoundException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommentsView.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a Link item to be shown as the topmost item in the view.
 *
 * Tapping on the link will prompt to open the link URL in the
 * platform browser.
 *
 * @return Link item
 */
private LinkItem createLinkItem() {
    // A listener to invoke whenever the link gets selected; either by
    // direct touch selection or by the selection command
    final LinkSelectionListener selectionListener = new LinkSelectionListener() {
        public void linkSelected(LinkThing link) {
            try {
                Main.getInstance().platformRequest(link.getUrl());
            }
            catch (ConnectionNotFoundException ex) {
                System.out.println("Connection not found: " + ex.getMessage());
            }
        }
    };
    linkItem = new LinkItem(link, getWidth(), true, selectionListener, null, this);

    return linkItem;
}
 
Example #2
Source File: Protocol.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets up the state of the connection, but
 * does not actually connect to the server until there's something
 * to do.
 *
 * @param theUrl           URL object
 * @param mode             The access mode, ignored
 *                         timeout exceptions, ignored
 *
 * @return reference to this connection
 *
 * @exception IllegalArgumentException If a parameter is invalid.
 * @exception ConnectionNotFoundException If the connection cannot be
 *             found.
 * @exception IOException  If some other kind of I/O error occurs.
 */
private Connection open(HttpUrl theUrl, int mode)
    throws IOException, IllegalArgumentException,
    ConnectionNotFoundException {

    url = theUrl;

    initStreamConnection(mode);

    if (url.port == -1) {
        url.port = default_port;
    }

    if (url.host == null) {
        throw new IllegalArgumentException("missing host in URL");
    }

    hostAndPort = url.host + ":" + url.port;

    return this;
}
 
Example #3
Source File: AddContactTest.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
public void test(TestHarness th) {
    try {
        MIDletPeer midletPeer = new MIDletPeer();

        midletPeer.platformRequest("x-contacts:add?number=3393333333");
        th.check(hasNumber());
        th.check(getNumber(), "3393333333");

        midletPeer.platformRequest("x-contacts:add?");
        th.check(!hasNumber());
    } catch (ConnectionNotFoundException e) {
        th.fail("Unexpected exception: " + e);
    }
}
 
Example #4
Source File: MIDlet.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
public boolean platformRequest(String url)
		throws ConnectionNotFoundException {
	try {
		ContextHolder.getAppContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
	} catch (ActivityNotFoundException e) {
		throw new ConnectionNotFoundException();
	}

	return true;
}
 
Example #5
Source File: TestMIDletPeer.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
public void startApp() {
    try {
        platformRequest("http://localhost:8000/tests/test.html");
    } catch (ConnectionNotFoundException e) {
        e.printStackTrace();
        System.out.println("FAIL");
    }
}
 
Example #6
Source File: GameCanvasImplementation.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @inheritDoc
 */
public void execute(String url) {
    try {
        mid.platformRequest(url);
    } catch (ConnectionNotFoundException ex) {
        ex.printStackTrace();
    }
}
 
Example #7
Source File: AMIDletUpdater.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
public void startApp() {
    try {
        platformRequest("http://localhost:8000/tests/Manifest1Updated.jad");
    } catch (ConnectionNotFoundException e) {
        e.printStackTrace();
        System.out.println("FAIL");
    }
    Isolate.currentIsolate().exit(0);
}
 
Example #8
Source File: ProtocolPushImpl.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called when registration is established.
 * @param midletSuite MIDlet suite for the suite registering,
 *                   the suite only has to implement isRegistered,
 *                   checkForPermission, and getID.
 * @param connection generic connection <em>protocol</em>, <em>host</em>
 *               and <em>port number</em>
 *               (optional parameters may be included
 *               separated with semi-colons (;))
 * @param midlet  class name of the <code>MIDlet</code> to be launched,
 *               when new external data is available
 * @param filter a connection URL string indicating which senders
 *               are allowed to cause the MIDlet to be launched
 * @exception  IllegalArgumentException if the connection string is not
 *               valid
 * @exception IOException if the connection is already
 *              registered or if there are insufficient resources
 *              to handle the registration request
 * @exception ClassNotFoundException if the <code>MIDlet</code> class
 *               name can not be found in the current
 *               <code>MIDlet</code> suite
 */
public void registerConnection(MIDletSuite midletSuite, String connection, 
    String midlet, String filter) 
    throws IllegalArgumentException, IOException, ClassNotFoundException {

    checkIsNotHost(connection, true);

    /*
     * Attempt to open the connection to perform security check
     * int the context of the current MIDlet suite.
     */
    try {
        Class.forName(
            "com.sun.midp.io.j2me.serversocket.Socket");
    } catch (ClassNotFoundException e) {
        throw new ConnectionNotFoundException(
            "Connection not supported");
    }

    try {
        midletSuite.checkForPermission("javax.microedition.io.Connector.serversocket",
                                        connection);
    } catch (InterruptedException ie) {
        throw new InterruptedIOException(
            "Interrupted while trying to ask the user permission");
    }
}
 
Example #9
Source File: ProtocolPush.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check if host is not present.
 * @param connection generic connection <em>protocol</em>, <em>host</em>
 *               and <em>port number</em>
 *               (optional parameters may be included
 *               separated with semi-colons (;))
 * @param checkPort check if the port is not omitted
 * @exception  IllegalArgumentException if the connection contains no port
 *               value
 * @exception ConnectionNotFoundException if connection contains any host
 *               name
 */
protected void checkIsNotHost(String connection, boolean checkPort) 
    throws IllegalArgumentException, ConnectionNotFoundException {
    HttpUrl url = new HttpUrl(connection);
    // Server connections do not have a host
    if (url.host != null) {
        throw new ConnectionNotFoundException(
            "Connection not supported");
    }

    if (checkPort && url.port == -1) {
        throw new IllegalArgumentException("Port missing");
    }
}
 
Example #10
Source File: PushRegistryImpl.java    From pluotsorbet with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Register a dynamic connection with the
 * application management software. Once registered,
 * the dynamic connection acts just like a
 * connection preallocated from the descriptor file.
 * The internal implementation includes the storage name
 * that uniquely identifies the <code>MIDlet</code>.
 *
 * @param connection generic connection <em>protocol</em>, <em>host</em>
 *               and <em>port number</em>
 *               (optional parameters may be included
 *               separated with semi-colons (;))
 * @param midlet  class name of the <code>MIDlet</code> to be launched,
 *               when new external data is available
 * @param filter a connection URL string indicating which senders
 *               are allowed to cause the MIDlet to be launched
 *
 * @exception  IllegalArgumentException if the connection string is not
 *               valid
 * @exception ConnectionNotFoundException if the runtime system does not
 *              support push delivery for the requested
 *              connection protocol
 * @exception IOException if the connection is already
 *              registered or if there are insufficient resources
 *              to handle the registration request
 * @exception ClassNotFoundException if the <code>MIDlet</code> class
 *               name can not be found in the current
 *               <code>MIDlet</code> suite
 * @exception SecurityException if the <code>MIDlet</code> does not
 *              have permission to register a connection
 * @exception IllegalStateException if the MIDlet suite context is
 *              <code>null</code>.
 * @see #unregisterConnection
 */
public static void registerConnection(
        final String connection,
        final String midlet,
        final String filter)
        throws ClassNotFoundException,
            ConnectionNotFoundException, IOException {
    // Quick check of connection to be spec complaint
    if (connection == null) {
        throw new IllegalArgumentException("connection is null");
    }

    // Quick check of filter to be spec complaint
    if (filter == null) {
        throw new IllegalArgumentException("filter is null");
    }

    final MIDletSuite midletSuite = getMIDletSuite();

    /* This method should only be called by running MIDlets. */
    if (midletSuite == null) {
        throw new IllegalStateException("Not in a MIDlet context");
    }

    /*
     * Validate parameters and Push connection availability
     */
    checkMidlet(midletSuite, midlet);
    /*
     * Check permissions.
     */
    try {
        AccessController.
            checkPermission(PUSH_PERMISSION_NAME);
    } catch (InterruptedSecurityException ise) {
        throw new InterruptedIOException(
            "Interrupted while trying to ask the user permission");
    }

    ConnectionRegistry.registerConnection(
            midletSuite, connection, midlet, filter);
}
 
Example #11
Source File: PushRegistryImpl.java    From pluotsorbet with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Register a time to launch the specified application. The
 * <code>PushRegistry</code> supports one outstanding wake up
 * time per <code>MIDlet</code> in the current suite. An application
 * is expected to use a <code>TimerTask</code> for notification
 * of time based events while the application is running.
 * <P>If a wakeup time is already registered, the previous value will
 * be returned, otherwise a zero is returned the first time the
 * alarm is registered. </P>
 *
 * @param midlet  class name of the <code>MIDlet</code> within the
 *                current running <code>MIDlet</code> suite
 *                to be launched,
 *                when the alarm time has been reached
 * @param time time at which the <code>MIDlet</code> is to be executed
 *        in the format returned by <code>Date.getTime()</code>
 * @return the time at which the most recent execution of this
 *        <code>MIDlet</code> was scheduled to occur,
 *        in the format returned by <code>Date.getTime()</code>
 * @exception ConnectionNotFoundException if the runtime system does not
 *              support alarm based application launch
 * @exception ClassNotFoundException if the <code>MIDlet</code> class
 *              name can not be found in the current
 *              <code>MIDlet</code> suite
 * @see Date#getTime()
 * @see Timer
 * @see TimerTask
 */
public static long registerAlarm(
        final String midlet,
        final long time)
        throws ClassNotFoundException, ConnectionNotFoundException {

    final MIDletSuite midletSuite = getMIDletSuite();
    if (midletSuite == null) {
        throw new IllegalStateException("Not in a MIDlet context");
    }

    checkMidlet(midletSuite, midlet);

    AccessController.checkPermission(PUSH_PERMISSION_NAME);

    return ConnectionRegistry.registerAlarm(midletSuite, midlet, time);
}
 
Example #12
Source File: PushRegistryImpl.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
public long registerAlarm(String midlet, long time) throws ClassNotFoundException, ConnectionNotFoundException {
	// TODO Auto-generated method stub
	throw new ConnectionNotFoundException();
}
 
Example #13
Source File: Protocol.java    From pluotsorbet with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Connect to a server.
 * @exception  IOException  if an I/O error occurs.
 * @exception  ConnectionNotFoundException  if the host cannot be connected
 *              to
 * @exception  IllegalStateException  if there is no hostname
 * @exception  IllegalArgumentException  if the name is malformed
 */
private void connect() throws IOException {

    byte[] szHost;
    byte[] szIpBytes = null;
    int result;
    // Max length of IPv4 address is 4  
    // IMPL NOTE: IPv6 needs to have an address of length =16

    if (handle != -1) {
        // This method should only be called once.
        // IMPL NOTE: should use something other than handle for this check
        throw new RuntimeException("Illegal state for operation");
    }

    /*
     * The host and port were set by overriding the openPrim method of
     * our super class.
     */

    if (port < 0) {
        throw new IllegalArgumentException("Missing port number");
    }

    result = getIpNumber0(host, ipBytes);
    if (result == -1) {
        throw new
            ConnectionNotFoundException("Could not resolve hostname");
    }

    /*
     * JTWI security check, untrusted MIDlets cannot open port 80 or
     * 8080 or 443. This is so they cannot perform HTTP and HTTPS
     * requests on server without using the system code. The
     * system HTTP code will add a "UNTRUSTED/1.0" to the user agent
     * field for untrusted MIDlets.
     */
    if (!ownerTrusted && (port == 80 || port == 8080 || port == 443)) {
        throw new SecurityException(
            "Target port denied to untrusted applications");
    }

    open0(ipBytes, port);

    NetworkSubsystem.getInstance(classSecurityToken).
            registerSubsystem(this);
}
 
Example #14
Source File: Protocol.java    From pluotsorbet with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Open a client or server socket connection.
 * <p>
 * The name string for this protocol should be:
 * "socket://&lt;name or IP number&gt;:&lt;port number&gt;
 * <p>
 * We allow "socket://:nnnn" to mean an inbound server socket connection.
 *
 * @param token      security token of the calling class
 * @param name       the target for the connection
 * @param mode       I/O access mode
 *
 * @return client or server TCP socket connection
 *
 * @exception  IOException  if an I/O error occurs.
 * @exception  ConnectionNotFoundException  if the host cannot be connected
 *              to
 * @exception  IllegalArgumentException  if the name is malformed
 */
private Connection open(SecurityToken token, String name, int mode)
        throws IOException {
    HttpUrl url;
    ServerSocket serverSocket;

    if (name.charAt(0) != '/' || name.charAt(1) != '/') {
        throw new IllegalArgumentException(
                  "Protocol must start with \"//\"");
    }

    url = new HttpUrl("socket", name); // parse name into host and port

    /*
     * Since we reused the HttpUrl parser, we must make sure that
     * there was nothing past the authority in the URL.
     */
    if (url.path != null || url.query != null || url.fragment != null) {
        throw new IllegalArgumentException("Malformed address");
    }

    NetworkSubsystem.getInstance(classSecurityToken).ensureActive();

    host = url.host;
    port = url.port;
    
    /*
     * If 'host' == null then we are a server endpoint at
     * port 'port'.
     */

    if (host != null) {
        checkForPermission(name, token);
        initStreamConnection(mode);

        // this will call the connect method which uses the host and port
        connect();
        return this;
    }

    // We allow "socket://:nnnn" to mean an inbound TCP server socket.
    try {
        serverSocket = (ServerSocket)Class.forName(
              "com.sun.midp.io.j2me.serversocket.Socket").newInstance();
    } catch (Exception e) {
        throw new ConnectionNotFoundException("Connection not supported");
    }
        
    serverSocket.open(port, token);
    return (Connection)serverSocket;
}
 
Example #15
Source File: ConnectorServiceImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Connection open(String uri, int mode, boolean timeouts)
  throws IOException
{
  if (mode != Connector.READ &&
      mode != Connector.WRITE &&
      mode != Connector.READ_WRITE)
    throw new IllegalArgumentException("Variable mode has an invalid value");

  if (null==uri || uri.length()==0)
    throw new IllegalArgumentException("URI must not be null or empty");

  int schemeSeparator = uri.indexOf(':');

  if (schemeSeparator < 0) {
    throw new IllegalArgumentException("Not a valid URI");
  }

  String scheme = uri.substring(0, schemeSeparator);

  ConnectionFactory factory = getFactory(scheme);
  Connection retval = null;

  if (factory != null) {
    retval = factory.createConnection(uri, mode, timeouts);

  } else {

    // fall back to Connector.
    try {
      retval = Connector.open(uri, mode, timeouts);
    } catch (Exception e) {
      throw new ConnectionNotFoundException();
    }

  }

  if (retval == null)
    throw new ConnectionNotFoundException();
  else
    return retval;
}
 
Example #16
Source File: ConnectionRegistry.java    From pluotsorbet with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Register a time to launch the specified application. The
 * <code>PushRegistry</code> supports one outstanding wake up
 * time per <code>MIDlet</code> in the current suite. An application
 * is expected to use a <code>TimerTask</code> for notification
 * of time based events while the application is running.
 * <P>If a wakeup time is already registered, the previous value will
 * be returned, otherwise a zero is returned the first time the
 * alarm is registered. </P>
 *
 * @param midletSuite <code>MIDlet</code> suite to register alarm for
 * @param midlet  class name of the <code>MIDlet</code> within the
 *                current running <code>MIDlet</code> suite
 *                to be launched,
 *                when the alarm time has been reached
 * @param time time at which the <code>MIDlet</code> is to be executed
 *        in the format returned by <code>Date.getTime()</code>
 * @return the time at which the most recent execution of this
 *        <code>MIDlet</code> was scheduled to occur,
 *        in the format returned by <code>Date.getTime()</code>
 * @exception ConnectionNotFoundException if the runtime system does not
 *              support alarm based application launch
 */
public static long registerAlarm(MIDletSuite midletSuite,
        String midlet, long time)
        throws ConnectionNotFoundException {

    byte[] asciiName = Util.toCString(midlet + ","
              + time + ","
              + suiteIdToString(midletSuite));
    return addAlarm0(asciiName, time);
}
 
Example #17
Source File: Protocol.java    From pluotsorbet with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets up the state of the connection, but
 * does not actually connect to the server until there's something
 * to do. This is method by system classes.
 *
 * @param token Token with the HTTP permission set to the allowed level
 * @param fullUrl   Full URL of the connection
 *
 * @return reference to this connection
 *
 * @exception IllegalArgumentException If a parameter is invalid.
 * @exception ConnectionNotFoundException If the connection cannot be
 *             found.
 * @exception IOException  If some other kind of I/O error occurs.
 */
public Connection openPrim(SecurityToken token, String fullUrl)
        throws IOException, IllegalArgumentException,
        ConnectionNotFoundException {

    checkIfPermissionAllowed(token);
    return open(new HttpUrl(fullUrl), Connector.READ_WRITE);
}
 
Example #18
Source File: Protocol.java    From pluotsorbet with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets up the state of the connection, but
 * does not actually connect to the server until there's something
 * to do.
 *
 * @param name             The URL for the connection, without the
 *                         without the protocol part.
 * @param mode             The access mode, ignored
 * @param timeouts         A flag to indicate that the called wants
 *                         timeout exceptions, ignored
 *
 * @return reference to this connection
 *
 * @exception IllegalArgumentException If a parameter is invalid.
 * @exception ConnectionNotFoundException If the connection cannot be
 *             found.
 * @exception IOException  If some other kind of I/O error occurs.
 */
public Connection openPrim(String name, int mode, boolean timeouts)
        throws IOException, IllegalArgumentException,
        ConnectionNotFoundException {

    checkForPermission(name);
    return open(new HttpUrl(protocol, name), mode);
}
 
Example #19
Source File: ConnectionRegistry.java    From pluotsorbet with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Check the registration arguments.
 * @param connection preparsed connection to check
 * @param midlet  class name of the <code>MIDlet</code> to be launched,
 *               when new external data is available
 * @param filter a connection URL string indicating which senders
 *               are allowed to cause the MIDlet to be launched
 * @exception  IllegalArgumentException if connection or filter is not
 *               valid
 * @exception ConnectionNotFoundException if PushRegistry doesn't support
 *               this kind of connections
 */
static void checkRegistration(String connection, String midlet,
                              String filter)
                              throws ConnectionNotFoundException {
    ProtocolPush.getInstance(connection)
        .checkRegistration(connection, midlet, filter);
}
 
Example #20
Source File: MIDletPeer.java    From pluotsorbet with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Requests that the device handle (e.g. display or install)
 * the indicated URL.
 *
 * <p>If the platform has the appropriate capabilities and
 * resources available, it SHOULD bring the appropriate
 * application to the foreground and let the user interact with
 * the content, while keeping the MIDlet suite running in the
 * background. If the platform does not have appropriate
 * capabilities or resources available, it MAY wait to handle the
 * URL request until after the MIDlet suite exits. In this case,
 * when the requesting MIDlet suite exits, the platform MUST then
 * bring the appropriate application to the foreground to let the
 * user interact with the content.</p>
 *
 * <p>This is a non-blocking method. In addition, this method does
 * NOT queue multiple requests. On platforms where the MIDlet
 * suite must exit before the request is handled, the platform
 * MUST handle only the last request made. On platforms where the
 * MIDlet suite and the request can be handled concurrently, each
 * request that the MIDlet suite makes MUST be passed to the
 * platform software for handling in a timely fashion.</p>
 *
 * <p>If the URL specified refers to a MIDlet suite (either an
 * Application Descriptor or a JAR file), the request is
 * interpreted as a request to install the named package. In this
 * case, the platform's normal MIDlet suite installation process
 * SHOULD be used, and the user MUST be allowed to control the
 * process (including cancelling the download and/or
 * installation). If the MIDlet suite being installed is an
 * <em>update</em> of the currently running MIDlet suite, the
 * platform MUST first stop the currently running MIDlet suite
 * before performing the update. On some platforms, the currently
 * running MIDlet suite MAY need to be stopped before any
 * installations can occur.</p>
 *
 * <p>If the URL specified is of the form
 * <code>tel:&lt;number&gt;</code>, as specified in <a
 * href="http://rfc.net/rfc2806.html">RFC2806</a>, then the
 * platform MUST interpret this as a request to initiate a voice
 * call. The request MUST be passed to the &quot;phone&quot;
 * application to handle if one is present in the platform.</p>
 *
 * <p>Devices MAY choose to support additional URL schemes beyond
 * the requirements listed above.</p>
 *
 * <p>Many of the ways this method will be used could have a
 * financial impact to the user (e.g. transferring data through a
 * wireless network, or initiating a voice call). Therefore the
 * platform MUST ask the user to explicitly acknowledge each
 * request before the action is taken. Implementation freedoms are
 * possible so that a pleasant user experience is retained. For
 * example, some platforms may put up a dialog for each request
 * asking the user for permission, while other platforms may
 * launch the appropriate application and populate the URL or
 * phone number fields, but not take the action until the user
 * explicitly clicks the load or dial buttons.</p>
 *
 * @return true if the MIDlet suite MUST first exit before the
 * content can be fetched.
 *
 * @param URL The URL for the platform to load.
 *
 * @exception ConnectionNotFoundException if
 * the platform cannot handle the URL requested.
 *
 */
public native final boolean platformRequest(String URL)
        throws ConnectionNotFoundException;
 
Example #21
Source File: PushRegistryDelegate.java    From J2ME-Loader with Apache License 2.0 votes vote down vote up
public long registerAlarm(String midlet, long time) throws ClassNotFoundException, ConnectionNotFoundException;