- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试解析 SOAP 响应。我可以使用以下行显示完整的响应。
System.out.println("Response: " + out.toString());
但是,当我解析响应并编码解析的响应时,它显示错误的响应。
package-info.java
@XmlSchema(
namespace = "http://v3.hotel.wsapi.ean.com/",
elementFormDefault = XmlNsForm.QUALIFIED)
package com.ean;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;
我的代码
@XmlRootElement(name="getListResponse")
@XmlAccessorType(XmlAccessType.FIELD)
public class GetListResponse {
@XmlElement(name="HotelListResponse")
private HotelListResponse hotelListResponse;
public GetListResponse() {
this.hotelListResponse = new HotelListResponse();
}
…getter and setter
}
@XmlRootElement(name ="HotelListResponse")
@XmlAccessorType(XmlAccessType.FIELD)
public class HotelListResponse {
@XmlElement(name = "customerSessionId")
String customerSessionId;
@XmlElement(name = "numberOfRoomsRequested")
int numberOfRoomsRequested;
@XmlElement(name = "moreResultsAvailable")
boolean moreResultsAvailable;
@XmlElement(name = "cacheKey")
String cacheKey;
@XmlElement(name="cacheLocation")
String cachLocation;
@XmlElement(name = "HotelList")
HotelList hotelList;
public HotelListResponse() {
this.hotelList = new HotelList();
}
… getters and setters…
}
@XmlRootElement(name ="HotelList")
@XmlAccessorType(XmlAccessType.FIELD)
public class HotelList {
@XmlAttribute(name = "size")
int size;
@XmlAttribute(name = "activePropertyCount")
int activePropertyCount;
@XmlElement(name = "HotelSummary")
List <HotelSummary> hotelSummaries;
public HotelList() {
this.hotelSummaries = new ArrayList();
}
… getters and setters…
}
@XmlRootElement(name = "HotelSummary")
@XmlAccessorType(XmlAccessType.FIELD)
public class HotelSummary {
@XmlAttribute(name = "order")
int order;
@XmlElement(name = "hotelId")
int hotelId;
@XmlElement(name = "name")
String name;
@XmlElement(name = "address1")
String address1;
@XmlElement(name = "city")
String city;
@XmlElement(name = "stateProvinceCode")
String stateProvinceCode;
@XmlElement(name = "postalCode")
int postalCode;
@XmlElement(name = "countryCode")
String countryCode;
@XmlElement(name = "airportCode")
String airportCode;
@XmlElement(name = "supplierType")
String supplierType;
@XmlElement(name = "propertyCategory")
int propertyCategory;
@XmlElement(name = "hotelRating")
float hotelRating;
@XmlElement(name = "confidenceRating")
int confidenceRating;
@XmlElement(name = "amenityMask")
int amenityMask;
@XmlElement(name = "tripAdvisorRating")
float tripAdvisorRating;
@XmlElement(name = "locationDescription")
String locationDescription;
@XmlElement(name = "shortDescription")
String shortDescriptionl; //change amp to &
@XmlElement(name = "highRate")
String highRate;
@XmlElement(name = "lowRate")
float lowRate;
@XmlElement(name = "rateCurrencyCode")
String rateCurrencyCode;
@XmlElement(name = "latitude")
float latitude;
@XmlElement(name = "longitude")
float longitude;
@XmlElement(name = "proximityDistance")
float proximityDistance;
@XmlElement(name = "proximityUnit")
String proximityUnit;
@XmlElement(name = "hotelInDestination")
boolean hotelInDestination;
@XmlElement(name = "thumbNailUrl")
String thumbNailUrl;
@XmlElement(name = "deepLink")
String deepLink;
@XmlElement(name = "RoomRateDetailsList")
RoomRateDetailsList roomRateDetailsList;
public HotelSummary() {
this.roomRateDetailsList = new RoomRateDetailsList();
}
… getters and setters…
}
@XmlRootElement(name = "RoomRateDetailsList")
@XmlAccessorType(XmlAccessType.FIELD)
public class RoomRateDetailsList {
@XmlElement(name="RoomRateDetails")
List<RoomRateDetails> roomRateDetails;
public RoomRateDetailsList() {
this.roomRateDetails = new ArrayList();
}
.. getter and setter..
}
@XmlRootElement(name = "RoomRateDetails")
@XmlAccessorType(XmlAccessType.FIELD)
public class RoomRateDetails {
@XmlElement(name="roomTypeCode")
int roomTypeCode;
@XmlElement(name="rateCode")
int rateCode;
@XmlElement(name="maxRoomOccupancy")
int maxRoomOccupancy;
@XmlElement(name="quotedRoomOccupancy")
int quotedRoomOccupancy;
@XmlElement(name="minGuestAge")
int minGuestAge;
@XmlElement(name="roomDescription")
String roomDescription;
@XmlElement(name="promoId")
int promoId;
@XmlElement(name="promoDescription")
String promoDescription;
@XmlElement(name="currentAllotment")
int currentAllotment;
@XmlElement(name="propertyAvailable")
boolean propertyAvailable;
@XmlElement(name="propertyRestricted")
boolean propertyRestricted;
@XmlElement(name="expediaPropertyId")
int expediaPropertyId;
@XmlElement(name="rateKey")
String rateKey;
@XmlElement(name="RateInfo")
RateInfo rateInfo;
@XmlElement(name="ValueAdds")
ValueAdds valueAdds;
public RoomRateDetails() {
this.rateInfo = new RateInfo();
this.valueAdds = new ValueAdds();
}
… getters and setters…
}
@XmlRootElement(name = "RoomInfo")
@XmlAccessorType(XmlAccessType.FIELD)
public class RateInfo {
@XmlAttribute(name="priceBreakdown")
boolean priceBreakdown;
@XmlAttribute(name="promo")
boolean promo;
@XmlAttribute(name="rateChange")
boolean rateChange;
@XmlElement(name="ChargeableRateInfo")
ChargeableRateInfo chargeableRateInfo;
public RateInfo() {
this.chargeableRateInfo = new ChargeableRateInfo();
}
.. getters and setters…
}
@XmlRootElement(name = "ChargeableRateInfo")
@XmlAccessorType(XmlAccessType.FIELD)
public class ChargeableRateInfo {
@XmlAttribute(name="averageBaseRate")
float averageBaseRate;
@XmlAttribute(name="averageRate")
float averageRate;
@XmlAttribute(name="commissionableUsdTotal")
float commissionableUsdTotal;
@XmlAttribute(name="currencyCode")
String currencyCode;
@XmlAttribute(name="maxNightlyRate")
float maxNightlyRate;
@XmlAttribute(name="nightlyRateTotal")
float nightlyRateTotal;
@XmlAttribute(name="total")
float total;
@XmlElement(name="NightlyRatesPerRoom")
NightlyRatesPerRoom nightlyRatesPerRoom;
public ChargeableRateInfo() {
this.nightlyRatesPerRoom = new NightlyRatesPerRoom();
}
… getters and setters…
}
@XmlRootElement(name = "NightlyRatesPerRoom")
@XmlAccessorType(XmlAccessType.FIELD)
public class NightlyRatesPerRoom {
@XmlAttribute(name="size")
int size;
@XmlElement(name="NightlyRate")
NightlyRate nightlyRate;
public NightlyRatesPerRoom() {
this.nightlyRate = new NightlyRate();
}
… getters and setters…
}
@XmlRootElement(name = "NightlyRate")
@XmlAccessorType(XmlAccessType.FIELD)
public class NightlyRate {
@XmlAttribute(name="baseRate")
float baseRate;
@XmlAttribute(name="rate")
float rate;
@XmlAttribute(name="promo")
float promo;
public NightlyRate() {
}
… getters and setters…
}
@XmlRootElement(name = "ValueAdds")
@XmlAccessorType(XmlAccessType.FIELD)
public class ValueAdds {
@XmlAttribute(name="size")
private int size;
@XmlElement(name="ValueAdd")
private List<ValueAdd> valueAdd;
public ValueAdds() {
this.valueAdd = new ArrayList();
}
… getters and setters…
}
@XmlRootElement(name = "ValueAdd")
@XmlAccessorType(XmlAccessType.FIELD)
public class ValueAdd {
@XmlAttribute(name="id")
private int id;
@XmlElement(name="description")
private String description;
public ValueAdd() {
}
… getters and setters…
}
代码
try {
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = soapConnectionFactory.createConnection();
SOAPFactory soapFactory = SOAPFactory.newInstance();
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
SOAPHeader header = message.getSOAPHeader();
header.detachNode();
SOAPBody body = message.getSOAPBody();
Name bodyName;
bodyName = soapFactory.createName("getList",
"v3", "http://v3.hotel.wsapi.ean.com/");
SOAPBodyElement getList
= body.addBodyElement(bodyName);
Name childName = soapFactory.createName("HotelListRequest");
SOAPElement HotelListRequest = getList.addChildElement(childName);
……Here, I add child nodes of the request…...
message.writeTo(System.out); //show message details
URL endpoint = new URL("http://dev.api.ean.com/ean-services/ws/hotel/v3");
SOAPMessage response = connection.call(message, endpoint);
connection.close();
SOAPMessage sm = response;
System.err.println("Response:");
ByteArrayOutputStream out = new ByteArrayOutputStream();
sm.writeTo(out);
System.err.println(">>>" + out.toString());
System.err.println(">>>>>>>>>>>parse:");
SOAPBody sb = response.getSOAPBody();
DOMSource source = new DOMSource(sb);
HotelListResponse results = new HotelListResponse();
results = (HotelListResponse) JAXB.unmarshal(source, HotelListResponse.class);
JAXBContext context = JAXBContext.newInstance(HotelListResponse.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
System.err.println("Response *******");
m.marshal(results, System.out);
System.err.println("116872:" + results.getHotelList().getHotelSummaries().get(0).getHotelId());
} catch (Exception ex) {
ex.printStackTrace();
}
实际响应
Response:
Response:>>><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:getListResponse xmlns:ns2="http://v3.hotel.wsapi.ean.com/">
<HotelListResponse>
<customerSessionId>0ABAAA95-28B2-5914-7952-0331AC9069EA</customerSessionId>
<numberOfRoomsRequested>1</numberOfRoomsRequested>
<moreResultsAvailable>true</moreResultsAvailable>
<cacheKey>-41118b29:146950321ac:-69e1</cacheKey>
<cacheLocation>10.176.160.143:7300</cacheLocation>
<HotelList size="25" activePropertyCount="119">
<HotelSummary order="0">
<hotelId>150241</hotelId>
<name>Rydges World Square</name>
<address1>389 Pitt Street</address1>
<city>Sydney</city>
<stateProvinceCode>NW</stateProvinceCode>
<postalCode>2000</postalCode>
<countryCode>AU</countryCode>
<airportCode>SYD</airportCode>
<supplierType>E</supplierType>
<propertyCategory>1</propertyCategory>
<hotelRating>4.5</hotelRating>
<confidenceRating>52</confidenceRating>
<amenityMask>1343491</amenityMask>
<tripAdvisorRating>3.5</tripAdvisorRating>
<locationDescription>Near Darling Harbour</locationDescription>
<shortDescription>&lt;p&gt;&lt;b&gt;Property Location&lt;/b&gt; &lt;br /&gt;With a stay at Rydges World Square, you&apos;ll be centrally located in Sydney, steps from World Square Shopping Centre and minutes from Capitol Theatre. This 4.5-star</shortDescription>
<highRate>218.64</highRate>
<lowRate>218.64</lowRate>
<rateCurrencyCode>USD</rateCurrencyCode>
<latitude>-33.8766</latitude>
<longitude>151.20752</longitude>
<proximityDistance>0.5492472</proximityDistance>
<proximityUnit>MI</proximityUnit>
<hotelInDestination>true</hotelInDestination>
<thumbNailUrl>/hotels/1000000/570000/565000/564969/564969_91_t.jpg</thumbNailUrl>
<deepLink>http://travel.ian.com/index.jsp?pageName=hotAvail&amp;cid=55505&amp;hotelID=150241&amp;mode=2&amp;numberOfRooms=1&amp;room-0-adult-total=2&amp;room-0-child-total=0&amp;arrivalMonth=5&amp;arrivalDay=18&amp;departureMonth=5&amp;departureDay=19&amp;showInfo=true&amp;locale=en_US&amp;currencyCode=USD</deepLink>
<RoomRateDetailsList>
<RoomRateDetails>
<roomTypeCode>200156055</roomTypeCode>
<rateCode>202768754</rateCode>
<maxRoomOccupancy>2</maxRoomOccupancy>
<quotedRoomOccupancy>2</quotedRoomOccupancy>
<minGuestAge>0</minGuestAge>
<roomDescription>Special: Deluxe King - Check-In from 8:30pm</roomDescription>
<promoId>201528081</promoId>
<promoDescription>Sale! Save 25% on this Stay.</promoDescription>
<currentAllotment>10</currentAllotment>
<propertyAvailable>true</propertyAvailable>
<propertyRestricted>false</propertyRestricted>
<expediaPropertyId>564969</expediaPropertyId>
<rateKey>0ABAAA85-18B2-9914-6952-0351AC9069DF</rateKey>
<RateInfo priceBreakdown="true" promo="true" rateChange="false">
<ChargeableRateInfo averageBaseRate="218.64" averageRate="218.64" commissionableUsdTotal="218.64" currencyCode="USD" maxNightlyRate="218.64" nightlyRateTotal="218.64" total="218.64">
<NightlyRatesPerRoom size="1">
<NightlyRate baseRate="218.64" rate="218.64" promo="false"/>
</NightlyRatesPerRoom>
</ChargeableRateInfo>
</RateInfo>
<ValueAdds size="1">
<ValueAdd id="2048">
<description>Free Wireless Internet</description>
</ValueAdd>
</ValueAdds>
</RoomRateDetails>
<RoomRateDetails>
...
>>>>>>>>>>>parse:
Response *******
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<HotelListResponse xmlns="http://v3.hotel.wsapi.ean.com/">
<numberOfRoomsRequested>0</numberOfRoomsRequested>
<moreResultsAvailable>false</moreResultsAvailable>
<HotelList size="0" activePropertyCount="0"/>
</HotelListResponse>
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:635)
at java.util.ArrayList.get(ArrayList.java:411)
at com.expedia.Engine.retrieveHotels(Engine.java:135)
at com.hotelsdotcom.App.main(App.java:17)
最佳答案
在正确的级别解码
当前您正在解码与 soap:Body
元素相对应的 XML 节点,而是需要向下导航到 HotelListResponse
元素并对其进行解码。
您可以尝试以下方法:
DOMSource source = new DOMSource(sb.getFirstChild().getFirstChild());
注意您的命名空间资格
在您编码的 XML 中,所有元素均显示为通过 http://v3.hotel.wsapi.ean.com/
进行限定,但您尝试解码的文档却没有具有此命名空间限定,因此您应该从 package-info
类中删除 @XmlSchema
注释。
使用Unmarshaller
而不是JAXB.unmarshal
而不是执行以下操作:
results = (HotelListResponse) JAXB.unmarshal(source, HotelListResponse.class);
我建议这样做:
JAXBContext jc = JAXBContext.newInstance(HotelListResponse.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
results = unmarshaller.unmarshal(source, HotelListResponse.class).getValue();
当您使用采用类参数的 unmarshal
方法时,您是在告诉 JAXB XML 对应的类,而不是由根元素自动确定它。
results = (HotelListResponse) JAXB.unmarshal(source, HotelListResponse.class)
由于 XML 文档的级别错误,JAXB 无法将其与您的域模型进行匹配。因此仅填充默认值。这就是为什么结果充满 0
或 false
值的原因。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<HotelListResponse xmlns="http://v3.hotel.wsapi.ean.com/">
<numberOfRoomsRequested>0</numberOfRoomsRequested>
<moreResultsAvailable>false</moreResultsAvailable>
<HotelList size="0" activePropertyCount="0"/>
</HotelListResponse>
关于java - 解析的 SOAP 响应与收到的响应不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24131822/
我正在使用 SOA 客户端 Firefox 插件向某些 ONVIF 摄像机发送 SOAP 请求。您将在下面看到“GetServices”请求。它对于一台相机工作正常,但对于另一台(AXIS 相机)我收
我正在使用 SOA 客户端 Firefox 插件向某些 ONVIF 摄像机发送 SOAP 请求。您将在下面看到“GetServices”请求。它对于一台相机工作正常,但对于另一台(AXIS 相机)我收
有谁知道 Fiddler 是否可以显示 ASMX Web 服务的原始 SOAP 消息?我正在使用 Fiddler2 和 Storm 测试一个简单的 Web 服务,结果各不相同(Fiddler 显示纯
使用 SOAP 协议(protocol)时,是否可以使用 SOAP 取消挂起的远程函数调用? 我看到三种不同的情况: A) 向需要很长时间才能完成的服务发出请求。例如,当复制包含大量文件的目录时,可以
人们还在写吗SOAP services还是已经通过了它的技术architectural shelf life ?人们是否回归二进制格式? 最佳答案 SOAP 的替代方案不是二进制格式。 我认为您看到了
SOAP 协议(protocol)工作的默认端口号是多少? 最佳答案 没有“SOAP 协议(protocol)”之类的东西。 SOAP 是一种 XML 模式。 但是,它通常通过 HTTP(端口 80)
之间有什么区别 和 以及如何在它们之间切换? 如何将响应从 具有定义的命名空间 "http://schemas.xmlsoap.org/soap/envelope/" ,它的特殊含义是底层 XML
我正在从 Mule 进行 SOAP 调用。我正在使用 default-exception-strategy 来捕获异常。发生异常时,如何发送我自己的故障代码和故障字符串而不是通用的 soap 故障消息
我正在编写一个 powershell 脚本,它将每 10 分钟 ping 一次soap web 服务,以使其保持活跃状态,从而提高性能。我们已经在 IIS 中尝试了多种技术,应用程序池空闲超时和只
如有任何帮助,我们将不胜感激;我已经研究了几天了。 下面是我目前得到的代码;不幸的是,当我运行它时出现 HTTP 415 错误; 无法处理消息,因为内容类型为“text/xml; charset=UT
我们需要使用其他团队开发的网络服务。使用 JAX-WS用于生成网络服务。我们正在使用 wsimport 生成客户端 stub 。 问题是我需要将以下信息作为 header 与 SOAP 正文一起传递:
我的意思是,真正的互操作:从 Java 到 .NET,从 PHP 到 Java,等等。 我之所以这样问,是因为我们的权力希望我们使用 SOAP Web 服务实现面向公众的 API,并且我试图强调支持
我写了一个拦截器进行测试。但是我在Interceptor中获得的Soap消息正文始终为null。 我的Cxf是Apache-CXF-2.4.0 bean.xml是这样的:
我正在尝试查询货币的 netsuite api。以下soap请求在SOAP UI客户端中对我有用。但是我很难尝试使用 ruby 的 savon gem 0.9.7 版进行相同的工作。
我创建了一个示例 Mule 流,首先根据 http://www.mulesoft.org/documentation/display/current/Consuming+Web+Services+wi
我正在尝试使用此 SOAP 服务:http://testws.truckstop.com:8080/v13/Posting/LoadPosting.svc?singleWsdl使用 node-soap
我有几个 SoapUI 测试步骤,其中响应返回空(即“-> 空/空响应”),这正是我所期望的。 如何断言对测试步骤请求的响应为空? 到目前为止,我已经尝试了以下但没有运气: 审查可用的断言,无需定制
我正在尝试构建一个手动 HTTP 请求,以便从我认为是相当简单的 SOAP Web 服务调用中返回响应。但是,我无法正确构建请求,并且没有得到我期望的响应。 适用wsdl声明: wsdl 目标命名空间
我正在尝试使用 Insomnia 调用 SOAP 电话 - 特别是试图让帖子成功。我将 URL 定义为端点,并将正文类型作为带有 SOAP 内容(信封、标题、正文)的 XML。我在标题中定义了用户 I
我正在学习 SOAP 实现,并且对于 SOAP 1.2 信封的适当 namespace URI 感到有些困惑。 w3c specification for SOAP指的是“http://www.w3.
我是一名优秀的程序员,十分优秀!