Results 1 to 3 of 3
  1. #1
    pista is offline Member
    Join Date
    Jul 2010
    Posts
    2
    Rep Power
    0

    Default Problem with Axis2 and JSON when calling web service in javascript

    Hi all. I have a problem when calling Axis2 web service from javascript. I want to use it with JSON format. So as Axis2 has JSON support, I have set both messageFormatter and messageBuilder like it is in documentation. Also I am using DynamicResponseHandler.
    Now, when I call it from javascript using GET method, it's working, but when I change it to POST, it not works. I am new to this, so I don't know, where is the problem. In Axis2 docs there is written that default is POST, so it should works, but for me not. Response never come back from server, and server is processing something till I stop him.

    Here is my service class

    package com.yms.tis.json;

    import org.apache.axis2.context.OperationContext;
    import org.apache.axis2.context.ServiceContext;

    public class JSONService {

    public void init(ServiceContext serviceContext) {

    }

    public void destroy(ServiceContext serviceContext) {

    }

    public void setOperationContext(OperationContext operationContext) {

    }

    public MenuItem[] getMenu() {

    MenuItem[] menu = new MenuItem[3];

    for (int i = 0; i < menu.length; i++) {
    MenuItem menuItem = new MenuItem(i, "menuitem" + i,
    "<div>toto je xxx content</div>");
    menu[i] = menuItem;
    }
    return menu;
    }

    }

    Here is the java script code:

    this is working

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script src="javascript/jquery-1.4.2.min.js" type="text/javascript"></script>
    </head>
    <body>
    RESULT:<br />
    <div id="result_panel">
    </div>
    </body>
    <script type="text/javascript">
    $.ajax({
    url: 'services/JSONService/getMenu?response=application/json',
    dataType: "json",
    type : "GET",
    success: function (xxx) {
    $("#result_panel").html(xxx.getMenuResponse.retu rn[0].content); },
    error: function (html) {
    alert('ERROR');
    }
    });
    </script>
    </html>

    and this not:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script src="javascript/jquery-1.4.2.min.js" type="text/javascript"></script>
    </head>
    <body>
    RESULT:<br />
    <div id="result_panel">
    </div>
    </body>
    <script type="text/javascript">
    $.ajax({
    url: 'services/JSONService/getMenu',
    dataType: "json",
    contentType: "application/json; charset=utf-8",
    type : "POST",
    success: function(msg) {
    $("#ReturnMessage").html(msg.d);
    },
    error: function (html) {
    alert('ERROR');
    }
    });
    </script>
    </html>

    Can you tell me what I've done wrong, please?
    Thanks a lot for any help.

  2. #2
    Zaffi is offline Member
    Join Date
    Jan 2011
    Posts
    1
    Rep Power
    0

    Default Same problem

    Hi Pista,

    did you get it working?

    I'm trying to connect to an axis2 json WS with dynamic response handler from android emulator. But if i set the contenType to "application/json" i will get no response from axis.

  3. #3
    pista is offline Member
    Join Date
    Jul 2010
    Posts
    2
    Rep Power
    0

    Default 'traditional' parameter

    Yes, the problem was that parameter traditional = true was missing for POST type, so it should looks like :

    var _json_request = function (method, data, callback, allowParalel) {
    var self = this;

    var url = 'services/TestService/' + method + '?response=application/json',
    responseElement = method + 'Response';

    var newRequest = $.ajax({
    type: 'POST',
    url: url,
    dataType: 'json',
    data: data,
    timeout: 10000,
    traditional: true,
    success: function (response) {
    $('#result_panel').html(response[responseElement]['return']);
    },
    error: function (response) {
    alert('Chyba v komunikácii so serverom!');
    }
    });

    Hope this helps you.

Similar Threads

  1. JSON Lib: json-lib-1.0-jdk13.jar
    By Raghuraman K in forum Advanced Java
    Replies: 3
    Last Post: 05-13-2010, 11:00 AM
  2. axis2 thread
    By sheky in forum Java Software
    Replies: 2
    Last Post: 01-06-2010, 11:38 AM
  3. JSON from javascript to java servlet
    By boss-tech in forum Java Servlet
    Replies: 1
    Last Post: 09-18-2009, 09:27 AM
  4. [SOLVED] calling javascript from applet method
    By shwein in forum Java Applets
    Replies: 5
    Last Post: 11-01-2008, 05:45 PM
  5. [SOLVED] calling javascript from applet
    By shwein in forum Java Applets
    Replies: 5
    Last Post: 11-01-2008, 12:45 AM

Tags for this Thread

Posting Permissions

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