users@grizzly.java.net

Re: SEVERE error thrown with grizzly-http-webserver-1.7.2 - SOLVED BOTH THAT and HTTPS example question

From: Danijel <danijel.bjelajac_at_gmail.com>
Date: Wed, 12 Mar 2008 11:32:18 -0700 (PDT)

Hello All,

just to let you know that I've figured out this HTTPS support problem.
:clap:
I did not set up SSLImplementation and my algorithm was wrong one

Here is the code for working EmbeddedSSLServer in case somebody is
interested in it

import java.net.HttpURLConnection;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.sun.grizzly.SSLConfig;
import com.sun.grizzly.http.SelectorThread;
import com.sun.grizzly.ssl.SSLSelectorThread;
import com.sun.grizzly.tcp.Adapter;
import com.sun.grizzly.tcp.OutputBuffer;
import com.sun.grizzly.tcp.Request;
import com.sun.grizzly.tcp.Response;
import com.sun.grizzly.util.buf.ByteChunk;
import com.sun.grizzly.util.net.jsse.JSSEImplementation;

public class EmbeddedSSLServer implements Adapter {
        private static Logger logger = Logger.getLogger( "grizzly.test" );
        private SSLConfig sslConfig;

        private void setUp() {
                sslConfig = new SSLConfig();
                // override system properties
                sslConfig.setTrustStoreFile( "c:/temp/key/ssltest-cacerts.jks" );
                logger.log( Level.INFO, "SSL certs path: " + sslConfig.getTrustStoreFile()
);
                sslConfig.setKeyStoreFile( "c:/temp/key/ssltest-keystore.jks" );
                logger.log( Level.INFO, "SSL keystore path: " +
sslConfig.getKeyStoreFile() );
                SSLConfig.DEFAULT_CONFIG = sslConfig;
        }

        private SelectorThread createSelectorThread( int port ) {
                SSLSelectorThread selectorThread = new SSLSelectorThread();
                SSLSelectorThread.setWebAppRootPath( "/dev/null" );
                selectorThread.setPort( port );
                selectorThread.setSSLConfig( sslConfig );
                try {
                        selectorThread.setSSLImplementation( new JSSEImplementation() );
                } catch ( ClassNotFoundException e ) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                // selectorThread.setSelectorReadThreadsCount(5);
                return selectorThread;
        }

        public static void main( String[] args ) {
                EmbeddedSSLServer server = new EmbeddedSSLServer();
                server.setUp();
                SelectorThread selectorThread = server.createSelectorThread( 8282 );
                selectorThread.setAdapter( server );
                selectorThread.setDisplayConfiguration( true );
                try {
                        selectorThread.initEndpoint();
                        selectorThread.startEndpoint();
                } catch ( Exception e ) {
                        System.out.println( "Exception in SelectorThread: " + e );
                } finally {
                        if ( selectorThread.isRunning() ) {
                                selectorThread.stopEndpoint();
                        }
                }
        }

        public void service( Request request, Response response ) throws Exception
{
                String requestURI = request.requestURI().toString();
                System.out.println( "New incoming request with URI: " + requestURI );
                response.setStatus( HttpURLConnection.HTTP_OK );
                byte[] bytes = "Here is my response text".getBytes();
                ByteChunk chunk = new ByteChunk();
                response.setContentLength( bytes.length );
                response.setContentType( "text/plain" );
                chunk.append( bytes, 0, bytes.length );
                OutputBuffer buffer = response.getOutputBuffer();
                buffer.doWrite( chunk, response );
                response.finish();
        }

        public void afterService( Request request, Response response ) throws
Exception {
                request.recycle();
                response.recycle();
        }

        public void fireAdapterEvent( String string, Object object ) {
        }
}


Danijel wrote:
>
> Hello Jeanfrancois,
>
> Thanks for the help,
> doing SelectorThread.setWebAppRootPath("/dev/null");
> solves the SEVERE error problem.
> I've posted an issue as you asked and assigned it to you(hope that is ok).
> Can you or someone else help me with HTTPS support part?
> I can not find example with SSLSelectorThread used on the server side.
> I tried configuring it with SSLConfig and then do same thing as with
> EmbeddedServer.
>
> Here is my code for this, I get browser prompt about certificate but
> service metod is never called.
> Is it a problem with algorithm, or am I using this completly wrong.
> I'm trying to do same thing as with EmbeddedServer, just to call it and
> get response but over HTTPS,
> again not static content is served.
>
>
> import java.net.HttpURLConnection;
> import java.util.logging.Level;
> import java.util.logging.Logger;
>
> import com.sun.grizzly.SSLConfig;
> import com.sun.grizzly.http.SelectorThread;
> import com.sun.grizzly.ssl.SSLSelectorThread;
> import com.sun.grizzly.tcp.Adapter;
> import com.sun.grizzly.tcp.OutputBuffer;
> import com.sun.grizzly.tcp.Request;
> import com.sun.grizzly.tcp.Response;
> import com.sun.grizzly.util.buf.ByteChunk;
>
> public class EmbeddedSSLServer implements Adapter {
> private static Logger logger = Logger.getLogger( "grizzly.test" );
> private SSLConfig sslConfig;
>
> private void setUp() {
> sslConfig = new SSLConfig();
> // override system properties
> sslConfig.setTrustStoreFile( "c:/temp/key/ssltest-cacerts.jks" );
> logger.log( Level.INFO, "SSL certs path: " +
> sslConfig.getTrustStoreFile() );
> sslConfig.setKeyStoreFile( "c:/temp/key/ssltest-keystore.jks" );
> logger.log( Level.INFO, "SSL keystore path: " +
> sslConfig.getKeyStoreFile() );
> // SSLConfig.DEFAULT_CONFIG = sslConfig;
> }
>
> private SelectorThread createSelectorThread( int port ) {
> SSLSelectorThread selectorThread = new SSLSelectorThread();
> SSLSelectorThread.setWebAppRootPath( "/dev/null" );
> selectorThread.setPort( port );
> selectorThread.setSSLConfig( sslConfig );
> // selectorThread.setSelectorReadThreadsCount(5);
> selectorThread.setAlgorithmClassName(
> SSLEchoStreamAlgorithm.class.getName() );
> return selectorThread;
> }
>
> public static void main( String[] args ) {
> EmbeddedSSLServer server = new EmbeddedSSLServer();
> server.setUp();
> SelectorThread selectorThread = server.createSelectorThread( 8282 );
> selectorThread.setAdapter( server );
> selectorThread.setDisplayConfiguration( true );
> try {
> selectorThread.initEndpoint();
> selectorThread.startEndpoint();
> } catch ( Exception e ) {
> System.out.println( "Exception in SelectorThread: " + e );
> } finally {
> if ( selectorThread.isRunning() ) {
> selectorThread.stopEndpoint();
> }
> }
> }
>
> public void service( Request request, Response response ) throws
> Exception {
> String requestURI = request.requestURI().toString();
> System.out.println( "New incoming request with URI: " + requestURI );
> response.setStatus( HttpURLConnection.HTTP_OK );
> byte[] bytes = "Here is my response text".getBytes();
> ByteChunk chunk = new ByteChunk();
> response.setContentLength( bytes.length );
> response.setContentType( "text/plain" );
> chunk.append( bytes, 0, bytes.length );
> OutputBuffer buffer = response.getOutputBuffer();
> buffer.doWrite( chunk, response );
> response.finish();
> }
>
> public void afterService( Request request, Response response ) throws
> Exception {
> request.recycle();
> response.recycle();
> }
>
> public void fireAdapterEvent( String string, Object object ) {
> }
> }
>
>
>
> Jeanfrancois Arcand-2 wrote:
>>
>> Hi Daniel,
>>
>> Danijel wrote:
>>> Hello all,
>>>
>>> I've been using grizzly for some time now, since version 1.5.X
>>> I was developing an app that was suppose to receive data over http and
>>> then
>>> using ARP return response later or after expiration of some time
>>> interval.
>>> My app did not need a full web app running, meaning I did not have a
>>> need
>>> for any web pages, servlets, filters, web.xml or anything like that.
>>> First I tried jetty continuations and that did not work for me.
>>> Then I found grizzly, embedded it with it and it worked great. I was
>>> able to
>>> receive data on port via http protocol and eventually I figured out your
>>> AsyncFilter stuff and completed the app.
>>
>> Good@
>>
>>>
>>> First for my getting to know grizzly purpose I created this simple
>>> EmbeddedServer class just to figure out how to initialy receive data.
>>
>> Might be good to blog about it (if you can :-))!
>>
>>
>>>
>>> With all the different jars before complete http bundle that was
>>> published
>>> and with 1.7.1 version of
>>> grizzly-http-webserver jar this simple class works fine.
>>> But when I wanted to update to 1.7.2 version this SEVERE error shows up,
>>> even though everything still works.
>>
>> Oufff...At least I didn't break it to seriously :-)
>>
>>>
>>> Here is my EmbeddedServer server code and outputs running first 1.7.1
>>> jar
>>> and then output of 1.7.2 jar
>>> In both cases response get written to the web browser when I go to
>>> http://localhost:8282/test
>>>
>>> import java.net.HttpURLConnection;
>>> import com.sun.grizzly.http.SelectorThread;
>>> import com.sun.grizzly.tcp.Adapter;
>>> import com.sun.grizzly.tcp.OutputBuffer;
>>> import com.sun.grizzly.tcp.Request;
>>> import com.sun.grizzly.tcp.Response;
>>> import com.sun.grizzly.util.buf.ByteChunk;
>>>
>>> public class EmbeddedServer implements Adapter {
>>> public static void main( String[] args ) {
>>> SelectorThread selectorThread = new SelectorThread();
>>> selectorThread.setPort( 8282 );
>>> selectorThread.setAdapter( new EmbeddedServer() );
>>> selectorThread.setDisplayConfiguration( true );
>>> try {
>>> selectorThread.initEndpoint();
>>> selectorThread.startEndpoint();
>>> } catch ( Exception e ) {
>>> System.out.println( "Exception in SelectorThread: " + e );
>>> } finally {
>>> if ( selectorThread.isRunning() ) {
>>> selectorThread.stopEndpoint();
>>> }
>>> }
>>> }
>>>
>>> public void service( Request request, Response response ) throws
>>> Exception
>>> {
>>> String requestURI = request.requestURI().toString();
>>> System.out.println( "New incoming request with URI: " + requestURI );
>>> response.setStatus( HttpURLConnection.HTTP_OK );
>>> byte[] bytes = "Here is my response text".getBytes();
>>> ByteChunk chunk = new ByteChunk();
>>> response.setContentLength( bytes.length );
>>> response.setContentType( "text/plain" );
>>> chunk.append( bytes, 0, bytes.length );
>>> OutputBuffer buffer = response.getOutputBuffer();
>>> buffer.doWrite( chunk, response );
>>> response.finish();
>>> // }
>>> }
>>>
>>> public void afterService( Request request, Response response ) throws
>>> Exception {
>>> request.recycle();
>>> response.recycle();
>>> }
>>>
>>> @Override
>>> public void fireAdapterEvent( String arg0, Object arg1 ) {
>>> // TODO Auto-generated method stub
>>> }
>>> }
>>>
>>>
>>> Output using grizzly-http-webserver-1.7.1.jar :
>>>
>>> Mar 7, 2008 5:21:05 PM com.sun.grizzly.http.SelectorThread
>>> displayConfiguration
>>> INFO:
>>> Grizzly configuration for port 8282
>>> maxThreads: 20
>>> minThreads: 5
>>> ByteBuffer size: 8192
>>> useDirectByteBuffer: false
>>> useByteBufferView: false
>>> maxHttpHeaderSize: 8192
>>> maxKeepAliveRequests: 256
>>> keepAliveTimeoutInSeconds: 30
>>> Static File Cache enabled: true
>>> Stream Algorithm : com.sun.grizzly.http.algorithms.NoParsingAlgorithm
>>> Pipeline : com.sun.grizzly.http.LinkedListPipeline
>>> Round Robin Selector Algorithm enabled: false
>>> Round Robin Selector pool size: 0
>>> recycleTasks: true
>>> Asynchronous Request Processing enabled: false
>>> New incoming request with URI: /test
>>>
>>>
>>> Output using grizzly-http-webserver-1.7.2.jar :
>>>
>>> Mar 7, 2008 5:24:53 PM com.sun.grizzly.http.SelectorThread initEndpoint
>>> SEVERE: File Cache is not enabled. Make sure the setWebAppRootPath() is
>>> invoked before starting this SelectorThread
>>
>> Yes that's a mess I've to fix. See:
>>
>> http://www.nabble.com/-Q--StaticResourcesAdapter-no-longer-implemented-in748-td15181158.html
>>
>> Mainly, make sure you call
>> SelectorThread.WebApplicationRootPath("static-folder-path"), or set it
>> to /dev/null if you aren't servicing any static pages.
>>
>> The SEVERE will go away.
>>
>> Do you mind filling an issue? I need to re-work my last change :-)
>>
>> https://grizzly.dev.java.net/issues/
>>
>> Thanks
>>
>> -- Jeanfrancois
>>
>>> Mar 7, 2008 5:24:53 PM com.sun.grizzly.http.SelectorThread
>>> displayConfiguration
>>> INFO:
>>> Grizzly configuration for port 8282
>>> maxThreads: 5
>>> minThreads: 5
>>> ByteBuffer size: 8192
>>> useDirectByteBuffer: false
>>> useByteBufferView: false
>>> maxHttpHeaderSize: 8192
>>> maxKeepAliveRequests: 256
>>> keepAliveTimeoutInSeconds: 30
>>> Static File Cache enabled: true
>>> Stream Algorithm : com.sun.grizzly.http.algorithms.NoParsingAlgorithm
>>> Pipeline : com.sun.grizzly.http.LinkedListPipeline
>>> Round Robin Selector Algorithm enabled: false
>>> Round Robin Selector pool size: 0
>>> recycleTasks: true
>>> Asynchronous Request Processing enabled: false
>>> New incoming request with URI: /test
>>>
>>> Notice second line in this last 1.7.2 output, what changed?
>>> Do I need to worry about it?
>>>
>>> Also now I need to extend my app to support https, I tried using
>>> SSLSelectorThread,
>>> I set SSLConfig to it, and pretty much first wanted to try same thing
>>> like
>>> with this EmbeddedServer
>>>
>>> But event though when I go to https://localhost:8282/test I get prompted
>>> about unsigned certificate, service method never gets called.
>>>
>>> Can someone help me with HTTPS support?
>>> I can not find some example of using Grizzly as HTTPS server, does
>>> anyone
>>> has one?
>>>
>>> Thanks and sorry for such a long post
>>>
>>> -----
>>> --
>>> Danijel
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
>> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>>
>>
>>
>
>


-----
--
Danijel
-- 
View this message in context: http://www.nabble.com/SEVERE-error-thrown-with-grizzly-http-webserver-1.7.2-tp15900600p16011573.html
Sent from the Grizzly - Users mailing list archive at Nabble.com.