我有一个看起来像的模式片段
<xs:element name="dataValue">
<xs:complexType>
<xs:sequence>
<xs:element name="value" type="xs:anyType"\>
</xs:sequence>
</xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)
hyperjaxb3生成的类包含以下片段:
@XmlElement(required = true)
protected Object value;
@Transient
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
@Basic
@Column(name = "VALUEOBJECT")
public String getValueObject() {
if (JAXBContextUtils.
isMarshallable("org.lcogt.schema", this.getValue())) {
return JAXBContextUtils.unmarshall("org.lcogt.schema", this.getValue());
} else {
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
据我所知,hibernate将很难持久化纯对象,因此hyperjaxb假设该对象可以被解组为XML字符串并且生成的String是持久的.在我的情况下,这不是真的,但我可以保证toString()方法将返回一些有用的东西.我希望生成的代码看起来更像:
@XmlElement(required = true)
protected Object value;
@Transient
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = …Run Code Online (Sandbox Code Playgroud) 某些设备(例如webrelay)返回原始XML以响应HTTPGet请求.也就是说,回复不包含有效的HTTP标头.多年来,我使用以下代码从这些设备中检索信息:
private InputStream doRawGET(String url) throws MalformedURLException, IOException
{
try
{
URL url = new URL(url);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setConnectTimeout(5000);
con.setReadTimeout(5000);
return con.getInputStream();
}
catch (SocketTimeoutException ex)
{
throw new IOException("Timeout attempting to contact Web Relay at " + url);
}
}
Run Code Online (Sandbox Code Playgroud)
在openJdk 7中,sun.net.www.protocol.http.HttpURLConnection添加了以下行,这意味着任何带有无效标头的HTTP响应都会生成IOException:
1325 respCode = getResponseCode();
1326 if (respCode == -1) {
1327 disconnectInternal();
1328 throw new IOException ("Invalid Http response");
1329 }
Run Code Online (Sandbox Code Playgroud)
如何从Java 7新世界中需要HTTPGet请求的服务器获取"无头"XML?