Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

J2ME and RMI or CORBA

 
omar bili
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i have just stated with the J2ME and i want to know
if my MIDlet application can use CORBA or RMI
and how can i show an image in my Form.
regards, omar
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well J2ME does contain SocketConnections and you could use such to contact RMI. However, usually, because of the costs association with Wireless, most outside calls are done stateless and quick request response, which tends to lead to Servlets on the server-side handling all your work for you. So the Servlet could use RMI on behalf of the wireless device, if needed.

Mark
 
omar bili
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, and thanks Mark for replying.
i found a servlet and a small MIDlet
that can read from this servlet some info
but i was wondering how i can send some data
to the servlet from my MIDlet.
here are the two classes:
/*the Servlet: */
public class ss extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public void destroy() {
}
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String message = "Greeting from the Server:\nOmar" ;
response.setContentType("text/plain");
response.setContentLength(message.length());
PrintWriter out = response.getWriter();
out.println(message);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
public String getServletInfo() {
return "Short description";
}

}

/* the MIDlet */

import java.io.*;

import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class HitServlet
extends MIDlet
implements CommandListener {
private Display mDisplay;
private Form mMainForm;
private StringItem mMessageItem;
private Command mExitCommand, mConnectCommand;

public HitServlet() {
mMainForm = new Form("HitServlet");
mMessageItem = new StringItem(null, "");
mExitCommand = new Command("Exit", Command.EXIT, 0);
mConnectCommand = new Command("Connect",
Command.SCREEN, 0);
mMainForm.append(mMessageItem);
mMainForm.addCommand(mExitCommand);
mMainForm.addCommand(mConnectCommand);
mMainForm.setCommandListener(this);
}

public void startApp() {
mDisplay = Display.getDisplay(this);
mDisplay.setCurrent(mMainForm);
}

public void pauseApp() {}

public void destroyApp(boolean unconditional) {}

public void commandAction(Command c, Displayable s) {
if (c == mExitCommand)
notifyDestroyed();
else if (c == mConnectCommand) {
Form waitForm = new Form("Waiting...");
mDisplay.setCurrent(waitForm);
Thread t = new Thread() {
public void run() {
connect();
}
};
t.start();
}
}

private void connect() {
HttpConnection hc = null;
InputStream in = null;
String url = getAppProperty("HitServlet.URL");
//System.out.println("this is the url: " + url);


try {
hc = (HttpConnection)Connector.open("http://localhost:8081/servlet/ss");
in = hc.openInputStream();

int contentLength = (int)hc.getLength();
System.out.println(contentLength+"") ;

byte[] raw = new byte[contentLength];
int length = in.read(raw);

in.close();
hc.close();

// Show the response to the user.
String s = new String(raw, 0, length);
mMessageItem.setText(s);
}
catch (IOException ioe) {
mMessageItem.setText("Error: " + ioe.toString());
}
mDisplay.setCurrent(mMainForm);
}
}

Regards, Omar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic