users@grizzly.java.net

Re: Make an http proxy with grizzly

From: yann Blazart <yann.blazart_at_gmail.com>
Date: Wed, 22 Aug 2012 11:54:48 +0200

Now with the last grizzly 3.0-Snapshot it works !


2012/8/22 Oleksiy Stashok <oleksiy.stashok_at_oracle.com>

> Hi,
>
>
> On 08/22/2012 11:26 AM, yann Blazart wrote:
>
> batch ? I mean bath !! :)
>
> Oh, that makes sense :)
>
>
> Well, just one more question. I want to make this tools more things, so
> I will code an admin interface. Is it possible to use embedded glassfish to
> make my admin gui with jee6 things, and use the grizzly 3.0 snapshot you
> made ? (if I put it on classpath before glassfish ?)
>
> Unfortunately it will not work w/ Glassfish 3.x, we use different Grizzly
> version there 1.9.x, which is not compliant w/ 2.x+.
>
>
> In case if it is possible, I think I can make a servlet to make my proxy
> ? Is there a way to access to grizzly Request from HttpRequest ?
>
> In Grizzly we have a http-servlet module, which implements subset of
> Servlet 3.1 standard. You can use that if you want.
>
> Thanks.
>
> WBR,
> Alexey.
>
> PS: can we move this discussion back to mailing list, cause it might be an
> interesting topic for other folks.
>
>
>
> Thanks a lot.
>
> 2012/8/21 Oleksiy Stashok <oleksiy.stashok_at_oracle.com>
>
>>
>> On 08/21/2012 07:45 PM, yann Blazart wrote:
>>
>> Thanks ! Do you have made another snapshot release to correct the issue ?
>>
>> Yep. Should be available now.
>>
>>
>> I will test after, I have to make the batch of my son now ;)
>>
>> :)
>>
>> WBR,
>> Alexey.
>>
>>
>>
>> 2012/8/21 Oleksiy Stashok <oleksiy.stashok_at_oracle.com>
>>
>>> Hi,
>>>
>>> I found one more issue in Grizzly related to CONNECT method and HTTP/1.1.
>>> Also attaching changed JNTLMProxy project with some fixes. For sure I'd
>>> recommend to improve ProxyHttpHandler code (the part responsible for
>>> CONNECT method processing), but I think you know that even better :)
>>>
>>> Thanks.
>>>
>>> WBR,
>>> Alexey.
>>>
>>>
>>> On 08/21/2012 02:25 PM, yann Blazart wrote:
>>>
>>> Ouuups ! Thanks for the mistake, I change the out with the socket one.
>>> Well I send you a zip with the Maven project.
>>>
>>>
>>> The test to launch is ProxyServerTest2. You have to comment/uncomment
>>> lines 32/33 if you are behind a proxy or not.
>>>
>>> It's crappy code.
>>>
>>> Thanks.
>>>
>>>
>>> 2012/8/21 Oleksiy Stashok <oleksiy.stashok_at_oracle.com>
>>>
>>>> Hi,
>>>>
>>>> if you can give me working project (maven2 based?) sources w/ all the
>>>> dependencies and proper proxy addresses, so I can run it as it is?
>>>> From your sources I see that you don't send any data to proxy, in the
>>>> onDataAvailable method you read data and them it back to the sender.
>>>>
>>>> WBR,
>>>> Alexey.
>>>>
>>>>
>>>> On 08/21/2012 12:16 PM, yann Blazart wrote:
>>>>
>>>> Well I made quickly a crapy code but it doesn't work, the NIO read 112
>>>> byte from input stream, but no more
>>>> To remember, I lust play with the socket gived by HttpProxyclient (du
>>>> to NTLM auth)
>>>> The logs are after the following code
>>>>
>>>>
>>>>
>>>>
>>>> HttpHost target = new HttpHost(host,
>>>>> Integer.parseInt(port));
>>>>> Socket socket;
>>>>> if (proxyHost != null) {
>>>>> ProxyClient proxyClient = new ProxyClient();
>>>>> if (credentials instanceof NTCredentials) {
>>>>>
>>>>> proxyClient.getAuthSchemeRegistry().register("ntlm", new
>>>>> NTLMSchemeFactory());
>>>>> }
>>>>> System.out.println("Proxy tunnel");
>>>>> socket = proxyClient.tunnel(proxyHost, target,
>>>>> credentials);
>>>>> } else {
>>>>> socket = new Socket(target.getHostName(),
>>>>> target.getPort());
>>>>> }
>>>>> final Socket secSocket = socket;
>>>>>
>>>>> final NIOInputStream in = request.createInputStream();
>>>>> final OutputStream out = response.getOutputStream();
>>>>> out.write(("HTTP/1.1 200 Connection etablished\r\n" +
>>>>> CONNECT_OK_HEADERS).getBytes());
>>>>> out.flush();
>>>>> System.out.println("200 sended ");
>>>>>
>>>>>
>>>>> final WritableByteChannel outChannel =
>>>>> Channels.newChannel(out);
>>>>> final Set ended = new HashSet();
>>>>> in.notifyAvailable(new ReadHandler() {
>>>>> @Override
>>>>> public void onDataAvailable() throws Exception {
>>>>> System.out.println("DATA IN !!!!!!!");
>>>>> final Buffer buffer = in.readBuffer();
>>>>> final ByteBuffer byteBuffer =
>>>>> buffer.toByteBuffer();
>>>>> try {
>>>>> while (byteBuffer.hasRemaining()) {
>>>>> System.out.println("DATA IN !!!!!!! ---> "
>>>>> + byteBuffer.remaining());
>>>>> outChannel.write(byteBuffer);
>>>>> }
>>>>> } finally {
>>>>> buffer.tryDispose();
>>>>> }
>>>>> in.notifyAvailable(this);
>>>>> }
>>>>> @Override
>>>>> public void onError(Throwable thrwbl) {
>>>>> System.out.println("ERRRRRRORRR");
>>>>> response.setStatus(500, thrwbl.getMessage());
>>>>> ended.add(new Object());
>>>>> }
>>>>> @Override
>>>>> public void onAllDataRead() throws Exception {
>>>>> System.out.println("DATAENDDDDDD");
>>>>> final Buffer buffer = in.readBuffer();
>>>>> final ByteBuffer byteBuffer =
>>>>> buffer.toByteBuffer();
>>>>> try {
>>>>> while (byteBuffer.hasRemaining()) {
>>>>> out.write(byteBuffer.array());
>>>>> }
>>>>> } finally {
>>>>> buffer.tryDispose();
>>>>> }
>>>>> response.setStatus(HttpStatus.ACCEPTED_202);
>>>>> ended.add(new Object());
>>>>> }
>>>>> });
>>>>> Thread tread = new Thread(new Runnable() {
>>>>> @Override
>>>>> public void run() {
>>>>> try {
>>>>> System.out.println("read from socket");
>>>>> byte[] buffer = new byte[400];
>>>>> int readed = 0;
>>>>> while ((readed =
>>>>> secSocket.getInputStream().read(buffer)) > -1) {
>>>>> System.out.println("readed = " + readed);
>>>>> out.write(buffer, 0, readed);
>>>>> }
>>>>> System.out.println(" --> stop copy from
>>>>> socket to out : " + readed);
>>>>> } catch (IOException ex) {
>>>>> throw new RuntimeException(ex);
>>>>> }
>>>>> }
>>>>> });
>>>>> Thread twrite = new Thread(new Runnable() {
>>>>> @Override
>>>>> public void run() {
>>>>> try {
>>>>> while (ended.size() < 0) {
>>>>> Thread.sleep(100);
>>>>> }
>>>>> } catch (Exception ex) {
>>>>> throw new RuntimeException(ex);
>>>>> }
>>>>> }
>>>>> });
>>>>>
>>>>> tread.start();
>>>>> twrite.start();
>>>>> tread.join();
>>>>> twrite.join();
>>>>> IOUtils.closeQuietly(secSocket);
>>>>> return null;
>>>>> }
>>>>> throw new IllegalArgumentException("Unknown method : " +
>>>>> methodString);
>>>>> }
>>>>> }
>>>>
>>>>
>>>>
>>>>> request = CONNECT,mail.google.com:443
>>>>> - header host = mail.google.com
>>>>> - header proxy-connection = Keep-Alive
>>>>> - header user-agent = Apache-HttpClient/UNAVAILABLE (java 1.5)
>>>>> *Proxy tunnel
>>>>> 200 sended
>>>>> read from socket*
>>>>> Allow unsafe renegotiation: false
>>>>> Allow legacy hello messages: true
>>>>> Is initial handshake: true
>>>>> Is secure renegotiation: false
>>>>> %% No cached client session
>>>>> *** ClientHello, TLSv1
>>>>> RandomCookie: GMT: 1345543579 bytes = { 102, 194, 84, 234, 92, 156,
>>>>> 104, 221, 109, 82, 112, 194, 168, 78, 76, 125, 144, 46, 148, 91, 176, 66,
>>>>> 86, 40, 137, 92, 185, 11 }
>>>>> Session ID: {}
>>>>> Cipher Suites: [SSL_RSA_WITH_RC4_128_MD5, SSL_RSA_WITH_RC4_128_SHA,
>>>>> TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA,
>>>>> TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_256_CBC_SHA,
>>>>> TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_256_CBC_SHA,
>>>>> SSL_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA,
>>>>> SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_DES_CBC_SHA,
>>>>> SSL_DHE_RSA_WITH_DES_CBC_SHA, SSL_DHE_DSS_WITH_DES_CBC_SHA,
>>>>> SSL_RSA_EXPORT_WITH_RC4_40_MD5, SSL_RSA_EXPORT_WITH_DES40_CBC_SHA,
>>>>> SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA,
>>>>> SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
>>>>> Compression Methods: { 0 }
>>>>> ***
>>>>> main, WRITE: TLSv1 Handshake, length = 81
>>>>> main, WRITE: SSLv2 client hello message, length = 110
>>>>> *DATA IN !!!!!!!
>>>>> DATA IN !!!!!!! ---> 112
>>>>> --> stop copy from socket to out : -1*
>>>>> *ERRRRRRORRR*
>>>>> main, handling exception: javax.net.ssl.SSLException: Unrecognized SSL
>>>>> message, plaintext connection?
>>>>> main, SEND TLSv1 ALERT: fatal, description = unexpected_message
>>>>> main, WRITE: TLSv1 Alert, length = 2
>>>>> main, called closeSocket()
>>>>> main, IOException in getSession(): javax.net.ssl.SSLException:
>>>>> Unrecognized SSL message, plaintext connection?
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>