解组对java对象的肥皂响应

时间:2016-06-14 10:37:58

标签: java xml soap unmarshalling

以下是需要转换为Java对象的SOAP响应

 <?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
    <ns0:HelpDesk_Query_ServiceResponse xmlns:ns0="urn:XXXX_HPD_IncidentInterface_WS__XXXXX" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <ns0:Assigned_Group>TIM-CSDWINDOWS-ADMIN</ns0:Assigned_Group>
        <ns0:Assigned_Group_Shift_Name/>
        <ns0:Assigned_Support_Company>India  Ltd</ns0:Assigned_Support_Company>
        <ns0:Assigned_Support_Organization>TIM-CSD</ns0:Assigned_Support_Organization>
        <ns0:Assignee>Akshay Patwardhan</ns0:Assignee>
        <ns0:Categorization_Tier_1>TIM</ns0:Categorization_Tier_1>
        <ns0:Categorization_Tier_2>ATT</ns0:Categorization_Tier_2>
        <ns0:Categorization_Tier_3>C Drive Enablement</ns0:Categorization_Tier_3>
        <ns0:City>HYDERABAD</ns0:City>
        <ns0:Closure_Manufacturer/>
        <ns0:Closure_Product_Category_Tier1/>
        <ns0:Closure_Product_Category_Tier2/>
        <ns0:Closure_Product_Category_Tier3/>
        <ns0:Closure_Product_Model_Version/>
        <ns0:Closure_Product_Name/>
        <ns0:Company>India  Ltd</ns0:Company>
        <ns0:Contact_Company>India  Ltd</ns0:Contact_Company>
        <ns0:Contact_Sensitivity>Standard</ns0:Contact_Sensitivity>
        <ns0:Country>India</ns0:Country>
        <ns0:Department>TIM-India </ns0:Department>
        <ns0:Summary>Test</ns0:Summary>
        <ns0:Notes>Host Name: INHYTZPC03456 Detailed Business Justification: test Project/ODC Name: TIM Your Current Location Details: </ns0:Notes>
        <ns0:First_Name>Venkata</ns0:First_Name>
        <ns0:Impact>4-Minor/Localized</ns0:Impact>
        <ns0:Last_Name>Sabbarapu</ns0:Last_Name>
        <ns0:Manufacturer/>
        <ns0:Middle_Initial/>
        <ns0:Organization>XXX_TIM</ns0:Organization>
        <ns0:Phone_Number>XXXXXX Extn: 67 -XXXXXX</ns0:Phone_Number>
        <ns0:Priority>Medium</ns0:Priority>
        <ns0:Priority_Weight>10</ns0:Priority_Weight>
        <ns0:Product_Categorization_Tier_1/>
        <ns0:Product_Categorization_Tier_2/>
        <ns0:Product_Categorization_Tier_3/>
        <ns0:Product_Model_Version/>
        <ns0:Product_Name/>
        <ns0:Region>India</ns0:Region>
        <ns0:Reported_Source>Self Service</ns0:Reported_Source>
        <ns0:Resolution/>
        <ns0:Resolution_Category/>
        <ns0:Resolution_Category_Tier_2/>
        <ns0:Resolution_Category_Tier_3/>
        <ns0:Service_Type>User Service Request</ns0:Service_Type>
        <ns0:Site>BHD-SEZ</ns0:Site>
        <ns0:Site_Group>HYDERABAD</ns0:Site_Group>
        <ns0:Status>Assigned</ns0:Status>
        <ns0:Status_Reason xsi:nil="true" />
        <ns0:Urgency>3-Medium</ns0:Urgency>
        <ns0:VIP>No</ns0:VIP>
        <ns0:ServiceCI/>
        <ns0:ServiceCI_ReconID/>
        <ns0:HPD_CI/>
        <ns0:HPD_CI_ReconID/>
        <ns0:HPD_CI_FormName/>
        <ns0:z1D_CI_FormName/>
    </ns0:HelpDesk_Query_ServiceResponse>
</soapenv:Body>
</soapenv:Envelope>

这是我的pojo

@XmlAccessorType(XmlAccessType.FIELD)
public class Response {

String Assigned_Group;
String Assigned_Group_Shift_Name;
String Assigned_Support_Company;
String Assigned_Support_Organization;
String Assignee;
String Categorization_Tier_1;
String Categorization_Tier_2;
String Categorization_Tier_3;
String City;
public String getAssigned_Group() {
    return Assigned_Group;
}
public void setAssigned_Group(String assigned_Group) {
    Assigned_Group = assigned_Group;
}
public String getAssigned_Group_Shift_Name() {
    return Assigned_Group_Shift_Name;
}
public void setAssigned_Group_Shift_Name(String assigned_Group_Shift_Name) {
    Assigned_Group_Shift_Name = assigned_Group_Shift_Name;
}
public String getAssigned_Support_Company() {
    return Assigned_Support_Company;
}

这是UnMarshall代码

    Unmarshaller unmarshaller = JAXBContext.newInstance(Response.class).createUnmarshaller();
    Document bodyDoc = soapResponse.getSOAPBody().extractContentAsDocument();
    Response request = (Response) unmarshaller.unmarshal(bodyDoc);

它给出了javax.xml.bind.UnmarshalException。 有些人可以帮我创建Java POJO和UnMarshall上面对java Object的soap XML响应。

2 个答案:

答案 0 :(得分:-1)

我建议使用wsimport来生成SOAP客户端。还有Maven Plugin

答案 1 :(得分:-2)

或工具wsdl2java,它将为您创建课程。使用肥皂堆的工具(cxf,axis2 ......)

相关问题