Hi,

PFA the required source code files.

Regards,
Anshuk


Anshuk wrote:
> 
> Hi,
> 
> I was trying to make a small utility like a proxy server which would be
> used to get hold of the httprequest message sent by the http client,
> decode the request, and then pass the same httprequest to the actual
> server. In the same context, I was trying to use the example provide by
> mina for httpserver and proxy, reusing the codes of HttpRequestDecoder,
> HttpRequestMessage, HttpResponseEncoder,
> HttpResponseMessage,ClientToProxyIoHandler,ServerToProxyIoHandler and
> AbstractProxyIoHandler.
> 
> Now the proxy gets started at a particular port, say 1234 and also binds
> to the actual destination server, the code for which is:
> 
> -----------------------------------------------------------------------------------------------------------------------------------------
> 
>        IoAcceptor acceptor = new SocketAcceptor();
>        int DEFAULT_PORT = 1234;
>        int port = DEFAULT_PORT;
>        int svrport = 8080;
>        String svrhost = "localhost";
>        IoAcceptor acceptor = new SocketAcceptor();
>        SocketAcceptorConfig cfg = new SocketAcceptorConfig();
>        cfg.setReuseAddress(true);
>        cfg.getFilterChain().addLast("protocolFilter", new
> ProtocolCodecFilter(new                                                       
>                                 
>          HttpServerProtocolCodecFactory()));
>          IoConnector connector = new SocketConnector();
>         ((IoConnectorConfig)
> connector.getDefaultConfig()).setConnectTimeout(30);
>         ClientToProxyIoHandler handler = new ClientToProxyIoHandler(
>                 new ServerToProxyIoHandler(), connector, new
> InetSocketAddress(
>                               svrhost, svrport));
>         acceptor.bind(new InetSocketAddress(port), handler, cfg);
> -----------------------------------------------------------------------------------------------------------------------------------------
> 
> The issue that I am facing is when the client send the httprequest to the
> proxy, the proxy decodes the message and then the messagereceived function
> of the ClientToProxyIoHandler is fired, the code for which is:
> 
> -----------------------------------------------------------------------------------------------------------------------------------------
> CharsetEncoder encoder = Charset.defaultCharset().newEncoder();
> HttpRequestMessage requestMessage = (HttpRequestMessage) message;
> ByteBuffer buf = ByteBuffer.allocate(64);
> buf.setAutoExpand(true);
>         buf.put(CRLF);
>         for (Iterator it =
> requestMessage.getHeaders().entrySet().iterator(); it
>         .hasNext();) 
>         {
>                       Entry entry = (Entry) it.next();
>                       buf.putString((String)entry.getKey(),encoder);
>                       buf.putString(": ", encoder);
>                       //buf.putObject(entry.getValue());
>                       String[] entryValueArry = (String[]) entry.getValue();
>                       for(int i = 0; i < entryValueArry.length;i++)
>                       {
>                               buf.putString(entryValueArry[i],encoder);
>                       }
>                       buf.put(CRLF);
>     
>         }
>         buf.put(CRLF);
> buf.putString(requestMessage.getRequestBody(),encoder);
> buf.flip();
> ByteBuffer wb = ByteBuffer.allocate(buf.remaining());
> buf.mark();
> wb.put(buf);
> wb.flip();
> ((IoSession) session.getAttachment()).write(wb);
> buf.reset();
> SessionLog.info(session,
> buf.getString(Charset.defaultCharset().newDecoder()));
> -----------------------------------------------------------------------------------------------------------------------------------------
> 
> After the buffer is written into the session, it is getting stuck somehow,
> and the message is not being sent to the actual server,I am not really
> sure, where it is getting stuck and why.
> 
> Can anyone let me know what can be the problem here, please let if anybody
> requires the complete source code so that I can send it across.
>         
> Thanks.
> 
> Regards,
> Anshuk
> 
http://www.nabble.com/file/p13989655/AbstractProxyIoHandler.java
AbstractProxyIoHandler.java 
http://www.nabble.com/file/p13989655/ClientToProxyIoHandler.java
ClientToProxyIoHandler.java 
http://www.nabble.com/file/p13989655/HttpRequestDecoder.java
HttpRequestDecoder.java 
http://www.nabble.com/file/p13989655/HttpRequestMessage.java
HttpRequestMessage.java 
http://www.nabble.com/file/p13989655/HttpResponseEncoder.java
HttpResponseEncoder.java 
http://www.nabble.com/file/p13989655/HttpResponseMessage.java
HttpResponseMessage.java 
http://www.nabble.com/file/p13989655/HttpServerProtocolCodecFactory.java
HttpServerProtocolCodecFactory.java 
http://www.nabble.com/file/p13989655/MonProxy.java MonProxy.java 
http://www.nabble.com/file/p13989655/ServerToProxyIoHandler.java
ServerToProxyIoHandler.java 
-- 
View this message in context: 
http://www.nabble.com/Using-Proxy-utiliy-to-send-receive-http-messages-tf4886685s16868.html#a13989655
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.

Reply via email to