I have problem that my Spring Rest Controllers is mapped other way than RestyGWT would like.
My application is on: http://localhost:8080/restgwt/
According to web.xml:
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/action-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
My Spring service/controller listen on:
http://localhost:8080/restgwt/service/test
But my RestyGWT service calls this url:
http://localhost:8080/restgwt/restgwt/test
And I don't know how to tell to RestyGWT to change url. Please help.
I know that the simplest solution would be changing in web.xml file servlet url-pattern parameter
from: <url-pattern>/service/*</url-pattern>
to: <url-pattern>/restgwt/*</url-pattern>
but I would like to make RestyGWT to change it's behaviour.
Here paste some additional code:
TestService on GWT side
package pl.korbeldaniel.restgwt.client;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.fusesource.restygwt.client.MethodCallback;
import org.fusesource.restygwt.client.RestService;
public interface TestService extends RestService {
#GET
#Path("test")
public void getInfo(MethodCallback<TestPojo> test);
}
TestService on Spring side
package pl.korbeldaniel.restgwt.server;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
#RestController()
public class TestService {
#RequestMapping(value = "test", method = RequestMethod.GET)
public #ResponseBody TestEntity getInfo() {
TestEntity test = new TestEntity();
System.out.println("Hit server for getting _1");
return new TestEntity();
}
}
Reffering to the official documentation:
Configuring service root URLs
There are two ways to configure service root URLs which are appended with the #Path annotation property when building the final service URL. For single service root URL the Defaults.setServiceRoot(String) method can be used. When several services with different service roots are used the #Options annotation is equipped with the serviceRootKey property which can be set to read service root entries provided with the static ServiceRoots.add(String, String) method.
Defaults.setServiceRoot(new Resource( GWT.getModuleBaseURL()).resolve("../rest").getUri());
So my REST path for RestyGWT becomes http://domain-name/myGwtAppModuleName/rest/furtherPath
where furtherPath is javax.ws.rs #Path(..) value
Putting the line directly in GIN ClientModule failed with java.lang.UnsatisfiedLinkError: com.google.gwt.core.client.impl.Impl.getModuleBaseURL()Ljava/lang/String
To avoid error this I've wrapped it up
public class ClientModule extends AbstractPresenterModule {
#Override
protected void configure(){
//your installs and binds here
bind(RestyGwtConfig.class).asEagerSingleton();
}
}
public class RestyGwtConfig {
static {
Defaults
.setServiceRoot(new Resource( GWT.getModuleBaseURL()).resolve("../rest").getUri());
}
}
Related
I am getting a 404 response from a #RestController returning an object.
Everything seems fine as I get a correct response from another url in the same #RestController, but it is a different class.
I see no exception or any other error in the logs though. Only 404.
Problematic class is defines as follows:
public class Menu implements Serializable {
private static final long serialVersionUID=1L;
private String url;
private List<Menu> submenu;
... getters and setters ...
}
I have no problems with a similar class. Only difference is there is a List of String instead of a List of Menu.
What may be causing the problem?
EDIT:
Didn't want to add too much code to the question.
This is the Controller:
package org.web.ui.controller;
import java.io.IOException;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Collection;
import javax.annotation.Resource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpResponse;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.databind.ObjectMapper;
import mx.org.ife.rfe.siirfe.comun.web.bean.LoginStatus;
import mx.org.ife.rfe.siirfe.comun.web.controller.UserLoginController;
import mx.org.ife.rfe.siirfe.comun.web.ui.model.Menu;
#RestController
#RequestMapping("/menu")
public class menuController {
private LoginStatus loginStatus ;
public menuController() {
ArrayList<String> _roles = new ArrayList<>();
_roles.add("TESTCASE");
loginStatus = new LoginStatus();
loginStatus.setRoles(_roles);
loginStatus.setAnonymous(true);
loginStatus.setError(false);
}
#RequestMapping(value = "/app.do")
public Menu app(HttpResponse response) {
return new Menu();
}
#RequestMapping(value="/test1.do")
public LoginStatus test1(Principal user) {
return loginStatus;
}
}
This is LoginStatus class
public class LoginStatus implements Serializable {
private static final long serialVersionUID = 1L;
private boolean anonymous = true;
private Boolean error;
private String errorMessage;
private List<String> roles;
... Getters and Setters ...
}
This is in the web.xml
<servlet>
<servlet-name>spring-dispatcher-servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:/webApplicationContext.xml,
classpath*:/environmentContext.xml,
classpath*:/daoContext.xml,
classpath*:/menuContext.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-dispatcher-servlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
Now, a get request to hostname/menu/app.do returns a 404 error code while a get request to hostname/menu/test1.do returns a correctly formatted json object.
I ommited initialization of the menu for simplicity.
Example outputs from test with wget:
$ wget wlcap1:9102/siilnere-web/menu/app.do -O -
--2016-12-08 18:16:51-- http://wlcap1:9102/siilnere-web/menu/app.do
Resolving wlcap1... 172.19.94.15
Connecting to wlcap1|172.19.94.15|:9102... connected.
HTTP request sent, awaiting response... 404 Not Found
2016-12-08 18:16:51 ERROR 404: Not Found.
06:16 PM
$ wget wlcap1:9102/siilnere-web/menu/test1.do -O -
--2016-12-08 18:16:55-- http://wlcap1:9102/siilnere-web/menu/test1.do
Resolving wlcap1... 172.19.94.15
Connecting to wlcap1|172.19.94.15|:9102... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/json]
Saving to: 'STDOUT'
2016-12-08 18:16:55 (7.62 MB/s) - written to stdout [101]
06:16 PM
$ wget wlcap1:9102/siilnere-web/menu/test1.do -O - 2>/dev/null
{"roles":["EJEMPLO"],"token":null,"anonymous":true,"error":false,"errorMessage":null,"username":null}
In your app(...) controller method, I think that HttpResponse is not a valid param. It should be ServletResponse or HttpServletResponse. You can refer to the list of accepted param types of a controller method here: http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestMapping.html
I have a strange behaviour with a Spring Data Rest implementation (version 2.5.2.RELEASE).
I'm trying to register a #Bean of ResourceProcessor<Resource<Entity>>, but there is something strange.
I'm trying with two kinds of solutions:
1) Declaring the #Bean in a class:
#Bean
public ResourceProcessor<Resource<Author>> authorProcessor() {
return new ResourceProcessor<Resource<Author>>() {
#Override
public Resource<Author> process(Resource<Author> resource) {
System.out.println("method process of bean ResourceProcessor of class RepositoryBaseConfiguration");
return resource;
}
};
}
2) Implementing the interface ResourceProcessor:
#Component
public class AuthorResourceProcessor implements ResourceProcessor<Resource<Author>> {
#Override
public Resource<Author> process(Resource<Author> resource) {
System.out.println("method process of class AuthorResourceProcessor");
return resource;
}
}
The processors are completely ignored: the message is never printed.
I noticed that the class org.springframework.data.rest.webmvc.ResourceProcessorInvoker has a constructor:
public ResourceProcessorInvoker(Collection<ResourceProcessor<?>> processors) {
//...
}
This constructor is invoked 2 times at the start of the application instead of only one time (as I will expect), and I don't understand why.
The first time, the "processors" variable is solved with the two beans (as expected) and with the bean org.springframework.data.rest.webmvc.ProfileResourceProcessor.
But the second time, the "processors" variable is solved with only the bean org.springframework.data.rest.webmvc.ProfileResourceProcessor.
The second configuration #Override the first one.
Any idea?
The problem depends on the configurations loaded at the startup of the application.
I had this configuration on the web.xml:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/spring-web-config.xml</param-value>
</context-param>
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>org.springframework.data.rest.webmvc.RepositoryRestDispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
So, the ContextLoaderListener loaded the correct configuration in the first time; the "load-on-startup" property of the servlet "RepositoryRestDispatcherServlet" launch a second context configuration load.
I also had a custom class that extended org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration, but this custom class was ignored by the moment that the constructor of RepositoryRestDispatcherServlet load the default RepositoryRestMvcConfiguration, causing the lost of the configurations.
To solve that issue I have created a custom RepositoryRestDispatcherServlet in this way:
public class AppRepositoryRestDispatcherServlet extends DispatcherServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
public AppRepositoryRestDispatcherServlet() {
configure();
}
public AppRepositoryRestDispatcherServlet(WebApplicationContext webApplicationContext) {
super(webApplicationContext);
configure();
}
private void configure() {
setContextClass(AnnotationConfigWebApplicationContext.class);
setContextConfigLocation(RepositoryBaseConfiguration.class.getName());
}
}
The class is the same as RepositoryRestDispatcherServlet, with the only difference that in the setContextConfigLocation is passed the custom class that extends RepositoryRestMvcConfiguration (RepositoryBaseConfiguration in this example).
Obviously I had to update the web.xml as follows:
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>my.package.AppRepositoryRestDispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
In this way, the configuration is correctly loaded and mantained.
in order to get my basic rest-api (only GET) working, i created this setup:
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>app</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>app</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>app</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
next i have this api controller:
package packagename.controller.api;
import java.util.concurrent.atomic.AtomicLong;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import packagename.model.Home;
#RestController
public class HomeApiController {
#RequestMapping("/api/home")
public Home greeting() {
return new Home(1, "asdas");
}
}
and the actual Home model:
package packagename.model;
public class Home {
private final long id;
private final String content;
public Home(long id, String content) {
this.id = id;
this.content = content;
}
public long getId() {
return id;
}
public String getContent() {
return content;
}
}
When i create the war file and put it into the webapps folder of my tomcat server, i open "localhost:8080/webappname/api/home".
Next i get 404-error, but i have no idea why.
Anybody could help me with this setup?
Thanks and Greetings!
You've mixed spring boot with traditional web application.
RestController is enough and there is no need to specify a web.xml.
What you need is removing web.xml and add dependency spring-boot-starter-tomcat and marking it as provided and change packaging to war and configuring war plugin continue without a web.xml.
And document http://docs.spring.io/spring-boot/docs/1.4.0.BUILD-SNAPSHOT/reference/htmlsingle/#build-tool-plugins-maven-packaging could help.
Please let me know if any question.
I have two servers (Apache and JBoss AS7) and I need to provide access to all http methods to a client. All these request must be sent via ajax.
Example of the client code:
$.ajax({
type: "get",
url: "http://localhost:9080/myproject/services/mobile/list",
crossDomain: true,
cache: false,
dataType: "json",
success: function(response) {
console.log(response);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(textStatus);
console.log(jqXHR.responseText);
console.log(errorThrown);
}
});
In JBoss AS7 I'm using RESTEasy, implementing CORS as follows:
#Path("/mobile")
#Provider
#ServerInterceptor
public class GroupMobile implements MessageBodyWriterInterceptor {
#Inject
private GroupDAO groupDAO;
#GET
#Path("/list")
#Produces(MediaType.APPLICATION_JSON)
public List<Group> getGroups() {
return groupDAO.listAll();
}
#Override
public void write(MessageBodyWriterContext context) throws IOException,
WebApplicationException {
context.getHeaders().add("Access-Control-Allow-Origin", "*");
context.proceed();
}
#OPTIONS
#Path("/{path:.*}")
public Response handleCORSRequest(
#HeaderParam("Access-Control-Request-Method") final String requestMethod,
#HeaderParam("Access-Control-Request-Headers") final String requestHeaders) {
final ResponseBuilder retValue = Response.ok();
if (requestHeaders != null)
retValue.header("Access-Control-Allow-Headers", requestHeaders);
if (requestMethod != null)
retValue.header("Access-Control-Allow-Methods", requestMethod);
retValue.header("Access-Control-Allow-Origin", "*");
return retValue.build();
}
}
web.xml and beans.xml are empty files.
When I access MyIP:8080 (Apache), I get the error message:
XMLHttpRequest cannot load http://localhost:9080/myproject/services/mobile/list?_=1359480354190. Origin http://MyIP:8080 is not allowed by Access-Control-Allow-Origin.
Does anybody know what is wrong?
The newest resteasy (3.0.9-Final) include a utility class org.jboss.resteasy.plugins.interceptors.CorsFilter.
You can add the CorsFilter object into Application's singleton
objects set, or add it into ProviderFactory in ResteasyDeployment
directly.
The following is the sample application class:
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import org.jboss.resteasy.plugins.interceptors.CorsFilter;
#ApplicationPath("/api")
public class RestApplication extends javax.ws.rs.core.Application {
Set<Object> singletons;
#Override
public Set<Class<?>> getClasses() {
HashSet<Class<?>> clazzes = new HashSet<>();
clazzes.add(VersionService.class);
return clazzes;
}
#Override
public Set<Object> getSingletons() {
if (singletons == null) {
CorsFilter corsFilter = new CorsFilter();
corsFilter.getAllowedOrigins().add("*");
singletons = new LinkedHashSet<Object>();
singletons.add(corsFilter);
}
return singletons;
}
}
The problem you are having is your are trying to do cross-site scripting. You accessed the page at http://MyIP:8080 and so the browser is preventing you from accessing resources outside that domain. This is very browser specific and browser based work arounds will all be different (you can disable security in Chrome globally, and on a per site basis in IE).
If you load the page as http://localhost:8080, it should then allow you access the query. Alternatively, you can implement a proxy which will forward the request.
Sounds like the issue is related to https://issues.jboss.org/browse/RESTEASY-878. You may not be able to catch CORS preflight requests with MessageBodyWriterInterceptor. Try using servlet filters (#WebFilter) instead.
Well, I have implemented a small solution, first I do a interceptor in my project Web
I created a class called "CORSInterceptor" the class is of the way.
import org.jboss.resteasy.annotations.interception.ServerInterceptor;
import org.jboss.resteasy.core.ResourceMethod;
import org.jboss.resteasy.core.ServerResponse;
import org.jboss.resteasy.spi.Failure;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.interception.MessageBodyWriterContext;
import org.jboss.resteasy.spi.interception.MessageBodyWriterInterceptor;
import org.jboss.resteasy.spi.interception.PreProcessInterceptor;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
#Provider
#ServerInterceptor
public class CorsInterceptor implements PreProcessInterceptor, MessageBodyWriterInterceptor {
/**
* The Origin header set by the browser at each request.
*/
private static final String ORIGIN = "Origin";
/**
* The Access-Control-Allow-Origin header indicates which origin a resource it is specified for can be
* shared with. ABNF: Access-Control-Allow-Origin = "Access-Control-Allow-Origin" ":" source origin string | "*"
*/
private static final String ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin";
//
private static final ThreadLocal<String> REQUEST_ORIGIN = new ThreadLocal<String>();
//
private final Set<String> allowedOrigins;
public CorsInterceptor(){
this.allowedOrigins = new HashSet<String>();
this.allowedOrigins.add("*");
}
#Override
public ServerResponse preProcess(HttpRequest request, ResourceMethod method) throws Failure, WebApplicationException {
if (!allowedOrigins.isEmpty()) {
REQUEST_ORIGIN.set(request.getHttpHeaders().getRequestHeaders().getFirst(ORIGIN));
}
return null;
}
#Override
public void write(MessageBodyWriterContext context) throws IOException, WebApplicationException {
if (!allowedOrigins.isEmpty() && (allowedOrigins.contains(REQUEST_ORIGIN.get()) || allowedOrigins.contains("*"))) {
context.getHeaders().add(ACCESS_CONTROL_ALLOW_ORIGIN, REQUEST_ORIGIN.get());
}
context.proceed();
}
}
In the File Web.xml, I add it
<context-param>
<param-name>resteasy.providers</param-name>
<param-value><package>.CorsInterceptor</param-value>
</context-param>
package: Ubication of the class.
Request JQuery that I have used.
$.ajax({
type: 'GET',
dataType: "json",
crossDomain : true,
cache:false,
url: "http://localhost:12005/ProyectoWebServices/ws/servicioTest",
success: function (responseData, textStatus, jqXHR) {
alert("Successfull: "+responseData);
},
error: function (responseData, textStatus, errorThrown) {
alert("Failed: "+responseData);
}
});
it worked fine for me. I hope that it can help you.
I faced the same issue recently and adding my solution which worked for me:
Following is what I did :
I created a class extending javax.ws.rs.core.Application and added a Cors Filter to it.
To the CORS filter, I added corsFilter.getAllowedOrigins().add("http://localhost:4200");.
Basically, you should add the URL which you want to allow Cross-Origin Resource Sharing. Ans you can also use "*" instead of any specific URL to allow any URL.
public class RestApplication
extends Application
{
private Set<Object> singletons = new HashSet<Object>();
public MessageApplication()
{
singletons.add(new CalculatorService()); //CalculatorService is your specific service you want to add/use.
CorsFilter corsFilter = new CorsFilter();
// To allow all origins for CORS add following, otherwise add only specific urls.
// corsFilter.getAllowedOrigins().add("*");
System.out.println("To only allow restrcited urls ");
corsFilter.getAllowedOrigins().add("http://localhost:4200");
singletons = new LinkedHashSet<Object>();
singletons.add(corsFilter);
}
#Override
public Set<Object> getSingletons()
{
return singletons;
}
}
And here is my web.xml:
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Restful Web Application</display-name>
<!-- Auto scan rest service -->
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/rest</param-value>
</context-param>
<listener>
<listener-class>
org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
</listener-class>
</listener>
<servlet>
<servlet-name>resteasy-servlet</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.app.RestApplication</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
There are some custom changes which you might not require or change like :
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
OR
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
OR
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/rest</param-value>
</context-param>
The most important code which I was missing when I was getting this issue was, I was not adding my class extending javax.ws.rs.Application i.e RestApplication to the init-param of <servlet-name>resteasy-servlet</servlet-name>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.app.RestApplication</param-value>
</init-param>
And therefore my Filter was not able to execute and thus the application was not allowing CORS from the URL specified.
PS: I am using RestEasy version: 3.12.1.Final
I am working with sample REST service with Apache CXF, But somehow I am not able to call the service. My implementation class is,
package com.ananth.lab.cfxrest.service;
import com.ananth.lab.cfxrest.vo.Address;
import com.ananth.lab.cfxrest.vo.Employee;
import org.springframework.stereotype.Service;
import javax.jws.WebService;
import javax.ws.rs.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
#Path("/cservice")
#Produces("application/xml")
public class EmployeeService {
#GET
#Path("/emp")
public Employee getEmployee() {
Address address1 = new Address();
address1.setCity("Chennai");
address1.setZip(63);
List<Address> list = new ArrayList<Address>();
Address address2 = new Address();
address2.setCity("Bangalore");
address2.setZip(49);
list.add(address1);
list.add(address2);
Employee emp = new Employee();
emp.setAddress(list);
emp.setEmployeeId("001");
emp.setEmployeeName("Ananth");
return emp;
}
}
My web.xml file is,
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Hello world REST service with apache cxf</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/beans.xml,WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
I deployed in Tomcat and the context path is "Lab". So I am trying to access the service like:
http://localhost:8080/Lab/cservice/emp
I am getting
No service was found.
I think you should make sure that your Employee class have a correctly "#" remark. just like below:
#XmlRootElement(name="cservice")
public class Employee (){
private String employeeId;
private String employeeName;
...
#XmlElement(name="employeeId")
public void setEmployeeId(String employeeId){
...
}
public String getEmployeeId(){
return this.employeeId;
}
#XmlElement(name="employeeName")
public void setEmployeeName(String employeeId){
...
}
public String getEmployeeName(){
return this.employeeName
}
...
...
}
and I suggest you to check WEB-INF/beans.xml & WEB-INF/applicationContext.xml.
Make sure your request url endpoint match your server endpoint.
combine url in web.xml and beans.xml result your endpoint