How to deserialize object in java SimpleXML - java

i have to send request by soap. and i use Retrofit2.
i cant convert and deserialize the response. in type of xml like "xsi" instance "xmlns" its my problem.
this is my response
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:requestCPResponse xmlns:ns2="http://incomingwebchannel.hrz.jpos.org/">
<return xsi:type="ns2:jiringBillInqOut" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<refNo>091015900983</refNo>
<responseCode>03</responseCode>
</return>
</ns2:requestCPResponse>
</S:Body>
</S:Envelope>
and this is my retrofit interface
#POST("/nafis-web-3/services/mobile")
Call<UsStatesResponseEnvelope> requestCP(#Body UsStatesRequestEnvelope body);
this is my request code
new RequestCallback<>(activity, true, ApiClient.createApi(activity).requestCP(envelope), new RequestListener<UsStatesResponseEnvelope>() {
#Override
public void onResponse(#NonNull final Response<UsStatesResponseEnvelope> response) {
try {
com.teskaco.transactionsample.utils.Log.e(response.body().getBody().getUsStatesCPResponse().getStatesResponseReturn().getResponseCode());
} catch (Exception e) {
Log.e("TAG", e.getMessage());
}
}
#Override
public void onFailure(#NonNull int code, #NonNull JsonObject jsonObject) {
}
});
and this is my model. UsStatesResponseBody.clss
#Root(name = "S:Envelope")
#NamespaceList({
#Namespace( prefix = "S", reference = "http://schemas.xmlsoap.org/soap/envelope/")})
public class UsStatesResponseEnvelope {
#Element(name = "S:Body", required = false)
private UsStatesResponseBody body;
public UsStatesResponseBody getBody() {
return body;
}
public void setBody(UsStatesResponseBody body) {
this.body = body;
}
}
class UsStatesResponseBody.clss
#Root(name = "S:Body", strict = false)
public class UsStatesResponseBody {
#Element(name = "ns2:requestCPResponse",required = false)
private UsStatesCPResponse cpResponse;
public UsStatesCPResponse getUsStatesCPResponse() {
return cpResponse;
}
public void UsUsStatesCPResponse(UsStatesCPResponse responseReturn) {
this.cpResponse = responseReturn;
}
}
UsStatesCPResponse.clss
#Root(name = "ns2:requestCPResponse", strict = false)
#NamespaceList({
#Namespace( prefix = "ns2", reference = "http://incomingwebchannel.hrz.jpos.org/")})
public class UsStatesCPResponse {
#Element(name = "return",required = false)
private UsStatesResponseReturn responseReturn;
public UsStatesResponseReturn getStatesResponseReturn() {
return responseReturn;
}
public void UsStatesResponseReturn(UsStatesResponseReturn responseReturn) {
this.responseReturn = responseReturn;
}
}
UsStatesResponseReturn.clss
#Root(name = "return", strict = false)
#NamespaceList({
#Namespace( prefix = "xsi:type", reference = "ns2:jiringBillInqOut"),
#Namespace( prefix = "xsi", reference = "http://www.w3.org/2001/XMLSchema-instance")
})
public class UsStatesResponseReturn {
#Element(name = "refNo",required = false)
private String refNo;
#Element(name = "responseCode",required = false)
private String responseCode;
public String getRefNo() {
return refNo;
}
public void setRefNo(String refNo) {
this.refNo = refNo;
}
public String getResponseCode() {
return responseCode;
}
public void setResponseCode(String responseCode) {
this.responseCode = responseCode;
}
}

i solve with tray and error.
Parent class
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Namespace;
import org.simpleframework.xml.Root;
#Root(name = "S:Envelope" ,strict = false)
#Namespace(prefix = "S", reference = "http://schemas.xmlsoap.org/soap/envelope/")
public class BuyResponseEnvelope {
#Element(name = "Body")
private BuyResponseBody body;
public BuyResponseBody getBody() {
return body;
}
public void setBody(BuyResponseBody body) {
this.body = body;
}
}
Body class
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;
#Root(name = "S:Body" ,strict = false)
public class BuyResponseBody {
#Element(name = "requestCPResponse")
private BuyCPResponse cpResponse;
public BuyCPResponse getCpResponse() {
return cpResponse;
}
public void setCpResponse(BuyCPResponse cpResponse) {
this.cpResponse = cpResponse;
}
}
request cp class
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Namespace;
import org.simpleframework.xml.Root;
#Root(name = "ns2:requestCPResponse",strict = false)
#Namespace( prefix = "ns2", reference = "http://incomingwebchannel.hrz.jpos.org/")
public class BuyCPResponse {
#Element(name = "return")
private BuyResponseReturn responseReturn;
public BuyResponseReturn getResponseReturn() {
return responseReturn;
}
public void setResponseReturn(BuyResponseReturn responseReturn) {
this.responseReturn = responseReturn;
}
}
and return class
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Namespace;
import org.simpleframework.xml.NamespaceList;
import org.simpleframework.xml.Root;
#Root(name = "return",strict = false)
#Namespace( prefix = "xsi", reference = "http://www.w3.org/2001/XMLSchema-instance")
public class BuyResponseReturn {
#Element(name = "refNo")
private String refNo;
#Element(name = "responseCode")
private String responseCode;
public String getRefNo() {
return refNo;
}
public void setRefNo(String refNo) {
this.refNo = refNo;
}
public String getResponseCode() {
return responseCode;
}
public void setResponseCode(String responseCode) {
this.responseCode = responseCode;
}
}

Related

Api returns blob variable as null

Already created Rest Api in Spring Boot function which create new order with few variables and also with picture as a Blob and send it to the database.
And i it all works as it should, but right now when I'm trying get this picture as a response from database I'm getting this Blob as a null.
My Controller code is as shown below.
#GetMapping(path = "/getallorders")
public List<OrderAllUsersResponse> getAllOrders() {
List<OrderAllUsersResponse> returnValue = new ArrayList<>();
List<OrderEntity> orders = orderRepostiory.findAllOrders();
ModelMapper modelMapper = new ModelMapper();
for (int i=0; i < orders.size(); i++) {
returnValue.add(modelMapper.map(orders.get(i), OrderAllUsersResponse.class));
}
return returnValue;
}
My Repository code is as shown below.
public interface OrderRepostiory extends JpaRepository<OrderEntity, Long> {
#Query(value = "SELECT * FROM 34671478_opionion.cargo", nativeQuery = true)
List<OrderEntity> findAllOrders();
}
#Entity(name = "cargo")
public class OrderEntity implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
#Column(nullable = false)
private String orderId;
#Column(nullable = false)
private String customer;
#Column(nullable = false)
private String loadingCompanyName;
#Column(nullable = false)
private String loadingCity;
#Column(nullable = false)
private String loadingPostcode;
#Column(nullable = false)
private String dateOfLoading;
#Column(nullable = false)
private String unloadingCompanyName;
#Column(nullable = false)
private String unloadingCity;
#Column(nullable = false)
private String unloadingPostcode;
#Column(nullable = false)
private String dateOfUnloading;
#Column(nullable = false)
private Double nettoPrice;
#Column(nullable = false)
private Double bruttoPrice;
#Column(nullable = false)
private String information;
#Column(nullable = false)
private Boolean paymentStatus = false;
#ManyToOne
#NotFound(action= NotFoundAction.IGNORE)
#JoinColumn(name = "company_id")
private CompanyEntity companyDetails;
#Lob
#Column(name = "photo", columnDefinition="BLOB")
private byte[] data;
public byte[] getData() {
return data;
}
public void setData(byte[] data) {
this.data = data;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getCustomer() {
return customer;
}
public void setCustomer(String customer) {
this.customer = customer;
}
public String getLoadingCompanyName() {
return loadingCompanyName;
}
public void setLoadingCompanyName(String loadingCompanyName) {
this.loadingCompanyName = loadingCompanyName;
}
public String getLoadingCity() {
return loadingCity;
}
public void setLoadingCity(String loadingCity) {
this.loadingCity = loadingCity;
}
public String getLoadingPostcode() {
return loadingPostcode;
}
public void setLoadingPostcode(String loadingPostcode) {
this.loadingPostcode = loadingPostcode;
}
public String getDateOfLoading() {
return dateOfLoading;
}
public void setDateOfLoading(String dateOfLoading) {
this.dateOfLoading = dateOfLoading;
}
public String getUnloadingCompanyName() {
return unloadingCompanyName;
}
public void setUnloadingCompanyName(String unloadingCompanyName) {
this.unloadingCompanyName = unloadingCompanyName;
}
public String getUnloadingCity() {
return unloadingCity;
}
public void setUnloadingCity(String unloadingCity) {
this.unloadingCity = unloadingCity;
}
public String getUnloadingPostcode() {
return unloadingPostcode;
}
public void setUnloadingPostcode(String unloadingPostcode) {
this.unloadingPostcode = unloadingPostcode;
}
public String getDateOfUnloading() {
return dateOfUnloading;
}
public void setDateOfUnloading(String dateOfUnloading) {
this.dateOfUnloading = dateOfUnloading;
}
public Double getNettoPrice() {
return nettoPrice;
}
public void setNettoPrice(Double nettoPrice) {
this.nettoPrice = nettoPrice;
}
public Double getBruttoPrice() {
return bruttoPrice;
}
public void setBruttoPrice(Double bruttoPrice) {
this.bruttoPrice = bruttoPrice;
}
public CompanyEntity getCompanyDetails() {
return companyDetails;
}
public void setCompanyDetails(CompanyEntity companyDetails) {
this.companyDetails = companyDetails;
}
public String getInformation() {
return information;
}
public void setInformation(String information) {
this.information = information;
}
public Boolean getPaymentStatus() {
return paymentStatus;
}
public void setPaymentStatus(Boolean paymentStatus) {
this.paymentStatus = paymentStatus;
}
public String getOrderId() {
return orderId;
}
public void setOrderId(String orderId) {
this.orderId = orderId;
}
}
Below I show you how response result like from Postman.
As u can see the variable 'photo' is as a null. How can i fix it to get it as a for example byte64string
Below is OrderAllUsersResponse class code:
For modelMapper's default mapping mechanism, your source (OrderEntity) and destination (OrderAllUsersResponse) objects should be similar to each other.
#Entity(name = "cargo")
public class OrderEntity implements Serializable {
#Lob
#Column(name = "photo", columnDefinition="BLOB")
private byte[] data;
public byte[] getData() {
return data;
}
public void setData(byte[] data) {
this.data = data;
}
}
and
import com.fasterxml.jackson.annotation.JsonProperty;
public class OrderAllUsersResponse {
#JsonProperty("photo")
private byte[] data;
public byte[] getData() {
return data;
}
public void setData(byte[] data) {
this.data = data;
}
}
If the source field name is different from the destination field name then to define property mappings, you will use ModelMapper's TypeMap.
#Entity(name = "cargo")
public class OrderEntity implements Serializable {
#Lob
#Column(name = "photo", columnDefinition="BLOB")
private byte[] data;
public byte[] getData() {
return data;
}
public void setData(byte[] data) {
this.data = data;
}
}
and
public class OrderAllUsersResponse {
private byte[] photo;
public byte[] getPhoto() {
return photo;
}
public void setPhoto(byte[] photo) {
this.photo = photo;
}
}
TypeMaping
#GetMapping(path = "/getallorders")
public List<OrderAllUsersResponse> getAllOrders() {
List<OrderAllUsersResponse> returnValue = new ArrayList<>();
List<OrderEntity> orders = orderRepostiory.findAllOrders();
ModelMapper modelMapper = new ModelMapper();
TypeMap<OrderEntity, OrderAllUsersResponse> propertyMapper = modelMapper.createTypeMap(OrderEntity.class, OrderAllUsersResponse.class);
for (int i=0; i < orders.size(); i++) {
propertyMapper.addMapping(OrderEntity::getData, OrderAllUsersResponse::setPhoto);
returnValue.add(modelMapper.map(orders.get(i), OrderAllUsersResponse.class));
}
return returnValue;
}

unexpected XML tag. expected: {http://schemas.xmlsoap.org/soap/envelope/}Body but found: {http://schemas.xmlsoap.org/soap/envelope/}Envelope

Am working with SOAP XML I have validate my xml online it's fine, but when send to server am getting error message "unexpected XML tag. expected: {http://schemas.xmlsoap.org/soap/envelope/}Body but found: {http://schemas.xmlsoap.org/soap/envelope/}Envelope", this is the xml am sending
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:pos="http://pos/">
<soapenv:Header>
<soapenv:Body>
<pos:balanceInquiry>
<iccData></iccData>
<pinBlock></pinBlock>
<terminalId></terminalId>
</pos:balanceInquiry>
</soapenv:Body>
</soapenv:Header>
I have removed values in tags everything remained the same.
#Root(name = "soapenv:Envelope")
#NamespaceList({
#Namespace( prefix = "soapenv", reference = "http://schemas.xmlsoap.org/soap/envelope/"),
#Namespace( prefix = "pos", reference = "http://pos/")
})
public class XMLRequestEnvelope {
#Element(name = "soapenv:Header", required = false)
private XMLRequestHeader header;
public XMLRequestHeader getHeader() {
return header;
}
public void setHeader(XMLRequestHeader header) {
this.header = header;
}
}
#Root(name = "soapenv:Header", strict = false)
public class XMLRequestHeader {
#Element(name = "soapenv:Body", required = false)
private XMLRequestBody body;
public XMLRequestBody getBody() {
return body;
}
public void setBody(XMLRequestBody body) {
this.body = body;
}
}
#Root(name = "soapenv:Body", strict = false)
public class XMLRequestBody {
#Element(name = "pos:balanceInquiry",required = false)
private XMLBalanceInquiry xmlBalanceInquiry;
public XMLBalanceInquiry getXmlBalanceInquiry() {
return xmlBalanceInquiry;
}
public void setXmlBalanceInquiry(XMLBalanceInquiry xmlBalanceInquiry) {
this.xmlBalanceInquiry = xmlBalanceInquiry;
}
}
#Root(name = "pos:balanceInquiry", strict = false)
public class XMLBalanceInquiry {
#Element(name = "iccData", required = false)
private String emvData;
#Element(name = "pinBlock", required = false)
private String pinBlock;
#Element(name = "phoneNo", required = false)
private String phoneNo;
#Element(name = "terminalId", required = false)
private String terminalId;
public String getEmvData() {
return emvData;
}
public void setEmvData(String emvData) {
this.emvData = emvData;
}
public String getPinBlock() {
return pinBlock;
}
public void setPinBlock(String pinBlock) {
this.pinBlock = pinBlock;
}
public String getPhoneNo() {
return phoneNo;
}
public void setPhoneNo(String phoneNo) {
this.phoneNo = phoneNo;
}
public String getTerminalId() {
return terminalId;
}
public void setTerminalId(String terminalId) {
this.terminalId = terminalId;
}
}

Specifying root and child nodes with JAXB

Staying within JAXB how would I refactor MyNote so that it conforms to:
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Which is well formed but not valid, to my understanding. Current output:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<MyNotes>
<Note>
<note>XY3Z1RGEO9W79LALCS</note>
<to>LJAY9RNMUGGENGNND9</to>
<from>GOVSHVZ3GJWC864L7X</from>
<heading>EX6LGVE5LGY4A6B9SK</heading>
<body>L95WYQNMEU1MFDRBG4</body>
</Note>
</MyNotes>
which is too flat, rather than nested as the example.
I believe this makes note the root element, with other elements being children nodes to note if I'm using correct terminology.
The MyNote class:
package net.bounceme.dur.jaxb.hello.world;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
#XmlType(propOrder = {"note", "to", "from", "heading", "body"})
#XmlRootElement(name = "note")
public class MyNote {
private String note;
private String to;
private String from;
private String heading;
private String body;
public String getNote() {
return note;
}
#XmlElement(name = "note")
public void setNote(String note) {
this.note = note;
}
public String getTo() {
return to;
}
#XmlElement(name = "to")
public void setTo(String to) {
this.to = to;
}
public String getFrom() {
return from;
}
#XmlElement(name = "from")
public void setFrom(String from) {
this.from = from;
}
public String getHeading() {
return heading;
}
#XmlElement(name = "heading")
public void setHeading(String heading) {
this.heading = heading;
}
public String getBody() {
return body;
}
#XmlElement(name = "body")
public void setBody(String body) {
this.body = body;
}
#Override
public String toString() {
return note + to + from + heading + body;
}
}
The MyNotes class:
package net.bounceme.dur.jaxb.hello.world;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement(name = "MyNotes")
public class MyNotes {
private static final Logger LOG = Logger.getLogger(MyNotes.class.getName());
private List<MyNote> myNotes = new ArrayList<>();
public MyNotes() {
}
public List<MyNote> getMyNotes() {
LOG.info(myNotes.toString());
return myNotes;
}
#XmlElement(name = "Note")
public void setMyNotes(List<MyNote> myNotes) {
LOG.info(myNotes.toString());
this.myNotes = myNotes;
}
public void add(MyNote myNote) {
LOG.info(myNote.toString());
myNotes.add(myNote);
}
#Override
public String toString() {
StringBuffer str = new StringBuffer();
for (MyNote note : this.myNotes) {
str.append(note.toString());
}
return str.toString();
}
}
exercising the MyNote and MyNotes classes:
public MyNotes unmarshallMyNotesFromFile(URI uri) throws Exception {
File file = new File(uri);
JAXBContext jaxbContext = JAXBContext.newInstance(MyNotes.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
MyNotes myNotes = (MyNotes) jaxbUnmarshaller.unmarshal(file);
return myNotes;
}
public void marshallMyNotesAndWriteToFile(MyNotes notes, URI uri) throws Exception {
JAXBContext jaxbContext = JAXBContext.newInstance(MyNotes.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(notes, new File(uri));
jaxbMarshaller.marshal(notes, System.out);
}
I'm looking to grab this xml through the web; first need to match the structure to the example.
You are very close. You need to change how you name your xmlElement for myNotes in MyNotes class. Also MyNote should not have a note field itself (according to your desired xml). Your edited classes would look like this (I also removed the logging statements for my convenience):
#XmlType(propOrder = { "to", "from", "heading", "body"})
#XmlRootElement(name = "note")
public class MyNote {
private String to;
private String from;
private String heading;
private String body;
public String getTo() {
return to;
}
#XmlElement(name = "to")
public void setTo(String to) {
this.to = to;
}
public String getFrom() {
return from;
}
#XmlElement(name = "from")
public void setFrom(String from) {
this.from = from;
}
public String getHeading() {
return heading;
}
#XmlElement(name = "heading")
public void setHeading(String heading) {
this.heading = heading;
}
public String getBody() {
return body;
}
#XmlElement(name = "body")
public void setBody(String body) {
this.body = body;
}
#Override
public String toString() {
return to + from + heading + body;
}
}
and MyNotes:
#XmlRootElement(name = "MyNotes")
public class MyNotes {
private List<MyNote> myNotes = new ArrayList<>();
public MyNotes() {
}
public List<MyNote> getMyNotes() {
return myNotes;
}
#XmlElement(name = "note")
public void setMyNotes(List<MyNote> myNotes) {
this.myNotes = myNotes;
}
public void add(MyNote myNote) {
myNotes.add(myNote);
}
#Override
public String toString() {
StringBuffer str = new StringBuffer();
for (MyNote note : this.myNotes) {
str.append(note.toString());
}
return str.toString();
}
}

How do I reference a JAXB POJO in a mule flow

I have successfully unmarshalled an XML document into a JAXB object but now, I would like to reference the object in the flow and insert the value of it's properties into a database table.
The flow is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="10009" basePath="/ipay/bra" doc:name="HTTP Listener Configuration"/>
<mulexml:jaxb-context name="JAXB_Context" packageNames="com.dhg.api" doc:name="JAXB Context"/>
<flow name="transaction_initiation_testFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/transaction" doc:name="HTTP">
<http:response-builder>
<http:header headerName="Content-Type" value="text/xml"/>
</http:response-builder>
</http:listener>
<mulexml:jaxb-xml-to-object-transformer returnClass="com.dhg.api.PAYMENTS" jaxbContext-ref="JAXB_Context" doc:name="XML to JAXB Object"/>
<logger message="#[payload.transaction.email]" level="INFO" doc:name="Logger"/>
<echo-component doc:name="Echo"/>
</flow>
</mule>
The object is as follows:
package com.dhg.api;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {"transaction"})
#XmlRootElement(name = "PAYMENTS")
public class PAYMENTS {
#XmlElement(name = "TRANSACTION", required = true)
protected PAYMENTS.TRANSACTION transaction;
public PAYMENTS.TRANSACTION getTRANSACTION() {
return transaction;
}
public void setTRANSACTION(PAYMENTS.TRANSACTION value) {
this.transaction = value;
}
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"entity",
"useraddress1",
"useraddress2",
"useraddress3",
"usercountry",
"userparish",
"totalamount",
"payer",
"status",
"ipaynumber",
"email"
})
public static class TRANSACTION {
#XmlElement(name = "ENTITY", required = true)
protected PAYMENTS.TRANSACTION.ENTITY entity;
#XmlElement(name = "USERADDRESS1", required = true)
protected String useraddress1;
#XmlElement(name = "USERADDRESS2", required = true)
protected String useraddress2;
#XmlElement(name = "USERADDRESS3", required = true)
protected String useraddress3;
#XmlElement(name = "USERCOUNTRY", required = true)
protected String usercountry;
#XmlElement(name = "USERPARISH", required = true)
protected String userparish;
#XmlElement(name = "TOTALAMOUNT")
protected float totalamount;
#XmlElement(name = "PAYER", required = true)
protected String payer;
#XmlElement(name = "STATUS", required = true)
protected String status;
#XmlElement(name = "IPAYNUMBER")
protected int ipaynumber;
#XmlElement(name = "EMAIL", required = true)
protected String email;
#XmlAttribute(name = "txdate")
protected String txdate;
#XmlAttribute(name = "txno")
protected String txno;
public PAYMENTS.TRANSACTION.ENTITY getENTITY() {
return entity;
}
public void setENTITY(PAYMENTS.TRANSACTION.ENTITY value) {
this.entity = value;
}
public String getUSERADDRESS1() {
return useraddress1;
}
public void setUSERADDRESS1(String value) {
this.useraddress1 = value;
}
public String getUSERADDRESS2() {
return useraddress2;
}
public void setUSERADDRESS2(String value) {
this.useraddress2 = value;
}
public String getUSERADDRESS3() {
return useraddress3;
}
public void setUSERADDRESS3(String value) {
this.useraddress3 = value;
}
public String getUSERCOUNTRY() {
return usercountry;
}
public void setUSERCOUNTRY(String value) {
this.usercountry = value;
}
public String getUSERPARISH() {
return userparish;
}
public void setUSERPARISH(String value) {
this.userparish = value;
}
public float getTOTALAMOUNT() {
return totalamount;
}
public void setTOTALAMOUNT(float value) {
this.totalamount = value;
}
public String getPAYER() {
return payer;
}
public void setPAYER(String value) {
this.payer = value;
}
public String getSTATUS() {
return status;
}
public void setSTATUS(String value) {
this.status = value;
}
public int getIPAYNUMBER() {
return ipaynumber;
}
public void setIPAYNUMBER(int value) {
this.ipaynumber = value;
}
public String getEMAIL() {
return email;
}
public void setEMAIL(String value) {
this.email = value;
}
public String getTxdate() {
return txdate;
}
public void setTxdate(String value) {
this.txdate = value;
}
public String getTxno() {
return txno;
}
public void setTxno(String value) {
this.txno = value;
}
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"account"
})
public static class ENTITY {
#XmlElement(name = "ACCOUNT", required = true)
protected PAYMENTS.TRANSACTION.ENTITY.ACCOUNT account;
#XmlAttribute(name = "biller")
protected String biller;
public PAYMENTS.TRANSACTION.ENTITY.ACCOUNT getACCOUNT() {
return account;
}
public void setACCOUNT(PAYMENTS.TRANSACTION.ENTITY.ACCOUNT value) {
this.account = value;
}
public String getBiller() {
return biller;
}
public void setBiller(String value) {
this.biller = value;
}
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"details"
})
public static class ACCOUNT {
#XmlElement(name = "DETAILS", required = true)
protected PAYMENTS.TRANSACTION.ENTITY.ACCOUNT.DETAILS details;
#XmlAttribute(name = "bpnumber")
protected Integer bpnumber;
public PAYMENTS.TRANSACTION.ENTITY.ACCOUNT.DETAILS getDETAILS(){
return details;
}
public void setDETAILS(PAYMENTS.TRANSACTION.ENTITY.ACCOUNT.DETAILS value) {
this.details = value;
}
public Integer getBpnumber() {
return bpnumber;
}
public void setBpnumber(Integer value) {
this.bpnumber = value;
}
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"dockey"
})
public static class DETAILS {
#XmlElement(name = "DOCKEY")
protected List<PAYMENTS.TRANSACTION.ENTITY.ACCOUNT.DETAILS.DOCKEY> dockey;
public List<PAYMENTS.TRANSACTION.ENTITY.ACCOUNT.DETAILS.DOCKEY> getDOCKEY() {
if (dockey == null) {
dockey = new ArrayList<PAYMENTS.TRANSACTION.ENTITY.ACCOUNT.DETAILS.DOCKEY>();
}
return this.dockey;
}
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"value"
})
public static class DOCKEY {
#XmlValue
protected String value;
#XmlAttribute(name = "payment")
protected Float payment;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public Float getPayment() {
return payment;
}
public void setPayment(Float value) {
this.payment = value;
}
}
}
}
}
}
}
After unmarshalling, the object is instantiated as com.dhg.api.PAYMENTS#some_random_string, which makes it difficult to reference. So my question is simply, how can I refer to this object and be able to access the values for use elsewhere in the flow.
Thanks for your help.
Your setter/getter is not compliant with property names in :
public PAYMENTS.TRANSACTION getTRANSACTION() {
return transaction;
}
public void setTRANSACTION(PAYMENTS.TRANSACTION value) {
this.transaction = value;
}
So in <logger message="#[payload.transaction.email]" level="INFO" doc:name="Logger"/> the transaction part is null.
The correct getter name is getTransaction and is the same for setter. Change them please

Android simpleXML Element '[element Name]' is already used

I have tried to use other problems brought up on this website, but none of them relate to what I am doing.
I am trying to 'deserialize' soap xml using simpleXML for an Android application. I'm getting closer and closer to getting this, but I have hit a brick wall here.
When I run my code, I get the following error:
org.simpleframework.xml.core.PersistenceException: Element 'serviceOrderCT' is already used with #org.simpleframework.xml.Element(name=, type=void, data=false, required=true) on field 'serviceOrderCT' private serviceOrderCT GetServiceOrdersResult.serviceOrderCT at line 26
So, the problem seems to be with the 'GetServiceOrdersResult.java' class (code below), but I can't put my finger on what it is.
I have been at this for hours and have gotten nowhere.
Help to get passed this problem would be appreciated.
Thanks.
[EDIT: Here's the XML File]
<GetServiceOrdersResponse xmlns="http://tempuri.org/">
<GetServiceOrdersResult xmlns:a="http://schemas.datacontract.org/2004/07/MobileWebService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:serviceOrderCT>
<a:_bill_to_Customer_No_>xxxxx</a:_bill_to_Customer_No_>
<a:_bill_to_Name>xxxxxxx</a:_bill_to_Name>
<a:_customer_No_ i:nil="true" />
<a:_description />
<a:_fix_By_Date>xxxxxxxxxxxxx</a:_fix_By_Date>
<a:_fix_By_Time />
<a:_fixed_Date>xxxxxxxxxxxx</a:_fixed_Date>
<a:_fixed_Time>xxxxxxxxxxxxxx</a:_fixed_Time>
<a:_name>xxxxxxxxxxxxxxx</a:_name>
<a:_no_>xxxxxxxxxxxxxxxxxxx</a:_no_>
<a:_order_Date>xxxxxxxxxxxxxxx</a:_order_Date>
<a:_order_Time>xxxxxxxxxxxxx</a:_order_Time>
<a:_responded_Date>xxxxxxxxxxxxxxxxxx</a:_responded_Date>
<a:_responded_Time />
<a:_response_Date>xxxxxxxxxxxxxxxxxx</a:_response_Date>
<a:_response_Time>xxxxxxxxxxxxxxxxxxxx</a:_response_Time>
<a:_transaction_Status>xxxxxxxxxxxxxxx</a:_transaction_Status>
<a:_your_Reference />
</a:serviceOrderCT>
<a:serviceOrderCT>
a:_bill_to_Customer_No_>xxxxx</a:_bill_to_Customer_No_>
<a:_bill_to_Name>xxxxxxx</a:_bill_to_Name>
<a:_customer_No_ i:nil="true" />
<a:_description />
<a:_fix_By_Date>xxxxxxxxxxxxx</a:_fix_By_Date>
<a:_fix_By_Time />
<a:_fixed_Date>xxxxxxxxxxxx</a:_fixed_Date>
<a:_fixed_Time>xxxxxxxxxxxxxx</a:_fixed_Time>
<a:_name>xxxxxxxxxxxxxxx</a:_name>
<a:_no_>xxxxxxxxxxxxxxxxxxx</a:_no_>
<a:_order_Date>xxxxxxxxxxxxxxx</a:_order_Date>
<a:_order_Time>xxxxxxxxxxxxx</a:_order_Time>
<a:_responded_Date>xxxxxxxxxxxxxxxxxx</a:_responded_Date>
<a:_responded_Time />
<a:_response_Date>xxxxxxxxxxxxxxxxxx</a:_response_Date>
<a:_response_Time>xxxxxxxxxxxxxxxxxxxx</a:_response_Time>
<a:_transaction_Status>xxxxxxxxxxxxxxx</a:_transaction_Status>
<a:_your_Reference />
</a:serviceOrderCT>
</GetServiceOrdersResult>
</GetServiceOrdersResponse>
Envelope.java
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;
#Root
public class Envelope {
#Element(name = "Body")
private Body body;
public Body getBody() {
return body;
}
}
Body.java
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Path;
import org.simpleframework.xml.Root;
import java.util.List;
public class Body {
#Element(name = "GetServiceOrdersResponse")
private GetServiceOrdersResponse getServiceOrdersResponse;
public GetServiceOrdersResponse getServiceOrdersResponse() {
return getServiceOrdersResponse;
}
}
GetServiceOrdersResponse.java
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Path;
public class GetServiceOrdersResponse {
#Element(name = "GetServiceOrdersResult")
private GetServiceOrdersResult getServiceOrdersResult;
public GetServiceOrdersResult getGetServiceOrdersResult() {
return getServiceOrdersResult;
}
}
GetServiceOrdersResult.java
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Path;
import org.simpleframework.xml.Root;
import java.util.List;
public class GetServiceOrdersResult {
#Element
private serviceOrderCT serviceOrderCT;
public serviceOrderCT getServiceOrderCT() {
return serviceOrderCT;
}
}
serviceOrderCT
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Namespace;
import org.simpleframework.xml.Root;
public class serviceOrderCT {
#Element(name = "_bill_to_Customer_No_", required = false)
private String billToCustomerNo;
#Element(name = "_bill_to_Name", required = false)
private String billToName;
#Element(name = "_customer_No_", required = false)
private String customerNo;
#Element(name = "_description", required = false)
private String description;
#Element(name = "_fix_By_Date", required = false)
private String fixByDate;
#Element(name = "_fix_By_Time", required = false)
private String fixByTime;
#Element(name = "_fixed_Date", required = false)
private String fixedDate;
#Element(name = "_fixed_Time", required = false)
private String fixedTime;
#Element(name = "_name", required = false)
private String name;
#Element(name = "_no_", required = false)
private String no;
#Element(name = "_order_Date", required = false)
private String orderDate;
#Element(name = "_order_Time", required = false)
private String orderTime;
#Element(name = "_responded_Date", required = false)
private String respondedDate;
#Element(name = "_responded_Time", required = false)
private String respondedTime;
#Element(name = "_response_Date", required = false)
private String responseDate;
#Element(name = "_response_Time", required = false)
private String responseTime;
#Element(name = "_transaction_Status", required = false)
private String transactionStatus;
#Element(name = "_your_Reference", required = false)
private String yourReference;
public serviceOrderCT() {
}
public String getBillToCustomerNo() {
return billToCustomerNo;
}
public void setBillToCustomerNo(String billToCustomerNo) {
this.billToCustomerNo = billToCustomerNo;
}
public String getBillToName() {
return billToName;
}
public void setBillToName(String billToName) {
this.billToName = billToName;
}
public String getCustomerNo() {
return customerNo;
}
public void setCustomerNo(String customerNo) {
this.customerNo = customerNo;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getFixByDate() {
return fixByDate;
}
public void setFixByDate(String fixByDate) {
this.fixByDate = fixByDate;
}
public String getFixByTime() {
return fixByTime;
}
public void setFixByTime(String fixByTime) {
this.fixByTime = fixByTime;
}
public String getFixedDate() {
return fixedDate;
}
public void setFixedDate(String fixedDate) {
this.fixedDate = fixedDate;
}
public String getFixedTime() {
return fixedTime;
}
public void setFixedTime(String fixedTime) {
this.fixedTime = fixedTime;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public String getOrderDate() {
return orderDate;
}
public void setOrderDate(String orderDate) {
this.orderDate = orderDate;
}
public String getOrderTime() {
return orderTime;
}
public void setOrderTime(String orderTime) {
this.orderTime = orderTime;
}
public String getRespondedDate() {
return respondedDate;
}
public void setRespondedDate(String respondedDate) {
this.respondedDate = respondedDate;
}
public String getRespondedTime() {
return respondedTime;
}
public void setRespondedTime(String respondedTime) {
this.respondedTime = respondedTime;
}
public String getResponseDate() {
return responseDate;
}
public void setResponseDate(String responseDate) {
this.responseDate = responseDate;
}
public String getResponseTime() {
return responseTime;
}
public void setResponseTime(String responseTime) {
this.responseTime = responseTime;
}
public String getTransactionStatus() {
return transactionStatus;
}
public void setTransactionStatus(String transactionStatus) {
this.transactionStatus = transactionStatus;
}
public String getYourReference() {
return yourReference;
}
public void setYourReference(String yourReference) {
this.yourReference = yourReference;
}
}
Main.java
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
import java.io.File;
public class Main {
public static void main(String[] args) {
try {
Serializer serializer = new Persister();
File result = new File("C:\\Users\\xxxxxxxx\\Documents\\file.xml");
Envelope example = serializer.read(Envelope.class, result);
System.out.println(example.getBody().getServiceOrdersResponse().getGetServiceOrdersResult().getServiceOrderCT().getBillToCustomerNo());
} catch (Exception e) {
e.printStackTrace();
}
}
}
So, I solve my problem, a day after asking for help, on my own Yet again.
You have to implement an ElementList, if you want to get all three serviceOrderCTs. It was only picking up one.
If I removed the other two, I would get something back.
Advice for anyone who reads this, stick with the official documentation. It will help you a lot. http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php#list

Categories