I need help to convert the soap request and response to Java Object. So that I can marshal and un-marshal it.
Note: I am new to soap services and tried built in tool but not able to convert into Java Object.
Request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sen="http://schemas.xmlsoap.org/sendSmsMSDP" xmlns:met="http://schemas.xmlsoap.org/soap/MetaInfoReq">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>ravi</wsse:Username>
<wsse:Password>more</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<sen:SendSmsMSDPRequest>
<sen:MetaInfo>
<met:ConsumerReqInfo>
<met:circleId>1</met:circleId>
<met:serviceName>sendSmsMSDP_SV</met:serviceName>
<met:channelName>CG</met:channelName>
<met:segment>PREPAID</met:segment>
<met:key>345</met:key>
<met:version>1.0</met:version>
</met:ConsumerReqInfo>
</sen:MetaInfo>
<sen:SRVsendSmsMSDPReq>
<sen:requestType>SMSSubmitReq</sen:requestType>
<sen:userName>usernME</sen:userName>
<sen:password>PASSWORD</sen:password>
<sen:mobileNumber>XXXXXXXXXX</sen:mobileNumber>
<sen:message>hello</sen:message>
<sen:originAddress>0987</sen:originAddress>
<sen:type>0</sen:type>
</sen:SRVsendSmsMSDPReq>
</sen:SendSmsMSDPRequest>
</soapenv:Body>
</soapenv:Envelope>
Response:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sen="http://schemas.xmlsoap.org/soap/envelope/" xmlns:met="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<sen:SendSmsMSDPResponse>
<sen:MetaInfo>
<met:ConsumerReqInfo>
<met:circleId>123</met:circleId>
<met:serviceName>sendSmsMSDP_SV</met:serviceName>
<met:channelName>cc</met:channelName>
<met:segment>pre</met:segment>
<met:key>345</met:key>
<met:version>1.0</met:version>
</met:ConsumerReqInfo>
<met:StatusInfo>
<met:errorCode>WWI00000I</met:errorCode>
<met:errorStatus>0</met:errorStatus>
<met:errorDesc>The Request has been processed Successfully</met:errorDesc>
<met:errorCategory>SUCCESS</met:errorCategory>
</met:StatusInfo>
</sen:MetaInfo>
</sen:SendSmsMSDPResponse>
</soapenv:Body>
</soapenv:Envelope>
Also, if you know some resources for soap services that will be really helpful.
Thanks for your time.
**For Response **
Here is my classes but its failing.
#XmlRootElement(name = "SendSmsMSDPResponse")
#XmlAccessorType(XmlAccessType.FIELD)
public class SendSmsMSDPResponse {
#XmlElement(name = "MetaInfo")
private MetaInfo MetaInfo;
public MetaInfo getMetaInfo() {
return MetaInfo;
}
public void setMetaInfo(MetaInfo metaInfo) {
MetaInfo = metaInfo;
}
}
#XmlRootElement(name = "MetaInfo")
#XmlAccessorType(XmlAccessType.FIELD)
public class MetaInfo {
#XmlElement(name = "ConsumerReqInfo")
private ConsumerReqInfo ConsumerReqInfo;
#XmlElement(name = "StatusInfo")
private StatusInfo StatusInfo;
public ConsumerReqInfo getConsumerReqInfo() {
return ConsumerReqInfo;
}
public void setConsumerReqInfo(ConsumerReqInfo consumerReqInfo) {
ConsumerReqInfo = consumerReqInfo;
}
public StatusInfo getStatusInfo() {
return StatusInfo;
}
public void setStatusInfo(StatusInfo statusInfo) {
StatusInfo = statusInfo;
}
}
#XmlRootElement(name = "ConsumerReqInfo")
#XmlAccessorType(XmlAccessType.FIELD)
public class ConsumerReqInfo {
#XmlElement(name = "circleId")
private String circleId;
#XmlElement(name = "serviceName")
private String serviceName;
#XmlElement(name = "channelName")
private String channelName;
#XmlElement(name = "segment")
private String segment;
#XmlElement(name = "key")
private String key;
#XmlElement(name = "version")
private String version;
//setters and getters
}
#XmlRootElement(name = "StatusInfo")
#XmlAccessorType(XmlAccessType.FIELD)
public class StatusInfo {
#XmlElement(name = "errorCode")
private String errorCode;
#XmlElement(name = "errorStatus")
private String errorStatus;
#XmlElement(name = "errorDesc")
private String errorDesc;
#XmlElement(name = "errorCategory")
private String errorCategory;
// setters and getters
}
Related
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:cs=\"urn:CardServices\" xmlns:ebppif1=\"urn:PaymentServer\" xmlns:el=\"urn:ExtListsServices\" xmlns:iiacs=\"urn:IIACardServices\" xmlns:lm=\"urn:Limits\">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring></faultstring>
<detail>
<ebppif1:PaymentServerException>
<provider>RSW</provider>
<error>129</error>
<description>201433</description>
<screen>RSW129</screen>
</ebppif1:PaymentServerException>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
How to create java object using #XmlRootElement,#XmlElement.
#XmlAccessorType(XmlAccessType.FIELD)
#XmlRootElement(name = "Fault", namespace = "http://schemas.xmlsoap.org/soap/envelope/")
#Data
public class FaultDto {
#XmlElement(name = "faultcode")
private String faultCode;
#XmlElement(name = "detail")
private DetailDto detail;
}
#XmlRootElement(name = "detail")
#XmlAccessorType(XmlAccessType.FIELD)
public class DetailDto {
#XmlElement(name = "PaymentServerException")
private PaymentExcepDto excepDto;
}
#XmlRootElement(name = "PaymentServerException")
#XmlAccessorType(XmlAccessType.FIELD)
public class PaymentExcepDto {
#XmlElement(name = "provider")
protected String provider;
#XmlElement(name = "error")
protected String error;
//others
}
I am getting this result : FaultDto(faultCode=SOAP-ENV:Client, detail=DetailDto(excepDto=null))
How to catch PaymentServerException ?
I have this soap response below and I need to parse it to a java object ...But all the fields are returning null when I print it. Below the classes that I am using to interpret the response.
I have been trying to use jaxb to unmarshall the content but none of my tries went right.
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns2:consultarPosicaoCotistaOnOfflineFundoResponse>
<ns2:listCotistaFundo>
<ns2:cotistaFundo>
<ns2:cdFundo>014588</ns2:cdFundo>
<ns2:nmCliente>BRADESCO FIC FIM GAVEA MACRO</ns2:nmCliente>
<ns2:dtPosicao>2021-02-18</ns2:dtPosicao>
<ns2:vlCota>1.3121393</ns2:vlCota>
<ns2:qtdCotas>43650.7211055</ns2:qtdCotas>
<ns2:vlCorrigido>57275.83</ns2:vlCorrigido>
<ns2:vlIr>221.1</ns2:vlIr>
<ns2:vlIof>0</ns2:vlIof>
<ns2:vlLiquidoResg>57054.73</ns2:vlLiquidoResg>
<ns2:vlContaCorrente>57054.73</ns2:vlContaCorrente>
<ns2:vlContaInvestimento>57054.73</ns2:vlContaInvestimento>
<ns2:noCnpjFundo>28428211000149</ns2:noCnpjFundo>
<ns2:icAfPosicao>F</ns2:icAfPosicao>
<ns2:vlAplicacao>49069.11</ns2:vlAplicacao>
<ns2:qtCotasBloqueadas>0</ns2:qtCotasBloqueadas>
<ns2:vlBrutoBloqueado>0</ns2:vlBrutoBloqueado>
<ns2:vlLiquidoBloqueado>0</ns2:vlLiquidoBloqueado>
<ns2:vlAplicacaoNaoCotizada>0</ns2:vlAplicacaoNaoCotizada>
<ns2:vlResgateNaoCotizado>0</ns2:vlResgateNaoCotizado>
</ns2:cotistaFundo>
</ns2:listCotistaFundo>
<ns3:responseMessages>
<ns3:message>
<ns3:code>EJCOT-0000</ns3:code>
<ns3:desc>Operação Concluída</ns3:desc>
</ns3:message>
</ns3:responseMessages>
</ns2:consultarPosicaoCotistaOnOfflineFundoResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Unmarshaller unmarshaller = JAXBContext.newInstance(ConsultarPosicaoCotistaOnOfflineFundoResponse.class).createUnmarshaller();
response = (ConsultarPosicaoCotistaOnOfflineFundoResponse) unmarshaller.unmarshal(soapMessage.getSOAPBody().extractContentAsDocument());
#XmlAccessorType(XmlAccessType.FIELD)
#XmlRootElement(name = "consultarPosicaoCotistaOnOfflineFundoResponse",
namespace = "http://totvs.cot.webservices")
public class ConsultarPosicaoCotistaOnOfflineFundoResponse implements Serializable {
private ListCotistaFundo[] listCotistaFundo;
public ListCotistaFundo[] getCotistaFundo() {
return listCotistaFundo;
}
#XmlElement(name ="listCotistaFundo",
namespace = "http://totvs.cot.webservices")
public void setCotistaFundos(ListCotistaFundo[] listCotistaFundo) {
this.listCotistaFundo = listCotistaFundo;
}
}
#XmlAccessorType(XmlAccessType.FIELD)
public class ListCotistaFundo {
#XmlElement(name = "cdFundo")
private String cdFundo;
#XmlElement(name = "nmCliente")
private String nmCliente;
#XmlElement(name = "dtPosicao")
private Date dtPosicao;
#XmlElement(name = "vlCota")
private BigDecimal vlCota;
#XmlElement(name = "qtdCotas")
private BigDecimal qtdCotas;
#XmlElement(name = "vlCorrigido")
private BigDecimal vlCorrigido;
#XmlElement(name = "vlIr")
private BigDecimal vlIr;
#XmlElement(name = "vlIof")
private BigDecimal vlIof;
#XmlElement(name = "vlLiquidoResg")
private BigDecimal vlLiquidoResg;
#XmlElement(name = "vlContaCorrente")
private BigDecimal vlContaCorrente;
#XmlElement(name = "vlContaInvestimento")
private BigDecimal vlContaInvestimento;
#XmlElement(name = "noCnpjFundo")
private double noCnpjFundo;
#XmlElement(name = "icAfPosicao")
private String icAfPosicao;
#XmlElement(name = "vlAplicacao")
private BigDecimal vlAplicacao;
#XmlElement(name = "qtCotasBloqueadas")
private BigDecimal qtCotasBloqueadas;
#XmlElement(name = "vlBrutoBloqueado")
private BigDecimal vlBrutoBloqueado;
#XmlElement(name = "vlLiquidoBloqueado")
private BigDecimal vlLiquidoBloqueado;
#XmlElement(name = "vlAplicacaoNaoCotizada")
private BigDecimal vlAplicacaoNaoCotizada;
#XmlElement(name = "vlResgateNaoCotizado")
private BigDecimal vlResgateNaoCotizado;
Getters and Setters ...
Does anyone have a tip in how to convert the response in Java object?
It could be an issue with namespace since I dont see namespaces declared in the XML. You could try setting the namespace as empty in both #XmlRootElement and #XmlElement as follows :
#XmlRootElement(name = "consultarPosicaoCotistaOnOfflineFundoResponse",
namespace = "")
#XmlElement(name ="listCotistaFundo", namespace = "")
I work with a SOAP web service. I want to recover the list productOrder from a java. My problem is that the list productOrder recovered from the java class is zero.
I dont't know how to recover this list from the java.
Below I explain my classes:
This is the request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="http://uciext.ws.hw3/wsdl">
<soapenv:Header/>
<soapenv:Body>
<wsdl:processOrder>
<!--Optional:-->
<arg0>
<vendorCode>330029</vendorCode>
<vendorName>My Shop</vendorName>
<orderNumber>1000339</orderNumber>
<!--1 or more repetitions:-->
<wsdl:productOrder>
<!--Optional:-->
<productSku>111</productSku>
<!--Optional:-->
<productName>Kindle Fire</productName>
<!--Optional:-->
<orderQuantity>5</orderQuantity>
</wsdl:productOrder>
</arg0>
</wsdl:processOrder>
</soapenv:Body>
</soapenv:Envelope>
I have the Order.java to parse this xml
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"vendorCode",
"vendorName",
"orderNumber",
"productOrder"
})
#XmlRootElement(name = "order")
public class Order {
#XmlElement(required = true)
protected String vendorCode;
#XmlElement(required = true)
protected String vendorName;
#XmlElement(required = true)
protected String orderNumber;
#XmlElement(required = true)
protected List<ProductOrder> productOrder;
public String getVendorCode() {
return vendorCode;
}
public void setVendorCode(String value) {
this.vendorCode = value;
}
public String getVendorName() {
return vendorName;
}
public void setVendorName(String value) {
this.vendorName = value;
}
public String getOrderNumber() {
return orderNumber;
}
public void setOrderNumber(String value) {
this.orderNumber = value;
}
public List<ProductOrder> getProductOrder() {
if (productOrder == null) {
productOrder = new ArrayList<ProductOrder>();
}
return this.productOrder;
}
}
I have a method processOrder in a interface and their implementation. This
is the interface
#WebService(targetNamespace = "http://uciext.ws.hw3/wsdl")
public interface OrderServiceWS {
#WebMethod
OrderConfirm processOrder(#WebParam(name="arg0", mode=Mode.IN) Order order) throws Exception;
}
processOrder is in the class
#XmlRootElement(name = "processOrder", namespace = "http://uciext.ws.hw3/wsdl")
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "processOrder", namespace = "http://uciext.ws.hw3/wsdl")
public class ProcessOrder {
#XmlElement(name = "arg0", namespace = "")
private com.uciext.ws.hw3.service.model.order.Order arg0;
public com.uciext.ws.hw3.service.model.order.Order getArg0() {
return this.arg0;
}
public void setArg0(com.uciext.ws.hw3.service.model.order.Order arg0) {
this.arg0 = arg0;
}
}
This is the interface implementation where is called the method processOrder.
#WebService(
portName = "OrderPort",
serviceName = "OrderService",
targetNamespace = "http://uciext.ws.hw3/wsdl",
endpointInterface = "com.uciext.ws.hw3.service.OrderServiceWS")
public class OrderServiceWSImpl implements OrderServiceWS {
private InventoryManagerImpl manager = new InventoryManagerImpl();
#Override
public OrderConfirm processOrder(Order order) throws Exception {
Util.log("SOAP processOrder request [ order=" + order);
Util.log("OrderServiceWS start processOrder");
OrderDAO orderDAO = new OrderDAO();
List<ProductOrder> productOrderList = new ArrayList<ProductOrder>();
List<ProductOrderDAO> productOrderDAOList = new ArrayList<ProductOrderDAO>();
ProductOrderDAO productOrderDAO1 = null;
ProductDAO productDAO = null;
OrderConfirm orderConfirm = null;
ProductOrder productOrder = null;
ProductConfirm productConfirm = null;
List<ProductConfirm> productConfirmList = new ArrayList<ProductConfirm>();
Double totalPrice = 0.0;
Util.log("OrderServiceWS start processOrder vendorCode "+order.getVendorCode());
orderDAO.setVendorCode(order.getVendorCode());
orderDAO.setVendorName(order.getVendorName());
orderDAO.setOrderId(Long.parseLong(order.getOrderNumber()));
Util.log("OrderServiceWS processOrder before productOrderList ");
productOrderList = order.getProductOrder();
Util.log("OrderServiceWS processOrder before productOrderList size "+productOrderList.size());
The value of vendorCode is right but productOrderList.size() is cero
I am sending a request to a webservice but it seems the request is invalid. I am sending a similar request using SoapUI and the webservice accepts it. I need to change my request to what SoapUI sends. How can I add namespaces to my request? WSDL is here.
I visited following pages but could not find a solution yet. 1,2,3
Code
SearchFlights
#XmlRootElement(name = "SearchFlights")
#XmlAccessorType(XmlAccessType.FIELD)
public class SearchFlights {
#XmlElement(name = "SoapMessage")
private SoapMessage soapMessage;
getter and setter
SoapMessage
#XmlRootElement(name = "SoapMessage")
#XmlAccessorType(XmlAccessType.FIELD)
public class WegoloSoapMessage {
#XmlElement(name = "Username")
private String username;
#XmlElement(name = "Password")
private String password;
#XmlElement(name = "LanguageCode")
private String languageCode;
#XmlElement(name = "Request")
private Request request;
getters and setters
Request
#XmlRootElement(name = "Request")
#XmlAccessorType(XmlAccessType.FIELD)
public class Request {
#XmlElement(name = "Departure")
private String departure;
#XmlElement(name = "Destination")
private String destination;
#XmlElement(name = "DepartureDate")
private String departureDate;
#XmlElement(name = "ReturnDate")
private String returnDate;
#XmlElement(name = "NumADT")
private int numADT;
#XmlElement(name = "NumINF")
private int numInf;
#XmlElement(name = "NumCHD")
private int numCHD;
#XmlElement(name = "CurrencyCode")
private String currencyCode;
#XmlElement(name = "WaitForResult")
private boolean waitForResult;
#XmlElement(name = "NearByDepartures")
private boolean nearByDepartures;
#XmlElement(name = "NearByDestinations")
private boolean nearByDestinations;
#XmlElement(name = "RROnly")
private boolean rronly;
#XmlElement(name = "MetaSearch")
private boolean metaSearch;
getters and setters
jaxb.index
SearchFlights
Flight
Flights
Leg
Legs
Outbound
Request
Response
WegoloSoapMessage
Code to send request
try {
SaajSoapMessageFactory soapMsgFac = new SaajSoapMessageFactory(
MessageFactory.newInstance());
soapMsgFac.afterPropertiesSet();
WebServiceTemplate webServiceTemplate = new WebServiceTemplate(
soapMsgFac);
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("com.myprojet.flights.wegolo");
marshaller.afterPropertiesSet();
webServiceTemplate.setMarshaller(marshaller);
webServiceTemplate.setUnmarshaller(marshaller);
webServiceTemplate.afterPropertiesSet();
Response response = (Response) webServiceTemplate
.marshalSendAndReceive(
"http://www5v80.elsyarres.net/service.asmx",
searchFlights,
new WebServiceMessageCallback() {
public void doWithMessage(WebServiceMessage message)
{
((SoapMessage)message).setSoapAction("ElsyArres.API/SearchFlights");
}
}
);
Response msg = (Response) response;
System.err.println("Wegolo >>>"
+ msg.getFlights().getFlight().size());
} catch (Exception s) {
s.printStackTrace();
}
}
My Request
SoapUI request
In your request there is no namesapce before elements like in request from SoapUI.
For example your element:
<SearchFlights>
SoupUI element:
<els:SearchFlights>
You should add namespace xmlns:els="ElsyArres.API" and prefix before all elements using code form here or here or here.
In SoapUI I've got this exception
<faultstring>Unmarshalling Error: unexpected element (uri:"http://ws.soap.rd.pl", local:"User"). Expected elements are <{}User></faultstring>
I really do not know wy I've got this issue. I've tried trip gave in Stack but still cant find the answer. #XmlRootElement is added so I'm really confused.
request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.soap.rd.pl/" xmlns:ws1="http://ws.soap.rd.pl">
<soapenv:Header/>
<soapenv:Body>
<ws:updateUser>
<!--Optional:-->
<ws1:User>
<ID>?</ID>
<!--Optional:-->
<Imie>?</Imie>
<!--Optional:-->
<Nazwisko>?</Nazwisko>
<!--Optional:-->
<ws1:Adres>
<!--Optional:-->
<id>?</id>
<!--Optional:-->
<Ulica>?</Ulica>
<!--Optional:-->
<Miasto>?</Miasto>
</ws1:Adres>
</ws1:User>
</ws:updateUser>
</soapenv:Body>
</soapenv:Envelope>
my dto:
#XmlRootElement(name = "Adres", namespace = "http://ws.soap.rd.pl")
#XmlAccessorType(XmlAccessType.FIELD)
public class AddressDto {
#XmlElement(name = "id", required = false)
public Long id;
#XmlElement(name = "Ulica", required = false)
public String street;
#XmlElement(name = "Miasto", required = false)
public String city;
#Override
public String toString() {
return "AddressDto [street=" + street + ", city=" + city + "]";
}
}
and the second one:
#XmlRootElement(name = "User", namespace = "http://ws.soap.rd.pl")
#XmlAccessorType(XmlAccessType.FIELD)
public class UserDto {
#XmlElement(name = "ID")
public long id;
#XmlElement(name = "Imie", required = false)
public String firstName;
#XmlElement(name = "Nazwisko", required = false)
public String lastName;
#XmlElement(name = "Adres", required = false)
public AddressDto addressDto;
#Override
public String toString() {
return "UserDto [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", addressDto=" + addressDto + "]";
}
}
if you need my webService definition:
#WebService(endpointInterface = "userService", serviceName = "userService", name = "userServive")
public interface UserService {
#WebMethod
public void updateUser(#WebParam(name = "User") UserDto user);
}
Try adding the targetNamespace to your #WebParam:
#WebMethod
public void updateUser(
#WebParam(name = "User", targetNamespace = "http://ws.soap.rd.pl")
UserDto user);