Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class RestletEndpoint extends DefaultEndpoint implements HeaderFilterStra
private static final int DEFAULT_PORT = 80;
private static final String DEFAULT_PROTOCOL = "http";
private static final String DEFAULT_HOST = "localhost";
private static final int DEFAULT_SOCKETTIMEOUT = 30000;

private Method restletMethod = Method.GET;

Expand All @@ -49,6 +50,7 @@ public class RestletEndpoint extends DefaultEndpoint implements HeaderFilterStra
private String protocol = DEFAULT_PROTOCOL;
private String host = DEFAULT_HOST;
private int port = DEFAULT_PORT;
private int socketTimeout = DEFAULT_SOCKETTIMEOUT;
private String uriPattern;

// Optional and for consumer only. This allows a single route to service multiple URI patterns.
Expand Down Expand Up @@ -124,6 +126,14 @@ public void setPort(int port) {
this.port = port;
}

public int getSocketTimeout() {
return socketTimeout;
}

public void setSocketTimeout(int socketTimeout) {
this.socketTimeout = socketTimeout;
}

public String getUriPattern() {
return uriPattern;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public RestletProducer(RestletEndpoint endpoint) throws Exception {
this.throwException = endpoint.isThrowExceptionOnFailure();
client = new Client(endpoint.getProtocol());
client.setContext(new Context());
client.getContext().getParameters().add("socketTimeout", String.valueOf(endpoint.getSocketTimeout()));
}

@Override
Expand Down Expand Up @@ -98,10 +99,10 @@ public void handle(Request request, Response response) {
} catch (Exception e) {
exchange.setException(e);
}
callback.done(false);
}
});

callback.done(false);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2014 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.restlet;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import static org.apache.camel.component.restlet.RestletTestSupport.portNum;
import org.junit.Test;

public class RestletProducerTimeoutTest extends RestletTestSupport {

@Test
public void testRestletProducerGet() throws Exception {
String out = template.requestBodyAndHeader("direct:start", null, "id", 123, String.class);
assertEquals(null, out);
}

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to("restlet:http://localhost:" + portNum + "/users/123/basic?timeout=500").to("log:reply");

from("restlet:http://localhost:" + portNum + "/users/{id}/basic")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Thread.sleep(1000);
}
});
}
};
}
}