My code is supposed to parse a SOAP response and populate the dropdown list. When I manually add the xml code it works but when I try to parse the SOAP response it runs into following error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at ex1_02_starter/dropDownList_creationCompleteHandler()[C:\Users\jack\Adobe Flash Builder 4.5\Workspace\Starter 1_02\src\ex1_02_starter.mxml:26]
at ex1_02_starter/___ex1_02_starter_Operation1_result()[C:\Users\jack\Adobe Flash Builder 4.5\Workspace\Starter 1_02\src\ex1_02_starter.mxml:41]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.rpc::AbstractOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\AbstractOperation.as:249]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:318]
at mx.rpc::Responder/result()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\Responder.as:56]
at mx.rpc::AsyncRequest/acknowledge()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:84]
at DirectHTTPMessageResponder/completeHandler()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:451]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
The SOAP Response that I am receiving
<?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>
<mycustomersResponse xmlns="http://Services.com">
<mycustomersReturn>
<age>28</age>
<name>Alex</name>
</mycustomersReturn>
<mycustomersReturn>
<age>29</age>
<name>Jack</name>
</mycustomersReturn>
<mycustomersReturn>
<age>30</age>
<name>Johny</name>
</mycustomersReturn>
</mycustomersResponse>
</soapenv:Body>
</soapenv:Envelope>
My Flex code
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:components="components.*"
xmlns:hellos="services.hellos.*"
height="957" creationComplete="initApp()" >
<fx:Style source="Styles.css"/>
<fx:Script>
<![CDATA[
import mx.collections.XMLListCollection;
import mx.events.FlexEvent;
import mx.messaging.messages.SOAPMessage;
import mx.rpc.events.ResultEvent;
[Bindable]
var _result:*;
private function initApp():void
{
mywebservice.mycustomers();
}
protected function
dropDownList_creationCompleteHandler(event:ResultEvent):void
{
var xml:XML = event.result as XML;
var xmlString:String = xml.toXMLString();
var patt:RegExp = new RegExp("xmlns[^\"]*\"[^\"]*\"", "gi");
var newXmlString:String = xmlString.replace(patt, "");
xml = new XML(newXmlString);
_result = new XMLListCollection(xml.mycustomersResponse.mycustomersReturn);
}
]]>
</fx:Script>
<fx:Declarations>
<s:WebService id="mywebservice"
wsdl="http://localhost:8081/WebServiceTest/services/Hellos?wsdl">
<s:operation name="mycustomers"
resultFormat="object"
result="dropDownList_creationCompleteHandler(event);"
/>
</s:WebService>
</fx:Declarations>
<s:FormItem label="Label">
<s:DropDownList id="dropDownList"
labelField="name">
<s:AsyncListView list="{_result}"/>
</s:DropDownList>
</s:FormItem>
</s:Application>
coming from here dropdown list does not show its values I slightly modified my example. There are two opportunities:
Strip namespace from xml
Utilize namespace
Those are shown in dropDownList and dropDownList2 code respectively.
Note, that you can not utilize namespace still using labelField property(at least I couldn't find a way). You have to use labelFunction to extract label.
<?xml version="1.0" encoding="utf-8"?>
<![CDATA[
import mx.collections.XMLListCollection;
import mx.events.FlexEvent;
import mx.messaging.messages.SOAPMessage;
[Bindable]
var _result:*;
[Bindable]
var _result2:*;
protected function
dropDownList_creationCompleteHandler(event:FlexEvent):void
{
var xml:XML = <Body>
<myusersResponse xmlns="http://Services.com">
<myusersReturn>
<name>Nicole</name>
<age>50</age>
</myusersReturn>
<myusersReturn>
<name>Jayne</name>
<age>40</age>
</myusersReturn>
<myusersReturn>
<name>Alex</name>
<age>33</age>
</myusersReturn>
</myusersResponse>
</Body>;
var xmlString:String = xml.toXMLString();
var patt:RegExp = new RegExp("xmlns[^\"]*\"[^\"]*\"", "gi");
var newXmlString:String = xmlString.replace(patt, "");
xml = new XML(newXmlString);
_result = new XMLListCollection(xml.myusersResponse.myusersReturn);
}
protected function dropDownList2_creationCompleteHandler(event:FlexEvent):void
{
var xml:XML = <Body>
<myusersResponse xmlns="http://Services.com">
<myusersReturn>
<name>Nicole</name>
<age>50</age>
</myusersReturn>
<myusersReturn>
<name>Jayne</name>
<age>40</age>
</myusersReturn>
<myusersReturn>
<name>Alex</name>
<age>33</age>
</myusersReturn>
</myusersResponse>
</Body>;
var ns:Namespace = new Namespace("http://Services.com");
_result2 = new XMLListCollection(xml.ns::myusersResponse.ns::myusersReturn);
}
private function dropDownList2_labelFunction(item:Object):String{
var itemXml:XML = item as XML;
var ns:Namespace = new Namespace("http://Services.com");
return item.ns::name;
}
]]>
</fx:Script>
<fx:Declarations>
</fx:Declarations>
<s:FormItem label="Label">
<s:DropDownList id="dropDownList"
creationComplete="dropDownList_creationCompleteHandler(event)"
labelField="name">
<s:AsyncListView list="{_result}"/>
</s:DropDownList>
<s:DropDownList id="dropDownList2"
creationComplete="dropDownList2_creationCompleteHandler(event)"
labelFunction="dropDownList2_labelFunction">
<s:AsyncListView list="{_result2}"/>
</s:DropDownList>
</s:FormItem>
I think you should use event.result..mycustomersReturn. That will return an XMLList with two items that you can then convert and use in your dropdown.
Use xml parsing with namespace definition:
protected function dropDownList_creationCompleteHandler(event:ResultEvent):void
{
namespace ns = "http://Services.com";
use namespace ns;
namespace ns_soapenv = "http://schemas.xmlsoap.org/soap/envelope/";
use namespace ns_soapenv;
var xml:XML = event.result as XML;
_result = xml.Body.mycustomersResponse.mycustomersReturn;
}
Related
after upgrading the Java implementation of Camel from 2.13.0 to 2.17.2 (and cxf-rt-frontend-jaxrs from 2.7.10 to 3.1.5, and spring framework from 3.2.8 to 4.3.2), the webapp that is serving as a proxy stopped working correctly.
The app is supposed to intercept a webservice request, modify fields that are defined in a properties file throught the ContextManager class, and forward the request to the correct endpoint.
After the upgrade, the app is unable to set the missing fields in the original request, thus returning the following message: "REQUEST_MESSAGE_NOT_COMPLIANT_WITH_SCHEMA - Your request message does not comply to the web service schema".
This is of course expected since the missing fields are not being set.
Any help would be greatly appreciated.
UPDATE:
The problem seems to be coming from the xpath method which in the previous version returned the correct node where some information needs to be set and now is returning null.
My Camel route definition is as follows:
CreditLimitRequestServiceRoute.class
public class CreditLimitRequestServiceRoute extends AbstractEHRoute {
#Autowired
private ContextManager contextManager;
#Override
public void configure() throws Exception {
Namespaces ns = new Namespaces("ns1", "http://ehsmartlink/commonError");
onException(SoapFault.class)
.to("consoleflux:message?level=ERROR&text=${exception.message}&content=${exception.detail}")
.setHeader("soapFaultDetail", simple("${exception.detail}"))
.choice()
.when(and(header("soapFaultDetail").isNotNull(), xpath("//ns1:commonError/errorType/text() = 'BusinessError'", ns, "soapFaultDetail")))
.to("consoleflux:finish?ignoreContent=true")
.otherwise()
.to("consoleflux:error?ignoreContent=true");
onException(Exception.class)
.to("consoleflux:error");
from("cxf:bean:creditLimitRequestServiceProxy?dataFormat=PAYLOAD").routeId("creditLimitRequestServiceRoute")
.log(LoggingLevel.INFO, "Invocation du WS").streamCaching()
.to("consoleflux:start?source=SOA&dest=EH&type=CREDIT_LIMIT")
.to("consoleflux:message?ignoreContent=true&text=Affectation du Contexte EH")
.setHeader("context").xpath("//context")
.bean(contextManager, "setContext")
.to("consoleflux:message?ignoreContent=true&text=Invocation du WS EH ${headers.operationName}")
.to("cxf:bean:creditLimitRequestService?dataFormat=PAYLOAD")
.to("consoleflux:finish");
}
}
AbstractEHRoute.class
public abstract class AbstractEHRoute extends RouteBuilder {
protected XPathBuilder xpath(String text, Namespaces namespaces, String headerName) {
XPathBuilder xpath = XPathBuilder.xpath(text).namespaces(namespaces);
xpath.setHeaderName(headerName);
return xpath;
}
}
ContextManager
package com.stef.soa.eh.integration.beans;
import static com.google.common.base.Objects.firstNonNull;
import static com.google.common.base.Strings.isNullOrEmpty;
import java.util.Map;
import java.util.UUID;
import org.apache.camel.Header;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
#Component
public class ContextManager {
private static final String USER_NAME = "userName";
private static final String USER_PASSWORD = "userPassword";
private static final String LANGUAGE_TEXT_IDENTIFIER = "languageTextIdentifier";
private static final String TRANSACTION_IDENTIFIER = "transactionIdentifier";
private static final String POLICIY_IDENTIFIER = "policyIdentifier";
private static final String POLICY_EXTENSION_IDENTIFIER = "policyExtensionIdentifier";
private static final String POLICY_EHBU_IDENTIFIER = "policyEHBUIdentifier";
private static final String IP_ADRESS = "ipAdress";
#Value("${eh.context.userName}")
private String userName;
#Value("${eh.context.userPassword}")
private String userPassword;
#Value("${eh.context.languageTextIdentifier}")
private String languageTextIdentifier;
#Value("${eh.context.policyIdentifier}")
private String policyIdentifier;
#Value("${eh.context.policyExtensionIdentifier}")
private String policyExtensionIdentifier;
#Value("${eh.context.policyEHBUIdentifier}")
private String policyEHBUIdentifier;
#Value("${eh.context.ipAdress}")
private String ipAdress;
public void setContext(#Header("context") Node context) {
Preconditions.checkNotNull(context, "Le contexte doit ĂȘtre renseignĂ©");
// Suppression des noeuds enfants avec sauvegarde les valeurs courantes dans une map
Map<String, String> currentValues = Maps.newHashMap();
NodeList list = context.getChildNodes();
for (int i = list.getLength() - 1; i >= 0; i--) {
Node child = list.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE && !isNullOrEmpty(child.getTextContent())) {
currentValues.put(child.getNodeName(), child.getTextContent());
}
context.removeChild(child);
}
// Ajout des noeuds enfants
appendChild(context, USER_NAME, userName, currentValues);
appendChild(context, USER_PASSWORD, userPassword, currentValues);
appendChild(context, LANGUAGE_TEXT_IDENTIFIER, languageTextIdentifier, currentValues);
appendChild(context, TRANSACTION_IDENTIFIER, UUID.randomUUID().toString(), currentValues);
appendChild(context, POLICIY_IDENTIFIER, policyIdentifier, currentValues);
appendChild(context, POLICY_EXTENSION_IDENTIFIER, policyExtensionIdentifier, currentValues);
appendChild(context, POLICY_EHBU_IDENTIFIER, policyEHBUIdentifier, currentValues);
appendChild(context, IP_ADRESS, ipAdress, currentValues);
}
private void appendChild(Node node, String name, String value, Map<String, String> currentValues) {
Document document = node.getOwnerDocument();
Element child = document.createElement(name);
child.setTextContent(firstNonNull(currentValues.get(name), value));
node.appendChild(child);
}
}
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="classpath:eh.properties, file:///${eh.home}/conf/eh.properties"
ignore-resource-not-found="true" system-properties-mode="OVERRIDE" />
<context:component-scan base-package="com.stef.soa.eh" />
<context:annotation-config />
<import resource="classpath:META-INF/eh/spring/broker.xml" />
<import resource="classpath:META-INF/eh/spring/camel.xml" />
<import resource="classpath:META-INF/eh/spring/cxf.xml" />
<import resource="classpath:META-INF/soa-console-flux-client/spring/context.xml"/>
</beans>
camel.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:http="http://cxf.apache.org/transports/http/configuration"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd" >
<!-- Camel Context -->
<camelContext xmlns="http://camel.apache.org/schema/spring" id="ehContext">
<properties>
<property key="org.apache.camel.xmlconverter.output.indent" value="yes"/>
<property key="org.apache.camel.xmlconverter.output.{http://xml.apache.org/xslt}indent-amount" value="4"/>
</properties>
<package>com.stef.soa.eh.integration</package>
</camelContext>
</beans>
cxf.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xmlns:http="http://cxf.apache.org/transports/http/configuration"
xmlns:sec="http://cxf.apache.org/configuration/security"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/cxf
http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd" >
<!-- Serveur Proxy, Certificat -->
<http:conduit name="*.http-conduit">
<http:client ProxyServer="${proxy.host}" ProxyServerPort="${proxy.port}"
ConnectionTimeout="${http.client.connectionTimeout}" ReceiveTimeout="${http.client.receiveTimeout}" />
<http:proxyAuthorization>
<sec:UserName>${proxy.username}</sec:UserName>
<sec:Password>${proxy.password}</sec:Password>
</http:proxyAuthorization>
<http:tlsClientParameters>
<sec:keyManagers keyPassword="${eh.keyStore.password}">
<sec:keyStore type="pkcs12" password="${eh.keyStore.password}" file="${eh.home}/${eh.keyStore.file}" />
</sec:keyManagers>
</http:tlsClientParameters>
</http:conduit>
<!-- Services Proxy et Cible -->
<cxf:cxfEndpoint
id="creditLimitRequestServiceProxy"
address="/creditLimitRequestService"
wsdlURL="META-INF/eh/wsdl/CreditLimitRequestService/EH_SMARTLINK_CreditLimitRequestServiceV4.wsdl"
serviceName="ns:CreditLimitRequestServiceV4"
endpointName="ns:CreditLimitRequestServiceV4"
xmlns:ns="http://ehsmartlink/CreditLimitRequestService/v4"
/>
<cxf:cxfEndpoint
id="creditLimitRequestService"
address="${eh.creditLimitRequestService.url}"
wsdlURL="META-INF/eh/wsdl/CreditLimitRequestService/EH_SMARTLINK_CreditLimitRequestServiceV4.wsdl"
serviceName="ns:CreditLimitRequestServiceV4"
endpointName="ns:CreditLimitRequestServiceV4"
xmlns:ns="http://ehsmartlink/CreditLimitRequestService/v4"
loggingFeatureEnabled="true"
/>
<cxf:cxfEndpoint
id="customerListRetrieveServiceProxy"
address="/customerListRetrieveService"
wsdlURL="META-INF/eh/wsdl/CustomerListRetrieveService/CustomerListRetrieveV2.wsdl"
serviceName="ns:CustomerListRetrieveServiceV2"
endpointName="ns:CustomerListRetrieveServiceV2"
xmlns:ns="http://ehsmartlink/CustomerListRetrieve/v2"
/>
<cxf:cxfEndpoint
id="customerListRetrieveService"
address="${eh.customerListRetrieveService.url}"
wsdlURL="META-INF/eh/wsdl/CustomerListRetrieveService/CustomerListRetrieveV2.wsdl"
serviceName="ns:CustomerListRetrieveServiceV2"
endpointName="ns:CustomerListRetrieveServiceV2"
xmlns:ns="http://ehsmartlink/CustomerListRetrieve/v2"
loggingFeatureEnabled="true"
/>
<cxf:cxfEndpoint
id="firstEuroListRepertoireReadServiceProxy"
address="/firstEuroListRepertoireReadService"
wsdlURL="META-INF/eh/wsdl/FirstEuroListRepertoireReadService/EH_SMARTLINK_FirstEuroListRepertoireReadService-v1.wsdl"
serviceName="ns:FirstEuroListRepertoireReadService-v1"
endpointName="ns:FirstEuroListRepertoireReadServicePort-v1_soap11"
xmlns:ns="http://eulerhermes.com/SMARTLINK/services/FirstEuroListRepertoireReadService/v1"
/>
<cxf:cxfEndpoint
id="firstEuroListRepertoireReadService"
address="${eh.firstEuroListRepertoireReadService.url}"
wsdlURL="META-INF/eh/wsdl/FirstEuroListRepertoireReadService/EH_SMARTLINK_FirstEuroListRepertoireReadService-v1.wsdl"
serviceName="ns:FirstEuroListRepertoireReadService-v1"
endpointName="ns:FirstEuroListRepertoireReadServicePort-v1_soap11"
xmlns:ns="http://eulerhermes.com/SMARTLINK/services/FirstEuroListRepertoireReadService/v1"
loggingFeatureEnabled="true"
/>
<cxf:cxfEndpoint
id="firstEuroListRepertoireUpdateServiceProxy"
address="/firstEuroListRepertoireUpdateService"
wsdlURL="META-INF/eh/wsdl/FirstEuroListRepertoireUpdateService/EH_SMARTLINK_FirstEuroListRepertoireUpdateService-v1.wsdl"
serviceName="ns:FirstEuroListRepertoireUpdateService-v1"
endpointName="ns:FirstEuroListRepertoireUpdateServicePort-v1"
xmlns:ns="http://eulerhermes.com/SMARTLINK/services/FirstEuroListRepertoireUpdateService/v1"
/>
<cxf:cxfEndpoint
id="firstEuroListRepertoireUpdateService"
address="${eh.firstEuroListRepertoireUpdateService.url}"
wsdlURL="META-INF/eh/wsdl/FirstEuroListRepertoireUpdateService/EH_SMARTLINK_FirstEuroListRepertoireUpdateService-v1.wsdl"
serviceName="ns:FirstEuroListRepertoireUpdateService-v1"
endpointName="ns:FirstEuroListRepertoireUpdateServicePort-v1"
xmlns:ns="http://eulerhermes.com/SMARTLINK/services/FirstEuroListRepertoireUpdateService/v1"
loggingFeatureEnabled="true"
/>
<cxf:cxfEndpoint
id="limitDetailReadServiceProxy"
address="/limitDetailReadService"
wsdlURL="META-INF/eh/wsdl/LimitDetailReadService/EH_SMARTLINK_LimitDetailReadService-v2.wsdl"
serviceName="ns:LimitDetailReadService-v2"
endpointName="ns:LimitDetailReadServicePort-v2"
xmlns:ns="http://eulerhermes.com/SMARTLINK/services/LimitDetailReadService/v2"
/>
<cxf:cxfEndpoint
id="limitDetailReadService"
address="${eh.limitDetailReadService.url}"
wsdlURL="META-INF/eh/wsdl/LimitDetailReadService/EH_SMARTLINK_LimitDetailReadService-v2.wsdl"
serviceName="ns:LimitDetailReadService-v2"
endpointName="ns:LimitDetailReadServicePort-v2"
xmlns:ns="http://eulerhermes.com/SMARTLINK/services/LimitDetailReadService/v2"
loggingFeatureEnabled="true"
/>
</beans>
I have following xml response :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:DealLookupResponse xmlns:ns2="http://www.starstandards.org/webservices/2005/10/transport" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="xsd:anyType">
<Deal>
<CompanyNumber>CN7</CompanyNumber>
<DealNumber>111</DealNumber>
<RecordStatus>A</RecordStatus>
<SalesPersons>
<SalesPerson>
<RecordType/>
<SalesPersonID>CL1</SalesPersonID>
<Status>A</Status>
<SaleDate>20140806</SaleDate>
<SalesPersonName>CLOSER 1</SalesPersonName>
<IncentiveCommission>0.00</IncentiveCommission>
<TotalCommission>0.00</TotalCommission>
</SalesPerson>
</SalesPersons>
</Deal>
</ns2:DealLookupResponse>
When I unmarshal this xml to Java Object, I get all values of Deal object but SalesPersons has one element in the list and all the properties of this element are null. What am I missing?
My DealLookupResponse class is
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"deal"
})
#XmlRootElement(name = "DealLookupResponse", namespace="http://www.starstandards.org/webservices/2005/10/transport")
public class DealLookupResponse {
#XmlElement(name = "Deal", required = false)
Deal deal;
public Deal getDeal() {
return deal;
}
public void setDeal(Deal deal) {
this.deal = deal;
}
}
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "Deal", propOrder = {
"companyNumber",
"dealNumber",
"recordStatus",
"salesPersons"
}, namespace = "http://www.starstandards.org/webservices/2005/10/transport")
public class Deal {
#XmlElement(name="CompanyNumber")
String companyNumber;
#XmlElement(name="DealNumber")
String dealNumber;
#XmlElement(name="RecordStatus")
String recordStatus;
#XmlElementWrapper
#XmlElement(name="SalesPerson")
List<SalesPerson> salesPersons;
}
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "SalesPerson", propOrder = {
"recordType",
"salesPersonID",
"status",
"saleDate",
"salesPersonName",
"incentiveCommission",
"totalCommission"
}, namespace = "http://www.starstandards.org/webservices/2005/10/transport")
public class SalesPerson {
#XmlElement(name="RecordType")
String recordType;
#XmlElement(name="SalesPersonID")
Long salesPersonID;
#XmlElement(name="Status")
String status;
#XmlElement(name="SaleDate")
Date saleDate;
#XmlElement(name="SalesPersonName")
String salesPersonName;
#XmlElement(name="IncentiveCommission")
Double incentiveCommission;
#XmlElement(name="TotalCommission")
Double totalCommission;
}
My unmarshalling code looks like this :
JAXBContext jc = JAXBContext.newInstance(DealLookupResponse.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
DealLookupResponse je = (DealLookupResponse)unmarshaller.unmarshal(xmlInputSource);
What You Currently Have
Since you haven't specified a name on the #XmlElementWrapper annotation you wil get the default behaviour.
#XmlElementWrapper
#XmlElement(name="SalesPerson")
List<SalesPerson> salesPersons;
This means it will correspond to the following XML:
<salesPersons>
<SalesPerson>
</SalesPerson>
<salesPersons>
How To Fix It
You need to change the #XmlElementWrapper annotation on the salesPersons field to be the following:
#XmlElementWrapper(name="SalesPersons")
#XmlElement(name="SalesPerson")
List<SalesPerson> salesPersons;
Debugging Tip
When you experience problems unmarshalling, populate your object model and then marshal it to XML. Then compare this XML to the XML you are unmarshalling to see if there are any differences.
Use this XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DealLookupResponse xmlns="http://www.starstandards.org/webservices/2005/10/transport" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="xsd:anyType">
<Deal>
<CompanyNumber>CN7</CompanyNumber>
<DealNumber>111</DealNumber>
<RecordStatus>A</RecordStatus>
<SalesPersons>
<SalesPerson>
<RecordType/>
<SalesPersonID>CL1</SalesPersonID>
<Status>A</Status>
<SaleDate>20140806</SaleDate>
<SalesPersonName>CLOSER 1</SalesPersonName>
<IncentiveCommission>0.00</IncentiveCommission>
<TotalCommission>0.00</TotalCommission>
</SalesPerson>
</SalesPersons>
</Deal>
</DealLookupResponse>
and below classes
DealLookupResponse
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "DealLookupResponse", propOrder = {
"Deal"
})
#XmlRootElement(name = "DealLookupResponse", namespace="http://www.starstandards.org/webservices/2005/10/transport")
public class DealLookupResponse {
#XmlElement(required = true)
Deal Deal;
}
Deal
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"CompanyNumber",
"DealNumber",
"RecordStatus",
"SalesPersons"
})
#XmlRootElement(name = "Deal", namespace="http://www.starstandards.org/webservices/2005/10/transport")
public class Deal {
#XmlElement(required = true)
String CompanyNumber;
#XmlElement(required = true)
String DealNumber;
#XmlElement(required = true)
String RecordStatus;
#XmlElementWrapper
#XmlElement(required = true)
List<SalesPerson> SalesPersons;
}
SalesPerson
#XmlType(name = "SalesPerson", propOrder = {
"RecordType",
"RalesPersonID",
"Status",
"SaleDate",
"SalesPersonName",
"IncentiveCommission",
"TotalCommission"
}, namespace = "http://www.starstandards.org/webservices/2005/10/transport")
public class SalesPerson {
#XmlElement(name="RecordType")
String RecordType;
#XmlElement(name="SalesPersonID")
Long RalesPersonID;
#XmlElement(name="Status")
String Status;
#XmlElement(name="SaleDate")
Date SaleDate;
#XmlElement(name="SalesPersonName")
String SalesPersonName;
#XmlElement(name="IncentiveCommission")
Double IncentiveCommission;
#XmlElement(name="TotalCommission")
Double TotalCommission;
}
I am consuming a WSDL in a Windows 8 app. I need to customize the SOAP request like
New SOAP Request:
</ns0:Header>
<ns0:Body>
<ns0:Request xmlns:ns0="http://www.ABC.co.il/2004/01/RetrieveEntityDetails/EntityDetailsRequest">
</ns0:Request></ns0:Body></ns0:Envelope>
Current SOAP Request:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
</s:Header>
<s:Body>
<RetrieveEntityDetailsXPOP_XmlRequest xmlns="http://tempuri.org/">
<RetrieveEntityDetailsXPOP_Xml xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<requestDoc>
</requestDoc>
</RetrieveEntityDetailsXPOP_Xml>
</RetrieveEntityDetailsXPOP_XmlRequest>
</s:Body>
</s:Envelope>
How will I change the namespace and set a request tag inside the body tag.
Code:
Client = new EAI_RetrieveEntityDetailsXP_ServiceSoapClient();
Client.RetrieveEntityDetailsXPOP_XmlCompleted += Client_RetrieveEntityDetailsXPOP_XmlCompleted;
XElement requestData = GetRequestData();
using (new OperationContextScope(Client.InnerChannel))
{
// Create a custom soap header
var msgHeader = MessageHeader.CreateHeader("myCustomHeader", string.Empty, "myValue");
// Add the header into request message
OperationContext.Current.OutgoingMessageHeaders.Add(msgHeader);
Client.RetrieveEntityDetailsXPOP_XmlAsync(requestData);
}
I have actually used HttpCleint to call this service by using following code. Using this we can generate the SOAP request as desired.
string soapString = ConstructSoapRequest();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("SOAPAction", SOAPActionUri);
var content = new StringContent(soapString, Encoding.UTF8, "text/xml");
using (var response = await client.PostAsync(Uri, content))
{
var soapResponse = await response.Content.ReadAsStringAsync();
return soapResponse;
}
}
private string ConstructSoapRequest()
{
return String.Format(#"<ns0:Envelope xmlns:ns0='http://www.cellcom.co.il/2004/01/std-headers'>
<ns0:Header>
</ns0:Header>
<ns0:Body>
<ns0:Request xmlns:ns0='http://www.cellcom.co.il/2004/01/RetrieveEntityDetails/EntityDetailsRequest'>
</ns0:Request></ns0:Body></ns0:Envelope>", 100);
}
I want to save some informaion to database when I send a request to mule service.
for this issue: I wrote below config in xml file:
<mule xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:mule-ss="http://www.mulesoft.org/schema/mule/spring-security"
xmlns:ss="http://www.springframework.org/schema/security" xmlns:jdbc="http://www.mulesoft.org/schema/mule/jdbc"
xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd
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/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.mulesoft.org/schema/mule/spring-security http://www.mulesoft.org/schema/mule/spring-security/3.3/mule-spring-security.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.mulesoft.org/schema/mule/jdbc http://www.mulesoft.org/schema/mule/jdbc/current/mule-jdbc.xsd ">
<spring:beans>
<spring:bean id="Initializer" name="Initializer" class="org.mule.example.scripting.IpClient" doc:name="Bean"/>
</spring:beans>
<notifications>
<notification event="COMPONENT-MESSAGE"/>
<notification-listener ref="Initializer"/>
</notifications>
<configuration doc:name="Configuration">
<expression-language>
<global-functions>
def parseIp(fullIp) {
return
fullIp.substring(fullIp.indexOf('/') + 1, fullIp.indexOf(':'))
}
</global-functions>
</expression-language>
</configuration>
<http:connector name="httpConnector" doc:name="HTTP\HTTPS">
<service-overrides sessionHandler="org.mule.session.NullSessionHandler" />
</http:connector>
<mule-ss:security-manager>
<mule-ss:delegate-security-provider
name="memory-dao" delegate-ref="authenticationManager" />
</mule-ss:security-manager>
<spring:beans>
<ss:authentication-manager alias="authenticationManager">
<ss:authentication-provider>
<ss:user-service id="userService">
<ss:user name="weather" password="weather" authorities="ROLE_ADMIN" />
</ss:user-service>
</ss:authentication-provider>
</ss:authentication-manager>
</spring:beans>
<flow name="Serive_test" doc:name="Serive_test">
<http:inbound-endpoint host="localhost" port="8089"
path="service/local-weather" exchange-pattern="request-response"
doc:name="HTTP">
<mule-ss:http-security-filter realm="mule-realm" />
</http:inbound-endpoint>
<async doc:name="Async">
<set-variable variableName="remoteClientAddress"
value="#[parseIp(message.inboundProperties['MULE_REMOTE_CLIENT_ADDRESS'])]"
doc:name="Variable" />
<message-properties-transformer
doc:name="myproperty" scope="session">
<add-message-property key="message.payload.remoteClientAddress"
value="#[parseIp(message.inboundProperties['MULE_REMOTE_CLIENT_ADDRESS'])]" />
</message-properties-transformer>
<component doc:name="classTest" class="org.mule.example.scripting.IpClient" />
</async>
<cxf:proxy-service service="Weather" doc:name="Weather_webservice"
wsdlLocation="http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl" namespace="http://ws.cdyne.com/WeatherWS/"
payload="envelope"></cxf:proxy-service>
<copy-properties propertyName="SOAPAction" doc:name="Property"></copy-properties>
<cxf:proxy-client doc:name="Weather_webservice"
payload="envelope" />
<outbound-endpoint address="http://wsf.cdyne.com/WeatherWS/Weather.asmx"
exchange-pattern="request-response" doc:name="HTTP"></outbound-endpoint>
</flow>
and IpClient class:
public class IpClient implements Callable,ModelNotificationListener<ModelNotification> {
#Override
public void onNotification(ModelNotification notification) {
// TODO Auto-generated method stub
System.out.println("Notification order event: " + notification.getActionName() );
if(notification.getAction() == ModelNotification.MODEL_DISPOSED || notification.getAction() == ModelNotification.MODEL_STOPPED){
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
ConnectDB c = new ConnectDB("localhost:3306", "accounting", "root", "");
String sql = " INSERT INTO weather (ip, date, CurrentState) VALUES (?,?,?) ";
PreparedStatement ps = null;
try {
ps = c.getConnnection().prepareStatement(sql);
ps.setString(1, "127.0.0.1");
ps.setString(2, dateFormat.format(date).toString());
ps.setString(3, notification.getActionName());
ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
c.close();
}
}
}
#Override
public Object onCall(MuleEventContext eventContext) throws Exception {
MuleMessage msg = eventContext.getMessage();
String remClient = msg.getProperty("remoteClientAddress", PropertyScope.INVOCATION);
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
ConnectDB c = new ConnectDB("localhost:3306", "accounting", "root", "");
String sql = " INSERT INTO weather (ip, date, CurrentState) VALUES (?,?,?) ";
PreparedStatement ps = c.getConnnection().prepareStatement(sql);
ps.setString(1, remClient);
ps.setString(2, dateFormat.format(date).toString());
ps.setString(3, msg.getMuleContext().getLifecycleManager().getCurrentPhase());
ps.executeUpdate();
c.close();
return msg.getPayload();
}
}
this program just works correctly if I start to run service. for example my service run before suddenly it was dissposed(for example my wsdl(http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl doesn't work)). my log program saved all records in state of start and after dissposing it works similar. if I stoped my service and run it again it works correctly and it saves all records in dissposed mode.
I don't know how to change my program that it saves correctly in runtime.
The (ill named) Initializer bean is not used as a <component> anywhere in the configuration so there's no way its onCall method will ever get called.
If your intention with:
<notification event="COMPONENT-MESSAGE"/>
is to have the Initializer called for each component invocation you then have to make it implement ComponentMessageNotificationListener (like you made it implement ModelNotificationListener).
How to display a list of data in Flex by getting key value pair from a wsdl web service? Please help.
It depends on your web service and data types it provides.
Many web services can return you a response as a list of objects.
Others give you a structured string.
In my example I use a simple public weather web service, which returns its XML as a string.
This is a service description: http://www.webservicex.com/globalweather.asmx?wsdl
This is a test page: http://www.webservicex.com/globalweather.asmx?test
I use the GetCitiesByCountry method to get this list:
//source code
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600" creationComplete="init()">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.CallResponder;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import services.globalweather.Globalweather;
private var ws:Globalweather = new Globalweather();
private var getCitiesByCountryCR:CallResponder;
private function init():void
{
getCitiesByCountryCR = new CallResponder();
getCitiesByCountryCR.addEventListener(ResultEvent.RESULT, onResult);
getCitiesByCountryCR.addEventListener(FaultEvent.FAULT, onFault);
}
private function onResult(evt:ResultEvent):void
{
var xml:XML = new XML(evt.result);
var xmlList:XMLList = xml.Table.City;
taCities.text = "";
for each (var item:XML in xmlList)
{
taCities.text += item.toString() + String.fromCharCode(13);
}
}
private function onFault(evt:FaultEvent):void
{
Alert.show("Fault!");
}
protected function getCities(event:MouseEvent):void
{
getCitiesByCountryCR.token = ws.GetCitiesByCountry(tiCountry.text);
}
]]>
</fx:Script>
<s:VGroup x="20" y="20" width="330" height="200">
<s:HGroup verticalAlign="bottom">
<s:Label text="Enter country name:"/>
<s:TextInput id="tiCountry" text="France"/>
<s:Button x="202" y="10" label="Get cities!" click="getCities(event)"/>
</s:HGroup>
<s:TextArea id="taCities" height="100%" width="100%"/>
</s:VGroup>
</s:Application>