#java #google-app-engine #rest #reverse-proxy #restlet
# #java #google-app-engine #rest #обратный прокси #restlet
Вопрос:
Пытаюсь запустить Restlet в AppEngine для использования в качестве обратного прокси для стороннего сервиса json / xml.
- Версия AppEngine 1.5.5
- Restlet GAE edition 2.1RC1
Я настраиваю Restlet в своем web.xml вот так :
<servlet>
<servlet-name>RestletServlet</servlet-name>
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
<init-param>
<param-name>org.restlet.application</param-name>
<param-value>be.koma.server.MyApplication</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>RestletServlet</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
Я добавил следующие банки в WEB-INF / lib, GAE версии 2.1RC1
org.json.jar
org.restlet.ext.crypto.jar
org.restlet.ext.gae.jar
org.restlet.ext.gwt.jar
org.restlet.ext.jackson.jar
org.restlet.ext.json.jar
org.restlet.ext.net.jar
org.restlet.ext.servlet.jar
org.restlet.ext.xml.jar
org.restlet.jar
Это реализация для be.koma.server.MyApplication ;
public class MyApplication extends Application {
@Override
public Restlet createInboundRoot() {
Router router = new Router(getContext());
String target = "http://otherservice.com/users.xml";
Redirector redirector = new Redirector(getContext(), target, Redirector.MODE_SERVER_OUTBOUND);
router.setDefaultMatchingMode(Router.MODE_FIRST_MATCH);
getConnectorService().getClientProtocols().add(Protocol.HTTP);
router.attachDefault(redirector);
return router;
}
}
Вызов otherservice.com из моего браузера или curl работает нормально.
Однако, когда я вызываю Restlet, я получаю 404, потому что клиентский протокол не может быть найден??
Oct 24, 2011 9:36:22 AM org.restlet.engine.log.LogFilter beforeHandle
FINE: Processing request to: "http://127.0.1.1:8888/api/otherservice/users.xml"
Oct 24, 2011 9:36:22 AM org.restlet.engine.component.HostRoute score
FINER: Call score for the "org.restlet.routing.VirtualHost@e3e496a" host: 1.0
Oct 24, 2011 9:36:22 AM org.restlet.engine.component.ServerRouter logRoute
FINE: Default virtual host selected
Oct 24, 2011 9:36:22 AM org.restlet.engine.component.HostRoute beforeHandle
FINE: Base URI: "http://127.0.1.1:8888". Remaining part: "/api/otherservice/users.xml"
Oct 24, 2011 9:36:22 AM org.restlet.routing.TemplateRoute score
FINER: Call score for the "/api" URI pattern: 0.5909091
Oct 24, 2011 9:36:22 AM org.restlet.routing.Router logRoute
FINE: Selected route: "/api" -> be.koma.server.MyApplication@668b1967
Oct 24, 2011 9:36:22 AM org.restlet.routing.TemplateRoute beforeHandle
FINER: 4 characters were matched
Oct 24, 2011 9:36:22 AM org.restlet.routing.TemplateRoute beforeHandle
FINE: New base URI: "http://127.0.1.1:8888/api". New remaining part: "/otherservice/users.xml"
Oct 24, 2011 9:36:22 AM org.restlet.routing.TemplateRoute beforeHandle
FINER: Delegating the call to the target Restlet
Oct 24, 2011 9:36:22 AM org.restlet.routing.TemplateRoute score
FINER: Call score for the "" URI pattern: 0.5
Oct 24, 2011 9:36:22 AM org.restlet.routing.Router logRoute
FINE: The default route was selected
Oct 24, 2011 9:36:22 AM org.restlet.routing.TemplateRoute beforeHandle
FINER: No characters were matched
Oct 24, 2011 9:36:22 AM org.restlet.routing.Redirector handle
INFO: Redirecting via client dispatcher to: http://otherservice.com/users.xml
Oct 24, 2011 9:36:22 AM org.restlet.engine.component.ClientRoute score
FINER: Call score for the "[WAR]" client: 0.0
Oct 24, 2011 9:36:22 AM org.restlet.routing.Router logRoute
FINE: The default route was selected
Oct 24, 2011 9:36:22 AM org.restlet.engine.component.ClientRouter getNext
WARNING: The protocol used by this request is not declared in the list of client connectors. (HTTP/1.1)
Oct 24, 2011 9:36:22 AM org.restlet.engine.log.LogFilter afterHandle
INFO: 2011-10-24 07:36:22 127.0.0.1 127.0.1.1 8888 GET /api/otherservice/users.xml - 404 439 0 28 http://127.0.1.1:8888 Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.1 (KHTML, like Gecko) Ubuntu/11.10 Chromium/14.0.835.202 Chrome/14.0.835.202 Safari/535.1 http://127.0.1.1:8888/test.html?gwt.codesvr=127.0.1.1:9997
Есть идеи?
Советы по отладке?
Какого понимания мне не хватает, это кажется таким тривиальным?
Ответ №1:
Спасибо Джерому в списке рассылки Restlet, дополнительные параметры инициализации решают проблему :
<servlet>
<servlet-name>RestletServlet</servlet-name>
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
<init-param>
<param-name>org.restlet.application</param-name>
<param-value>be.koma.server.MyApplication</param-value>
</init-param>
<init-param>
<param-name>org.restlet.clients</param-name>
<param-value>HTTP HTTPS</param-value>
</init-param>
</servlet>
Подробная информация
http://www.restlet.org/documentation/snapshot/gae/ext/org/restlet/ext/servlet/ServerServlet.html