Unable to send a byte to a Servlet

Hello,
I am trying to execute a simple example of HTTP communication found in the Carol Hammer's book "Creating Mobile Games". I can send data from the servlet to the midlet, but i cannot send a single byte from the midlet to the servlet.
I am using WTK version 2.2 for the devlopment and Tomcat 5.5.17 for running the servlet (in localhost)
Here is the (partial) code of the midlet :
public void communicationWithServlet() {
HttpConnection connection = null;
DataOutputStream dos = null;
DataInputStream dis = null;
try {
connection = (HttpConnection)Connector.open(SERVER_URL);
((HttpConnection)connection).setRequestMethod(HttpConnection.POST);
int rc = connection.getResponseCode();
if (rc != HttpConnection.HTTP_OK) {
throw new IOException("HTTP response code: " + rc);
     dos = connection.openDataOutputStream();
     System.out.println("before");
     dos.write((byte)100);
     System.out.println("after");
     dos.flush();
dis = connection.openDataInputStream();
     byte[] data = new byte[10];
     dis.readFully(data);
     message = new String(data);
     System.out.println(message);
} catch(Exception e) { }
finally {
try {
if(dis != null) { dis.close();}
if(connection != null) {connection.close();}
     catch(Exception e) {}
The midlet is blocked by the instruction : dos.write((byte)100);
Here is the code of the servlet :
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SimpleServlet extends HttpServlet {
     public void doPost(HttpServletRequest requete, HttpServletResponse reponse)
          throws ServletException, IOException {
               InputStream is = requete.getInputStream();
               int data= is.read();
               reponse.setContentType("text/html");
               PrintWriter out = reponse.getWriter();
               out.println("Hello");
               out.close();
Many thanks in advance for your help

If I delete the following lines :
int rc = connection.getResponseCode();
if (rc != HttpConnection.HTTP_OK) {
throw new IOException("HTTP response code: " + rc);
my problem is solved : the byte is sent to the servlet
But I would understand : why the call to the getResponseCode method prevents the midlet to send the byte to the servlet ?
Thanks for your help

Similar Messages

  • Unable to send 2304 bytes of print data! (USB write error)

    I got this error message when I try to print with either my airport extreme or express printer,
    but printing with my other macbook works just fine.
    So the problem is not the airport nor the driver. So please tell me what's wrong with my Mac!

    Awesome,
    Been racking my brain and the internet for days looking for anything that might work. I dont know if my cable was bad but it was a long one.  About 20' long.  I had to rearrange stuff but it is working like a champ now.  Thank you. Much love.
    JB

  • How to send array of bytes to a servlet and store it in a file

    Hi,
    How to send array of bytes to a servlet and store it in a file.
    I am new to Servlets. if possible for any one, please provide the code.
    Thanks,
    cmbl

    Through HTTP this is only possible with a POST request of which the encoding type is set to multipart/form-data. You can use Apache Commons FileUpload to parse such a multipart form data request into useable elements. From the other side (the client) you can use a HTML <input type="file"> element or a Java class with Apache Commons PostMethod API.
    You may find this article useful: http://balusc.blogspot.com/2007/11/multipartfilter.html

  • Setting attributes of image stored in byte array in servlet

    Hi,
    I am using a servlet to stream image (GIF) to the browser.
    Image is accessed by browser using the img tag. src attribute points to the servlet which send the image stream.
    Servlet has the image as the array of bytes. It simply write these bytes on the response object's output stream. It does not use any encoder.
    I get the image on the browser. But when I try to see the properties of the image I don't see the type of image. I also don't see the created time, modified time and size of the image. When I do Save As on this image it tries to save it as BMP instead of GIF. Also when I do the print preview I don't see the image in the preview window. When I try to print the web page, it prints everything except this image. I get small cross(image missing) on the printed page.
    I would like to know why the image attributes on browser go missing and why can't I print the image?
    I would like to add that I am getting the image as the array of bytes from a different application on which I do not have control.
    Thanks.

    Hi,
    I am using a servlet to stream image (GIF) to the browser.
    Image is accessed by browser using the img tag. src attribute points to the servlet which send the image stream.
    Servlet has the image as the array of bytes. It simply write these bytes on the response object's output stream. It does not use any encoder.
    I get the image on the browser. But when I try to see the properties of the image I don't see the type of image. I also don't see the created time, modified time and size of the image. When I do Save As on this image it tries to save it as BMP instead of GIF. Also when I do the print preview I don't see the image in the preview window. When I try to print the web page, it prints everything except this image. I get small cross(image missing) on the printed page.
    I would like to know why the image attributes on browser go missing and why can't I print the image?
    I would like to add that I am getting the image as the array of bytes from a different application on which I do not have control.
    Thanks.

  • How best to send double byte characters as http params

    Hi all
    I have a web app that accepts text that can be in many languages.
    I build up a http string and send the text as parameters to another webserver. Hence, whatever text I receive i need to be able to represent on a http query string.
    The parameters are sent as urlencoded UTF8. They are decoded by the second webserver back into unicode and saved to the db.
    Occassionally i find a character that i am unable to convert to a utf8 string and send as a parameter (usually a SJIS character). When this occurs, the character is encoded as '3F' - a question mark.
    What is the best way to send double byte characters as http parameters so they always are sent faithfully and not as question marks? Is my only option to use UTF16?
    example code
    <code>
    public class UTF8Test {
    public static void main(String args[]) {
    encodeString("\u7740", "%E7%9D%80"); // encoded UTF8 string contains question mark (3F)
    encodeString("\u65E5", "%E6%97%A5"); // this other japanese character converts fine
    private static void encodeString(String unicode, String expectedResult) {
    try {
    String utf8 = new String(unicode.getBytes("UTF8"));
    String utf16 = new String(unicode.getBytes("UTF16"));
    String encoded = java.net.URLEncoder.encode(utf8);
    String encoded2 = java.net.URLEncoder.encode(utf16);
    System.out.println();
    System.out.println("encoded string is:" + encoded);
    System.out.println("expected encoding result was:" + expectedResult);
    System.out.println();
    System.out.println("encoded string16 is:" + encoded2);
    System.out.println();
    } catch (Exception e) {
    e.printStackTrace();
    </code>
    Any help would be greatly appreciated. I have been struggling with this for quite some time and I can hear the deadline approaching all too quickly
    Thanks
    Matt

    Hi Matt,
    one last visit to the round trip issue:
    in the Sun example, note that UTF8 encoding is used in the method that produces the byte array as well as in the method that creates the second string. This is equivalent to calling:
    String roundTrip = new String(original.getBytes("UTF8"), "UTF8");//sun exampleWhereas, in your code you were calling:
    String utf8 = new String(unicode.getBytes("UTF8"))//Matt's code
    [/code attracted
    The difference is crucial.  When you call the string constructor without a second (encoding) argument, the default encoding (usually Cp1252) is used.  Therefore your code is equivalent toString utf8 = new String(unicode.getBytes("UTF8"), "Cp1252")//Matt's code
    i.e.you are encoding with one transformation format and decoding back with a different transformation format, so in general you won't get your original string back.
    Regarding safely sending multi-byte characters across the Internet, I'm not completely sure what the situation is because I don't do it myself. (When our program is run as an applet, the only interaction it has with the web server is to download various files). I've seen lots of people on this forum describing problems sending multi-byte characters and I can't tell whether the problem is with the software or with the programming. Two possible methods come to mind (of course you need to find out what your third party software is doing):
    1) use the DataOutput/InputStreams writeUTF/readUTF methods
    2) use the InputStreamReader/OutputStreamWriter pair with UTF8 encoding
    See this thread:
    http://forum.java.sun.com/thread.jsp?forum=16&thread=168630
    You should stick to UTF8. It is designed so that the bytes generated by encoding non-ASCII characters can be safely transmitted across the Internet. Bytes generated by UTF16 can be just about anything.
    Here's what I suggest:
    I am running a version of the Sun tutorial that has a program running on a server to which I can send a string and the program sends back the string reversed.
    http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html
    I haven't tried sending multi-byte characters but I will do so and test whether there are any transmission problems. (Assuming that the Sun cgi program itself correctly handles characters).
    More later,
    regards,
    Joe
    P.S.
    I thought one the reasons for the existence of UTF8 was to
    represent things like multi-byte characters in an ascii format?Not exactly. UTF8 encodes ascii characters into single bytes with the same byte values as ASCII encoding. This means that a document consisting entirely of ASCII characters is the same whether it was encoded as UTF8 or ASCII and can consequently be read in any ASCII document reader (e.g.notepad).

  • Error: 'Unable to send the request.  Verify the URL ... is valid and the...

    Hello,
    I'm attempting to connect to Essbase from Visual Studio 2005 with the use of the DataServer component.
    I'm using a URL;
    http://<myserver>:13080/aps/APS
    This URL seems to be valid if I plug it into a browser in that it returns a page listing the following information;
    Hyperion Provider Services
    Hyperion Provider Services - Release 9.3.1.0.0 Build 168
    ESS_ES_HOME: C:\Hyperion\AnalyticProviderServices
    domain file: C:\Hyperion\AnalyticProviderServices/data/domain.db
    essbase.properties: C:\Hyperion\AnalyticProviderServices/bin/essbase.properties
    log console enabled: false
    log file enabled: true
    log level: WARN
    log file name: C:/Hyperion/AnalyticProviderServices/bin/apsserver.log
    is trace enabled: false
    However, if I try and use this same URL in the DataServer component (using the 'Sign On' task) I'm shown the following error;
    'Unable to send the request. Verify the URL "http://<myserver>:13080/aps/APS" is valid and the servlet is running'
    So, any suggestions are much appreciated!
    Many thanks.

    Hi John,
    Yes, you're right. I've now installed the habnet server on the machine hosting Essbase and can access it via browser using;
    http://<myserver>::22080/EssbaseObjects/Servlet
    and this seems to be showing signs of life as it returns the following to the browser;
    =============================================================================
    Hyperion Habnet Servlet, Release 9.2.0
    Copyright 1997-1998, 2001-2006 Hyperion Solutions Corporation. All rights reserved.
    Hyperion Essbase Java API version 9.0.2
    Configuration:
    printXML=false
    printRequests=false
    connectionTimeout=300000
    checkInterval=60000
    forceMetadataCaching=false
    cacheTimeout=300000
    cacheInterval=60000
    EDSUrl=http://localhost:11080/eds/EssbaseEnterprise (optional)
    defaultEDSServer=localhost
    defaultDomain=Essbase
    defaultORBType=URL
    defaultPort=8080
    defaultUseConnectionPool=false
    defaultConnectionPerOperation=false
    defaultUseCluster=false
    defaultConnectionReadOnly=false
    netRetryCount=20
    netRetryInterval=1000
    testing configuration of required Java libraries:
    Essbase Java API (ess_japi.jar) *** OLDER VERSION ***
    Essbase Java API version detected - 9.0.0
    Java memory configuration:
    Maximum: 63 (Mb)
    Allocated: 31 (Mb)
    Free: 28 (Mb)
    XML (xerces.jar) is subject to:
    Apache Software License, Version 1.1
    Copyright (c) 1999-2001.
    The Apache Software Foundation.
    All rights reserved.
    SOAP (soap.jar) is subject to:
    Apache Software License, Version 2.0
    Copyright (c) 1999-2004.
    The Apache Software Foundation.
    All rights reserved.
    =============================================================================
    However.... when I try to connect using the DataServer I'm shown the same error message as beofre except for the change of URL. Can you remember if there were any other settings that needed to be made?
    I've also noticed the line above ' EDSUrl=http://localhost:11080/eds/EssbaseEnterprise (optional) ', this says 'the page cannot be displayed' if i try to access it from the habnet machine but I'm really not sure if this is relevant or not.
    Many thanks again for your time.
    Steve

  • I downloaded the whatsapp app to my new iphone, and when i wanted to create an account, i could not, it said, unable to send message. I downloaded it several times later, but i still could not create the account, it always said, unable to send, help

    I downloaded the whatsapp app to my new iphone, and when i wanted to create an account, i could not, it said, unable to send message. I downloaded it several times later, but i still could not create the account, it always said, unable to send, help

    I recommend reaching out to Citrix via their support system -
    http://www.citrix.com/products/receiver/resources-and-support.html
    The receiver app has a specific list of servers it's compatible with, if the server is not on the list the app won't work in OS X.
    http://support.citrix.com/servlet/KbServlet/download/28492-102-671726/Receiver%2 0for%20Mac%2011%204%20FAQ%20v1_1235.pdf
    Do you know what server you're connecting to?

  • Sending emails+attachment from a servlet

    Hi all,
    I'd like to send emails from within my servlet. There must be a possibility to attach a file that has been uploaded to the server in a previous request.
    Currently I'm using sun.net.smtp.SmtpClient to send simple emails.
    Does the sun-smtp-package provide a way to attach a file to an email?
    regards
    Steffen

    I'm not sure but I think the sun.net.smtp package is part of J2EE. I didn't need to download it. You will need a Base64-Encoding algorithm for transforming the file-data (the attachment) into the email message. OReillys servlet package provides a class for this (www.servlets.com).
    Below is an example how to send an email with a file attached to it. You will have to specify the name of an SMTP-Server. If you do not have one you can (for testing purposes) direct the email into a text file.
    try{
         String host = /** @todo place your smtp-server name or IP here */
         SmtpClient smtp = new SmtpClient(host);
         smtp.from(from);
         smtp.to(toList);
         PrintStream out = smtp.startMessage();
         Base64Encoder b64e = new Base64Encoder(out); // Base64Encoder is also a Stream which we will only use for the attachment-data
         /* uncomment this if there is no smtp-server. The email will be stored in a file
         File fEml = new File(/** @todo add your filePath here */+File.separatorChar+"out.eml");
         PrintStream out = new PrintStream(new FileOutputStream(fEml));*/
         out.println("From: "+from);
         out.println("To: "+toList);
         out.println("Subject: "+subject);
         out.println("Date: "+date.toString());
         out.println("MIME-Version: 1.0");
         // we have to declare the email multipart/mixed to notify the email client that this mail contains sub parts of different content-types
         out.println("Content-Type: multipart/mixed;");
         // the boundary-string separates the sub parts (just like in HTTP-Multipart-Requests)
         out.println("\tboundary=\"----=_next_part\"");
         out.println("\r");
         out.println("This is a multipart message in MIME format.");
         out.println("\r");
         // first sub part starts here - its the text message
         out.println("------=_next_part");
         // this sub part contains only plain text
         out.println("Content-Type: text/plain;");
         out.println("\tcharset=\"iso-8859-1\"");
         out.println("Content-Transfer-Encoding: 7bit");
         out.println("\r");
         // Message text goes here
         out.println(/** @todo place your message here */);
         out.println("\r");
         // now the attachment
    out.println("------=_next_part");
    out.println("Content-Type: application/octet-stream;");
    out.println("\tname=\""+fileName+"\"");
    out.println("Content-Transfer-Encoding: base64");
    out.println("Content-Disposition: attachment;");
    out.println("\tfilename=\""+fileName+"\"");
    out.println("\n");
    // encode file piece by piece
    File f = new File(/** @todo place your filepath here */+File.separatorChar+fileName);
    FileInputStream fis = new FileInputStream(f);
    int i = 0;
    do{
    byte[] content = {0, 0, 0};
    i = fis.read(content, 0, 3);
    if (i != -1){
                   b64e.write(content);
         }//if
    }while(i != -1);
    fis.close();
    fis = null;
    f = null;
         // this is it, all there's left to do is to flush our output-stream and clean up
         out.flush();
         b64e.close();
         out.close();
         b64e = null;
         smtp.closeServer();
         out = null;
         smtp = null;
    }catch(IOException ioe){
         ioe.printStackTrace();
    }//catch
    HTH
    Steffen

  • Servletengine Unable to send back last chunk: Software caused connection abort: socket write error

    I have created a bundle for the class com.xxx.cq.wcm.foundation.profile.impl.TnailImages from the foundation file com.day.cq.wcm.foundation.profile.impl.ProfileImages.
    Here are the changes I made ot this class
    1. width and height for the default foundation class ProfileImages to have our own default width and height in TnailImages.
    2. selectors changed to our own like
    * @scr.property name="sling.servlet.selectors" values.0="adjust"
    *                                              values.1="adjust.small"
    3.   Variable changed to  private static final String THUMBNAIL = "small";
    4. Metatype annotation won't compile for CQ5.5  I changed this  * @scr.component metatype="false"
           to
         * @Component(immediate = true)
    This bundle compiled successfully and I see it in OSGi felix console, it is in start mode. Even then I did a restart of this bundle as well as whole CQ5.
    When I call an image using the following tag
    <img  alt="" src="/content/dam/geometrixx/portraits/scott_reynolds.jpg.adjust.small.jpg">
    there are no spases anywhere
    the servlet ThumbNailImages is not being call, I see the following error in error.log
    servletengine Unable to send back last chunk: Software caused connection abort: socket write error
    this image is not being displayed in the page, firebug displays failed to load URL
    Default img works fine
    <img  alt="" src="/content/dam/geometrixx/portraits/scott_reynolds.jpg.prof.thumbnail.jpg">
    Class com.day.cq.wcm.foundation.profile.impl.ProfileImages is available in
    /libs/foundation/src/impl/src/main/java/com/day/cq/wcm/foundation/profile/impl/ProfileImag es.java
    Here are my annotations * @Component(immediate = true) * @scr.service * @scr.property name="sling.servlet.resourceTypes" value="nt:file" * @scr.property name="sling.servlet.extensions" values.0="res" *                          values.1="jpg" *                          values.2="png" *                          values.3="gif" * @scr.property name="sling.servlet.selectors" values.0="adjust" *                                              values.1="adjust.small" */ It seems that this servlet is not being called, when I invoke http://xyz.com:4502/content/dam/geometrixx/portraits/scott_reynolds.jpg.adjust.small.jpg I am getting 404 Cannot serve request to /content/dam/geometrixx/portraits/scott_reynolds.jpg.adjust.small.jpg in org.apache.sling.servlets.get.DefaultGetServlet
    3 (2013-05-20 11:02:40) TIMER_END{2,resolveServlet(JcrNodeResource, type=dam:Asset, superType=null, path=/content/dam/geometrixx/portraits/scott_reynolds.jpg)} Using servlet com.day.cq.dam.core.impl.servlet.BinaryProviderServlet 3 (2013-05-20 11:02:40) TIMER_END{2,ServletResolution} URI=/content/dam/geometrixx/portraits/scott_reynolds.jpg.adjust.small.jpg handled by Servlet=com.day.cq.dam.core.impl.servlet.BinaryProviderServlet
    It seems that my Servlet TnailImages is not being called, it is always going to default servlet.

    Hi Akhter,
    Seeme like in your servlet the value for resourceType set to nt:file. Change it to "sling/servlet/default" and verify.
    Thanks,
    Sham

  • HT3529 i am unable to send sms from my iphone 4s

    i am unable to send sms from my iphone 4s

    Try Settings > General > Reset > Reset Network Settings.
    If that does not resolve, SMS is a carrier feature, contact the carrier.

  • HT1267 I am unable to send messages on my iPhone.  I am getting an error when I send it. This just started this morning.

    This is my first timeo n Apple Support.  Suddenly this morning I am unable to send messages through my iPhone.  I can send messages to one number, but all the other numbers I am sending to I receive an error message.  Also, I can receive messages from the one number I can send to, but am unable to receive messages from any other number.  What do I do to fix this? 

    Hi Steve,
    No he has not turned iMessage off, infact when he sends me a message thru iMessage it says 'delivered'. I am at my wits end nd I don't know what to do anymore.

  • Unable to send the data entered in sap portal

    Hi
    All
    i am trying to configure and test  Leave Request  from portal. When, we create the leave request and submit for the first time, it is giving the error/message Unable to send the data entered However, if do a submit for the second time, the same leave request, it sends the leave request.
    Please share your valuable thoughts or solutions.Thanks in advance.
    Tanks
    Rafi Shaik

    Hi Rafi,
    We are also facing similar kind of issue.
    When i select type of leave as annual it is giving an error message as
    " Parameter  missing in call of method BUILD_ACTOR_SELECT_CLAUSE in class CA_PT_REQ_ACTOR "
    But when i select some other leave type and click review it is working fine, again if i click on previous step and change the leave type to annual it is working fine without giving any error message.
    Please let us know how you have solved your issue?
    Thanks.
    -Suresh

  • Unable to send out emails via outlook express since 06/29/2010

    Task '[email protected]" - Sending' reported error (0x80042109) : 'Outlook is unable to connect to your outgoing (SMTP) e-mail server. If you continue to receive this message, contact your server administrator or Internet service provider (ISP).'        This is a copy/paste of error message from Office Outlook  2003
    Our household has been unable to "send" outgoing emails since 06/29/2010.  This includes a wireless laptop and a PC. We both lost the ability to send emails same day.  We changed NOTHING and did not share emails with each other that would have corrupted our system. During this time I have had 2 Verizon techs dance around in the PC doing all the same things I did as well as what  the automated assistant did.  The last tech said the Outlook Express 6.0 was corrupted, and to unistall it and then reinstall;  this time 2 hours later, I think he just gave up).  That did not work either.  I tried using the Outlook Office and still got an error message for outging. Everything is set up as it was when it was working until 06/29/2010.  I was told that there was a new server being installed and that things wold be working by 07/02/2010... I have tried taking down the firewall, turning off virus protection (McAfee), changing from outgoing.yahoo.verizon.net to just outgoing.verizon.net, checking boxes, unchecked boxes. SMPT is set to 587.  We get incoming fine.  I hate using the "Verizon email site" as too much monkey motion to get to mail, but that's what we have been doing.  I even tried setting up a GMail account, again got mail still could not send.  Any ideas?

    Thank you for your response!  I even tried sending an email via dos prompt  with Telnet, got past "HELO", but when trying to get a  "RCPT TO"  (using outgoing.yahoo.verizon.net)  I got an "authorization required" response and then was dropped.  I have been passed around without a solution. I am about ready to change ISP, but really hate to as most of the time (years now) this has been a decent ISP. If Verizon is having a problem just say so, I can handle it, honesty would be nice, refreshing and not wasting so much of my time as well as the techs!

  • We purchased a new iPad2 and registered it using a 'new' iCloud email/ID. We are unable to send email from the iPad and iPhone. The error is: Cannot send mail. The user name or password for iCloud is incorrect.

    We purchased a new iPad2 and registered it using a 'new' iCloud email/ID. We are unable to send email from the iPad and iPhone. The error is:>> Cannot send mail. The user name or password for iCloud is incorrect.

    About ~20 hours later, this ended up solving itself. We can send email using the '.icloud' email from both the iPad and iPhone.  Advise would be 'wait' before you start seeking alteranatives like yahoo, hotmail, etc.  This definitely is a convenient way to keep all your 'cloud' information in a centralized place, including the common email...

  • Unable to send any email from my brand new ipad 2 and my iphone 3gs lately

    Lately I found that my Iphone & my brand new ipad2 are unable to send out any email. it keep mentioning about the outgoing setting.."the connection to the outgoing server"webmail..." failed.Additional Outgoing mail servers can be configures in setting, bla bla bla
    .I try look for some advices from apple suport communities seems doesn't work for me...pls help...>_<

    Anyone can help?

Maybe you are looking for

  • Unable to use dataitem action

    Hi Forum, I am building xMII's XML format document and in that I am using data item action to add data in a row. When i tried mentioning the document name,data item name and value in the 'configure object' option(data is mentioned at design time),  d

  • Ichat won't connect away from home.

    I have a new mac pro and I have a I mac at home both with cameras. While at home I use my wireless network and my other mac is wired. I have two accounts and it works and connects fine at home. But I travel for a living and I tried to connect at hote

  • Unable to handle the detail block data......

    Dear All, I am creating a form with 3 blocks. Control block, Header Block, Detail Block. First i have entered a record in the control block. Then i navigate to header block,entered the first record for Header Block. Then i navigate to Detail block,en

  • Trying to reinstall DW6 after a computer problem set restore point before I installed DW6

    It gets to the point of installing Creative Cloud.  That ends wth a message that Creative Cloud failed to install with no clue why. 

  • Generer clave de seguridad

    Buen día, alguien me puede ayudar a hacer un programa que haga lo siguiente: 1- establecer una clave de 3 digitos. 2- una vez registrada, en una botonera en el panel frontal teclear la clave. 3- si la clave introducida coincide con la estabelecida en