SERVICE_UNAVAILABLE Google Web Toolkit - gwt

I have a small GWT project ongoing and I keep getting this error everytime i run it in developement mode.
HTTP ERROR: 503
Problem accessing /Segnalazioni_Degrado.html. Reason:
SERVICE_UNAVAILABLE
--------------------------------------------------------------------------------
Powered by Jetty://
These are the service classes I've created: DataLayerService, DataLayerServiceAsync, DataLayerImpl
package com.tesi.client;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.List;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
#RemoteServiceRelativePath("dataLayer")
public interface DataLayerService extends RemoteService {
List<Segnalazione> getListaSegnalazioniAttivePerMappa();
}
.
package com.tesi.client;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.List;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface DataLayerServiceAsync {
void getListaSegnalazioniAttivePerMappa(AsyncCallback<List<Segnalazione>> callback);
}
.
package com.tesi.server;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.tesi.client.DataLayerService;
import com.tesi.client.Segnalazione;
public class DataLayerServiceImpl extends RemoteServiceServlet implements
DataLayerService {
#Override
public List<Segnalazione> getListaSegnalazioniAttivePerMappa() {
// TODO Auto-generated method stub
List<Segnalazione> listaSegnalazioniAttive= new ArrayList<Segnalazione>();
try {
Connection con = ConnectionPool.getInstance().getConnection();
Statement stmt = con.createStatement();
ResultSet segnalazioniAttive = stmt
.executeQuery("SELECT * FROM SEGNALAZIONI_ATTIVE");
while(segnalazioniAttive.next()) {
//popolo gli oggetti segnalazione
Segnalazione s = new Segnalazione();
s.setCategoria(segnalazioniAttive.getString("categoria"));
s.setData(segnalazioniAttive.getDate("data"));
s.setDescrizione(segnalazioniAttive.getString("descrizione"));
s.setIndirizzo(segnalazioniAttive.getString("indirizzo"));
s.setNum_civico(segnalazioniAttive.getInt("numero_civico"));
listaSegnalazioniAttive.add(s);
}
} catch (Exception ex) {
}
return listaSegnalazioniAttive;
}
}
.
And this is the way I've modified the web.xml file
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee">
<!-- Servlets -->
<servlet>
<servlet-name>greetServlet</servlet-name>
<servlet-class>com.tesi.server.GreetingServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>greetServlet</servlet-name>
<url-pattern>/segnalazioni_degrado/greet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>dataLayerServlet</servlet-name>
<servlet-class>com.tesi.server.DataLayerServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dataLayerServlet</servlet-name>
<url-pattern>/segnalazioni_degrado/dataLayer</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>Segnalazioni_Degrado.html</welcome-file>
</welcome-file-list>
</web-app>
Have you got any clue how to solve it?

Sorry everyone, it was a stupid mistake.
I simply had to remove the GreetServlet from web.xml as that is just an example servlet.
Thank you anyway.

Try changing this
#RemoteServiceRelativePath("dataLayer")
into this
#RemoteServiceRelativePath("/segnalazioni_degrado/dataLayer")
If this does not work, please post the server error log

Related

Junit class failing after ACS Commons version upgrade to 5.3.4

I upgraded ACS Commons version from 5.0.6 to 5.3.4 in my project and now can see most of the test classes failing with below error
org.junit.jupiter.api.extension.ParameterResolutionException: Failed to resolve parameter [io.wcm.testing.mock.aem.junit5.AemContext arg0] in method [void com.test.test.core.filters.LoggingFilterTest.doFilter(io.wcm.testing.mock.aem.junit5.AemContext) throws java.io.IOException,javax.servlet.ServletException]: Could not create io.wcm.testing.mock.aem.junit5.ResourceResolverMockAemContext instance.
at org.junit.jupiter.engine.execution.ExecutableInvoker.resolveParameter(ExecutableInvoker.java:232)
at org.junit.jupiter.engine.execution.ExecutableInvoker.resolveParameters(ExecutableInvoker.java:176)
at org.junit.jupiter.engine.execution.ExecutableInvoker.resolveParameters(ExecutableInvoker.java:137)
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:118)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:184)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:180)
a
Caused by: org.reflections.ReflectionsException: Scanner TypeAnnotationsScanner was not configured
at org.reflections.Store.get(Store.java:39)
at org.reflections.Store.get(Store.java:61)
at org.reflections.Store.get(Store.java:46)
Please find below my test class. I am using JUnit version as below
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.junit5</artifactId>
<version>4.0.4</version>
<scope>test</scope>
</dependency>
Attaching the class below:
import java.io.IOException;
import java.util.List;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo;
import org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest;
import org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import io.wcm.testing.mock.aem.junit5.AemContext;
import io.wcm.testing.mock.aem.junit5.AemContextExtension;
import uk.org.lidalia.slf4jext.Level;
import uk.org.lidalia.slf4jtest.LoggingEvent;
import uk.org.lidalia.slf4jtest.TestLogger;
import uk.org.lidalia.slf4jtest.TestLoggerFactory;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
#ExtendWith(AemContextExtension.class)
class LoggingFilterTest {
private LoggingFilter fixture = new LoggingFilter();
private TestLogger logger = TestLoggerFactory.getTestLogger(fixture.getClass());
#BeforeEach
void setup() {
TestLoggerFactory.clear();
}
#Test
void doFilter(AemContext context) throws IOException, ServletException {
MockSlingHttpServletRequest request = context.request();
MockSlingHttpServletResponse response = context.response();
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
requestPathInfo.setResourcePath("/content/test");
requestPathInfo.setSelectorString("selectors");
fixture.init(mock(FilterConfig.class));
fixture.doFilter(request, response, mock(FilterChain.class));
fixture.destroy();
List<LoggingEvent> events = logger.getLoggingEvents();
assertEquals(0, events.size());
}
}
Does anyone know why it is failing with the ACS Commons version change?
This is like breaking lot many junit test classes

jee 6 jaxrs get file not found

I have a utility project having the source and the application
package com.x.framework.api;
import java.security.Principal;
import javax.annotation.Resource;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.csx.enterprise.webframework.security.LDAPUser;
import com.csx.enterprise.webframework.util.FrameworkThreadProperties;
import com.csx.enterprise.webframework.util.Log;
import com.csx.enterprise.webframework.util.WebFrameworkConstants;
#Stateless
#Path("/security")
#Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public class SecurityResource {
#Resource
SessionContext ctx;
#GET
#Path("me")
#Produces(MediaType.APPLICATION_JSON)
public Response getMe() {
...
}
package com.x.framework.api;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
#ApplicationPath("/api")
public class JaxrsApplication extends Application{
}
I have a web project with web.xml
<servlet>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.x.framework.api.JaxrsApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
<filter-mapping>
<filter-name>CSXSecurityFilter</filter-name>
<url-pattern>/api/*</url-pattern>
</filter-mapping>
But when I hit the URL https://localhost:9443/webframework/api/security/me, I keeps getting Error 404: java.io.FileNotFoundException: SRVE0190E: File not found: /api/security/me. Any suggestions?
The coding is fine. I had to go to the installedApp directory and extracted the ear file and found the files were not updated accordingly by the Eclipse. So it's not a coding issue, but more of a publishing issue.

The servlets named [Myclass] and [mypropackage.Myclass] are both mapped to the url-pattern [/myclass] which is not permitted [duplicate]

This question already has answers here:
java.lang.IllegalArgumentException: The servlets named [X] and [Y] are both mapped to the url-pattern [/url] which is not permitted
(7 answers)
Closed 6 years ago.
The following error occurs when I start the server
Server Tomcat v7.0 Server at localhost failed to start.
When I look into the console for errors ,I think this is the problem "The servlets named [Myclass] and [mypropackage.Myclass] are both mapped to the url-pattern [/myclass] which is not permitted".
what is the problem here and how to fix it ?
Web.xml code
<?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" id="WebApp_ID"
version="3.0">
<display-name>myproject</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Myclass</servlet-name>
<servlet-class>mypropackage.Myclass</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Myclass</servlet-name>
<url-pattern>/myclass</url-pattern>
</servlet-mapping>
</web-app>
Servlet -class code :
package mypropackage;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class Myclass
*/
#WebServlet("/myclass")
public class Myclass extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* #see HttpServlet#HttpServlet()
*/
public Myclass() {
super();
// TODO Auto-generated constructor stub
}
/**
* #see Servlet#init(ServletConfig)
*/
public void init(ServletConfig config) throws ServletException {
// TODO Auto-generated method stub
}
/**
* #see HttpServlet#service(HttpServletRequest request,
HttpServletResponse response)
*/
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
System.out.println("service method");
String uname = "user";
String pass = "abcd";
String un = request.getParameter("username");
String pw = request.getParameter("password");
String msg = " ";
if(un.equals(uname) && pw.equals(pass))
{
msg = "hello" + un + "login successful";
}
else
{
msg = "hello" + pw + "login failed";
}
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println(msg);
}
}
This is logs in console:
Caused by: java.lang.IllegalArgumentException: The servlets named [Myclass] and [mypropackage.Myclass] are both mapped to the url-pattern [/myclass] which is not permitted
at org.apache.catalina.deploy.WebXml.addServletMapping(WebXml.java:293)
at org.apache.catalina.startup.ContextConfig.processAnnotationWebServlet(ContextConfig.java:2428)
at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2103)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2064)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2057)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1304)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:889)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:386)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5412)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
You indeed defined your servlet twice:
using #WebServlet("/myclass") annotation into class mypropackage.MyClass
Using web.xml where you defined servlet Myclass.
Both instances of servlet are mapped to the same URL and this is what container tells you. You just should use only one of the ways to define servlet: using annotations or using web.xml. I prefer to use web.xml but probably this is because I used to define servelts there years before the annotations were invented. So, you are welcome to make your choice yourself.
IMHO using web.xml is more flexible. You do not have to decide what is the URL you are mapping your servlet at development time and can deploy the same servlet several times and map it to multiple URLs.

(Servlet) Request to display the name of the user.... Error with Eclipse

i am facing problem while running example which shows how a parameter is passed to a servlet in request object from html page.
My index.html contails-
<form action="welcome" method="get">
Enter your name<input type="text" name="name"><br>
<input type="submit" value="login">
</form>
my .xml contains
<?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" id="WebApp_ID" version="3.0">
<display-name>FirstServlet</display-name>
<servlet>
<servlet-name>check</servlet-name>
<servlet-class>MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>check</servlet-name>
<url-pattern>/check</url-pattern>
</servlet-mapping>
</web-app>
and .java
package cmctest;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
String user=request.getParameter("user");
out.println("<h2> Welcome "+user+"</h2>");
} finally {
out.close();
}
}
}
when i am running this on server i am getting error,
please help me out to resolve this problem.
error image here
(remove dot please ~ i am new here and running low with rep >.< )
stack.imgur.com/iN85H[dot]jpg
i have even tried to run downloaded example in/for eclipse but still same error

Cannot make REST call with url-pattern other than /*

I'm trying to do a simple REST Web Application using Tomcat 7, Apache Wink, and the Jackson JSON Processor, but seem to be hitting a wall. If I look in my web.xml file, I see:
<!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>Example Web Application</display-name>
<servlet>
<servlet-name>ExampleServlet</servlet-name>
<servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.dummy.example.server.ExampleApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ExampleServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>
Now, if I substitute /* for the URL pattern instead, the REST call works, but when I use /services/*, it fails.
In my ExampleApplication I see:
package com.dummy.example.server;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
import org.codehaus.jackson.map.AnnotationIntrospector;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.introspect.JacksonAnnotationIntrospector;
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector;
public class ExampleApplication extends Application {
/**
* Get the list of service classes provided by this JAX-RS application
*/
#Override
public Set<Class<?>> getClasses() {
Set<Class<?>> serviceClasses = new HashSet<Class<?>>();
serviceClasses.add(com.dummy.example.server.services.Employee.class);
return serviceClasses;
}
#SuppressWarnings("deprecation")
#Override
public Set<Object> getSingletons() {
Set<Object> s = new HashSet<Object>();
// Register the Jackson provider for JSON
// Make (de)serializer use a subset of JAXB and (afterwards) Jackson annotations
// See http://wiki.fasterxml.com/JacksonJAXBAnnotations for more information
ObjectMapper mapper = new ObjectMapper();
AnnotationIntrospector primary = new JaxbAnnotationIntrospector();
AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();
AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary);
mapper.getDeserializationConfig().setAnnotationIntrospector(pair);
mapper.getSerializationConfig().setAnnotationIntrospector(pair);
// Set up the provider
JacksonJaxbJsonProvider jaxbProvider = new JacksonJaxbJsonProvider();
jaxbProvider.setMapper(mapper);
s.add(jaxbProvider);
return s;
}
}
And in my Employee class, I have:
package com.dummy.example.server.services;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.json.simple.JSONObject;
#Path("/services/employee")
#Produces(MediaType.APPLICATION_JSON)
#SuppressWarnings("unchecked")
public class Employee {
#GET
public JSONObject get() {
JSONObject json = new JSONObject();
json.put("Name", "Example");
return json;
}
}
Any ideas? I've been banging my head against this for some time now
The url-pattern parameter for your servlet (in the web.xml) is independent from the path you specify in your Employee class.
<servlet-mapping>
<servlet-name>ExampleServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
means your servlet listens on the /services/ sub-path.
#Path("/services/employee")
means that your REST application listens on the /services/employee "sub-sub-path".
So your webservice is exposed at localhost:8080/example/services/services/employee (the concatenation of the url-pattern and the #Path annotation).
If you want to expose it at localhost:8080/example/services/employee with the mentioned url-pattern, you need to change the Employee class needs to have:
#Path("employee")
Where would you expect /services/* to go? The web-app states what URL patterns the web application is willing to service. This makes the application server (e.g., JBoss, GlassFish) route /services/foo/bar/whatever to your web application. The Employee class will be invoked in response to a request to /services/employee so you can make that request. Nothing else is registered so /services/* should result in either a 404 or 400 response. Since /services/* is registered to your web application, I would expect a 400.