Java 通过CXF发送邮件
我正在基于CXF构建webservice,现在我正在通过代码将变量发送到某个URL中:Java 通过CXF发送邮件,java,spring,cxf,apache-servicemix,Java,Spring,Cxf,Apache Servicemix,我正在基于CXF构建webservice,现在我正在通过代码将变量发送到某个URL中: url = new URL(urlSSO + "/user"); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded")
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 Web服务将放在servicemix上,因此我需要一些非常快速的东西来发送变量,使用CXF您可以创建REST服务(JAX-RS)或Web服务(JAX-WS)。如果不明确需要JAX-WS,我建议您使用JAX-RS。使用REST服务,使用JAXB以JSON或XML的形式发送数据比
application/x-www-form-urlencoded
form更容易。我不知道您对问题的答案有何期待。这是访问web服务的客户端代码吗?如果是这样,请阅读此-。