使用XML文件的RESTful Web服务
除了FORMPARAM之外,还有其他方法可以将XML文件发送到RESTful Web服务吗使用XML文件的RESTful Web服务,xml,web-services,rest,jersey,Xml,Web Services,Rest,Jersey,除了FORMPARAM之外,还有其他方法可以将XML文件发送到RESTful Web服务吗 我的要求是开发一个Web服务,它使用一个XML文件,将其存储在我的本地计算机中,并返回一条声明,说明该文件已下载/保存。以下是要发布的代码,比SOAP更简单 // POST the XML string as text/xml via HTTPS public static String postRequest(String strRequest, String strURL) throws Excep
我的要求是开发一个Web服务,它使用一个XML文件,将其存储在我的本地计算机中,并返回一条声明,说明该文件已下载/保存。以下是要发布的代码,比SOAP更简单
// POST the XML string as text/xml via HTTPS
public static String postRequest(String strRequest, String strURL) throws Exception {
String responseXML = null;
try {
URL url = new URL(strURL);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;
byte[] requestXML = strRequest.getBytes();
// Set the appropriate HTTP parameters.
httpConn.setRequestProperty("Content-Length", String.valueOf(requestXML.length));
httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
// Send the String that was read into postByte.
OutputStream out = httpConn.getOutputStream();
out.write(requestXML);
out.close();
// Read the response and write it to standard out.
InputStreamReader isr = new InputStreamReader(httpConn.getInputStream());
BufferedReader br = new BufferedReader(isr);
String temp;
String tempResponse = "";
//Create a string using response from web services
while ((temp = br.readLine()) != null)
tempResponse = tempResponse + temp;
responseXML = tempResponse;
br.close();
isr.close();
} catch (java.net.MalformedURLException e) {
System.out.println("Error in postRequest(): Secure Service Required");
} catch (Exception e) {
System.out.println("Error in postRequest(): " + e.getMessage());
}
return responseXML;
}
RESTful wid运动衫是实际需求!签出——这就像没有
@FormParam
注释一样简单:@POST-public-void-store(String-xml){…
要实现RESTful,请不要从POST返回任何内容,除非内容中断(即默认的“200 OK”就足够了).Jersey可能会自己产生一个很好的错误消息。它在哪里使用我的XML文件?