Hot questions for Using GlassFish in web applications

Top Java Programmings / GlassFish / web applications

Question:

I'm walking with this error several weeks, i've never work with java web applications so i'm really lost on this.

My setup is:

  • Glassfish 5.0
  • Netbeans IDE 8.2
  • Java 8 Update 181 (64-bit)
  • Java 10.0.2 (64-bit)
  • Java SE Development Kit 8 Update 181 (64-bit)
  • Java(TM) SE Development Kit 10.0.2 (64-bit)

The error is the following:

Grave:   Exception while deploying the app [ociumfinal-ear] : Cannot resolve reference [Local ejb-ref name=chat.ChatUsers/usuarioEjb,Local 3.x interface =com.eventos.UsuarioFacadeLocal,ejb-link=null,lookup=,mappedName=,jndi-name=,refType=Session] because there are [2] ejbs in the application with interface com.eventos.UsuarioFacadeLocal. 

Interface(UsuarioFacadeLocal.java):

package com.eventos;

import java.util.List;
import javax.ejb.Local;
import javax.ejb.Remote;

@Local
public interface UsuarioFacadeLocal {

void create(Usuario usuario);

void edit(Usuario usuario);

void remove(Usuario usuario);

Usuario find(Object id);

List<Usuario> findByUsuario(String usuario);

List<Usuario> findAll();

List<Usuario> findAllUsuarioCliente();

List<Usuario> findRange(int[] range);

List<Usuario> findUsuarioLosed(String email);

int count();

}

Implementation(UsuarioFacade.java):

package com.eventos;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;


@Stateless
public class UsuarioFacade extends AbstractFacade<Usuario> implements 
UsuarioFacadeLocal {

@PersistenceContext(unitName = "com.eventos_ocium-ejb_ejbPU")
private EntityManager em;

@Override
protected EntityManager getEntityManager() {
    return em;
}

public UsuarioFacade() {
    super(Usuario.class);
}

@Override
public List<Usuario> findAll(){
    TypedQuery<Usuario> consultaUsuario= em.createNamedQuery("Usuario.findAll", Usuario.class);
    List<Usuario> lista= consultaUsuario.getResultList();
    return lista;
}

@Override
public List<Usuario> findAllUsuarioCliente(){
    TypedQuery<Usuario> consultaUsuario= em.createNamedQuery("Usuario.findAllUsuarioCliente", Usuario.class);
    List<Usuario> lista= consultaUsuario.getResultList();
    return lista;
}

@Override
public List<Usuario> findByUsuario(String usuario) {
    TypedQuery<Usuario> consultaUsuario= em.createNamedQuery("Usuario.findByUsuario", Usuario.class);
    consultaUsuario.setParameter("usuario", usuario);
    List<Usuario> lista= consultaUsuario.getResultList();
    return lista;
}

@Override
public List<Usuario> findUsuarioLosed(String email){
    TypedQuery<Usuario> consultaUsuario= em.createNamedQuery("Usuario.findUsuarioLosed", Usuario.class);
    consultaUsuario.setParameter("email", email);
    List<Usuario> lista= consultaUsuario.getResultList();
    return lista;
}

}

The code of the error itself(ChatUsers.java)(Is pretty big but it's only important the @EJB thing i guess..):

package chat;

import com.eventos.Usuario;
import com.eventos.UsuarioFacadeLocal;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;

@ManagedBean
@ApplicationScoped
public class ChatUsers implements Serializable {

private List<Usuario> usuariosConectados;
private List<Usuario> usuariosConectadosGeneral;
private List<Usuario> usuariosConectadosMayores;
private List<Usuario> usuariosConectadosMenores;
//(beanName = "ChatUsers")
@EJB
private UsuarioFacadeLocal usuarioEjb;

@PostConstruct
public void init() {
    usuariosConectados = new ArrayList<>();
    usuariosConectadosGeneral = new ArrayList<>();
    usuariosConectadosMayores = new ArrayList<>();
    usuariosConectadosMenores = new ArrayList<>();
}

public List<Usuario> getUsuariosConectados() {
    return usuariosConectados;
}

public void setUsuariosConectados(List<Usuario> usuariosConectados) {
    this.usuariosConectados = usuariosConectados;
}

public List<Usuario> getUsuariosConectadosGeneral() {
    return usuariosConectadosGeneral;
}

public void setUsuariosConectadosGeneral(List<Usuario> usuariosConectadosGeneral) {
    this.usuariosConectadosGeneral = usuariosConectadosGeneral;
}

public List<Usuario> getUsuariosConectadosMayores() {
    return usuariosConectadosMayores;
}

public void setUsuariosConectadosMayores(List<Usuario> usuariosConectadosMayores) {
    this.usuariosConectadosMayores = usuariosConectadosMayores;
}

public List<Usuario> getUsuariosConectadosMenores() {
    return usuariosConectadosMenores;
}

public void setUsuariosConectadosMenores(List<Usuario> usuariosConectadosMenores) {
    this.usuariosConectadosMenores = usuariosConectadosMenores;
}

public void removeUser(String user) {
    usuariosConectados.remove(dameUsuario(user));
}

public void addUser(String user) {
    Usuario usuario = dameUsuario(user);
    boolean add = true;
    for(Usuario item:usuariosConectados){
        if(item.getUsuario().equals(usuario.getUsuario())){
            add = false;
        }
    }
    if(add){
        usuariosConectados.add(usuario);
    }

}

public boolean containsUser(String user) {
    return usuariosConectados.contains(dameUsuario(user));
}

public void removeGeneralUser(String user) {
    usuariosConectadosGeneral.remove(dameUsuario(user));
}

public void addGeneralUser(String user) {
    Usuario usuario = dameUsuario(user);
    boolean add = true;
    for(Usuario item:usuariosConectadosGeneral){
        if(item.getUsuario().equals(usuario.getUsuario())){
            add = false;
        }
    }
    if(add){
        usuariosConectadosGeneral.add(usuario);
    }
}

public boolean containsGeneralUser(String user) {
    return usuariosConectadosGeneral.contains(dameUsuario(user));
}

public void removeMayorUser(String user) {
    usuariosConectadosMayores.remove(dameUsuario(user));
}

public void addMayorUser(String user) {
    Usuario usuario = dameUsuario(user);
    boolean add = true;
    for(Usuario item:usuariosConectadosMayores){
        if(item.getUsuario().equals(usuario.getUsuario())){
            add = false;
        }
    }
    if(add){
        usuariosConectadosMayores.add(usuario);
    }
}

public boolean containsMayorUser(String user) {
    return usuariosConectadosMayores.contains(dameUsuario(user));
}

public void removeMinorUser(String user) {
    usuariosConectadosMenores.remove(dameUsuario(user));
}

public void addMinorUser(String user) {
    Usuario usuario = dameUsuario(user);
    boolean add = true;
    for(Usuario item:usuariosConectadosMenores){
        if(item.getUsuario().equals(usuario.getUsuario())){
            add = false;
        }
    }
    if(add){
        usuariosConectadosMenores.add(usuario);
    }

}

public boolean containsMinorUser(String user) {
    return usuariosConectadosMenores.contains(dameUsuario(user));
}

public Usuario dameUsuario(String user){
    System.out.println(">>>>>>>>>>>>>>>>>>> dame usuario");
    Usuario usuario = usuarioEjb.findByUsuario(user).get(0);
    System.out.println(">>>>>>>>>>>>>>>>>>> dame usuario"+usuario.getUsuario());
    System.out.println(">>>>>>>>>>>>>>>>>>> dame usuario"+usuario.getClave());
    return usuario;
}

}

I've tried the solution of this post aswell: Cannot resolve reference Local ejb-ref

This error repeats in another interface if i "solve" this interface(with the solution of the post above), and then the error return to this interface if i apply aswell. Anyway im not sure im applying well the solution.

I've also tried to change @Local to @Remote with no success.

Any help here is like finding an oasis in a desert. Thanks

EDIT:

The error for this interface is seemingly solved, as i did like @kret answer (and the other post) and named the @EJB:

 @EJB(beanName="UsuarioFacade")
private UsuarioFacadeLocal usuarioEjb;

I was doing it wrong with the name(it must be the name of the interface)

Now it gives me the same error in another reference:

Exception while deploying the app [ociumfinal-ear] : Cannot resolve reference [Local ejb-ref name=net.ocium.ociumapp.modelo.ModeloApp/eventoEjb,Local 3.x interface =com.eventos.EventoFacadeLocal,ejb-link=null,lookup=,mappedName=,jndi-name=,refType=Session] because there are [2] ejbs in the application with interface com.eventos.EventoFacadeLocal. 

ModeloApp:

public class ModeloApp {

private List<Evento> listEventEjb;
private List<GranEvento> listGranEvenEjb;
private List<Promocion> listPromocionEjb;
private EventBus eventBus;
private static String CHANNEL = "/app/";

@EJB
private EventoFacadeLocal eventoEjb;
@EJB
private GranEventoFacadeLocal granEventoEjb;
@EJB
private PromocionFacadeLocal promocionEjb;
@EJB
private QuedadaFacadeLocal quedadaEjb;
@EJB
private UsuarioFacadeLocal usuarioEjb;
@EJB
private PersonaFacadeLocal personaEjb;
@EJB
private ImagenFacadeLocal imagenEjb;
@EJB
private ProvinciaFacadeLocal provinciaEjb;
@EJB
private PoblacionFacadeLocal poblacionEjb;
@EJB
private BbddFacadeLocal bbddEjb;
@EJB
private EventoUsuarioFacadeLocal eventoUsuarioEjb;
@EJB
private EventoMensajeFacadeLocal eventoMensajeEjb;
@EJB
private QuedadaUsuarioFacadeLocal quedadaUsuarioEjb;
@EJB
private ConversacionFacadeLocal conversacionEjb;
@EJB
private RoomFacadeLocal roomEjb;
@EJB
private PropuestaQuedadaFacadeLocal propuestaQuedadaEjb;


@Inject
private ServletContext ctx;

public ModeloApp() {

}

public String dameListQuedadas() {

    return null;
}

public String dameListEvenHoy(String city) {
    String resultado = "Prueba correcta"; 
    city = (String)fromString(city);
    try {
        Context ctx = new InitialContext();///ocium-web-1.0-SNAPSHOT/
        eventoEjb = (EventoFacadeLocal) ctx.lookup("java:global/ocium-web/EventoFacade!com.eventos.EventoFacadeLocal");
        listEventEjb = new ArrayList<>();
        listEventEjb = eventoEjb.findByFechaHoyProvincia(dameProvinciaDesdeCity(city));
        resultado = "Contexto creado correcta size es:" + listEventEjb.size();
    } catch (NamingException ex) {
        Logger.getLogger(ModeloApp.class.getName()).log(Level.SEVERE, null, ex);
        System.out.println("kkkkk" + ex.getMessage());
    }
    ListEvenHoy listado = new ListEvenHoy();
    listado.setListadoEventos(listEventEjb);
    resultado = toString(listado);
    return resultado;
}

The error is the same so I've tried this:

@EJB(beanName="EventoFacade")
private EventoFacadeLocal eventoEjb;
@EJB(beanName="EventoFacade")
private GranEventoFacadeLocal granEventoEjb;
@EJB(beanName="EventoFacade")
private PromocionFacadeLocal promocionEjb;
@EJB(beanName="EventoFacade")
private QuedadaFacadeLocal quedadaEjb;
@EJB(beanName="EventoFacade")
private UsuarioFacadeLocal usuarioEjb;
@EJB(beanName="EventoFacade")
private PersonaFacadeLocal personaEjb;
@EJB(beanName="EventoFacade")
private ImagenFacadeLocal imagenEjb;
@EJB(beanName="EventoFacade")
private ProvinciaFacadeLocal provinciaEjb;
@EJB(beanName="EventoFacade")
private PoblacionFacadeLocal poblacionEjb;
@EJB(beanName="EventoFacade")
private BbddFacadeLocal bbddEjb;
@EJB(beanName="EventoFacade")
private EventoUsuarioFacadeLocal eventoUsuarioEjb;
@EJB(beanName="EventoFacade")
private EventoMensajeFacadeLocal eventoMensajeEjb;
@EJB(beanName="EventoFacade")
private QuedadaUsuarioFacadeLocal quedadaUsuarioEjb;
@EJB(beanName="EventoFacade")
private ConversacionFacadeLocal conversacionEjb;
@EJB(beanName="EventoFacade")
private RoomFacadeLocal roomEjb;
@EJB(beanName="EventoFacade")
private PropuestaQuedadaFacadeLocal propuestaQuedadaEjb;

What gives me this error:

Exception while deploying the app [ociumfinal-ear] : Warning : Unable to determine local  business vs. remote business designation for  EJB 3.0 ref Local ejb-ref name=net.ocium.ociumapp.modelo.ModeloApp/granEventoEjb,Local 3.x interface =com.eventos.GranEventoFacadeLocal,ejb-link=EventoFacade,lookup=,mappedName=,jndi-name=,refType=Session

Glassfish-ejb-jar.xml:

<glassfish-ejb-jar>
<security-role-mapping>
<role-name>ADMINISTRATIVO</role-name>
<group-name>ADMINISTRATIVO</group-name>
</security-role-mapping>
<security-role-mapping>
<role-name>COMERCIAL</role-name>
<group-name>COMERCIAL</group-name>
<group-name>GERENCIA</group-name>
</security-role-mapping>
<security-role-mapping>
<role-name>CLIENTE</role-name>
<group-name>CLIENTE</group-name>
<group-name>GERENCIA</group-name>
</security-role-mapping>
<security-role-mapping>
<role-name>USUARIO</role-name>
<group-name>USUARIO</group-name>
<group-name>CLIENTE</group-name>
<group-name>COMERCIAL</group-name>
<group-name>ADMINISTRATIVO</group-name>
<group-name>COLABORADOR</group-name>
<group-name>GERENCIA</group-name>
</security-role-mapping>
<security-role-mapping>
<role-name>COLABORADOR</role-name>
<group-name>COLABORADOR</group-name>
<group-name>GERENCIA</group-name>
</security-role-mapping>
<security-role-mapping>
<role-name>GERENCIA</role-name>
<group-name>GERENCIA</group-name>
</security-role-mapping>
<enterprise-beans>
<ejb>
  <ejb-name>AcreedorFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/AcreedorFacade</jndi-name>
</ejb>
<ejb>
  <ejb-name>AnuncioFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/AnuncioFacade</jndi-name>
</ejb>
<ejb>
  <ejb-name>ClienteFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/ClienteFacade</jndi-name>
</ejb>
<ejb>
  <ejb-name>ContactoFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/ContactoFacade</jndi-name>
</ejb>
<ejb>
  <ejb-name>ContactoUsuarioFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/ContactoUsuarioFacadeLocal</jndi- 
name>
</ejb>
<ejb>
  <ejb-name>EmpleadoFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/EmpleadoFacade</jndi-name>
</ejb>
<ejb>
  <ejb-name>EventoFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/EventoFacade</jndi-name>
</ejb>
<ejb>
  <ejb-name>EventoMensajeFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/EventoMensajeFacade</jndi-name>
</ejb>
<ejb>
  <ejb-name>EventoUsuarioFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/EventoUsuarioFacade</jndi-name>
</ejb>
<ejb>
  <ejb-name>GranEventoFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/GranEventoFacade</jndi-name>
</ejb>
<ejb>
  <ejb-name>GrupoFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/Grupo</jndi-name>
</ejb>
<ejb>
  <ejb-name>ImagenFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/ImagenFacade</jndi-name>
</ejb>
<ejb>
  <ejb-name>NegocioFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/NegocioFacade</jndi-name>
</ejb>
<ejb>
  <ejb-name>PersonaFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/PersonaFacade</jndi-name>
</ejb>
<ejb>
  <ejb-name>PoblacionFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/PoblacionFacade</jndi-name>
</ejb>
<ejb>
  <ejb-name>PromocionFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/PromocionFacade</jndi-name>
</ejb>
<ejb>
  <ejb-name>VideoFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/VideoFacade</jndi-name>
</ejb>
<ejb>
  <ejb-name>UsuarioGrupoFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/UsuarioGrupoFacade</jndi-name>
</ejb>
<ejb>
  <ejb-name>UsuarioFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/UsuarioFacade</jndi-name>
  <ejb-ref>
    <ejb-ref-name>ejb_ref1</ejb-ref-name>
  </ejb-ref>
</ejb>
<ejb>
  <ejb-name>QuedadaUsuarioFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/QuedadaUsuarioFacade</jndi-name>
</ejb>
<ejb>
  <ejb-name>QuedadaFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/QuedadaFacade</jndi-name>
</ejb>
<ejb>
  <ejb-name>PropuestaQuedadaFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/PropuestaQuedadaFacade</jndi-name>
</ejb>
<ejb>
  <ejb-name>ProveedorFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/ProveedorFacade</jndi-name>
</ejb>
<ejb>
  <ejb-name>ProvinciaFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/ProvinciaFacade</jndi-name>
</ejb>
<ejb>
  <ejb-name>SeccionFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/SeccionFacade</jndi-name>
</ejb>
<ejb>
  <ejb-name>ConversacionFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/ConversacionFacadeLocal</jndi-name>
</ejb>
<ejb>
  <ejb-name>RoomFacade</ejb-name>
  <jndi-name>java:global/ocium-ejb/RoomFacadeLocal</jndi-name>
</ejb>
</enterprise-beans>
 </glassfish-ejb-jar>

Any idea is really welcome

Thanks

EDIT:

Made a new post with the detailed new error: Glassfish error while deploying ear web application with multiple EJB references


Answer:

"Cannot resolve reference (...) because there are [2] ejbs in the application with interface com.eventos.UsuarioFacadeLocal". There is problem with injection, container does not know which one bean do you want to have injected. Delete one of implementations or define name of wanted bean in @EJB annotation

Question:

I'm new to web application development using java ee, netbeans and mac. I initially decided to use glassfish as my server, but later I have changed my mind and decided to use tomcat instead.

When I created a web application project that include a tomcat server and tried to run it, I got error "Deployment error:Starting of Tomcat failed, the server port 8080 is already in use". I think it is due to the fact that my previous Glassfish server is using the port. How to stop the Glassfish server?


Answer:

asadmin is the command for controlling glassfish. Specifically, you want to stop the currently running domain.

To get a list of domains, try:

asadmin list-domains

To stop a given domain, try:

asadmin stop-domain <yourdomain>

Question:

I have followed instructions from http://zetcode.com/java/ejb/ to create a simple web app. It runs fine with eclipse, where it uses Glassfish server 4.1. To deploy to Tomcat, I simply copied the war file produced to the webapps folder of Tomcat 9. Tomecat 9 extracted the war file fine, and the HTML files work fine, but anything related to Java servlets fail, as shown below.

What could I be missing?


Answer:

Standard Tomcat distribution doesn't support EJBs. Use Tomcat EE for that, see for instance this answer.

Question:

I have data base connection which i have configured via a listener class i configured properly in DD

    <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">

   <listener>
        <listener-class>contpack.startL</listener-class>
    </listener>
    <context-param>
        <param-name>username</param-name>
        <param-value>root</param-value>
    </context-param>
    <context-param>
        <param-name>password</param-name>
        <param-value>root</param-value>
    </context-param>
    <context-param>
        <param-name>url</param-name>
        <param-value>jdbc:mysql://localhost:3306/mysql</param-value>
    </context-param>

    <servlet>
        <servlet-name>hell</servlet-name>
        <servlet-class>com.contpack.Dbc</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>hell</servlet-name>
        <url-pattern>/Dbc</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>home.html</welcome-file>
    </welcome-file-list>
</web-app>

but still i am not able to deploy the project and server log show that startL.java listener class was not found why is this so as config is proper with the name and the listener class is:

        package com.contpack;

        import javax.servlet.*;
        import javax.servlet.http.*;
        import model.Database;


        public class startL implements ServletContextListener {

        public void contextInitialized(ServletContextEvent event)
        {
                ServletContext sc = event.getServletContext();
                String url = sc.getInitParameter("url");
                String user_name = sc.getInitParameter("username");
                String password = sc.getInitParameter("password");
             //   String database = sc.getInitParameter("database");
                Database db = new Database(url,user_name,password);
            //System.out.println("in the listener!!");
                sc.setAttribute("db", db);

        }

        public void contextDestroyed(ServletContextEvent event)
        {

        }
    }

The stack trace for server Log is:

    [2014-08-01T20:53:59.112+0530] [glassfish 4.0] [SEVERE] [] [javax.enterprise.system.core] 
    [tid: _ThreadID=34 _ThreadName=admin-listener(3)]
    [timeMillis: 1406906639112] [levelValue: 1000]
    [[Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: contpack.startL.java]]

if i remove the Listener tag then app runs fine


Answer:

...
<listener>
    <listener-class>contpack.startL</listener-class>
</listener>
...

and your listener is in the package

package com.contpack;

that means your listener fully qualified name is

com.contpack.startL

So setting a correct listener class will help. Your web.xml should look like the following

...
<listener>
    <listener-class>com.contpack.startL</listener-class>
</listener>
...

Still it is always a good idea to follow java naming convention

Question:

I'm setting up a new GlassFish Server 4.1.1 with one Java web service deployed on it. The web service has one web method, which receives JSON as an input parameter and as result it also returns a JSON. To serialize/deserialize Java objects to/from JSON I'm using the Gson library. The web method is calling an other web service and one run is executing approximately 2-3 minutes. I'm calling this web service for example 6-10 times in a loop, so the web method is waiting approximately 16-30 minutes to return a value. The problem is timeout, but I don't know where and how to set it for my problem.

I try to call this Java web service from a Visual Studio C# project, where I added a web reference where I defined the web reference URL of the web service. I also set the time for how long should the XML Web service client wait for the reply to a synchronous XML Web service request to arrive. I set it to 10 hours as is shown below.

static string CallEARSjDE(string json)
{
    EARSWebReference.EARSWebService EARSWS = new EARSWebReference.EARSWebService();
    EARSWS.Timeout = 36000000;    // 10 hours

    return EARSWS.EARSjDE(json);
}

I also set a timeout for a web service request I make in the Java web method. I set it to 1 hour.

Gson gson = new Gson();
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(1 * 3600000).build();   // timeout set to 1 hour
HttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();
HttpPost post = new HttpPost(this.ServiceURL);
StringEntity postingString = new StringEntity(gson.toJson(problemLCSRequest));
post.setEntity(postingString);
post.setHeader("Content-type", "application/json");
HttpResponse response = httpClient.execute(post);
HttpEntity entity = response.getEntity();
String responseString = EntityUtils.toString(entity, "UTF-8");

ProblemLCSResponse responseJson = gson.fromJson(responseString, ProblemLCSResponse.class);

Besides these two timeouts I also set a timeout in GlassFish admin console. I did it in Configurations → server-config → Web Container section where I set the session timeout to 36.000 seconds (10 hours).

For example, when I call a web service inside a web method 6 times I get the desired response. But when I call the web service more than 6 times, it throws me an exception shown below. I think the reason for this exception is in the timeout, but I don't know which one causes it and where can I change it.

Warning: StandardWrapperValve[EARSWebService]: Servlet.service() for servlet EARSWebService threw exception java.nio.channels.ClosedByInterruptException at java.nio.channels.spi.AbstractInterruptibleChannel.end(AbstractInterruptibleChannel.java:202) at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:478) at org.glassfish.grizzly.nio.transport.TCPNIOUtils.flushByteBuffer(TCPNIOUtils.java:149) at org.glassfish.grizzly.nio.transport.TCPNIOUtils.writeCompositeBuffer(TCPNIOUtils.java:87) at org.glassfish.grizzly.nio.transport.TCPNIOAsyncQueueWriter.write0(TCPNIOAsyncQueueWriter.java:129) at org.glassfish.grizzly.nio.transport.TCPNIOAsyncQueueWriter.write0(TCPNIOAsyncQueueWriter.java:106) at org.glassfish.grizzly.nio.AbstractNIOAsyncQueueWriter.write(AbstractNIOAsyncQueueWriter.java:260) at org.glassfish.grizzly.nio.AbstractNIOAsyncQueueWriter.write(AbstractNIOAsyncQueueWriter.java:169) at org.glassfish.grizzly.nio.AbstractNIOAsyncQueueWriter.write(AbstractNIOAsyncQueueWriter.java:71) at org.glassfish.grizzly.nio.transport.TCPNIOTransportFilter.handleWrite(TCPNIOTransportFilter.java:126) at org.glassfish.grizzly.filterchain.TransportFilter.handleWrite(TransportFilter.java:191) at org.glassfish.grizzly.filterchain.ExecutorResolver$8.execute(ExecutorResolver.java:111) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) at org.glassfish.grizzly.filterchain.FilterChainContext.write(FilterChainContext.java:890) at org.glassfish.grizzly.filterchain.FilterChainContext.write(FilterChainContext.java:858) at org.glassfish.grizzly.http.io.OutputBuffer.flushBuffer(OutputBuffer.java:1029) at org.glassfish.grizzly.http.io.OutputBuffer.flushBinaryBuffers(OutputBuffer.java:1016) at org.glassfish.grizzly.http.io.OutputBuffer.flushAllBuffers(OutputBuffer.java:987) at org.glassfish.grizzly.http.io.OutputBuffer.flush(OutputBuffer.java:738) at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:291) at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:275) at org.apache.catalina.connector.CoyoteOutputStream.flush(CoyoteOutputStream.java:175) at java.io.FilterOutputStream.flush(FilterOutputStream.java:140) at com.ctc.wstx.io.UTF8Writer.flush(UTF8Writer.java:103) at com.ctc.wstx.sw.BufferingXmlWriter.flush(BufferingXmlWriter.java:225) at com.ctc.wstx.sw.BaseStreamWriter.flush(BaseStreamWriter.java:259) at com.sun.xml.ws.util.xml.XMLStreamWriterFilter.flush(XMLStreamWriterFilter.java:71) at com.sun.xml.ws.streaming.XMLStreamWriterUtil.getOutputStream(XMLStreamWriterUtil.java:103) at com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:403) at com.sun.xml.ws.message.AbstractMessageImpl.writeTo(AbstractMessageImpl.java:192) at com.sun.xml.ws.api.message.MessageWrapper.writeTo(MessageWrapper.java:226) at com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:144) at com.sun.xml.ws.encoding.SOAPBindingCodec.encode(SOAPBindingCodec.java:242) at com.sun.xml.ws.transport.http.HttpAdapter.encodePacket(HttpAdapter.java:636) at com.sun.xml.ws.transport.http.HttpAdapter.access$100(HttpAdapter.java:108) at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:878) at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:422) at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:169) at org.glassfish.webservices.JAXWSServlet.doPost(JAXWSServlet.java:169) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283) at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167) at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206) at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180) at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235) at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536) at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571) at java.lang.Thread.run(Thread.java:748)


Answer:

Finally, I found the right timeout to set. I had to go to the admin panel and inside Configurations → server-config → Network Config I had to set the HTTP Request Timeout of http-listener-1.