31

A week ago I downloaded Glassfish 4.1. Did a zip install. Attempted to use Admin Console to create a JDBC Connection Pool. Received this error message:

java.lang.IllegalStateException: getOutputStream() has already been called for this response

Lots of references to that error. Lots of people declared it "Asked & Answered". But I can't find a single reference anywhere to that problem, let alone a solution.

But if anyone believes it's been answered, please be sure to add a link to the solution to this problem: New installation. Did nothing but open the console and try to create a new JDBC Connection Pool.

Resource Type: javax.sql.DataSource.  
Vendor: MySql. 

I've stored mysql-connector-java-5.1.35.jar in \glassfish4\glassfish\lib

Here's the closest thing to a solution I found. But it was for GF v3.

I finally have tracked down the actual problem in my domain.xml: -Dorg.glassfish.web.rfc2109_cookie_names_enforced=false was missing in the domain.xml created by asupgrade. I just added it to the domain.xml jvm-options and GF v3 now works as expected. Added:
<jvm-options>-Dorg.glassfish.web.rfc2109_cookie_names_enforced=false</jvm-options>

Tried that. Didn't work. (I pasted the GF log entry to show the recommended line is added to the domain.xml GF used on startup.)

I tried digging out domain.xml from my old v3 server and using it in the new v4. That didn't work.

Other questions involving my Exception message all related to getting it with a deployed app -- mostly servlets. But this is a clean server. No apps have been installed.

I found a lot of links to people working on this Exception as a GF bug. Most are awhile ago. None gave a workaround or even said they'd ever solved it.

Can anyone offer a solution?
Or let me know if this is just a bug Oracle decided not to fix?
Or know of where I can find help? This is killing me.

In case it helps here is the GF log for a clean start up (with the jvm insert in the domain.xml.) It also shows the stack trace for the failed attempt to create a JDBC Connection Pool.

NOTE: I pulled out all [INFO] log entries. And the [WARNING] entries that are left all seem related to Grizzly.

[2015-10-09T12:21:24.598-1000] [] [INFO] [NCLS-GFLAUNCHER-00005] [javax.enterprise.launcher] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1444429284598] [levelValue: 800] [[
  JVM invocation command line:
C:\Program Files\Java\jdk1.8.0_05\bin\java.exe
-cp
C:/glassfish4/glassfish/modules/glassfish.jar
-XX:+UnlockDiagnosticVMOptions
-XX:NewRatio=2
-XX:MaxPermSize=192m
-Xmx512m
-javaagent:C:/glassfish4/glassfish/lib/monitor/flashlight-agent.jar
-client
-Djavax.xml.accessExternalSchema=all
-Djavax.net.ssl.trustStore=C:\glassfish4\glassfish\domains\domain1/config/cacerts.jks
-Djdk.corba.allowOutputStreamSubclass=true
-Dfelix.fileinstall.dir=C:\glassfish4\glassfish/modules/autostart/
-Dorg.glassfish.additionalOSGiBundlesToStart=org.apache.felix.shell,org.apache.felix.gogo.runtime,org.apache.felix.gogo.shell,org.apache.felix.gogo.command,org.apache.felix.shell.remote,org.apache.felix.fileinstall
-Dcom.sun.aas.installRoot=C:\glassfish4\glassfish
-Dfelix.fileinstall.poll=5000
-Djava.endorsed.dirs=C:\glassfish4\glassfish/modules/endorsed;C:\glassfish4\glassfish/lib/endorsed
-Djava.security.policy=C:\glassfish4\glassfish\domains\domain1/config/server.policy
-Dosgi.shell.telnet.maxconn=1
-Dfelix.fileinstall.bundles.startTransient=true
-Dcom.sun.enterprise.config.config_environment_factory_class=com.sun.enterprise.config.serverbeans.AppserverConfigEnvironmentFactory
-Dfelix.fileinstall.log.level=2
-Dorg.glassfish.web.rfc2109_cookie_names_enforced=false
-Djavax.net.ssl.keyStore=C:\glassfish4\glassfish\domains\domain1/config/keystore.jks
-Djava.security.auth.login.config=C:\glassfish4\glassfish\domains\domain1/config/login.conf
-Dfelix.fileinstall.disableConfigSave=false
-Dfelix.fileinstall.bundles.new.start=true
-Dcom.sun.aas.instanceRoot=C:\glassfish4\glassfish\domains\domain1
-Dosgi.shell.telnet.port=6666
-Dgosh.args=--nointeractive
-Dcom.sun.enterprise.security.httpsOutboundKeyAlias=s1as
-Dosgi.shell.telnet.ip=127.0.0.1
-DANTLR_USE_DIRECT_CLASS_LOADING=true
-Djava.awt.headless=true
-Dcom.ctc.wstx.returnNullForDefaultNamespace=true
-Djava.ext.dirs=C:\Program Files\Java\jdk1.8.0_05/lib/ext;C:\Program Files\Java\jdk1.8.0_05/jre/lib/ext;C:\glassfish4\glassfish\domains\domain1/lib/ext
-Djdbc.drivers=org.apache.derby.jdbc.ClientDriver
-Djava.library.path=C:/glassfish4/glassfish/lib;C:/ProgramData/Oracle/Java/javapath;C:/Windows/Sun/Java/bin;C:/Windows/System32;C:/Windows;C:/glassfish4/glassfish/ C:/Program Files/Dell/Dell Data Protection/Drivers/TSS/bin;C:/Program Files (x86)/Common Files/Intuit/QBPOSSDKRuntime;C:/Program Files (x86)/QuickTime/QTSystem;D:/Bulletproof/bpMySql/bin;C:/glassfish4/glassfish
com.sun.enterprise.glassfish.bootstrap.ASMain
-upgrade
false
-domaindir
C:/glassfish4/glassfish/domains/domain1
-read-stdin
true
-asadmin-args
--host,,,localhost,,,--port,,,4848,,,--secure=false,,,--terse=false,,,--echo=false,,,--interactive=true,,,start-domain,,,--verbose=false,,,--watchdog=false,,,--debug=false,,,--domaindir,,,C:\glassfish4\glassfish\domains,,,domain1
-domainname
domain1
-instancename
server
-type
DAS
-verbose
false
-asadmin-classpath
C:/glassfish4/glassfish/lib/client/appserver-cli.jar
-debug
false
-asadmin-classname
com.sun.enterprise.admin.cli.AdminMain]]

 [2015-10-09T12:21:27.864-1000] [glassfish 4.1] [WARNING] [] [org.glassfish.grizzly.config.Utils] [tid: _ThreadID=17 _ThreadName=RunLevelControllerThread-1444429287050] [timeMillis: 1444429287864] [levelValue: 900] [[
  Instance could not be initialized. Class=interface org.glassfish.grizzly.http.server.AddOn, name=http-listener-1, realClassName=org.glassfish.grizzly.http2.Http2AddOn]]

[2015-10-09T12:21:27.962-1000] [glassfish 4.1] [WARNING] [] [org.glassfish.grizzly.config.Utils] [tid: _ThreadID=17 _ThreadName=RunLevelControllerThread-1444429287050] [timeMillis: 1444429287962] [levelValue: 900] [[
  Instance could not be initialized. Class=interface org.glassfish.grizzly.http.server.AddOn, name=http-listener-2, realClassName=org.glassfish.grizzly.http2.Http2AddOn]]

[2015-10-09T12:21:27.970-1000] [glassfish 4.1] [WARNING] [] [org.glassfish.grizzly.config.Utils] [tid: _ThreadID=17 _ThreadName=RunLevelControllerThread-1444429287050] [timeMillis: 1444429287970] [levelValue: 900] [[
  Instance could not be initialized. Class=interface org.glassfish.grizzly.http.server.AddOn, name=admin-listener, realClassName=org.glassfish.grizzly.http2.Http2AddOn]]

[2015-10-09T12:21:31.120-1000] [glassfish 4.1] [WARNING] [] [org.glassfish.grizzly.config.Utils] [tid: _ThreadID=75 _ThreadName=pool-13-thread-1] [timeMillis: 1444429291120] [levelValue: 900] [[
  Instance could not be initialized. Class=interface org.glassfish.grizzly.http.server.AddOn, name=http-listener-1, realClassName=org.glassfish.grizzly.http2.Http2AddOn]]

[2015-10-09T12:21:31.135-1000] [glassfish 4.1] [WARNING] [] [org.glassfish.grizzly.config.Utils] [tid: _ThreadID=75 _ThreadName=pool-13-thread-1] [timeMillis: 1444429291135] [levelValue: 900] [[
  Instance could not be initialized. Class=interface org.glassfish.grizzly.http.server.AddOn, name=http-listener-2, realClassName=org.glassfish.grizzly.http2.Http2AddOn]]

[2015-10-09T12:21:37.895-1000] [glassfish 4.1] [WARNING] [] [javax.enterprise.system.container.web.com.sun.web.security] [tid: _ThreadID=48 _ThreadName=admin-listener(4)] [timeMillis: 1444429297895] [levelValue: 900] [[
  Context path from ServletContext:  differs from path from bundle: /]]

 [2015-10-09T12:22:46.963-1000] [glassfish 4.1] [WARNING] [] [javax.enterprise.web] [tid: _ThreadID=48 _ThreadName=admin-listener(4)] [timeMillis: 1444429366963] [levelValue: 900] [[
  StandardWrapperValve[FacesServlet]: Servlet.service() for servlet FacesServlet threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response
    at org.apache.catalina.connector.Response.getWriter(Response.java:777)
    at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:224)
    at com.sun.faces.context.ExternalContextImpl.getResponseOutputWriter(ExternalContextImpl.java:851)
    at com.sun.faces.context.PartialViewContextImpl.createPartialResponseWriter(PartialViewContextImpl.java:504)
    at com.sun.faces.context.PartialViewContextImpl.access$300(PartialViewContextImpl.java:79)
    at com.sun.faces.context.PartialViewContextImpl$DelayedInitPartialResponseWriter.getWrapped(PartialViewContextImpl.java:642)
    at javax.faces.context.PartialResponseWriter.startDocument(PartialResponseWriter.java:120)
    at com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError(AjaxExceptionHandlerImpl.java:202)
    at com.sun.faces.context.AjaxExceptionHandlerImpl.handle(AjaxExceptionHandlerImpl.java:127)
    at javax.faces.context.ExceptionHandlerWrapper.handle(ExceptionHandlerWrapper.java:100)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    at com.sun.webui.jsf.util.UploadFilter.doFilter(UploadFilter.java:233)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
    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.doChainInvoke(StandardPipeline.java:678)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
    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:745)
]]
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
George
  • 509
  • 2
  • 9
  • 25
  • Also faced it. I am afraid this is still unresolved issue: https://java.net/jira/browse/GLASSFISH-21353. Since Oracle abandoned commercial support for Glassfish, these things could be expected, but this is so basic functionality that makes me very disappointed. – Miljen Mikic Oct 11 '15 at 15:01

8 Answers8

30

According to the following JIRA tickets:

this is still an unresolved issue. Even though we can expect such things since Oracle abandoned a commercial support for Glassfish, it is still horrible that such basic functionality does not work.

However, if you are really desperate, there is a very nasty workaround. Glassfish arrives with a predefined JDBC pool DerbyPool that you probably won't need, unless you are dealing with Java DB. Feel free to edit it by changing Datasource classname to com.mysql.jdbc.jdbc2.optional.MysqlDataSource and adjusting additional properties to point on MySQL Server instance. Prior to doing this hack, make sure that you put MySQL connector to the Glassfish's lib folder.

UPDATE

Just noticed that there is a Glassfish version that has been patched, it is called Payara and available for download here. According to the documentation, it is a GlassFish 4.1 clone, patched and further developed by the community.

Miljen Mikic
  • 14,765
  • 8
  • 58
  • 66
  • It may be nasty, but to me it seems elegant. Unfortunately I also need a JMS Connection Factory (I think your suggestion also solves that because there is a jms/_defaultConnectionFactory). BUT ... then I need a JMS Destination Resouce for which nothing is configured and using the admin console to create one throw a class java.lang.RuntimeException. So if the problem is using GF 4 w/JMS its still not solved. – George Oct 11 '15 at 20:34
  • @George There is a comment under the second JIRA ticket, "Please note that not only JDBC Connection Pool is broken , due to this issue we can't create any of the following resources..". Unfortunately, it seems that this is a very serious issue. – Miljen Mikic Oct 11 '15 at 20:40
  • @George It is hard for me to say it since I have spent many wonderful years with Glassfish, but have you considered switching to e.g. WildFly ? God knows when this would be fixed. Look at this comment under the ticket: " I'm sorry for not responding earlier (*been busy with school projects and final exams*.."?! – Miljen Mikic Oct 11 '15 at 20:45
  • I'm overloaded but here's an update: I trashed v4.1. Was working back through prior versions, because I know there was a version that once worked. If 4.0 fails I will try Payara next. Re: WildFly I tired but I'm not a server guy. 95% of my need is to prototyple the client side Java GUI. And all that needs is basic JMS messaging back and forth with the server data base. So I loved GF's Admin console. And loved being able to autodeploy ".ear" packages. So intimidated by WildFly's need for XML. Maybe some day when really desperate (Any WildFly training classes yet?) – George Oct 12 '15 at 19:53
  • 1
    @George Try Payara - it is GF 4.1 with most of the bugs fixed. I also trashed v4.1, and continued successfully with Payara. – Miljen Mikic Oct 12 '15 at 20:00
  • Miljen solved the original question. Dump GlassFish 4.anything. Use Payara. Easy download. Admin console works exactly as it should. Trivial JDBC and JMS resources easily set up (just remember to store MySql Connector Jar in C:\payara41\glassfish\lib). [Grin ... is there any chance I can sneak in the question of what properties env needs [in InitialContext(env)] so my local client can do a JNDI lookup of the Resources Payara so easily configured? Payara is running on localhost. ] – George Oct 13 '15 at 03:11
  • @George Not sure that understood completely, but I usually perform JNDI lookup without any additional properties; just with `InitialContext ctx = new InitialContext(); SomeResource res = (SomeResource) ctx.lookup("jndi/something");` – Miljen Mikic Oct 13 '15 at 08:09
  • I think InitialContext() works inside an EJB container like an Enterprise Bean. [In that case /glassfish/lib has a jndi-properties file with this Key:Value Pair. Key="java.naming.factory.initial" Value: com.sun.enterprise.naming.impl.SerialInitContextFactory" the container looks up for itself]. But my client runs outside (for now on Eclipse). It needs InitialContext(env) with other properties ... and for some reason JBoss, Old GF, and I assume Payara all need different sets of them. And they are always difficult to find. A remote client will need still others. – George Oct 13 '15 at 22:46
  • I've restarted the InititialContext environment question as a new question. [link](http://stackoverflow.com/questions/33114983/what-are-environment-properties-for-payara-initialcontext-from-free-standing-jav) – George Oct 14 '15 at 01:17
  • @George I see, however unfortunately I am not familiar with performing the lookup outside the container. Good luck! – Miljen Mikic Oct 14 '15 at 08:30
18

I`ve just rolled back to the 4.1.0 from 4.1.1 - works fine. Realy insane bug of GlassFish :(

a.parfenov
  • 528
  • 6
  • 16
8

Have the same problem, and this will surely make me choose an other application servers, why not tomee, jboss, wildfly, ...

Anyway here is an other workarround, just paste this peace of xml into domain.xml (between the others connection pool)

<jdbc-connection-pool connection-validation-method="auto-commit" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" wrap-jdbc-objects="false" res-type="javax.sql.DataSource" name="mysql_dbuser_rootPool">
      <property name="URL" value="jdbc:mysql://localhost:3306/ANYDB?zeroDateTimeBehavior=convertToNull"></property>
      <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
      <property name="Password" value="THEPASS"></property>
      <property name="portNumber" value="3306"></property>
      <property name="databaseName" value="ANYDB"></property>
      <property name="User" value="THEUSER"></property>
      <property name="serverName" value="localhost"></property>
    </jdbc-connection-pool>

Hope that help

Pascal Fares
  • 21,959
  • 2
  • 14
  • 12
  • Thanks to everyone. But I took the last suggestion. Moved to WildFly. I loved Glassfish's approach. And Wildfly is horribly non-user-freindly. But had to give up. I needed JMS ... and I hate "workarounds. PS: I tried Payara on the way. I thought it was better than Glassfish, but couldn't find help there either. Too young I guess. – George Nov 10 '15 at 21:16
  • @George I guess you can mark this one as the accepted answer, as it works for your question. – orezvani Jan 15 '17 at 12:47
7

It is possible to manage JDBC connections with asadmin utility - AFAIK admin GUI is just a frontend to it.

The asadmin usage is described here: https://docs.oracle.com/cd/E26576_01/doc.312/e24928/jdbc.htm#GSADG00420

E.g.

asadmin> create-jdbc-connection-pool --datasourceclassname org.apache.derby.jdbc.ClientDataSource \\
  --restype javax.sql.XADataSource \\
  --property portNumber=1527:password=APP:user=APP:serverName=localhost:databaseName=sun-appserv-samples:connectionAttributes=\;create\\=true \\
  sample_derby_pool

Cheers,

JN01
  • 577
  • 5
  • 11
  • Here is an example which works for me: asadmin create-jdbc-connection-pool --datasourceclassname oracle.jdbc.pool.OracleDataSource --restype javax.sql.DataSource --property portNumber=1521:password=supergeheim:user=onlineshop_user:serverName=localhost Onlineshop //the values do not matter so much as there is no exception in the admin console if you edit the datasource. – the hand of NOD Mar 16 '17 at 19:26
4

This was a bug in GlassFish 4.1.1 as brothers have been mentioned, but it has been resolved in GlassFish 4.1.2 so you can simply download to it here, and for more info go here

Anas
  • 688
  • 7
  • 24
  • 1
    I would say that it is the best answer and the most right solution. Just update your GlassFish. In my case it helped (4.1.1 -> 4.1.2). – disable1992 Jun 20 '17 at 18:39
3

If you are using Oracle just edit the file ..glassfish/domains/domain1/config/domain.xml. Look for the resources tag and add:

<jdbc-connection-pool datasource-classname="oracle.jdbc.pool.OracleConnectionPoolDataSource" name="MyPoolName" res-type="javax.sql.ConnectionPoolDataSource">
  <property name="User" value="UserName"></property>
  <property name="URL" value="jdbc:oracle:thin:@//localhost:1521/xe"></property>
  <property name="Password" value="UserPassword"></property>
</jdbc-connection-pool>

Dont forget to copy the jdbc driver in lib, and change the URL to your needs. Next start glassfish, go to JDBC Connection Pools and test your connection.

  • Fabian,thanks for the help, but but me its too late. I took a prior suggestion to move to wildfly, and there's no going back. Hope it helps others though. Merrry Christmas – George Dec 12 '15 at 20:20
  • Also, you can do it from cli with: `asadmin create-jdbc-connection-pool --datasourceclassname oracle.jdbc.pool.OracleDataSource --restype javax.sql.DataSource --property user=myuser:password=mypassword:url="jdbc\:oracle\:thin\:@myserverip\:1521\:myschema" myConnectionPool`and to create a resource `asadmin create-jdbc-resource --connectionpoolid myConnectionPool jdbc/myJdbcResourceName` – cirovladimir May 08 '18 at 18:59
3

I had to do this in my assignment and was getting the same error while creating JDBC resources (Java runtime exception) and JDBC Connection pools (java.lang.IllegalStateException: getOutputStream() has already been called for this response)

I later realized this is a buggy version and our prof had already told us to use Glassfish 4.1 (https://glassfish.java.net/download-archive.html) and everything worked fine. If you don't have to use 4.1.1. please go for 4.1 instead.

VIshu Kamble
  • 125
  • 9
2

The nightly build contains the fix!.You can download the nightly build from Oracle