I am using eclipse Luna,tomcat 7 and axis 1.6. I am creating webservice for spring mvc controller. Here is my code
package com.hp.hpl.ress.phoenix.web;
import com.hp.hpl.ress.phoenix.service.*;
import com.hp.hpl.ress.phoenix.domain.*;
import com.hp.hpl.ress.phoenix.flex.service.HomeViewService;
import com.hp.hpl.ress.phoenix.flex.service.NotificationFacade;
import com.hp.hpl.ress.phoenix.flex.vo.UserVO;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.TimeZone;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class PhoenixController {
protected final Logger logger = Logger.getLogger(getClass().getName());
@Autowired
private InstallationService installationService;
@Autowired
private HomeViewService homeViewService;
@RequestMapping("/home.htm")
public ModelAndView showHomePage() {
List<Installation> allInstallations =
installationService.getAllInstallations();
ModelAndView mav = new ModelAndView("home");
mav.addObject("pageName", "Home Page");
mav.addObject("installations", allInstallations);
return mav;
}
@RequestMapping("/viewInstallation.htm")
public ModelAndView viewInstallation(@RequestParam("installationId") String
installationId) {
logger.debug("Started to render installation view: " + new Date());
Installation installation =
installationService.getInstallation(Integer.parseInt(installationId));
ModelAndView mav = new ModelAndView("viewInstallationDetail");
mav.addObject("pageName", "Installation detail");
mav.addObject("installation", installation);
logger.debug("Finished rendering installation view: " + new Date());
return mav;
}
@RequestMapping("/viewZone.htm")
public ModelAndView viewZone(@RequestParam("zoneId") String zoneId) {
logger.debug("Started to render zone view: " + new Date());
Zone zone = installationService.getZone(Integer.parseInt(zoneId));
ModelAndView mav = new ModelAndView("viewZoneDetail");
mav.addObject("pageName", "Zone detail");
mav.addObject("zone", zone);
logger.debug("Finished rendering zone view: " + new Date());
return mav;
}
@RequestMapping("/viewSensor.htm")
public ModelAndView viewSensor(@RequestParam("sensorId") String sensorId) {
logger.debug("Started to render sensor view: " + new Date());
Sensor sensor = installationService.getSensor(Integer.parseInt(sensorId));
Calendar start =
Calendar.getInstance(TimeZone.getTimeZone(sensor.getTimeZone()));
start.set(Calendar.HOUR_OF_DAY, 0);
start.set(Calendar.MINUTE, 0);
start.set(Calendar.SECOND, 0);
start.set(Calendar.MILLISECOND, 0);
Calendar end = (GregorianCalendar)start.clone();
end.add(Calendar.DATE, 1);
List<SensorReading> readings =
installationService.getRangeOfReadings(sensor, start, end);
ModelAndView mav = new ModelAndView("viewSensorDetail");
mav.addObject("pageName", "Installation details");
mav.addObject("sensor", sensor);
mav.addObject("readings", readings);
logger.debug("Finished rendering sensor view: " + new Date());
return mav;
}
@RequestMapping("/homeSummary.htm")
public ModelAndView homeSummary() {
ModelAndView mav = new ModelAndView("viewHomeSummary");
//yyyy/MM/dd HH:mm
UserVO userSummary = homeViewService.getUserSummary(1, "2010/08/01 00:00",
3);
mav.addObject("UserSummary", userSummary);
return mav;
}
public void setInstallationService(InstallationService installationService)
{
this.installationService = installationService;
}
}
When i try to create web service for this controller using eclipse i am getting Selection must be WSDL Error.. I tried many times. i have added axis 2 in project facets also,
I had your same problem and i used this solution. Using spring controller as services in this way:
@RequestMapping(value = "services/utente/getUtenteByUsername", method = RequestMethod.GET)
@ResponseBody
public String getUtenteDaUsername( @RequestParam("username") String username, Model model) {
utente = utenteBo.findByUsername(username);
String jsonResult = "";
if (utente != null) {
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
jsonResult = gson.toJson(utente);
return jsonResult;
}
else {
return null;
}
}
I've used json to send the response. Hope can helps you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.