0

サーバー上にいくつかの REST サービス (Jetty、RESTeasy) と GWT クライアントがあります。フロントエンドで Restlet-GWT モジュールを使用することにしました。

JSE クライアント (RESTeasy クライアント) を作成しましたが、サービスが適切に呼び出され (Jetty サーバーのログに SQL トレースが表示されます)、xml 応答が返されます。

次に、RestletでGWTから試しました。Web サービス (Jetty log) が呼び出されますが、null 応答があります。

Web サービス (バックエンド):

@GET
@Path("/getArt/{id}")
@Produces("application/xml")
public Art getArt(@PathParam("id")int id){
    Art art= artDAO.findById(id);
    return art;
}

フロントエンド GWT :

public class Front_End implements EntryPoint {

/**
 * This is the entry point method.
 */
public void onModuleLoad() {    
final Client client = new Client(Protocol.HTTP);
client.get("http://localhost:8080/rest/service/getArt/1", new Callback() {
    @Override
    public void onEvent(Request request, Response response) {

        System.out.println("Reponse : " + response.getEntity().getText());
    }
});
}

RESTeasy クライアントの動作:

public Object test(int id){
    try {

        ClientRequest request = new ClientRequest("http://localhost:8080/rest/service/getArt/"+id);

        request.accept("application/xml");
        ClientResponse<String> response = request.get(String.class);

        if (response.getStatus() == 200) 
        {
            Unmarshaller un = jc.createUnmarshaller();
            Object o = un.unmarshal(new StringReader(response.getEntity()));
            return o;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

RESTeasy と Restlet は「互換性」がありますか? バックエンドで RESTeasy の代わりに Restlet を使用する必要がありますか? 私は何が欠けていますか?

事前にThx

4

1 に答える 1

0

それはSOPの問題でした。私のサーバーはポート8080で実行され、GWTはポート8888で実行されていました。

私はプロキシを使用しました(クライアント側の/ warに入れてください):

proxy.jsp

<%@page import="javax.naming.Context"%>
<%@page import="javax.naming.InitialContext"%><%@page session="false"%>
<%@page import="java.net.*,java.io.*" %>

<%
try {
String reqUrl = request.getQueryString();
URL url = new URL(reqUrl.substring(4));

HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setDoOutput(true);
con.setRequestMethod(request.getMethod());
int clength = request.getContentLength();
if (clength > 0) {
    con.setDoInput(true);
    byte[] idata = new byte[clength];
    request.getInputStream().read(idata,0,clength);
    con.getOutputStream().write(idata,0,clength);
}
response.setContentType(con.getContentType());
BufferedReader rd = new BufferedReader(new InputStreamReader(con.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
    out.println(line);
}
rd.close();
} catch (Exception e) {
    e.printStackTrace();
    response.setStatus(500);
}
%>

次に、電話をかけるクラスでは、URLは次のようになります。

String url ="proxy.jsp?url=" + URL.encode("http://localhost:8080/rest/service/getArt/1");

それを解決する別の方法があります。https://developers.google.com/web-toolkit/doc/1.6/tutorial/Xsiteを確認してください。

于 2013-01-03T10:21:35.597 に答える