Call a web service from Seam

A simple question, but can someone provide a sample code on how someone will call a web service from the JBoss Seam framework and process the results?

I need to be able to integrate with the search platform provided by a private vendor that reveals its functionality as a web service. So, I'm just looking for some recommendations regarding how the code will look for calling this web service.

(As an example, you can choose any sample web service.)

+3
source share
3 answers

gajillion HTTP- (Restlet , , - ), GET. , HttpClient Apache Commons:

HttpClient client = new HttpClient();
HttpMethod method = new GetMethod("http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=restbook&query=HttpClient");
client.executeMethod(method);
+1
import org.restlet.Client;
import org.restlet.data.Protocol;
import org.restlet.data.Reference;
import org.restlet.data.Response;
import org.restlet.resource.DomRepresentation;
import org.w3c.dom.Node;

/**
 * Uses YAHOO! RESTful web service with XML.
 */
public class YahooSearch {
    private static final String BASE_URI = "http://api.search.yahoo.com/WebSearchService/V1/webSearch";

    public static void main(final String[] args) {
        if (1 != args.length) {
            System.err.println("You need to pass a search term!");
        } else {
            final String term = Reference.encode(args[0]);
            final String uri = BASE_URI + "?appid=restbook&query=" + term;
            final Response response = new Client(Protocol.HTTP).get(uri);
            final DomRepresentation document = response.getEntityAsDom();

            document.setNamespaceAware(true);
            document.putNamespace("y", "urn:yahoo:srch");

            final String expr = "/y:ResultSet/y:Result/y:Title/text()";
            for (final Node node : document.getNodes(expr)) {
                System.out.println(node.getTextContent());
            }
        }
    }
}

Restlet, Yahoo RESTful. , - , .

0
final Response response = new Client(Protocol.HTTP).get(uri);

, , -, .

, Restlet, ?
(, , .)

0

Source: https://habr.com/ru/post/1696809/


All Articles