wms-restlet-2.2.2.org.restlet.ext.simple

16:54:19.792 INFO  jd.cli.Main - Decompiling wms-restlet-2.2.2.org.restlet.ext.simple.jar
package org.restlet.ext.simple;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.List;
import org.restlet.Server;
import org.restlet.data.Protocol;
import org.restlet.ext.simple.internal.SimpleContainer;
import org.restlet.ext.simple.internal.SimpleServer;
import org.simpleframework.http.core.Container;
import org.simpleframework.http.core.ContainerServer;
import org.simpleframework.transport.connect.Connection;
import org.simpleframework.transport.connect.SocketConnection;

public class HttpServerHelper
  extends SimpleServerHelper
{
  public HttpServerHelper(Server server)
  {
    super(server);
    getProtocols().add(Protocol.HTTP);
  }
  
  public void start()
    throws Exception
  {
    String addr = ((Server)getHelped()).getAddress();
    if (addr != null)
    {
      InetAddress iaddr = InetAddress.getByName(addr);
      
      setAddress(new InetSocketAddress(iaddr, ((Server)getHelped()).getPort()));
    }
    else
    {
      int port = ((Server)getHelped()).getPort();
      if (port > 0) {
        setAddress(new InetSocketAddress(((Server)getHelped()).getPort()));
      }
    }
    Container container = new SimpleContainer(this);
    ContainerServer server = new ContainerServer(container, getDefaultThreads());
    
    SimpleServer restletServer = new SimpleServer(server);
    Connection connection = new SocketConnection(restletServer);
    
    setConfidential(false);
    setContainerServer(server);
    setConnection(connection);
    
    InetSocketAddress address = (InetSocketAddress)getConnection().connect(getAddress());
    
    setEphemeralPort(address.getPort());
    super.start();
  }
}

/* Location:
 * Qualified Name:     org.restlet.ext.simple.HttpServerHelper
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.restlet.ext.simple;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.List;
import javax.net.ssl.SSLContext;
import org.restlet.Server;
import org.restlet.data.Protocol;
import org.restlet.engine.ssl.SslContextFactory;
import org.restlet.engine.ssl.SslUtils;
import org.restlet.ext.simple.internal.SimpleContainer;
import org.restlet.ext.simple.internal.SimpleServer;
import org.simpleframework.http.core.Container;
import org.simpleframework.http.core.ContainerServer;
import org.simpleframework.transport.connect.Connection;
import org.simpleframework.transport.connect.SocketConnection;

public class HttpsServerHelper
  extends SimpleServerHelper
{
  public HttpsServerHelper(Server server)
  {
    super(server);
    getProtocols().add(Protocol.HTTPS);
  }
  
  public void start()
    throws Exception
  {
    SslContextFactory sslContextFactory = SslUtils.getSslContextFactory(this);
    
    SSLContext sslContext = sslContextFactory.createSslContext();
    String addr = ((Server)getHelped()).getAddress();
    if (addr != null)
    {
      InetAddress iaddr = InetAddress.getByName(addr);
      
      setAddress(new InetSocketAddress(iaddr, ((Server)getHelped()).getPort()));
    }
    else
    {
      int port = ((Server)getHelped()).getPort();
      if (port > 0) {
        setAddress(new InetSocketAddress(((Server)getHelped()).getPort()));
      }
    }
    Container container = new SimpleContainer(this);
    ContainerServer server = new ContainerServer(container, getDefaultThreads());
    
    SimpleServer filter = new SimpleServer(server);
    Connection connection = new SocketConnection(filter);
    setConfidential(true);
    setContainerServer(server);
    setConnection(connection);
    
    InetSocketAddress address = (InetSocketAddress)getConnection().connect(getAddress(), sslContext);
    
    setEphemeralPort(address.getPort());
    super.start();
  }
}

/* Location:
 * Qualified Name:     org.restlet.ext.simple.HttpsServerHelper
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.restlet.ext.simple;

import java.net.InetSocketAddress;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.restlet.Server;
import org.restlet.engine.adapter.HttpServerHelper;
import org.restlet.util.Series;
import org.simpleframework.http.core.ContainerServer;
import org.simpleframework.transport.connect.Connection;

public abstract class SimpleServerHelper
  extends HttpServerHelper
{
  private volatile boolean confidential;
  private volatile Connection connection;
  private volatile ContainerServer containerServer;
  private volatile InetSocketAddress address;
  
  public SimpleServerHelper(Server server)
  {
    super(server);
  }
  
  protected Connection getConnection()
  {
    return connection;
  }
  
  public int getDefaultThreads()
  {
    return Integer.parseInt(getHelpedParameters().getFirstValue("defaultThreads", "5"));
  }
  
  protected ContainerServer getContainerServer()
  {
    return containerServer;
  }
  
  protected InetSocketAddress getAddress()
  {
    return address;
  }
  
  public boolean isConfidential()
  {
    return confidential;
  }
  
  protected void setConfidential(boolean confidential)
  {
    this.confidential = confidential;
  }
  
  protected void setConnection(Connection connection)
  {
    this.connection = connection;
  }
  
  protected void setContainerServer(ContainerServer container)
  {
    containerServer = container;
  }
  
  protected void setAddress(InetSocketAddress address)
  {
    this.address = address;
  }
  
  public synchronized void start()
    throws Exception
  {
    super.start();
    getLogger().info("Starting the Simple " + getProtocols() + " server on port " + ((Server)getHelped()).getPort());
  }
  
  public synchronized void stop()
    throws Exception
  {
    getLogger().info("Stopping the Simple server");
    try
    {
      getConnection().close();
    }
    catch (Exception e)
    {
      getLogger().log(Level.FINE, "Exception while closing the server socket. Can probably be safely ignored.", e);
    }
    if (getContainerServer() != null) {
      getContainerServer().stop();
    }
  }
}

/* Location:
 * Qualified Name:     org.restlet.ext.simple.SimpleServerHelper
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.restlet.ext.simple.internal;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.channels.SocketChannel;
import java.security.cert.Certificate;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
import org.restlet.Server;
import org.restlet.data.Method;
import org.restlet.engine.adapter.ServerCall;
import org.restlet.engine.header.Header;
import org.restlet.engine.ssl.SslUtils;
import org.restlet.util.Series;

public class SimpleCall
  extends ServerCall
{
  private final org.simpleframework.http.Request request;
  private volatile boolean requestHeadersAdded;
  private final org.simpleframework.http.Response response;
  private final String version;
  
  SimpleCall(Server server, org.simpleframework.http.Request request, org.simpleframework.http.Response response, boolean confidential)
  {
    super(server);
    version = (request.getMajor() + "." + request.getMinor());
    this.request = request;
    this.response = response;
    setConfidential(confidential);
    requestHeadersAdded = false;
  }
  
  public boolean abort()
  {
    try
    {
      getSocket().close();
    }
    catch (IOException e) {}
    return true;
  }
  
  public void flushBuffers()
    throws IOException
  {
    response.commit();
  }
  
  public void complete()
  {
    try
    {
      response.commit();
    }
    catch (Exception ex)
    {
      getLogger().log(Level.WARNING, "Unable to commit the response", ex);
    }
  }
  
  public List<Certificate> getCertificates()
  {
    SSLEngine sslEngine = getSslEngine();
    if (sslEngine != null)
    {
      SSLSession sslSession = sslEngine.getSession();
      if (sslSession != null) {
        try
        {
          return Arrays.asList(sslSession.getPeerCertificates());
        }
        catch (SSLPeerUnverifiedException e)
        {
          getLogger().log(Level.FINE, "Can't get the client certificates.", e);
        }
      }
    }
    return null;
  }
  
  public String getCipherSuite()
  {
    SSLEngine sslEngine = getSslEngine();
    if (sslEngine != null)
    {
      SSLSession sslSession = sslEngine.getSession();
      if (sslSession != null) {
        return sslSession.getCipherSuite();
      }
    }
    return null;
  }
  
  public String getClientAddress()
  {
    return request.getClientAddress().getAddress().getHostAddress();
  }
  
  public int getClientPort()
  {
    SocketChannel socket = getSocket();
    return socket != null ? socket.socket().getPort() : -1;
  }
  
  protected long getContentLength()
  {
    return request.getContentLength();
  }
  
  public String getHostDomain()
  {
    return super.getHostDomain();
  }
  
  public String getMethod()
  {
    return request.getMethod();
  }
  
  public InputStream getRequestEntityStream(long size)
  {
    try
    {
      return request.getInputStream();
    }
    catch (Exception ex) {}
    return null;
  }
  
  public Series<Header> getRequestHeaders()
  {
    Series<Header> result = super.getRequestHeaders();
    if (!requestHeadersAdded)
    {
      List<String> names = request.getNames();
      for (String name : names) {
        result.add(name, request.getValue(name));
      }
      requestHeadersAdded = true;
    }
    return result;
  }
  
  public InputStream getRequestHeadStream()
  {
    return null;
  }
  
  public String getRequestUri()
  {
    return request.getTarget();
  }
  
  public OutputStream getResponseEntityStream()
  {
    try
    {
      return response.getOutputStream();
    }
    catch (Exception ex) {}
    return null;
  }
  
  private SocketChannel getSocket()
  {
    return (SocketChannel)request.getAttribute("org.restlet.ext.simple.socket");
  }
  
  private SSLEngine getSslEngine()
  {
    return (SSLEngine)request.getAttribute("org.restlet.ext.simple.engine");
  }
  
  public Integer getSslKeySize()
  {
    Integer keySize = null;
    String sslCipherSuite = getCipherSuite();
    if (sslCipherSuite != null) {
      keySize = SslUtils.extractKeySize(sslCipherSuite);
    }
    return keySize;
  }
  
  protected byte[] getSslSessionIdBytes()
  {
    SSLEngine sslEngine = getSslEngine();
    if (sslEngine != null)
    {
      SSLSession sslSession = sslEngine.getSession();
      if (sslSession != null) {
        return sslSession.getId();
      }
    }
    return null;
  }
  
  public String getVersion()
  {
    return version;
  }
  
  protected boolean isClientKeepAlive()
  {
    return request.isKeepAlive();
  }
  
  public void writeResponseHead(org.restlet.Response restletResponse)
    throws IOException
  {
    for (Header header : getResponseHeaders()) {
      response.addValue(header.getName(), header.getValue());
    }
    response.setCode(getStatusCode());
    response.setDescription(getReasonPhrase());
    if ((!Method.HEAD.equals(restletResponse.getRequest().getMethod())) && (restletResponse.getEntity() == null)) {
      response.setContentLength(0L);
    }
  }
}

/* Location:
 * Qualified Name:     org.restlet.ext.simple.internal.SimpleCall
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.restlet.ext.simple.internal;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.restlet.Server;
import org.restlet.ext.simple.SimpleServerHelper;
import org.simpleframework.http.Request;
import org.simpleframework.http.Response;
import org.simpleframework.http.core.Container;

public class SimpleContainer
  implements Container
{
  private volatile SimpleServerHelper helper;
  
  public SimpleContainer(SimpleServerHelper helper)
  {
    this.helper = helper;
  }
  
  public SimpleServerHelper getHelper()
  {
    return helper;
  }
  
  public void handle(Request request, Response response)
  {
    getHelper().handle(new SimpleCall((Server)getHelper().getHelped(), request, response, getHelper().isConfidential()));
    try
    {
      response.close();
    }
    catch (Exception e)
    {
      getHelper().getLogger().log(Level.FINE, "Exception while closing the Simple response's output stream", e);
    }
  }
}

/* Location:
 * Qualified Name:     org.restlet.ext.simple.internal.SimpleContainer
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.restlet.ext.simple.internal;

import java.io.IOException;
import java.nio.channels.SocketChannel;
import java.util.Map;
import javax.net.ssl.SSLEngine;
import org.simpleframework.transport.Server;
import org.simpleframework.transport.Socket;

public class SimpleServer
  implements Server
{
  public static final String PROPERTY_SOCKET = "org.restlet.ext.simple.socket";
  public static final String PROPERTY_ENGINE = "org.restlet.ext.simple.engine";
  private final Server server;
  
  public SimpleServer(Server server)
  {
    this.server = server;
  }
  
  public void process(Socket socket)
    throws IOException
  {
    Map<String, Object> map = socket.getAttributes();
    SSLEngine engine = socket.getEngine();
    SocketChannel channel = socket.getChannel();
    
    map.put("org.restlet.ext.simple.engine", engine);
    map.put("org.restlet.ext.simple.socket", channel);
    
    server.process(socket);
  }
  
  public void stop()
    throws IOException
  {
    server.stop();
  }
}

/* Location:
 * Qualified Name:     org.restlet.ext.simple.internal.SimpleServer
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
1

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd