0

我正在构建基于 CXF 的网络服务,现在我通过代码将变量发送到某个 URL:

url = new URL(urlSSO + "/user");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");

connection.setRequestProperty("Content-Length","" + Integer.toString(urlParameters.getBytes().length));
connection.setRequestProperty("Content-Language", "en-EN");

connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);

// Send request
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();

// Get Response
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer response = new StringBuffer();
while ((line = rd.readLine()) != null) {
    response.append(line);
    response.append('\r');
}
rd.close();

userInfo = response.toString();
if (userInfo != null) {
    //do something
} else {
    // some problem with user
    return "home";
}

但我想知道是否有一些更简单的方法可以用 CXF 做到这一点?

我的意思是,也许 CXF 有内置的东西?

我认为这段代码可能需要很长时间才能发送并从其他 servlet 获得响应......这个 CXF 网络服务将放在 servicemix 上,所以我需要一些非常快速的东西来发送变量

4

0 回答 0