×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    15

    Improvment of JAVA MMS library v1.1

    Hi everyone.

    I want to discuss about JAVA MMS library v1.1, suggest some improvements to the communication (over HTTP) part of this library and provide some beta code.

    I noticed such thing: when I sumbit a MMS message to Nokia
    MMSC and some data (i.e. receiver address) is invalid I get quite long delay (few minutes, maybe 4-5) and the my session is timed out at socket level.

    I checked the communication part of JAVA MMS library v1.1 and I found that it uses standard classes of java.net.* package. All we know that HTTP client is too "weak" until the JAVA v1.4, it lacks 2 most important features:

    1. Ability to configure proxy (at HTTP session level).
    2. Timeouts.

    In order to have code which is backward compatible I deciced not to migrate to the JAVA1.4 - I decided include the HTTP client from Jakarta Commons project. All information (including JavaDocs, tutorial, source, binaries) about this project can be found here http://jakarta.apache.org/commons/httpclient/. The Commmons Http Client has lots of useful features, but I guess you can discover it yourselfs .

    So, download the commons-httpclient-2.0-rc1.jar in order to get my modification working. I must say my code isn't very well-formed, maybe it's missing something - feel free to modify it. But don't forget to provide the community with your modifications

    I have implemented 2 additional methods to the MMSender class in order to keep backward compatibility:

    1st method:
    /**
    * Sends a Multimedia Message having proxy server's data, timeout's value and an array of bytes representing the message.
    *
    * @param buf the array of bytes representing the Multimedia Message.
    */
    public MMResponse send(String sProxyHost, int nProxyPort, int nTimeout, byte[] buf) throws MMSenderException
    {


    MMResponse hResponse = send(sProxyHost, nProxyPort, nTimeout, buf,204);

    return hResponse;
    }

    2nd method:

    /**
    * Sends a Multimedia Message having an array of bytes representing the message
    * and specifying the success code returned by the MMSC and sending timeout.
    * Additionally you can specify proxy server (w/ proxy server port) and
    * connection timeout.
    *
    * @param sProxyHost URL of proxy server.
    * @param nProxyPort proxy server port.
    * @param nTimeOut MMS sending timeout.
    * @param buf the array of bytes representing the Multimedia Message.
    * @param successcode the success code returned by the MMSC. Generally it is 204.
    */
    public MMResponse send(String sProxyHost, int nProxyPort, int nTimeout, byte[] buf, int successcode) throws MMSenderException
    {

    URL url = null;
    OutputStream out = null;
    int responseCode = 0;
    String responseMessage = "";
    MMResponse hResponse = null;

    // Checking the URL of MMSC where our MMS message will be passed.
    try
    {
    url = new URL(m_sUrl);
    }
    catch (MalformedURLException e)
    {
    System.out.println("Bad MMSC URL, reason - " + e.getMessage() + ".");
    throw new MMSenderException(e.getMessage());
    }

    // Decode the header of the Multimedia Message
    MMDecoder decoder=new MMDecoder();
    decoder.setMessage(buf);
    try
    {
    decoder.decodeHeader();
    }
    catch (MMDecoderException e)
    {
    System.out.println("MMS decoding failed, reason - " + e.getMessage() + ".");
    throw new MMSenderException(e.getMessage());
    }

    MMMessage mmMsg=decoder.getMessage();

    // Creating and initializing the Http client:
    PostMethod post = new PostMethod(m_sUrl);
    HttpClient httpClient = new HttpClient();
    HostConfiguration hostConf = new HostConfiguration();

    // a) MMSC URL;
    try
    {
    hostConf.setHost(new URI(m_sUrl));
    }
    catch(URIException urie)
    {
    System.out.println("Bad host's configuration, reason - " + urie.getMessage() + ".");
    throw new MMSenderException(urie.getMessage());
    }

    // b) proxy (if needed);
    if (sProxyHost != null)
    hostConf.setProxy(sProxyHost, nProxyPort);
    // c) connection timeout (setConnectionTimeout), data retrieval timeout (setTimeout),
    // "connectio production" timeout (setHttpConnectionFactoryTimeout).
    httpClient.setConnectionTimeout(nTimeout*1000);
    httpClient.setTimeout(nTimeout*1000);
    httpClient.setHttpConnectionFactoryTimeout(nTimeout*1000);

    // Extracting MMS message's headers.
    Enumeration eHeader = hHeader.keys();
    while (eHeader.hasMoreElements())
    {
    String strHeaderKey = (String)eHeader.nextElement();
    String value = (String)hHeader.get(strHeaderKey);
    post.setRequestHeader(strHeaderKey, value);
    }
    post.setRequestHeader("Content-Type","application/vnd.wap.mms-message");
    post.setRequestHeader("Content-Length",Integer.toString(buf.length));

    try
    {
    // Adding body
    ByteArrayInputStream reqData = new ByteArrayInputStream(buf);
    post.setRequestBody(reqData);

    // Executing POST to the MMSC.
    hResponse = new MMResponse();
    responseCode = httpClient.executeMethod(hostConf, post);
    responseMessage = post.getStatusText();

    // Getting response body.
    byte[] responseBody = post.getResponseBody();
    // Releasing http connection.
    post.releaseConnection();

    // Forming MMSC's response:
    hResponse.setResponseCode(responseCode);
    hResponse.setResponseMessage(responseMessage);

    // a) extracting all headers from the HTTP POST response;
    Header[] respHeaders = post.getResponseHeaders();
    for(int index = 0 ; index < respHeaders.length ; index++)
    {
    if (respHeaders[index].getName().equals("Content-Type"))
    hResponse.setContentType(respHeaders[index].getValue());
    else
    hResponse.addHeader(respHeaders[index].getName(), respHeaders[index].getValue());
    }

    // b) setting response's body.
    hResponse.setContentLength(responseBody != null ? responseBody.length:0);
    hResponse.setContent(responseBody);
    }
    catch (IOException e)
    {
    e.printStackTrace();
    throw new MMSenderException(e.getMessage());
    }
    // Providing the caller with MMSC's response.
    return hResponse;
    }

    That's all.

    Best regards,
    Artûras Baranauskas
    Last edited by Arturas; 2003-10-03 at 08:57.

  2. #2
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    474
    Great, Arturas -- thanks for your efforts.

    I have to take this opportunity to remind everyone, however, that the MMS Library is not supported by ForumNokia any longer. We recommend using it as a "getting started" tool.

    That said, see the sticky note about SMIL problems -- you can't use 1.2 to create SMIL MMSs either. You still have to use 1.0 for Originating messages, and 1.2 for Terminating...

    -paul / ForumNokia

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    15
    Hi Paul.

    Since the JAVA MMS library is a "starter's tool", what would you suggest to use in production systems ? Does Nokia have some supported library for that purpose ?

    Thanks in advance,
    Arturas B.

  4. #4
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    474
    Nokia Mobile Server Services SDK is the supported tool.

    -paul / ForumNokia

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    15
    Thank you Paul, I'm thinking about migration to SDK's libraries.

    But the question remains - does the SDK support those
    properties like timeouts, proxies at connection, session
    level ?
    I know I can set proxy at OS level but it's not what I expect here
    - there are lot of other application running on the same machine
    and not all of those needs proxy. Same thing about timeouts.
    Is there ant way to "fine-tune" MMS sending with this SDK ?

    BTW, you are free to reuse my code (that I have implemented in
    JAVA MMS Library) in your SDK ;D.

    BR,
    Arturas B.

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    36

    Proxy

    Actually with the proxy it's easy, just add the following switches to your java command:

    -DproxySet=true -DproxyHost=yourHttpProxy -DproxyPort=8080

  7. #7
    Registered User
    Join Date
    Mar 2003
    Posts
    15
    Not so easy, believe me.

    What about other applications (HTTP clients) that run under the same JAVA VM ? Not all of those need PROXY, but it will be forced to use it. My idea is to have ability to set poxy at session (HTTP) level instead of having "global" settings .

    I have implemented my idea in the Nokia JAVA MMS Library v1.1. I have also checked the sources of Nokia Mobile Server Services SDK - it is not that easy to apply my idea here since Apache's Commons HtppClient API differs from JAVA's standard Http client.

    BR,
    Arturas Baranauskas

  8. #8
    Registered User
    Join Date
    Aug 2003
    Posts
    36
    Hi Arturas,

    Couldn't you actually start several JVMs, so the one that needs a proxy gets one and others don't? So far I'm not aware of any other way to define a proxy for EAIF but via the command line switch.

    I'm using Nokia JAVA MMS Library v1.1. too and I just put it all together for a bulk interface including smil, text and images.

    Btw. I'm just looking for a way to include simple html in MMS message, but so far it didn't work and I can't find any samples. Could you maybe point me to some helpfull document?

    Best regards,
    Marko

  9. #9
    Registered User
    Join Date
    Mar 2003
    Posts
    15
    With multiple JVM started you can get into the "out of memory" trouble and session level settings help to aviod this problem.

    About HTML in MMS message.
    You can do it - add a HTML content part into a MMS message. It works fine. There is another problem - it may happen that your handset doesn't support HTML. I have been testing HTML in MMS with Nokia 7650, SonyEricsson t68i - these phones do not render HTML. I.e., with Nokia 7650 you can see that your MMS contain object which isn't displayed and you can view it as plain HTML.

    BR,
    Arturas Baranauskas

  10. #10
    Registered User
    Join Date
    Aug 2003
    Posts
    36
    Hi Arturas,

    Thanks for the tip, but this html thing is really grating: I'm testing with Nokia 3650 and it always says "unable to display message, select objects...". The html object displays as html under attachments and opens more or less fine. That's if I'm using smil:
    mm.setContentType(IMMConstants.CT_APPLICATION_MULTIPART_RELATED);
    mm.setMultipartRelatedType(IMMConstants.CT_APPLICATION_SMIL);

    If I try
    mm.setContentType(IMMConstants.CT_APPLICATION_MULTIPART_MIXED);
    or
    mm.setContentType(IMMConstants.CT_TEXT_HTML);
    then attachment becomes att1.txt. The error message remains the same.

    Do you have a sample for html? Regretfully Nokia documents are a bit thin when it comes to samples and hands on info.

    BR,
    Marko

  11. #11
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    474
    I think this may be due to a "bug" I ran into the other day that I haven't taken the time to figure out -- when using the old libraries, if I set the type to multipart/mixed, it seems that setContentID method doesn't work -- or at least whatever is set gets "deleted" in the encoding process...

    Have a look at the hex dump of the message you create, and see if you can verify that the Content-Location header (I assume you're setting that?) is indeed getting "removed", and is basically nowhere to be found.

    -paul / ForumNokia

  12. #12
    Registered User
    Join Date
    Aug 2003
    Posts
    36
    Paul,

    I'm using Nokia MMS Java libraries 1.1.
    The attachment itself arrives on the phone, so it certainly doesn't get deleted. I'm inclined to believe that the problem is in MMMessage.setContentType. Currently I'm trying:

    MMMessage mm...
    mm.setVersion(IMMConstants.MMS_VERSION_10);
    mm.setMessageType(IMMConstants.MESSAGE_TYPE_M_SEND_REQ);
    mm.setFrom("121234/TYPE=PLMN");
    mm.addToAddress("+49179000000/TYPE=PLMN");
    mm.setContentType(IMMConstants.CT_APPLICATION_MULTIPART_RELATED);
    mm.setMultipartRelatedType(IMMConstants.CT_TEXT_HTML);


    And this must me wrong, but I can't find the right way, that's why I'm bugging people here for help.

    BR,
    Marko

  13. #13
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    474
    1)I'm not saying that the attachment gets "deleted", just the ContentLocation header -- it seems to be ignored during the encoding.

    2)Using HTML as the presentation language is not supported. That's what you are doing in these two lines:

    mm.setContentType(IMMConstants.CT_APPLICATION_MULTIPART_RELATED);
    mm.setMultipartRelatedType(IMMConstants.CT_TEXT_HTML);

    If you want to *include* an HTML file as one of the parts of the message, that is one thing, but trying to use it as the presentation part is something completely different.

    But maybe Arturas can clarify that he's just including HTML as a part of the message, and not doing what you're trying to do.

    I would expect to see something like this in the SMIL:

    <text src="myhtml.html" region="Text" />

    And then you have included the html file as a part of the message, given it the appropriate headers (e.g.ContentLocation has to be "myhtml.html", ContentType should be "text/html")....

    -paul / ForumNokia

  14. #14
    Registered User
    Join Date
    Mar 2003
    Posts
    15
    Hmmmm... Very interesting.

    I set the content type of MMMessage to CT_APPLICATION_MULTIPART_MIXED, but I get the same result - an "invisible" object in the MMS message. Could it be that I set content id of content part incorrectly ? In my code it looks like this:

    content.setContentId("<"+ (++m_nContentPartID) +">");

    Is it correct ?

    BR,
    Arturas B.

  15. #15
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    474
    What do you mean "invisible"?

    It will NOT show up in the MMS Viewer, b/c HTML is not a supported media type in the MMS Viewer. It will always only show up in the Objects list.

    The *problem* that I think there is, is this:
    when using ...MIXED as the message type, the ContentID and/or ContentLocation fields that you set in your Java code are NOT encoded into the message, so when you look at the Objects list you just see att1 or att2 or whatever, instead of the name / number you gave it with the setContentID method.

    Your code looks fine.

    -paul / ForumNokia

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •