2012-06-15 86 views
1

基本上我有2个RESTful服务:一个使用Java构建,使用Tomcat服务器,另一个使用PHP构建并使用Apache服务器。 有没有什么办法可以让Tomcat的应用程序成为Apache的应用程序的使用者?在Tomcat应用程序中使用Apache的应用程序

从Tomcat的web服务的地址为:

http://localhost:8080/myapp1 

和Apache的应用程序是在地址:

http://localhost:80/myapp2. 

我想要的是在使用Apache的REST式服务的响应

HttpGet httpget = new HttpGet(http://localhost:80/myapp2/items); 

目前我答:Tomcat的一个,像这样从Java代码中使用m收到404-Not Found。有没有办法做到这一点?还是有另一种方式来使服务沟通?

+0

是否将Apache httpd配置为仅在特定主机名下为虚拟主机提供服务?您的基于PHP的RESTful应用程序是否配置为在默认VirtualHost下运行? –

回答

0

忘记发布答案。我感到非常愚蠢 - 我的代码出错了。它按预期工作。下面是从Tomcat调用Apache服务器的简单示例:

final static String BASE_URL = "http://localhost:80/proiect/"; 

    private String getResponse(String title) { 
     HttpClient httpclient = new DefaultHttpClient(); 
     String url = (title != null && title.length() > 0) ? BASE_URL + "?title=" + title : BASE_URL; 
     HttpGet httpget = new HttpGet(url); 
     String response; 
     try { 
      ResponseHandler<String> responseHandler = new BasicResponseHandler(); 
      response = httpclient.execute(httpget, responseHandler); 
      return response; 

     } catch (ClientProtocolException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

     return null; 
    } 
相关问题