How to upload raw XML data via POST to URL in Talend? - talend

I am trying to upload an xml file to a url so that I can retrieve response in XML.
I tried using thttprequest
But it says, "Can't write output after reading input."
What am I doing wrong?
The request.xml is this
<?xml version="1.0" encoding="UTF-8" ?>
<request xmlns="http://www.isinet.com/xrpc42"
src="app.id=PartnerApp,env.id=PartnerAppEnv,partner.email=EmailAddress" >
<fn name="LinksAMR.retrieve">
<list>
<!-- WHO'S REQUESTING -->
<map>
<val name="username">username</val>
<val name="password">test</val>
</map>
<!-- WHAT'S REQUESTED -->
<map>
<list name="WOS">
<val>timesCited</val>
<val>ut</val>
<val>doi</val>
<val>sourceURL</val>
<val>citingArticlesURL</val>
<val>relatedRecordsURL</val>
</list>
</map> <!--end "return_data" -->
<!-- LOOKUP DATA -->
<map>
<!-- QUERY "cite_1" -->
<map name="cite_1">
<val name="atitle">article title string</val>
<val name="stitle">full journal title</val>
<val name="issn">1234-5678</val>
<val name="vol">12</val>
<val name="issue">12</val>
<val name="year">2008</val>
<val name="doi">doi_string</val>
<val name="ut">isi_ut_num</val>
<val name="spage">1234</val>
<!-- authors list can be used to specify multiple authors -->
<list name="authors">
<val>First, AU</val>
<val>Second, AU</val>
<val>Third, AU</val>
</list>
</map> <!-- end of cite_id-->
<-- QUERY "cite_2"
<map name="cite_2">
...
</map>
-->
</map> <!-- end of citations -->
</list>
</fn>
</request>
I am posting to the web of science url
https://ws.isiknowledge.com/cps/xrpc
Normally, if there was a mistake, I should be getting a response that something went wrong in XML. I am not even getting that.
I tried using tRestClient but I am unsure of how to upload a file to the url through it. Also this post might hold some clues. https://jira.talendforge.org/browse/TDI-31574

You can also upload a string instead of the file. But for this you need to use tJava_Row, since tJava can't work with one row at a time.
URL url = new URL("https://ws.isiknowledge.com/cps/xrpc");
StringBuilder response_content = new StringBuilder();
String data=row1.content;
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
// System.out.println(line);
response_content.append(line);
}
String output=response_content.toString();
wr.close();
rd.close();
row2.content=(output);

I used tJava component
URL url = new URL("https://ws.isiknowledge.com/cps/xrpc");
StringBuilder content = new StringBuilder();
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("POST");
c.setDoOutput(true);
c.setDoInput(true);
c.setUseCaches(false);
c.setRequestProperty("Content-Type", "application/xml");
c.connect();
byte[] buffer = new byte[1024];
int cbuffer = 0;
InputStream is = new BufferedInputStream(new FileInputStream("C:\\Users\\dhiraj\\workspace\\request.xml"));
OutputStream os = new BufferedOutputStream(c.getOutputStream());
while ((cbuffer = is.read(buffer)) != -1) {
os.write(buffer, 0, cbuffer);
}
os.flush();
os.close();
is.close();
if (HttpURLConnection.HTTP_OK == c.getResponseCode()) {
is = new BufferedInputStream(
c.getInputStream());
while ((cbuffer = is.read(buffer)) != -1) {
content.append(new String(
buffer, 0, cbuffer));
}
is.close();
} else {
System.err.println(c.getResponseCode() + ":" + c.getResponseMessage());
}
row1.ResponseContent = content.toString();
c.disconnect();

Related

Verifying Signed Xml Generated From Java In NET

I have the below XML,
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Response xmlns="http://www.site.ae/g">
<Message xml:id="message">
<Header>
<Service>Read</Service>
<Action>SomeAction</Action>
</Header>
<Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="SomeDataType">
<Status>Success</Status>
<Data>
<Id>123</Id>
</Data>
</Body>
</Message>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"/>
<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<Reference URI="#message">
<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue>SomeValue</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>
SomeValue
</SignatureValue>
<KeyInfo>
<X509Data>
<X509Certificate>
SomeValue
</X509Certificate>
</X509Data>
</KeyInfo>
</Signature>
</Response>
The above XML genereted from a java application. The java application team provided us 3 certificate to verify the above xml. I have created 3 objects in C#,
var clientCert = new X509Certificate2("clientCert.cer");
var intermediateCert = new X509Certificate2("intermediateCert.cer");
var rootCert = new X509Certificate2("rootCert.cer");
One is root, second one is intermediate and third one is certificate. I have created the below code,
var xmlDoc = new XmlDocument();
xmlDoc.PreserveWhitespace = true;
xmlDoc.Load("above.xml");
bool result = VerifyXml(xmlDoc, clientCert);
private static Boolean VerifyXml(XmlDocument Doc, X509Certificate2 Key)
{
// Create a new SignedXml object and pass it
// the XML document class.
var signedXml = new System.Security.Cryptography.Xml.SignedXml(Doc);
// Find the "Signature" node and create a new XmlNodeList object.
XmlNodeList nodeList = Doc.GetElementsByTagName("Signature");
// Throw an exception if no signature was found.
if (nodeList.Count <= 0)
{
throw new CryptographicException("Verification failed: No Signature was found in the document.");
}
// Though it is possible to have multiple signatures on
// an XML document, this app only supports one signature for
// the entire XML document. Throw an exception
// if more than one signature was found.
if (nodeList.Count >= 2)
{
throw new CryptographicException("Verification failed: More that one signature was found for the document.");
}
// Load the first <signature> node.
signedXml.LoadXml((XmlElement)nodeList[0]);
// Check the signature and return the result.
return signedXml.CheckSignature(Key, true);
}
But the above code result is always return false. Is there is something I am missing? Is .NET support verifying the xml generated from java?
Got Answer from
Verify SignatureValue And DigestValue Using Sha256 RSA

How to set up jersey and swagger-ui with properties file for setting url variable?

I have a Maven spring application that uses Jersey for a REST API. I have a properties file for each of the environments that I want to deploy the code to.
For example, dev.properties looks like:
hostUrl=https://dev.foo.net/
basePathUrl=/bar/restapi
And test.properties looks like
hostUrl=https://test.foo.net/
basePathUrl=/bar/restapi
I then use spring beans to configure swagger for each environment:
<bean id="beanConfig" class="io.swagger.jaxrs.config.BeanConfig">
<property name="title" value="Swagger App"/>
<property name="version" value="1.0.0" />
<property name="schemes" value="http" />
<property name="host" value="#{envSpecificProperties.hostUrl}" />
<property name="basePath" value="#{envSpecificProperties.basePathUrl}"/>
<property name="resourcePackage" value="com.foo.bar.rest"/>
<property name="scan" value="true"/>
</bean>
<context:property-placeholder
properties-ref="envSpecificProperties" />
<util:properties id="envSpecificProperties"
location="WEB-INF/classes/file-#{xjpEnvironment.domain}.properties" />
<xjp:environment />
My question is, how can I use these same properties files for setting up swagger-ui in index.html so that swagger-ui does not have to be hard coded like this
<script type="text/javascript">
$(function () {
var url = window.location.search.match(/url=([^&]+)/);
if (url && url.length > 1) {
url = decodeURIComponent(url[1]);
} else {
url = "http://localhost:8080/foo/bar/restapi/swagger.json";
}
And can instead be set dynamically with the properties files in some way like:
<script type="text/javascript">
$(function () {
var url = window.location.search.match(/url=([^&]+)/);
if (url && url.length > 1) {
url = decodeURIComponent(url[1]);
} else {
url = "#{beanConfig.host}" + "#{beanConfig.basePath}" + "swagger.json";
}
Please let me know if this is possible with maven swagger jersey and spring.
Thanks!
You can add a Bootstrap servlet and set the bean config in there, using values from your properties file.
For more details refer to:
https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-Jersey-2.X-Project-Setup-1.5 and Setting the Api Version with Swagger UI
To set the values in index.html dynamically, use JavaScript functions to form the url. Something like this:
url = "http://" + window.location.host + window.location.pathname + "api/swagger.json";

KSOAP2 complex request property not being seen

I'm having a problem sending a complex SOAP request to a third-party company server (server can have no changes) from an android device. I'm using KSOAP2 library and one of the properties is missing (server is giving an error which occurs when klausimai is null. Also the same namespace in my request is repeated multiple times when KSOAP2 generates the XML, since I pass a lot of PropertyInfo. My question is, why could the server see other properties (it would also give an error about the null ones) But doesn't see klausimai ?
Sample request XML for WS given by server company
?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<teiktiTemineAtaskaita xmlns="http://tempuri.org/">
<userName>apps</userName>
<password>mob2015*</password>
<uzduotiesNr>24287</uzduotiesNr>
<inspektavimas xmlns:a="http://schemas.datacontract.org/2004/07/DssisMP" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:apsilankymuObjekteSkaicius i:nil="true" />
<a:atstovai i:nil="true" />
<a:darbdavioBuveinesAdresas i:nil="true" />
<a:darbdavioGimimoData i:nil="true" />
<a:darbdavioKodas>110871120</a:darbdavioKodas>
<a:darbdavioLytis i:nil="true" />
<a:darbdavioPagrindineEkonomineVeikla i:nil="true" />
<a:darbdavioPavadinimas i:nil="true" />
<a:darbdavioPavarde i:nil="true" />
<a:darbdavioTipas i:nil="true" />
<a:darbdavioVardas i:nil="true" />
<a:inspektavimoNr>11112245</a:inspektavimoNr>
<a:inspektavimoPradzia>2015-07-23T00:00:00+03:00</a:inspektavimoPradzia>
<a:inspektavimoTiksloKodas>111</a:inspektavimoTiksloKodas>
<a:institucijos i:nil="true" />
<a:savivaldybesKodas i:nil="true" />
<a:temineAtaskaita>
<a:klausimai>
<a:TAKlausimas>
<a:atsakymas>2</a:atsakymas>
<a:eilNr>1.</a:eilNr>
<a:klausimas i:nil="true" />
<a:kodas>1000</a:kodas>
<a:komentaras i:nil="true" />
</a:TAKlausimas>
<a:TAKlausimas>
<a:atsakymas>1</a:atsakymas>
<a:eilNr>1.1.</a:eilNr>
<a:klausimas i:nil="true" />
<a:kodas>1001</a:kodas>
<a:komentaras i:nil="true" />
</a:TAKlausimas>
<a:TAKlausimas>
<a:atsakymas>3</a:atsakymas>
<a:eilNr>2.</a:eilNr>
<a:klausimas i:nil="true" />
<a:kodas>1002</a:kodas>
<a:komentaras i:nil="true" />
</a:TAKlausimas>
</a:klausimai>
<a:nr>BIOCIDŲ PRIEŽIŪRA-0050-0007</a:nr>
<a:rekomendacijos i:nil="true" />
<a:surasymoData>2015-07-23T00:00:00+03:00</a:surasymoData>
<a:tipas>9</a:tipas>
</a:temineAtaskaita>
<a:tikrintaEkonomineVeikla i:nil="true" />
<a:tikrintaNakti i:nil="true" />
<a:tikrintasObjektas i:nil="true" />
<a:tikrintoObjektoAdresas i:nil="true" />
<a:tikrintoObjektoPavadinimas i:nil="true" />
<a:vadovoAsmensKodas i:nil="true" />
<a:vadovoGimimoData i:nil="true" />
<a:vadovoLytis i:nil="true" />
<a:vadovoPareigos i:nil="true" />
<a:vadovoPavarde i:nil="true" />
<a:vadovoVardas i:nil="true" />
</inspektavimas>
</teiktiTemineAtaskaita>
</s:Body>
</s:Envelope>
My HTTPTransport request dump XML generated by KSOAP2
<?xml version="1.0" encoding="UTF-8"?>
<v:Envelope xmlns:v="http://schemas.xmlsoap.org/soap/envelope/" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<v:Header />
<v:Body>
<teiktiTemineAtaskaita xmlns="http://tempuri.org/">
<userName>apps</userName>
<password>mob2015*</password>
<uzduotiesNr>212855</uzduotiesNr>
<n0:inspektavimas xmlns:n0="http://tempuri.org/">
<inspektavimoNr i:null="true" />
<n1:inspektavimoPradzia xmlns:n1="http://schemas.datacontract.org/2004/07/DssisMP" i:type="d:dateTime">2015-07-26T21:00:00.000Z</n1:inspektavimoPradzia>
<inspektavimoTiksloKodas>1101</inspektavimoTiksloKodas>
<darbdavioKodas>120163917</darbdavioKodas>
<darbdavioPavadinimas>Statybos ir remonto uždaroji akcinė bendrovė "RISTATYBA"</darbdavioPavadinimas>
<darbdavioTipas>1</darbdavioTipas>
<darbdavioBuveinesAdresas i:null="true" />
<darbdavioPagrindineEkonomineVeikla i:null="true" />
<vadovoAsmensKodas>721788222</vadovoAsmensKodas>
<vadovoVardas>tvt</vadovoVardas>
<vadovoPavarde>gtvt</vadovoPavarde>
<vadovoPareigos>5</vadovoPareigos>
<n2:vadovoGimimoDiena xmlns:n2="http://schemas.datacontract.org/2004/07/DssisMP" i:type="d:dateTime">2015-07-22T21:00:00.000Z</n2:vadovoGimimoDiena>
<vadovoLytis>0</vadovoLytis>
<tikrintasObjektas>3</tikrintasObjektas>
<tikrintoObjektoPavadinimas i:null="true" />
<tikrintoObjektoAdresas i:null="true" />
<savivaldybesKodas>46</savivaldybesKodas>
<tikrintaEkonomineVeikla i:null="true" />
<apsilankymuObjekteSkaicius i:null="true" />
<tikrintaNakti>0</tikrintaNakti>
<n3:temineAtaskaita xmlns:n3="http://schemas.datacontract.org/2004/07/DssisMP">
<n3:nr i:null="true" />
<n3:tipas i:type="d:int">18</n3:tipas>
<n3:surasymoData i:type="d:dateTime">2015-07-22T09:53:59.822Z</n3:surasymoData>
<n3:klausimai>
<n3:TAKlausimas>
<n3:kodas i:type="d:string">3183</n3:kodas>
<n3:eilNr i:type="d:string">1.1.</n3:eilNr>
<n3:klausimas i:null="true" />
<n3:atsakymas i:type="d:int">1</n3:atsakymas>
<n3:komentaras i:null="true" />
</n3:TAKlausimas>
<n3:TAKlausimas>
<n3:kodas i:type="d:string">3184</n3:kodas>
<n3:eilNr i:type="d:string">1.1.1.</n3:eilNr>
<n3:klausimas i:null="true" />
<n3:atsakymas i:type="d:int">2</n3:atsakymas>
<n3:komentaras i:null="true" />
</n3:TAKlausimas>
</n3:klausimai>
<n3:rekomendacijos i:type="d:string">Gyghugyb</n3:rekomendacijos>
</n3:temineAtaskaita>
</n0:inspektavimas>
</teiktiTemineAtaskaita>
</v:Body>
</v:Envelope>
My Java code for request creation
List<Questionnaire> questionnaireList = new ArrayList<>();
String METHOD_NAME = "teiktiTemineAtaskaita";
String SOAP_ACTION = "http://tempuri.org/IDssisMP/" + METHOD_NAME;
String A_NAMESPACE = "http://schemas.datacontract.org/2004/07/DssisMP";
String I_NAMESPACE = "http://www.w3.org/2001/XMLSchema-instance";
String NAMESPACE = "http://tempuri.org/";
String URL = "http://dvs/dssis_ws_test/DssisMP.svc";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
UserInfo userInfo = UserInfo.getAll().get(0);
request.addProperty("userName", userInfo.getUserName());
request.addProperty("password", userInfo.getPassword());
request.addProperty("uzduotiesNr", taskId);
CompanyInfo ci = CompanyInfo.getByTaskCompanyId(taskId, companyId);
if (ci == null) {
sendResponseFailed(responseHandler);
//starter validation
} else {
//adding all the non-complex properties
SoapObject inspektavimas = new SoapObject(NAMESPACE, "inspektavimas");
if (ci.getInspectationId() != 0) {
inspektavimas.addProperty("inspektavimoNr", ci.getInspectationId());
} else {
inspektavimas.addProperty("inspektavimoNr", null);
}
if (ci.getDateInspectation() != null) {
PropertyInfo p = new PropertyInfo();
p.setNamespace(A_NAMESPACE);
p.setName("inspektavimoPradzia");
p.setType(MarshalDate.class);
p.setValue(ci.getDateInspectation());
inspektavimas.addProperty(p);
} else {
sendResponseFailed(responseHandler);
}
if (ci.getGoalId() != 0) {
inspektavimas.addProperty("inspektavimoTiksloKodas", ci.getGoalId());
} else {
sendResponseFailed(responseHandler);
}
if (ci.getObjectName() != null) {
inspektavimas.addProperty("tikrintoObjektoPavadinimas", ci.getObjectName());
} else { inspektavimas.addProperty("tikrintoObjektoPavadinimas", null);
}
if (ci.getObjectAddress() != null) {
inspektavimas.addProperty("tikrintoObjektoAdresas", ci.getObjectAddress());
} else {
inspektavimas.addProperty("tikrintoObjektoAdresas", null);
}
//...
SoapObject soTemineAtaskaita = new SoapObject(A_NAMESPACE, "temineAtaskaita");
TemineAtaskaita temineAtaskaita = TemineAtaskaita.getByTaskCompanyThemeCode(taskId, companyId, themeCode);
PropertyInfo p = new PropertyInfo();
p.setNamespace(A_NAMESPACE);
p.setName("nr");
if (temineAtaskaita != null && temineAtaskaita.getAtaskaitosNr() != null) {
p.setValue(temineAtaskaita.getAtaskaitosNr());
soTemineAtaskaita.addProperty(p);
} else {
p.setValue(null);
soTemineAtaskaita.addProperty(p);
}
Theme theme = Theme.getByTaskCompanyThemeCode(taskId, companyId, themeCode);
if (theme != null) {
PropertyInfo pType = new PropertyInfo();
pType.setNamespace(A_NAMESPACE);
pType.setName("tipas");
pType.setValue(theme.getThemeCode());
soTemineAtaskaita.addProperty(pType);
PropertyInfo pDate = new PropertyInfo();
pDate.setNamespace(A_NAMESPACE);
pDate.setName("surasymoData");
pDate.setValue(theme.getDate());
pDate.setType(MarshalDate.class);
soTemineAtaskaita.addProperty(pDate);
}
//adding klausimai property which is not seen
SoapObject klausimai = new SoapObject(A_NAMESPACE, "klausimai");
List <Answer> answers = Answer.getByTaskCompanyThemeCode(taskId, companyId, themeCode);
for (Answer answer : answers) {
SoapObject soTAKlausimas = new SoapObject(A_NAMESPACE, "TAKlausimas");
PropertyInfo pCode = new PropertyInfo();
pCode.setNamespace(A_NAMESPACE);
pCode.setName("kodas");
pCode.setValue(answer.getQuestionId());
soTAKlausimas.addProperty(pCode);
Questionnaire questionnaire = Questionnaire.getById(answer.getQuestionId()).get(0);
PropertyInfo pEilNr = new PropertyInfo();
pEilNr.setNamespace(A_NAMESPACE);
pEilNr.setName("eilNr");
pEilNr.setValue(questionnaire.getPosition());
soTAKlausimas.addProperty(pEilNr);
PropertyInfo pKlausimas = new PropertyInfo();
pKlausimas.setNamespace(A_NAMESPACE);
pKlausimas.setName("klausimas");
pKlausimas.setValue(null);
soTAKlausimas.addProperty(pKlausimas);
PropertyInfo pAnswer = new PropertyInfo();
pAnswer.setNamespace(A_NAMESPACE);
pAnswer.setName("atsakymas");
pAnswer.setValue(questionnaire.getPosition());
if (answer.getAnswer() == QuestionItem.STATUS.YES.ordinal())
pAnswer.setValue(1);
else if (answer.getAnswer() == QuestionItem.STATUS.NO.ordinal())
pAnswer.setValue(2);
else if (answer.getAnswer() == QuestionItem.STATUS.UNKNOWN.ordinal())
pAnswer.setValue(3);
else if (answer.getAnswer() == QuestionItem.STATUS.PLAIN.ordinal())
pAnswer.setValue(null);
soTAKlausimas.addProperty(pAnswer);
PropertyInfo pComment = new PropertyInfo();
pComment.setNamespace(A_NAMESPACE);
pComment.setName("komentaras");
if (answer.getComment() != null && !answer.getComment().replace(" ", "").replace(" ", "").isEmpty()) {
pComment.setValue(answer.getComment());
} else {
pComment.setValue(null);
}
soTAKlausimas.addProperty(pComment);
klausimai.addSoapObject(soTAKlausimas);
}
soTemineAtaskaita.addSoapObject(klausimai);
if (theme != null) {
PropertyInfo pSuggestions = new PropertyInfo();
pSuggestions.setNamespace(A_NAMESPACE);
pSuggestions.setName("rekomendacijos");
if (theme.getSuggestions() != null && !theme.getSuggestions().replace(" ", "").replace(" ", "").isEmpty()) {
pSuggestions.setValue(theme.getSuggestions());
} else {
pSuggestions.setValue(null);
}
soTemineAtaskaita.addProperty(pSuggestions);
}
inspektavimas.addSoapObject(soTemineAtaskaita);
request.addSoapObject(inspektavimas);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setAddAdornments(false);
envelope.implicitTypes = true;
envelope.setOutputSoapObject(request);
new MarshalDate().register(envelope);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, 45 * 1000);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
final SoapObject response = (SoapObject) envelope.getResponse();
****//...****
}
Well as it turns out, I managed to work together with server company, and the problem was ordering inside temineAtaskaita tag. klausimai property should have been the first property to give, althought outside in inspektavimas tag, ordering is not important and that is confusing.
Other problem now occurs is that, everything inside inspektavimas is null because the properties have no namespace. And adding them as PropertyInfo gives a lot of repeated namespaces (n0, n1,...,n20) in XML request Dump and server doesn't handle it. But this is another problem.

how to delete a scenario in atg through API methods

I have created a scenario by creating a myScenario.sdl in my local config folder /atg/registry/data/scenarios/myScenario.sdl
myScenario.sdl
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE process SYSTEM "dynamosystemresource:/atg/dtds/pdl/pdl_1.0.dtd">
<process author="admin" creation-time="1413804041263" enabled="false" last-modified-by="admin" modification-time="1413804191188">
<segment migrate-subjects="true">
<segment-name>ItemAddedToOrder</segment-name>
<!--================================-->
<!--== Item added to order Quantity with fraction is defined -->
<!--================================-->
<event id="1">
<event-name>atg.commerce.order.ItemAddedToOrder</event-name>
<filter construct="event-property-filter" operator="isNotNull">
<event-property construct="event-property">
<property-name>quantityWithFraction</property-name>
</event-property>
</filter>
</event>
<!--================================-->
<!--== Log a message message: Quantity With Fraction is Defines logTriggeringEvent: true -->
<!--================================-->
<action id="2">
<action-name>Log a message</action-name>
<action-param name="message">
<constant>Quantity With Fraction is Defines</constant>
</action-param>
<action-param name="logTriggeringEvent">
<constant type="java.lang.Boolean">true</constant>
</action-param>
</action>
</segment>
</process>
And enabled the scenario:
Registry scenarioRegistry = scenarioManager.getScenarioRegistry();
byte[] data = (byte[]) scenarioRegistry.getItem(pScenarioPath);
String xml = null;
if (data != null) {
xml = new String(data, "UTF-8");
} else {
Assert.fail("No scenario is existed to enable/disable");
}
String updatedXml;
if (scenarioState && xml != null) {
updatedXml = xml.replaceAll("enabled=\"false\"", "enabled=\"true\"");
} else {
updatedXml = xml.replaceAll("enabled=\"true\"", "enabled=\"false\"");
}
scenarioRegistry.putItem(pScenarioPath, updatedXml.getBytes("UTF-8"));
Now with this above written code, I can both disable or enable the scenario by changing the state as false and true respectively. But I want to delete the scenario(please remember, my requirement is DELETE not DISABLE SCENARIO). I know using scenarioManager.updateScenario() deleted the scenario. Is my understanding right?
One more thing, I know I can delete the scenario directly from ACC. But I need to code via code not manually from ACC.
Please share your thoughts!
Did you try scenarioRegistry.removeItem(path);

Full Serialization in Worfklow 4.0

I'm trying to serialize a workflow (using C#'s workflow 4.0) to retrieve the full workflow XAML and have hit a wall.
I've got an activity (myActivity) that I've created. The contents of the xaml file that describes this activity is:
<Activity mc:Ignorable="sap" x:Class="atest.MySuite" >
<Sequence sap:VirtualizedContainerService.HintSize="222,501">
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<Sequence DisplayName="First Sequence" sap:VirtualizedContainerService.HintSize="200,99">
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
</Sequence>
<Sequence DisplayName="Second Sequence" sap:VirtualizedContainerService.HintSize="200,99">
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
</Sequence>
<Sequence DisplayName="Third Sequence" sap:VirtualizedContainerService.HintSize="200,99">
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
</Sequence>
</Sequence>
</Activity>
Note that the sub sequences show up in the XAML.
When I go to serialize this activity, I use the code I found on MSDN:
using (var sw = new StreamWriter(somePath))
{
sw.Write(a.Log.ToString());
StringBuilder sb = new StringBuilder();
StringWriter tw = new StringWriter(sb);
XamlWriter xw = ActivityXamlServices.CreateBuilderWriter(new XamlXmlWriter(tw, new XamlSchemaContext()));
XamlServices.Save(xw, myActivity);
string serializedActivity = sb.ToString();
}
But the string that comes out the other end is simply:
<?xml version="1.0" encoding="utf-16"?><MySuite xmlns="clr-namespace:atest;assembly=Wtf.Automation.atest" xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation" />
I've poked around on MSDN and on stackoverflow, but haven't found a way to retrive the full XAML of a custom activity (given an instance of that activity) like what I've described in my xaml file, not just this truncated version.
Does anyone know if there's a way? Code samples and/or pointers would be greatly appreciated.
Thanks!
I believe your issue is that ActivityXamlServices.CreateBuilderWriter works with ActivityBuilder instances. Try
XamlServices.Save(xw, new ActivityBuilder { Implementation = myActivity });
Serialize:
public static string ActivityToXaml(Activity activity)
{
StringBuilder xaml = new StringBuilder();
using (XmlWriter xmlWriter = XmlWriter.Create(xaml, new XmlWriterSettings { Indent = true, OmitXmlDeclaration = false, }))
using (XamlWriter xamlWriter = new XamlXmlWriter(xmlWriter, new XamlSchemaContext()))
using (XamlWriter xamlServicesWriter = ActivityXamlServices.CreateBuilderWriter(xamlWriter))
{
XamlServices.Save(xamlServicesWriter, new ActivityBuilder { Implementation = activity });
}
return xaml.ToString();
}
Deserialize:
public static Activity ActivityFromXaml(string activityXaml)
{
using (var reader = new StringReader(activityXaml))
{
return ActivityXamlServices.Load(reader);
}
}