5 Replies Latest reply on Feb 13, 2020 11:39 AM by jaikiran

    Why do Entity objects write to Wildfly log and console, but Websocket Endpoint won't?

    gberish

      This is my fouth try on 3 forums, and I can't even get insulted.

      So I assume the question is bad.

       

      Therefore, I hope someone takes pity and points me to the right starting point.

       

      My app is deployed in an EAR packaged to Wildfly. (The package outline is below).

       

      The package deploys One Websocket Endpoint, and two Java Persistence Entity objects. It deploys without error.

       

      When the The HTML script opens a new websocket an alert() confirms it returned an [object WebSocket]

       

      On instatiation both Entites write to System.out, and also use my handler to log to the Wildfly console & server.log.

      But I can't get the Websocket Endpoint to write to anything. 

      Not System.out. 

      Not the server.log.

      Not to the console.

       

      I'm obviously missing some structural understanding of how wildfly treats Websockets.  I.e. differently from other java classes..

      I mean simple Logging shouldn't require rocket science. Should it?

       

      Any help would be very much appreciated.

       

      This seems the most relevant part of my logging code:

         import java.util.logging.Logger;

        @ServerEndpoint("/WSTestSocket")

        public class WSEndpoint {

            @Transient

            final Logger logger = Logger.getLogger(WSEndpoint.class.getName());

       

      This is the EAR Package Outline.

      WSTest.ear

        META-INF

          application.xml

          MANEFEST.MF

        WSTest.jar

          META-INF

            MANIFEST.MF

            peristence.xml

          org

            america3

              websockets

                persistance

                  DataCarrier.class

                  EntityParent.class

                  Member.class

                  Name.class

                sockets

                  WSEndpoint.class

        WSTest.war

          META-INF

            MANIFEST.MF

          scripts

            scripts.js

          WEB-INF

            web.xml

          index.html

        • 1. Re: Why do Entity objects write to Wildfly log and console, but Websocket Endpoint won't?
          jaikiran

          Hello George,

           

          I see that you are using java.util.logging package to do the logging. Is there any specific logging.properties that you are using for your application? Also, can you post the snippet of the code where the logging is being done? What level are you using to log that message (debug(), info())?

          • 2. Re: Why do Entity objects write to Wildfly log and console, but Websocket Endpoint won't?
            gberish

            Thanks jaikiran

             

            I set my logging properties for the handler in the standalone-full.xml

             

              <profile>

                    <subsystem xmlns="urn:jboss:domain:logging:3.0">

            ...

                        <console-handler name="MY-CONSOLE" autoflush="true">

                            <formatter>

                                <named-formatter name="MY-PATTERN"/>

                            </formatter>

                            <target name="System.out"/>

                        </console-handler>

            ...

                        <logger category="org.america3" use-parent-handlers="false">

                            <level name="INFO"/>

                            <handlers>

                                <handler name="WSTEST"/>

                            </handlers>

                        </logger>

            ...

                        <formatter name="MY-PATTERN">

                            <pattern-formatter pattern="MeMeMe%s%n"/>

                        </formatter>

             

            Here is the code in my classes used to log

            FROM Member.java

                 //constructors

                public Member() {

                   System.out.println("\n************************ Member: System.out from Constructor");

                  logger.info("************************ Member: Logged from Constructor");

             

            FROM WSEndpoint

             

                @OnOpen

                public void open(Session session) {

                  System.out.println("\n************************ WSEndpoint: System.out from OnOpen");

                  logger.info("************************ WSEndpoint: Logged from OnOpen");

                }

            Which should be called when the HTML script instatiates a new socket with

                var socketURL = "ws://localhost:8080/WSTest/WSTestSocket";

                function openUp (){

                   if (!appsocket) {

                      alert("Opening: appsocket " + socketURL);

                     appsocket = new WebSocket(socketURL);

                     alert("appsocket open: " + appsocket); **** This returns [object:Websocket]]

             

            And this is what wildfly's log shows when it is started and deploys my EAR app:

                The Name and Member entities are clearly logging to the console. See "MeMeMe"

                And System.out is also logging to the console

             

            10:46:40,763 INFO  [stdout] (ServerService Thread Pool -- 66)

            10:46:40,764 INFO  [stdout] (ServerService Thread Pool -- 66) ************************ Member: System.out from Constructor

            MeMeMe************************ Member: Logged from Constructor

            10:46:40,796 INFO  [stdout] (ServerService Thread Pool -- 66)

            10:46:40,796 INFO  [stdout] (ServerService Thread Pool -- 66) ************************ Name: System.out from Constructor

            MeMeMe************************ Name: Logged from Constructor

             

            But nothing is showing up from WSEndpoint.java

             

            Hope you can suggest somewhere else to look.

            This is killing me

            • 3. Re: Why do Entity objects write to Wildfly log and console, but Websocket Endpoint won't?
              jaikiran

              What is the fully qualified package name of the WSEndpoint?

              • 4. Re: Why do Entity objects write to Wildfly log and console, but Websocket Endpoint won't?
                gberish

                Cudos to  jaikiran

                 

                Based on your hints I found I was right. 

                It was a dumb error that had nothing to do with logging..

                 

                The Ear had two modules:

                WSTest.jar that deployed the Session Beans and

                WSTest.war that deployed the HTML and script files,

                And I had the socket class in WSTest.jar with the Session Beans.

                 

                I'm not sure if this is the only solution, but based on your suggestions I moved the socket to WSTest.war's META-INF/classes folder.

                .

                And all worked.

                 

                I wish I knew how to use the forum better.

                But since this is under your reply, can I  check you comment with Correct Answer to see that you get credit?  You were the only programmer who helped,and I appreciate it.

                • 5. Re: Why do Entity objects write to Wildfly log and console, but Websocket Endpoint won't?
                  jaikiran

                  Hello George, I'm really glad that my hint helped you sort out the issue.

                  But since this is under your reply, can I  check you comment with Correct Answer to see that you get credit? 

                  I think you should mark your own answer as the correct one (that's a perfectly acceptable practice). That way other users get to know the exact change you did which got you past it.

                   

                  P.S: If you still want to credit my previous reply, you can "Like" it (there's a like link in each post) or even mark the reply as "Helpful".