2014-11-06 119 views
2

我的RESTful服務是如何使用Apache的駱駝來調用RESTful Web服務

import java.util.List; 
import javax.ws.rs.GET; 
import javax.ws.rs.Path; 
import javax.ws.rs.PathParam; 
import javax.ws.rs.Produces; 
import org.hibernate.Query; 
import org.hibernate.Session; 
import org.json.JSONArray; 


@Path("/detailsservice/") 
public class DetailsService { 
Dao d=new Dao(); 

@GET 
@Path("/details/{id}/") 
@Produces("text/xml") 

public Details getDetails(@PathParam("id") String id) { 

    Session hs = d.dao(); 
    Details de = (Details) hs.load(Details.class,new Integer(id)); 

    return de; 
} 
} 

我用碼頭服務器

import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; 
import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; 


public class Server { 

protected Server() throws Exception { 
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); 
    sf.setResourceClasses(DetailsService.class); 
    System.out.println("two"); 
    sf.setResourceProvider(DetailsService.class, new SingletonResourceProvider(new DetailsService())); 
    sf.setAddress("http://localhost:9000/"); 
    sf.create(); 
} 

public static void main(String args[]) throws Exception { 
    new Server(); 
    System.out.println("Server ready..."); 

    Thread.sleep(5 * 6000 * 1000); 
    System.out.println("Server exiting"); 
    System.exit(0); 
} 

} 

暴露在網絡上這項服務,我該如何使用Apache的駱駝調用此服務。 請詳細解釋我,因爲我是駱駝新手。 在此先感謝

+0

你知道https://camel.apache.org/rest.html? – 2014-11-06 08:50:28

+0

您可以使用camel-http或camel-http4組件發送http請求,也可以使用camel-cxfrs發送請求。 – 2014-11-08 08:27:55

+0

任何人都請幫助我。我需要一個例子。 – 2014-11-11 05:14:23

回答

1

可以使用http4組件:

<route> 
    <from uri="http4://localhost:9000/detailsservice/details/1234" /> 
    <!-- add your processors here --> 
    <to uri="..." /> 
</route>