Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import org.restlet.Application;
- import org.restlet.Client;
- import org.restlet.Component;
- import org.restlet.Restlet;
- import org.restlet.data.MediaType;
- import org.restlet.data.Parameter;
- import org.restlet.data.Protocol;
- import org.restlet.representation.Representation;
- import org.restlet.representation.StringRepresentation;
- import org.restlet.resource.ClientResource;
- import org.restlet.resource.ResourceException;
- import org.restlet.resource.ServerResource;
- import org.restlet.routing.Router;
- import org.restlet.util.Series;
- public class ProxyTest extends Application
- {
- public static class ConnectorTest extends ServerResource
- {
- @Override
- protected Representation get() throws ResourceException {
- ClientResource client = new ClientResource("https://www.google.com/");
- Representation result = client.get();
- try {
- System.out.println(client.getStatus());
- System.out.println(result.getText().length());
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- finally {
- client.release();
- }
- return new StringRepresentation("Done.", MediaType.TEXT_PLAIN);
- }
- }
- @Override
- public Restlet createInboundRoot() {
- Router router = new Router(getContext());
- router.attach("/connect", ConnectorTest.class);
- return router;
- }
- private static void attachClient(Component c, Protocol protocol) {
- Client client = c.getClients().add(protocol);
- Series<Parameter> parameters = client.getContext().getParameters();
- parameters.add("proxyHost", "192.168.100.210");
- parameters.add("proxyPort", "8888");
- }
- public static void main(String[] args) throws Exception {
- ProxyTest proxyTest = new ProxyTest();
- Component c = new Component();
- c.getServers().add(Protocol.HTTP, 8080);
- attachClient(c, Protocol.HTTP);
- attachClient(c, Protocol.HTTPS);
- c.getDefaultHost().attachDefault(proxyTest);
- c.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement