Empty MESSAGE body using OutputStream.write

Hello

I have problems with the write method of OutputStream. Specifically, the MESSAGE body is empty, even if I specify data in the write() method. An HTTP request is made, I see it in the server logs and I get a return status of 200 OK, but data is sent just never. Any ideas?

Here is the code in question: (I'm overrideing the variable inputFromUser for testing purposes)

public boolean fetch(String inputFromUser) throws IOException {
        System.out.println("Fetch called with input " + inputFromUser);
        boolean contentAvailable = false;

        HttpConnection httpConn = null;

        inputFromUser = "name=javabb";

        httpConn = (HttpConnection)Connector.open(TEST_URL+get_connection_directive(), Connector.READ_WRITE);
        httpConn.setRequestMethod(HttpConnection.POST);
        httpConn.setRequestProperty("Accept", "*/*");
        httpConn.setRequestProperty("Accept-Encoding", "gzip, deflate, compress");
        httpConn.setRequestProperty("Content-Length", Integer.toString(inputFromUser.length()));
        httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

        OutputStream output = null;

        output = httpConn.openOutputStream();

        output.write(inputFromUser.getBytes());
        output.flush();

        // Getting the response code will open the connection,
        // send the request, and read the HTTP response headers.
        // The headers are stored until requested.
        int status = 0;

        status = httpConn.getResponseCode();            

        if (status == HttpConnection.HTTP_OK)
        {               

            InputStream input = null;

            input = httpConn.openInputStream();

            if(httpConn.getEncoding().toLowerCase().equals("gzip")) {
                input = new GZIPInputStream(input);
            }                   

            // Check to see if there's content

            int contentLength = (int) httpConn.getLength();

            byte[] bytes = null;

            bytes = IOUtilities.streamToBytes(input);

            StringBuffer raw = new StringBuffer(new String(bytes, "UTF-8"));                        

            if ( contentLength > 0 )
            {
                setContent(raw.toString());

                contentAvailable =  true;

                System.out.println("Response: " + raw.toString());

            }
            else {
                System.out.println("Content-length < 1");
            }

            input.close();

        }
        else
        {
            setStatus(status);
            System.out.println("HTTP Status of: " + status);
            contentAvailable = false;
        }  

        httpConn.close();

        return contentAvailable;

    }

You do not close the output stream.  I suspect that might have something to do with the problem.

Also there are a few changes that I would say that may contribute to your problem.

(1) you say:

httpConn.setRequestProperty ("Content-Length", Integer.toString (inputFromUser.length ()));

inputFromUser is now a string.  Its length is not necessairly the same as the number of bytes that you get when you convert it to bytes.  Then you really should convert it to bytes and then find the length.

(2) copy the following code:

inputFromUser.getBytes)

Converts the string using the default value of the ISO8859-1 BlackBerry (could remembered that bad).  This will convert most of the Latin type characters, but does not work for special characters, and other languages.  You must choose a code that matches what the server expects, which is usually UTF - 8.

With those two changes, your code might look like:

Byte [] postBytes = null;

try {}

postBytes = inputFromUser.getBytes("UTF-8");

} catch (Exception e) {}

cannot be done with UTF - 8

}

httpConn.setRequestProperty ("Content-Length", Integer.toString (postBytes.length));

and then, later

output. Write (postBytes);

Let us know if these three changes (close, UTF - 8 and setting the length correctly) solve your problem.

Tags: BlackBerry Developers

Similar Questions

  • El Capitan mail app - the message body empty conversations

    Hello

    I have this problem: Mac Mini end of 2012, El Capitan 10.11.4, Mail with POP3 and IMAP accounts 9.3 app mixed, Classic view (mailboxes on the left, the list of the top right of the mail messages, the body of the message below on the right). I have just a few messages from Inbox of 2000 + (says the header to Mail.app window).

    When I open the mail application, I can see the body of the message (body), as long as I select just a simple mail, non-conversation in the list. The problem starts when

    I click on some 'conversation' (blue triangle) mail: the mail body field appears empty, except the headers. Double click opens an empty window (just e-mail header fields are written). The second problem is, when I click again to all mail non-conversation - body is now empty (but it worked just a moment ago!).

    Smoking using mail app, but only until what I click on message "conversation."

    I have tried to box the letters a regeneration, the PRAM reset, removed the ~/Library/Mail/V3/MailData / envelope *, ExternalUpdates. * I don't have any mail extensions, the problem exists with and without web browser running, I don't have any antivirus running.

    In Mail I could solve this problem by checking and unchecking "arrange by conversation" (point of view' menu) several times.

  • empty messages appear in the junk e-mail folder

    Hello

    Strange empty messages are appearing in my junk e-mail folder. These messages have NO content, NO subject, NO sender and a weird date (1970). These messages are NOT from my server. If I empty my "junk" folder, they disappear, but reappear after half a day or more. They are automatically classified as spam (I also use the Junqilla plugin).

    They're not a disaster, but so strange, I'm afraid they are a symptom of something worse...

    Help appreciated!

    JR

    Right-click on junk and select 'empty junk '.
    Right click on junk e-mail and select "compact".

    As he explains what compaction is and why it is important, read the info at this link:

  • How can I stop MAIL issuing hundreds of empty messages?

    I work under El Capitan. It often happens that the Mail is encroaching on my screen out literally hundreds of messages of the Virgin, which is a real nuisance. What can I do? Get rid of the mail, I use Gmail (on Google) to my emails? But can you really delete mail, or disable it? Thank you.

    Hello JEHAN1,

    I understand that you have encountered problems with empty messages in the mail. I can certainly see how to receive hundreds of messages would be relative. I'm happy to help you.

    Reconstruction of your mailbox can solve this problem. Please follow the steps in this link:

    Address postal (El Capitan): rebuild the mailboxes

    If the problem persists, try to test in safe mode. It will also be your Mac to run some checks and prevent some software launch. Here, use the steps in safe mode:

    Try safe mode if your Mac does not end commissioning

    Have an amazing day!

  • Apple Mail displays empty messages

    Hello

    For two days, Apple mail displays various empty messages across multiple e-mail accounts.

    However, when you look at the raw source through view, there certainly the text to display.

    In addition, the preview text is always displayed correctly.

    I can access my mail online and verify that messages have in effect of content.

    I've already tried

    • Rebuild the mailboxes
    • Import mailboxes mailbox outside of the V3 folder
    • Delete the V2 file envelope index file
    • Subtract the cache.db file caches in the container folder
    • Deleting the file plist in the Preferences folder

    What can be done to fix this?

    I have attached a screenshot as reference.

    Kind regards

    Isaiah van Hunen

    It turns out that the software IBM report was the culprit.

    I'm pretty shocked as the official software, legal IBM, designed to protect my Mac broke.

    I recommend not to install or use; Apparently, it is not well developed.

    Kind regards

    Isaiah van H.

    < personal information under the direction of the host >

  • If I click on an email link in a web page instead of an empty message is opened I still get noise toward the top of the screen with a log-in for googlemail. I don't have and won't have a googlemail account. I just want to be able to send e-mail messages b

    If I click on an email link in a web page instead of an empty message is opened I still get noise toward the top of the screen with a log-in for googlemail. I don't have and won't have a googlemail account. I just want to be able to send e-mail messages by using Outlook.

    See this article.

    http://support.Mozilla.com/en-us/KB/changing+the+e-mail+program+used+by+Firefox

  • Whenever I update "send/receive" a message asking me to write the network password and user name.

    I am connected to wifi in the hotel (Orange) and I can't SEND email, I just have to receive them.

    Whenever I update "send/receive" a message asking me to write the network password and user name. This from my mail server (not orange because that one is ok I have access to the internet).

    Most of the suppliers do not let you send if you are not connected through them, or they have special settings.  So for now, see if you can access your e-mail via webmail and use this interface and in the future, contact your ISP and ask them if there is a way to send emails when you are connected through a different network.

    Steve

  • Windows Messaging automatically sends an empty message

    When I open an e-mail and press the button to write a message, it sends automatically empty messages.  This happens randomly, different people on different days.  I checked for viruses and cannot find anything.  I wonder if it happens when I have too many either in the e-mail box or sent box?

    1: try to compact and repair the database.
     
     
     
    2: Download the free version of this tool. First check the updates and then run a full scan.
     
     
     
  • Line break when writing text using OutputStream file

    This seems to be a bit of a stupid question, but I am confused. I write a simple eventLog for my program that, at the present time, contains a few hexagonal channels. Since OutputStream has not an writeLine or writeln method, there is no innate line breaks, and they all appear on a single line. Pretty simple to fix... or so I thought. The line break character is rejected. I tried \n, \r, 0x0A, 0x0C, 0x0D, 0x1E,"(\n".getBytes), br = [] byte {/ * insert line break ratings here host * /}... Each is replaced by a small black box. How can I programmatically insert a line break in a .txt with OutputStream.write (*) file?

    Testing this on the generic "BOLD" 9000 Simulator.

    public void log (String entry)
      {
        //Circular Buffer logic
        if (eventLog.size () == 100)
        {
          eventLog.removeElementAt (0);
        }
    
        eventLog.addElement (entry);
    
        //TODO: Remove this
        flushLog ();
      }
    
      //Empty log to external file
      public void flushLog ()
      {
        FileConnection logWriter;
    
        try
        {
          logWriter = (FileConnection) Connector.open
                      ("file:///SDCard/BlackBerry/documents/log.txt",
                       Connector.READ_WRITE);
        }
        catch (IOException e)
        {
          //Debug
          System.out.println ("ERROR: File connection could no be created.");
          System.out.println (e);
    
          return;
        }
    
        try
        {
          try
          {
            if (!logWriter.exists ())
            {
              logWriter.create ();
    
              //Debug
              System.out.println ("Log Successfully created");
            }
          }
          catch (Exception e)
          {
            //Debug
            System.out.println (e);
          }
    
          //Debug
          System.out.println (logWriter);
          System.out.println ("Creating output stream...");
    
          OutputStream logOut = logWriter.openOutputStream ();
    
          //Debug
          System.out.println ("OutputStream successfully created");
    
          try
          {
            for (int count = 0; count < 100; count++)
            {
              //Debug
              System.out.println ("Log Write Loop: " + count);
    
              logOut.write (((String) eventLog.elementAt (count)).getBytes ());
    
              //test
              //byte [] br = {0x0A, 0x0C, 0x0D, 0x1E};
    
              String br = "\n";
              logOut.write (br.getBytes ());
            }
          }
          catch (ArrayIndexOutOfBoundsException e)
          {
            //Debug
            System.out.println ("Buffer not full");
          }
          catch (Exception e)
          {
            //Debug
            System.out.println (e);
          }
    
          logOut.close ();
        }
        catch (IOException e)
        {
          //Debug
          System.out.println ("Error writing event log: May be incomplete.");
          System.out.println (e);
        }
        finally
        {
          try
          {
            logWriter.close ();
          }
          catch (IOException e)
          {
            //Debug
            System.out.println ("Error closing log Stream");
            System.out.println (e);
          }
        }
      }
    

    Confused,.

    ~ Dom

    Windows, Notepad, whatever, expects CRLF for line breaks. \n gives you PMQ, which works very well on ' nix systems; \r\n is what you want. Clever Publishers to Windows will load of each convention, but not Notepad.

    BlackBerry probably isn't ' nix based. It's just a convention of line break.

  • How to generate the message body to call the API REST Eloqua?

    I can GET my contact details via the URL: https://secure.eloqua.com/Api/rest/2.0/data/contact/229?xsrfToken=80267e50-30db-4e16-9dd3-7d42ef75dc2d as below:

    GET the answer:

    {

    'type': 'Contact,'

    'currentStatus': 'Action pending ',.

    "id": "229."

    'converted': '1439800672 ',.

    "depth':"full. "

    « nom » : » [email protected] ",

    "updatedAt": "1440662349",

    "accountName": "Oracle."

    "address1": "333333333",

    'city': 'unknown ',.

    "country':"KR. "

    ' 'emailAddress': ' [email protected] ",

    "emailFormatPreference": "not specified."

    "fieldValues can only be:

    [

    {

    'type': 'FieldValue ',.
    'id': '100005.

    },

    {

    'type': 'FieldValue ',.
    'id': '100017.

    },

    {

    'type': 'FieldValue ',.
    'id': '100023.

    },

    {

    'type': 'FieldValue ',.
    'id': '100024.

    },

    {

    'type': 'FieldValue ',.
    'id': "100032,"
    'value': 'CZZOC000000000229 '.

    },

    {

    'type': 'FieldValue ',.
    'id': '100033.

    },

    {

    'type': 'FieldValue ',.
    'id': '100034.

    },

    {

    'type': 'FieldValue ',.
    'id': '100035.

    },

    {

    'type': 'FieldValue ',.
    'id': '100036 ".

    },

    {

    'type': 'FieldValue ',.
    'id': '100041.

    },

    {

    'type': 'FieldValue ',.
    'id': '100043.

    },

    {

    'type': 'FieldValue ',.
    'id': '100044.

    },

    {

    'type': 'FieldValue ',.
    'id': '100045.

    },

    {

    'type': 'FieldValue ',.
    'id': '100046.

    },

    {

    'type': 'FieldValue ',.
    'id': '100047'

    },

    {

    'type': 'FieldValue ',.
    'id': '100048.

    },

    {

    'type': 'FieldValue ',.
    'id': '100049.

    },

    {

    'type': 'FieldValue ',.
    'id': '100051.

    },

    {

    'type': 'FieldValue ',.
    'id': '100065.

    },

    {

    'type': 'FieldValue ',.
    'id': '100066.

    },

    {

    'type': 'FieldValue ',.
    'id': '100068.

    },

    {

    'type': 'FieldValue ',.
    "id': '100069."
    'value': 'in Europe.

    },

    {

    'type': 'FieldValue ',.
    'id': '100072.

    },

    {

    'type': 'FieldValue ',.
    'id': '100081.

    },

    {

    'type': 'FieldValue ',.
    "id': '100171."
    "value": "oracle.com.

    },

    {

    'type': 'FieldValue ',.
    "id': '100172."
    "value': 'Ken Jin."

    },

    {

    'type': 'FieldValue ',.
    'id': '100174.

    },

    {

    'type': 'FieldValue ',.
    'id': '100175'

    },

    {

    'type': 'FieldValue ',.
    'id': '100176.

    },

    {

    'type': 'FieldValue ',.
    'id': '100177.

    },

    {

    'type': 'FieldValue ',.
    'id': '100178.

    },

    {

    'type': 'FieldValue ',.
    'id': '100179.

    },

    {

    'type': 'FieldValue ',.
    'id': '100180.

    },

    {

    'type': 'FieldValue ',.
    'id': '100184.

    },

    {

    'type': 'FieldValue ',.
    'id': '100187.

    },

    {

    'type': 'FieldValue ',.
    'id': '100188.

    },

    {

    'type': 'FieldValue ',.
    'id': '100189.

    },

    {

    'type': 'FieldValue ',.
    'id': '100190.

    },

    {

    'type': 'FieldValue ',.
    'id': '100191.

    },

    {

    'type': 'FieldValue ',.
    'id': '100192.

    },

    {

    'type': 'FieldValue ',.
    'id': '100193.

    },

    {

    'type': 'FieldValue ',.
    'id': '100194.

    },

    {

    'type': 'FieldValue ',.
    "id': '100195."
    'value': 'KenJinL888MJ '.

    },

    {

    'type': 'FieldValue ',.
    'id': '100196.

    },

    {

    'type': 'FieldValue ',.
    'id': '100197.

    },

    {

    'type': 'FieldValue ',.
    "id': '100198."
    'value': 'unknown '.

    },

    {

    'type': 'FieldValue ',.
    "id': '100199."
    'value': '66.0000.

    },

    {

    'type': 'FieldValue ',.
    "id': '100200."
    ' 'value': ' [email protected] "

    },

    {

    'type': 'FieldValue ',.
    "id': '100201."
    'value': 'female '.

    },

    {

    'type': 'FieldValue ',.
    'id': '100202.

    },

    {

    'type': 'FieldValue ',.
    "id': '100203."
    'value': 'Energy & Utilities '.

    },

    {

    'type': 'FieldValue ',.
    "id': '100204."
    'value': '0.0000 '.

    },

    {

    'type': 'FieldValue ',.
    "id': '100205."
    'value': '0.0000 '.

    },

    {

    'type': 'FieldValue ',.
    "id': '100206 Uganda."

    },

    {

    'type': 'FieldValue ',.
    'id': '100207.

    },

    {

    'type': 'FieldValue ',.
    'id': '100208.

    },

    {

    'type': 'FieldValue ',.
    'id': '100209.

    },

    {

    'type': 'FieldValue ',.
    'id': '100210.

    },

    {

    'type': 'FieldValue ',.
    'id': '100211.

    },

    {

    'type': 'FieldValue ',.
    "id': '100212."
    'value': "day 1".

    },

    {

    'type': 'FieldValue ',.
    "id': '100213."
    'value': 'Purple '.

    },

    {

    'type': 'FieldValue ',.
    "id': '100214."
    'value': 'unknown '.

    },

    {

    'type': 'FieldValue ',.
    'id': '100215.

    },

    {

    'type': 'FieldValue ',.
    'id': '100216.

    },

    {

    'type': 'FieldValue ',.
    'id': '100217.

    },

    {

    'type': 'FieldValue ',.
    "id': '100218."
    'value': '1.0000.

    },

    {

    'type': 'FieldValue ',.
    'id': '100219.

    },

    {

    'type': 'FieldValue ',.
    "id': '100220."
    'value': 'Purple '.

    },

    {

    'type': 'FieldValue ',.
    "id': '100221."
    'value': 'school '.

    },

    {

    'type': 'FieldValue ',.
    "id': '100222."
    'value': "don't like".

    },

    {

    'type': 'FieldValue ',.
    'id': '100223.

    },

    {

    'type': 'FieldValue ',.
    'id': '100224.

    },

    {

    'type': 'FieldValue ',.
    'id': '100225.

    },

    {

    'type': 'FieldValue ',.
    "id': '100226."
    "value':" ' 0 - 5 hours/week ""

    },

    {

    'type': 'FieldValue ',.
    'id': '100227.

    },

    {

    'type': 'FieldValue ',.
    "id': '100228."
    'value': 'PC '.

    },

    {

    'type': 'FieldValue ',.
    "id': '100229."
    "value':" ' 0 - 5 hours/week ""

    },

    {

    'type': 'FieldValue ',.
    'id': '100230.

    },

    {

    'type': 'FieldValue ',.
    'id': '100231.

    },

    {

    'type': 'FieldValue ',.
    'id': '100232.

    },

    {

    'type': 'FieldValue ',.
    'id': '100233.

    },

    {

    'type': 'FieldValue ',.
    "id': '100234."
    'value': '0.0000 '.

    },

    {

    'type': 'FieldValue ',.
    'id': '100235.

    },

    {

    'type': 'FieldValue ',.
    'id': '100236.

    },

    {

    'type': 'FieldValue ',.
    "id': '100237."
    'value': '2 '.

    },

    {

    'type': 'FieldValue ',.
    'id': '100238'

    },

    {

    'type': 'FieldValue ',.
    'id': '100239.

    },

    {

    'type': 'FieldValue ',.
    'id': '100240.

    }

    ],

    "FirstName": "Ken."

    'isBounceback': 'false. '

    'isSubscribed': 'true ',.

    'Name': 'Jin ',.

    'subscriptionDate': '1439800672 '.

    }

    However, I get an error response if I want to update my contact information via a call to POST the URL: https://secure.eloqua.com/Api/rest/2.0/data/contact?xsrfToken=80267e50-30db-4e16-9dd3-7d42ef75dc2d

    For example: update my "lastName" to "Kim" current value "Jin".

    POST request: <-I think it's a bad Message body that I don't know the correct format... Almost of the Eloqua REST API documents mentioned on GET rather than POST.

    {"id": "229",}

    ' 'emailAddress': ' [email protected] ",

    {'Name': 'Kim'}


    POST reply:

    [{'type' ": 'ObjectValidationError',' container': {'type': 'ObjectKey', 'objectType': 'Contact'}, 'ownership':"emailAddress","requirement": {'type': 'UniquenessRequirement', 'uniquenessScope': 'global'}, 'value' ': ' '[email protected]'}]

    Could someone tell me how to build a correct Message to the body?  Using the above example (updated an existing contact name) would be much better. Thank you!

    A POST is used to create new records in the database of Eloqua.  If you want to update an existing record, you want to use a call PUT.

  • Email - the message body of the formatting of bursting

    Hello

    I'm working on a breaking email delivery control file, but have a problem with setting shaped body "e-mail." It is always in text format - does not recognize the html format. I first thought it's just my vision of the configuration, but find that it does not also other e-mail providers (yahoo, google, etc.).

    Kindly share your habits of formatting of the message body in the breaking control file. I use EBS 11.5.10.2 (XML Publisher 5.6.3).

    Thanks in advance.

    I think it will work for you, use html for the body within CDATA.


         


         
                   
                   

    Please find attached Pick slip number ${PICK_SLIP_NUMBER}.


                   


    Kind regards
                   Company
    Address1
    Address2
    Phone: 123-456-7890
    Fax: 123-456-7890
                   


              
         ]]>








  • I used to write in two languages (English and Italan). When I use my Mac, it's easy: I just change the language, and my keyboard is the same (i.e., International English). What I use my iPad pro, instead, he also spends my hardware keyboard.

    I used to write in two languages (English and Italan). When I use my Mac, it's easy: I just change the language, and my keyboard is the same (i.e., International English). What I use my iPad pro, instead, he also spends my physical keyboard, so that for example if I type [keyboard I get an e. It is very annoying and makes the keyboard quite useless. Keeping fixed language I would get bad suggested words.

    You will need to define your physical layout being the same for English and Italian in settings > general > keyboard > keyboard > keyboard material

  • Empty message when you reply to an E-mail

    I have installed iOS 10.11.3. Since then, whenever I hit the button "answer" mail an empty message appears. No signature block, to the email address in, nothing. does anyone else know this? Is there a solution? A reboot will sometimes solve the problem, but it's a pain in the rear to restart everytime I want to reply to an email.

    Thank you very much.

    Steve W.

    Remove any third-party antivirus, security, cleaner, management, stimulate, software, you may have installed on your computer.

  • My phone calls come in the form of text messages and use the tone of the message text and not ringing.

    My phone calls on my iPhone 5 c pass as text messages and the sound message is used and not the ringing of a phone call.

    Calls can only come in the form of text messages. Go to settings > sounds and make sure you have the right tone selected.

  • Mail 9.2 and courier iCloud - no message body is displayed, that the body of the subject

    With Mail 9.2, iCloud mail displays only the body of the subject; to view the message body requires restart Mail 9.2 every time.  See also an accumulation of e-mail messages not appearing in the box iCloud mail drafts mailbox.

    A

    Please, back up all data. Rebuild the mailbox.

    B

    From the Mail menu bar, you select

    ▹ mail preferences... ▹ Accounts ▹ behaviors of the ball

    and uncheck the box marked

    Store drafts on the server

Maybe you are looking for

  • Why IS MY IPHONE HOME SCREEN is NOT in ALPHABETICAL ORDER WHEN I DOWNLOAD a NEW application?

    So, every time I download a new application, which is not in alphabetical order because it is listed as "Loading"... "or"install... ". "or a similar label. The application remains in the alphabetical list as to where he would be if he were actually t

  • Misfortunes of time stamp

    A code I have build to generate and acquire waveform signals and then write them in a text file with the appropriate time stamp is attached. As it is, I've linked only the portion of scripture to the acquired signals (I intend to write then generated

  • Scan to computer option removed the Panel controls after update?

    Hello Normally, you can choose the option to scan a document in the Panel, and then you have another screen where contrast you where able to choose the DPI... But, as you can see, now after an update, the option "Analyze a document" is part... I can

  • advantages of Windows 7 service pack 1

    What are the benefits of 1 (beta) windows 7 service pack?

  • Invoking one Popup Popup, another

    The child popup displays a taskflow in region. The taskflow has required input parameters. (the parent popup has been also called since a taskflow running)allows to call the popup p1 parents (with task flow tf1) and child popup p2 ( with task flow tf