All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.automationrockstars.bmo.proxy.ProxyTest Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 * Copyright (c) 2015, 2016 Automation RockStars Ltd.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Apache License v2.0
 * which accompanies this distribution, and is available at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Contributors:
 *     Automation RockStars - initial API and implementation
 *******************************************************************************/
package com.automationrockstars.bmo.proxy;

import org.littleshoot.proxy.HttpFilters;
import org.littleshoot.proxy.HttpFiltersAdapter;
import org.littleshoot.proxy.HttpFiltersSourceAdapter;
import org.littleshoot.proxy.HttpProxyServer;
import org.littleshoot.proxy.impl.DefaultHttpProxyServer;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.HttpObject;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;

public class ProxyTest {


	

	
	public void startProxy() throws InterruptedException{
		HttpProxyServer server = DefaultHttpProxyServer.bootstrap()
				.withPort(8088)
				.withFiltersSource(new HttpFiltersSourceAdapter() {
					public HttpFilters filterRequest(HttpRequest originalRequest, ChannelHandlerContext ctx) {
						return new HttpFiltersAdapter(originalRequest) {
							@Override
							public HttpResponse clientToProxyRequest(HttpObject httpObject) {
								System.err.println("Request " + httpObject);
								return super.clientToProxyRequest(httpObject);
							}

							@Override
							public HttpObject serverToProxyResponse(HttpObject httpObject) {
								System.err.println("Response " + httpObject);
								return super.serverToProxyResponse(httpObject);
							}
						};
					}
				})
				.start(); 
		System.err.println("started");
		
		Thread.sleep(120000L);
		
		server.stop();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy