Список массивов как ответ веб-службы SOAP - PullRequest
0 голосов
/ 25 февраля 2019

Мне нужно поместить результат в каждый соответствующий результирующий атрибут (см. Изображение в URL ниже).но не повезло.Не могли бы вы помочь мне, что мне не хватает? Ответ дает мне результат, но все записи сгруппированы по одному атрибуту

SupportRequestSoapImpl .java

открытый класс SupportRequestSoapImpl {

public SupportRequestSoapImpl() {
}

@WebResult(name = "TicketStatusResponse", partName = "parameters",
           targetNamespace = "http://mncc.navy.mil/MnccMnpTicket")
@WebMethod(operationName = "GetTicketStatus")
public TicketStatusResponse getTicketStatus(@WebParam(name = "TicketStatusRequest", partName = "parameters",
                                                      targetNamespace = "http://mncc.navy.mil/MnccMnpTicket")
                                            TicketStatusRequest parameters) {
    TicketStatusResponse response = new TicketStatusResponse();
    ObjectFactory factory = new ObjectFactory();
    Context ctx = null;
    Connection conn = null;
    Hashtable<String, String> ht = new Hashtable<String, String>();
    List<TicketStatusDetails> resultList = new ArrayList<TicketStatusDetails>();
    ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");

    ht.put(Context.PROVIDER_URL, "t3://localhost:7101");

    try {
        ctx = new InitialContext(ht);
        DataSource ds = (DataSource) ctx.lookup("jdbc/AjayOrcl");

        conn = ds.getConnection();

        final String typeName = "xxTicketStatusRec";
        final String typeTableName = "xxTicketStatusTbl";

        final StructDescriptor structDescriptor = StructDescriptor.createDescriptor(typeName.toUpperCase(), conn);
        final ResultSetMetaData metaData = structDescriptor.getMetaData();

        String sql = "Begin xxSRTicketsPkg.ticketStatus(?,?); End;";
        CallableStatement cs = null;
        cs = conn.prepareCall(sql);
        cs.setString(1, parameters.getDodId());
        cs.registerOutParameter(2, Types.ARRAY, typeTableName.toUpperCase());
        cs.execute();

        TicketStatusDetails tkctDtls = new TicketStatusDetails();

        Object[] data = (Object[]) ((Array) cs.getObject(2)).getArray();
        if (data != null) {

            for (int i = 0; i < data.length - 1; i++) {
                Object tmp = data[i];
                Struct row = (Struct) tmp;
                int index = 1;

                for (Object attribute : row.getAttributes()) {
                    if (metaData.getColumnName(index).equalsIgnoreCase("TICKETNUMBER")) {
                        System.out.println("Ticket Number: " + attribute);
                        tkctDtls.getTicketNumberAndCaseTypeAndCaseSubtype()
                            .add(factory.createTicketStatusDetailsCaseSubtype(String.valueOf(attribute)));                           
                    }

                    if (metaData.getColumnName(index).equalsIgnoreCase("CASESUBTYPE")) {
                        System.out.println("Case Sub Type: " + attribute);
                        tkctDtls.getTicketNumberAndCaseTypeAndCaseSubtype()
                            .add(factory.createTicketStatusDetailsCaseSubtype((String) attribute));                           
                    }

                    if (metaData.getColumnName(index).equalsIgnoreCase("OPENDATE")) {
                        System.out.println("Open Date: " + attribute);
                        tkctDtls.getTicketNumberAndCaseTypeAndCaseSubtype()
                            .add(factory.createTicketStatusDetailsCaseSubtype(timestampAsString((Timestamp) attribute)));
                    }

                    if (metaData.getColumnName(index).equalsIgnoreCase("SUMMARY")) {
                        System.out.println("Summary: " + attribute);
                        tkctDtls.getTicketNumberAndCaseTypeAndCaseSubtype()
                            .add(factory.createTicketStatusDetailsCaseSubtype((String) attribute));

                    }

                    if (metaData.getColumnName(index).equalsIgnoreCase("CASETYPE")) {
                        System.out.println("Case Type: " + attribute);
                        tkctDtls.getTicketNumberAndCaseTypeAndCaseSubtype()
                            .add(factory.createTicketStatusDetailsCaseSubtype((String) attribute));
                    }

                    if (metaData.getColumnName(index).equalsIgnoreCase("CLOSEDATE")) {
                        System.out.println("Close Date: " + attribute);
                        if (attribute != null) {
                            tkctDtls.getTicketNumberAndCaseTypeAndCaseSubtype()
                                .add(factory.createTicketStatusDetailsCaseSubtype(timestampAsString((Timestamp) attribute)));
                        }
                    }

                    if (metaData.getColumnName(index).equalsIgnoreCase("RESOLUTION")) {
                        System.out.println("Resolution: " + attribute);
                        tkctDtls.getTicketNumberAndCaseTypeAndCaseSubtype()
                            .add(factory.createTicketStatusDetailsCaseSubtype((String) attribute));
                    }

                    ++index;
                }

                resultList.add(tkctDtls);

            }
            response.getTicketDetails().addAll(resultList);
        }
    }

    catch (NamingException e) {
        e.printStackTrace();
    }

    catch (SQLException e) {
        e.printStackTrace();
    }

    finally {

        try {
            conn.close();
            ctx.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    } // finally

    return response;
}

public static String timestampAsString(Timestamp timestamp) {
    return DateTimeFormat.forPattern("ddMMyyyy").print(timestamp.getTime());
}

}

TicketStatusResponse.java

@ XmlAccessorType (XmlAccessType.FIELD) @XmlType (name = "", propOrder = {"ticketDetails", "errorMsg"}) @XmlRootElement (name = "TicketStatusResponse")

открытый класс TicketStatusResponse {

<code>protected List<TicketStatusDetails> ticketDetails;
protected String errorMsg;

/**
 * Gets the value of the ticketDetails property.
 * 
 * <p>
 * This accessor method returns a reference to the live list,
 * not a snapshot. Therefore any modification you make to the
 * returned list will be present inside the JAXB object.
 * This is why there is not a <CODE>set</CODE> method for the ticketDetails property.
 * 
 * <p>
 * For example, to add a new item, do as follows:
 * <pre>
 *    getTicketDetails().add(newItem);
 * 
* * *

* Объекты следующего типав списке разрешены * {@link TicketStatusDetails} * * * / public List getTicketDetails () {if (ticketDetails == null) {ticketDetails = new ArrayList ();} return this.ticketDetails;} / ** * Получает значение свойства errorMsg.* * @return * возможным объектом является * {@link String} * * / public String getErrorMsg () {return errorMsg;} / ** * Устанавливает значение свойства errorMsg.* * @param value * допустимым объектом является * {@link String} * * / public void setErrorMsg (String value) {this.errorMsg = value;}

}

TicketStatusDetails.java

@ XmlAccessorType (XmlAccessType.FIELD) @XmlType (name = "TicketStatusDetails", propOrder ={"ticketNumberAndCaseTypeAndCaseSubtype"})

открытый класс TicketStatusDetails {

<code>@XmlElementRefs({
    @XmlElementRef(name = "ticketNumber", namespace = "http://mncc.navy.mil/MnccMnpTicket", type = JAXBElement.class),
    @XmlElementRef(name = "caseSubtype", namespace = "http://mncc.navy.mil/MnccMnpTicket", type = JAXBElement.class),
    @XmlElementRef(name = "creationDate", namespace = "http://mncc.navy.mil/MnccMnpTicket", type = JAXBElement.class),
    @XmlElementRef(name = "summary", namespace = "http://mncc.navy.mil/MnccMnpTicket", type = JAXBElement.class),
    @XmlElementRef(name = "caseType", namespace = "http://mncc.navy.mil/MnccMnpTicket", type = JAXBElement.class),
    @XmlElementRef(name = "closedDate", namespace = "http://mncc.navy.mil/MnccMnpTicket", type = JAXBElement.class),
    @XmlElementRef(name = "resolution", namespace = "http://mncc.navy.mil/MnccMnpTicket", type = JAXBElement.class)
})
protected List<JAXBElement<?>> ticketNumberAndCaseTypeAndCaseSubtype;

/**
 * Gets the value of the ticketNumberAndCaseTypeAndCaseSubtype property.
 * 
 * <p>
 * This accessor method returns a reference to the live list,
 * not a snapshot. Therefore any modification you make to the
 * returned list will be present inside the JAXB object.
 * This is why there is not a <CODE>set</CODE> method for the ticketNumberAndCaseTypeAndCaseSubtype property.
 * 
 * <p>
 * For example, to add a new item, do as follows:
 * <pre>
 *    getTicketNumberAndCaseTypeAndCaseSubtype().add(newItem);
 * 
* * *

* Объекты следующих типов разрешены в списке * {@link JAXBElement} {@code <} {@ link String} {@ code>} * {@link JAXBElement} {@ code <} {@ link String} {@ code>} * {@link JAXBElement} {@ code <} {@ link XMLGregorianCalendar}{@code>} * {@link JAXBElement} {@ code <} {@ link String} {@ code>} * {@link JAXBElement} {@ code <} {@ link String} {@ code>} * {@link JAXBElement} {@ code <} {@ link XMLGregorianCalendar} {@ code>} * {@link JAXBElement} {@ code <} {@ link String} {@ code>} * * * / общедоступный список> getTicketNumberAndCaseTypeAndCaseSubtype () {if (ticketNumberAndCaseTypeAndCaseSubtype == null) {ticketNumberAndCaseTypeAndCaseSubtype = new ArrayList> ();} return this.ticketNumberAndCaseTypeAndCaseSubtype;}

}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...