Package org.restlet.data

Examples of org.restlet.data.Protocol


     *            The response to update.
     */
    public void handle(Request request, Response response) {
        // Associate the response to the current thread
        Response.setCurrent(response);
        Protocol protocol = request.getProtocol();

        if (protocol == null) {
            throw new UnsupportedOperationException(
                    "Unable to determine the protocol to use for this call.");
        }
View Full Code Here


      Iterator<Element> clientElements = top.getElementsByName(CLIENT);
      while (clientElements.hasNext()) {
         Element clientDef = clientElements.next();
         String protocol = clientDef.getAttributeValue("protocol");
         if (protocol!=null) {
            Protocol p = Protocol.valueOf(protocol.trim());
            clients.add(p);
         }
      } 
     
      Iterator<Element> interfaceElements = top.getElementsByName(SERVER);
      while (interfaceElements.hasNext()) {
         Element serverE = interfaceElements.next();
         String addr = serverE.getAttributeValue("address");
         String portS = serverE.getAttributeValue("port");
         String protocol = serverE.getAttributeValue("protocol");
         Protocol p = Protocol.HTTP;
         if (protocol!=null) {
            p = Protocol.valueOf(protocol.trim());
         }
         int port = portS==null ? p.getDefaultPort() : Integer.parseInt(portS);
         Server server = new Server(addr,port,p);
         servers.add(server);
        
         Iterator<Element> links = serverE.getElementsByName(LINK);
         while (links.hasNext()) {
View Full Code Here

     * Returns the protocol used or to be used, if known.
     *
     * @return The protocol used or to be used.
     */
    public Protocol getProtocol() {
        Protocol result = this.protocol;

        if ((result == null) && (getResourceRef() != null)) {
            // Attempt to guess the protocol to use
            // from the target reference scheme
            result = getResourceRef().getSchemeProtocol();
View Full Code Here

        }

        if (result == null) {
            // As a final option, try creating a client connector

            Protocol rProtocol = getProtocol();
            Reference rReference = getReference();
            Protocol protocol = (rProtocol != null) ? rProtocol
                    : (rReference != null) ? rReference.getSchemeProtocol()
                            : null;

            if (protocol != null) {
                result = new Client(protocol);
View Full Code Here

                version = null;
            }
        }

        // Set the protocol used for this request
        Protocol serverProtocol = getConnection().getHelper().getHelped()
                .getProtocols().get(0);
        setProtocol(new Protocol(serverProtocol.getSchemeName(),
                serverProtocol.getName(), serverProtocol.getDescription(),
                serverProtocol.getDefaultPort(),
                serverProtocol.isConfidential(), version));

        // Parse the host header
        String host = (getHeaders() == null) ? null : getHeaders()
                .getFirstValue(HeaderConstants.HEADER_HOST, true);
        String hostDomain = null;
        int hostPort = -1;

        if (host != null) {
            int colonIndex = host.indexOf(':');

            if (colonIndex != -1) {
                hostDomain = host.substring(0, colonIndex);
                hostPort = Integer.valueOf(host.substring(colonIndex + 1));
            } else {
                hostDomain = host;
                hostPort = getProtocol().getDefaultPort();
            }
        } else {
            if (!Protocol.SIP.getSchemeName().equals(
                    serverProtocol.getSchemeName())
                    && !Protocol.SIPS.getSchemeName().equals(
                            serverProtocol.getSchemeName())) {
                Context.getCurrentLogger()
                        .info("Couldn't find the mandatory \"Host\" HTTP header. Falling back to the IP address.");
                hostDomain = getConnection().getAddress();
                hostPort = getConnection().getPort();

                if (hostDomain == null) {
                    hostDomain = "localhost";
                }

                if (hostPort == -1) {
                    hostPort = getConnection().getHelper().getHelped()
                            .getActualPort();
                }

                if (hostPort == -1) {
                    getProtocol().getDefaultPort();
                }
            }
        }

        // Set the host reference
        Protocol protocol = getConnection().getHelper().getHelped()
                .getProtocols().get(0);
        StringBuilder sb = new StringBuilder();
        sb.append(protocol.getSchemeName()).append("://");
        sb.append(hostDomain);

        if ((hostPort != -1) && (hostPort != protocol.getDefaultPort())) {
            sb.append(':').append(hostPort);
        }

        setHostRef(sb.toString());
View Full Code Here

            // Test the given service URI which may be actually redirected.
            ClientResource cr = new ClientResource(serviceRef);
            if (cr.getNext() == null) {
                // The context does not provide a client connector.
                // Let instantiate our own.
                Protocol rProtocol = cr.getProtocol();
                Reference rReference = cr.getReference();
                Protocol protocol = (rProtocol != null) ? rProtocol
                        : (rReference != null) ? rReference.getSchemeProtocol()
                                : null;

                if (protocol != null) {
                    this.clientConnector = new Client(protocol);
View Full Code Here

     * @param request
     *            The request.
     * @return The protocol version.
     */
    protected static String getVersion(Request request) {
        Protocol protocol = request.getProtocol();
        String protocolVersion = protocol.getVersion();
        return protocol.getTechnicalName() + '/'
                + ((protocolVersion == null) ? "1.1" : protocolVersion);
    }
View Full Code Here

     * @param component
     *            The parent component to update.
     */
    private void addConnectors(Component component) {
        // Create the server connector
        Protocol protocol = getBaseRef().getSchemeProtocol();
        int port = getBaseRef().getHostPort();
        boolean exists = false;

        if (port == -1) {
            for (Server server : component.getServers()) {
                if (server.getProtocols().contains(protocol)
                        && (server.getPort() == protocol.getDefaultPort())) {
                    exists = true;
                }
            }

            if (!exists) {
View Full Code Here

            result = new SipRecipientInfo();
            String protocolToken = readToken();

            if (peek() == '/') {
                read();
                result.setProtocol(new Protocol(protocolToken, protocolToken,
                        null, -1, readToken()));
                if (peek() == '/') {
                    read();
                    result.setTransport(readToken());
                }
            } else {
                result.setProtocol(new Protocol("HTTP", "HTTP", null, -1,
                        protocolToken));
            }

            // Move to the next text
            if (skipSpaces()) {
View Full Code Here

         throw new AuthException("Missing 'href' property.");
      }
      serviceBase = baseURI==null ? URI.create(href) : baseURI.resolve(href);
      authURL = serviceBase.resolve("./auth?session=false").toString();
      sessionURL = serviceBase.resolve("./auth/").toString();
      Protocol protocol = Protocol.valueOf(serviceBase.getScheme());
      client = new Client(new Context(LOG),protocol);
      client.getContext().getAttributes().put("hostnameVerifier", org.apache.commons.ssl.HostnameVerifier.DEFAULT);
      parser = new XMLRepresentationParser();
      passwords = new TreeMap<String,String>();
      userCache = new Cache<String,User>(100,2*60*1000) {
View Full Code Here

TOP

Related Classes of org.restlet.data.Protocol

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.