What is the endpoint for POST of Axis 2 JSON Web Services?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

What is the endpoint for POST of Axis 2 JSON Web Services?

Bing Li
What is the endpoint for POST of Axis 2 JSON Web Services?

Dear all,

I created a JSON Web service with Axis2. The service can be invoked by RPC client properly.

The service code is as follows.

package com.greatfree.Study;

// Created: 03/21/2012, Bing Li
public class WeatherService
{
Weather weather;
public void setWeather(Weather weather)
{
this.weather = weather;
}
public Weather getWeather()
{
return this.weather;
}
}

package com.greatfree.Study;

import java.util.Date;

public class Weather
{
float temperature;
String forecast;
boolean rain;
float howMuchRain;
Date time;
public void setTemperature(float temp)
{
temperature = temp;
}
public float getTemperature()
{
return temperature;
}
public void setForecast(String fore)
{
forecast = fore;
}
public String getForecast()
{
return forecast;
}
public void setRain(boolean r)
{
rain = r;
}
public boolean getRain()
{
return rain;
}
public void setHowMuchRain(float howMuch)
{
howMuchRain = howMuch;
}
public float getHowMuchRain()
{
return howMuchRain;
}
public void setTime(Date time)
{
this.time = time;
}
public Date getTime()
{
return this.time;
}
}

When I access the GET method, getWeather, with Volley in Android, the below endpoint is used. Volley is a tool to access JSON Web services in Android (http://www.itsalif.info/content/android-volley-tutorial-http-get-post-put).


It works fine.

The code of Volley in Android is as below.

private void getJsonObjectRequest()
{
JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.GET, getURLJsonObj, new Response.Listener<JSONObject>()
{
@Override
public void onResponse(JSONObject response)
{
txtResponse.setText("Response: " + response.toString());
}
}, new Response.ErrorListener()
{

@Override
public void onErrorResponse(VolleyError error)
{
// TODO Auto-generated method stub
}
});

// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsObjRequest);
}

However, I don't know what is the endpoint for the POST method, setWeather.

The below one cannot be found by the server.


Using the below one, the error message on the server is org.apache.axis2.AxisFault: namespace mismatch require http://Study.greatfree.com found.
 

The volley code to invoke the above endpoint is as follows.

private void postJsonObjectRequest()
{
JSONObject obj = new JSONObject();
try
{
obj.put("temperature", "88.2");
obj.put("forecast", "Sunny");
obj.put("rain", "false");
obj.put("howMuchRain", "0.3");
}
catch (JSONException e)
{
e.printStackTrace();
}

JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.POST, postURLJsonObj, obj, new Response.Listener<JSONObject>()
{

@Override
public void onResponse(JSONObject response)
{
}
}, new Response.ErrorListener()
{

@Override
public void onErrorResponse(VolleyError error)
{
// TODO Auto-generated method stub
}
});

// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsObjRequest);
}

Could you please give me a hand?

Thanks so much!
LB