001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.camel.component.restlet;
018
019 import java.util.Map;
020
021 import org.apache.camel.Consumer;
022 import org.apache.camel.ExchangePattern;
023 import org.apache.camel.Processor;
024 import org.apache.camel.Producer;
025 import org.apache.camel.impl.DefaultEndpoint;
026 import org.restlet.data.Method;
027
028 /**
029 * Represents a <a href="http://www.restlet.org/"> endpoint</a>
030 *
031 * @version $Revision: 778401 $
032 */
033 public class RestletEndpoint extends DefaultEndpoint {
034
035 private static final int DEFAULT_PORT = 80;
036 private static final String DEFAULT_PROTOCOL = "http";
037 private static final String DEFAULT_HOST = "localhost";
038
039 private Method restletMethod = Method.GET;
040 private String protocol = DEFAULT_PROTOCOL;
041 private String host = DEFAULT_HOST;
042 private int port = DEFAULT_PORT;
043 private String uriPattern;
044 private RestletBinding restletBinding;
045 private Map<String, String> realm;
046
047 public RestletEndpoint(RestletComponent component, String remaining, RestletBinding restletBinding) throws Exception {
048 super(remaining, component);
049 this.restletBinding = restletBinding;
050 }
051
052 public boolean isSingleton() {
053 return true;
054 }
055
056 @Override
057 public boolean isLenientProperties() {
058 // true to allow dynamic URI options to be configured and passed to external system.
059 return true;
060 }
061
062 public Consumer createConsumer(Processor processor) throws Exception {
063 return new RestletConsumer(this, processor);
064 }
065
066 public Producer createProducer() throws Exception {
067 return new RestletProducer(this);
068 }
069
070 public void connect(RestletConsumer restletConsumer) throws Exception {
071 ((RestletComponent)getComponent()).connect(restletConsumer);
072 }
073
074 public void disconnect(RestletConsumer restletConsumer) throws Exception {
075 ((RestletComponent)getComponent()).disconnect(restletConsumer);
076 }
077
078 public Method getRestletMethod() {
079 return restletMethod;
080 }
081
082 public void setRestletMethod(Method restletMethod) {
083 this.restletMethod = restletMethod;
084 }
085
086 public String getProtocol() {
087 return protocol;
088 }
089
090 public void setProtocol(String protocol) {
091 this.protocol = protocol;
092 }
093
094 public String getHost() {
095 return host;
096 }
097
098 public void setHost(String host) {
099 this.host = host;
100 }
101
102 public int getPort() {
103 return port;
104 }
105
106 public void setPort(int port) {
107 this.port = port;
108 }
109
110 public String getUriPattern() {
111 return uriPattern;
112 }
113
114 public void setUriPattern(String uriPattern) {
115 this.uriPattern = uriPattern;
116 }
117
118 public RestletBinding getRestletBinding() {
119 return restletBinding;
120 }
121
122 public void setRestletBinding(RestletBinding restletBinding) {
123 this.restletBinding = restletBinding;
124 }
125
126 public Map<String, String> getRealm() {
127 return realm;
128 }
129
130 public void setRealm(Map<String, String> realm) {
131 this.realm = realm;
132 }
133
134 @Override
135 public ExchangePattern getExchangePattern() {
136 // should always use in out for restlet
137 return ExchangePattern.InOut;
138 }
139 }