How to get the new message id after a sync/delete request - activesync

When a message is deleted, my application will send a Sync request with a Delete command within the Commands element. The application also sets the DeletesAsMoves option so that the message is not deleted permanently, but instead moved to the Deleted Items folder. This all works great. However, my challenge is to now move the message back out of the Deleted Items folder. This is failing because once the message is deleted in the Sync command, its message id changes.
In the MoveItems request, the new message id comes back in the response. Is there a similar way for me to track the changed message id after a Sync/Delete command?
Below is the request:
<?xml version="1.0"?>
<Sync>
<Collections>
<Collection>
<Class>Email</Class>
<SyncKey>{F8654B17-4BF2-439F-9875-22EDDE1138FF}154</SyncKey>
<CollectionId>03cd385d379ece4988b9c88834382ea7-68cc1f</CollectionId>
<DeletesAsMoves/>
<GetChanges/>
<WindowSize>50</WindowSize>
<Options>
<FilterType>2</FilterType>
<Truncation>7</Truncation>
</Options>
<Commands>
<Delete>
<ServerId>3:225</ServerId>
</Delete>
</Commands>
</Collection>
</Collections>
</Sync>
And the response:
<?xml version="1.0"?>
<Sync>
<Collections>
<Collection>
<Class>Email</Class>
<SyncKey>{F8654B17-4BF2-439F-9875-22EDDE1138FF}155</SyncKey>
<CollectionId>03cd385d379ece4988b9c88834382ea7-68cc1f</CollectionId>
<Status>1</Status>
</Collection>
</Collections>
</Sync>
The response indicates that the delete command was successful, however the message is now in another folder with an entirely new ServerId. I would like to be able to know what that new ServerId is.

Related

How to create malformed XML (SOAP request) in nodejs

I have been given a task to generate malformed SOAP Request and checking for what kind of error response I receive.
For example:
const payload = `
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:test="urn:TEST"
>
<soap:Body>
<test:GetOperatingDataValues
xmlns:test="urn:TEST"
>
<test:ListId>1</test:ListId>
</test:GetOperatingDataValues>
</soap:Body>
</soap:Envelope>`
Now, if I send the above request body to the backend server like :
const result = axios.post("backendServer", payload)
console.log(result) will give the response from backend (in this case, response from GetOperatingDataValues function for listId 1)
Now, I have to modify that payload in different ways like, removing the end tag, different opening and closing tag names, deleting '<' from any tag, or removing '/' from end tags, different method name, etc and send that payload and check for the error response.
Is there any way to modify the correctly formed xml to malformed xml (in node js).
I have gone through different packages such as xml2js, fast-xml-parser. But these packages just form the correct xml.
Any help would be highly appreciated.
I would have thought it fairly obvious that to create a non-XML file, you don't want to use an XML tool. Just treat the XML as a character string and apply a regular expression, for example replacing </ by <.

ServiceResponse Result is always null (JAXB, KIE Workbench & KIE Server 6.5.0)

I have a project setup in KIE Workbench, version 6.5.0 and a KIE execution server 6.5.0 running, all on the same local Wildfly 10. It is working fine.
I have a simple rule that is being executed in a stateless KieSession, no process or whatsoever. I expect the rule to validate basic information and to add information about the fired validations to a global variable. In the example I am testing I just modify a global variable to see if it works, but for some reason I never get a result from the service, which I expect to have at least something.
This is the JAXB request I send:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<batch-execution lookup="kieSessionStateless">
<insert disconnected="false" entry-point="DEFAULT" return-object="false" out-identifier="myorganization.myproject.bom.MyObject">
<object xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="myObject">
<myDescription>description</myDescription>
<myID>0</myID>
</object>
</insert>
<set-global out-identifier="globalList" identifier="globalList">
<object xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaxbListWrapper">
<type>LIST</type>
</object>
</set-global>
<get-objects out-identifier="globalList"/>
<fire-all-rules max="-1"/>
</batch-execution>
The rule that is executed is quite simple:
rule "MY FIRST RULE"
when
myorganization.myproject.bom.MyObject( myID == 0 )
then
myorganization.myproject.bom.GlobalResponses globalResponses = new myorganization.myproject.bom.GlobalResponses();
globalResponses.setRuleName("MY FIRST RULE");
globalResponses.setRuleResponse("MY ID IS 0");
globalList.add(globalResponses);
System.out.println("MY ID IS 0");
end
And in the Wildfly console I see the line printed without any additional information (like a stacktrace of an error), so I conclude all is working well:
13:04:36,315 INFO [stdout] (default task-39) MY ID IS 0
But I always get the same response: it indicates that the "process" has terminated correctly (so it seems at first sight) and therefore I am expecting that Result has something (an empty xml response, an xml response with some data in it, ...):
System.out.println("Message: "+response.getMsg());
System.out.println("Result: "+response.getResult());
System.out.println("Type: "+response.getType());
Message: Container KieContainer successfully called.
Result: null
Type: SUCCESS
Response: ServiceResponse[SUCCESS, msg='Container KieContainer successfully called.']
The client is called with KieServicesClient:
KieServicesConfiguration config = KieServicesFactory.
newRestConfiguration(urlKieServer,
name,
password);
config.setMarshallingFormat(MarshallingFormat.JAXB);
KieServicesClient client = KieServicesFactory.newKieServicesClient(config);
JAXBContext jaxbContext = DroolsJaxbHelperProviderImpl.createDroolsJaxbContext(classNames, null);
Marshaller marshaller = jaxbContext.createMarshaller();
StringWriter xml = new StringWriter();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(command, System.out);
marshaller.marshal(command, xml);
ServiceResponse<String> response = client.executeCommands("instances/"+containerName, xml.toString());
I am missing something but I really do not know what.
All the related projects are on GitHub. Since I cannot post more than two links, I will add the direct links in a comment.
This question is also on:
Drools User group
I was able to complete the life cycle and send a valid request and obtain a valid answer. Part of my problem was the code used to construct the XML. The best way to construct a valid JAXB request is by using the API provided by KIE, an example can be found
here.
Anyway interested in establishing connection to a KIE Server 6.5.0 with a generic client project can consult the code on my GitHub.

Sending my app a command in Cortana just searches Bing for my query string

I am writing a Cortana "background app", and trying to call it from Cortana. Here is my VCD file:
<?xml version="1.0" encoding="utf-8" ?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">
<CommandSet xml:lang="en-us" Name="MinimalCommandSet_en-us">
<AppName>Mini</AppName>
<Example>test foo</Example>
<Command Name="TestCommand">
<Example>test foo</Example>
<ListenFor>test foo</ListenFor>
<Feedback> Testing... </Feedback>
<VoiceCommandService Target="VoiceCommandService"/>
</Command>
</CommandSet>
</VoiceCommands>
I go and type "Mini test foo" in Cortana, but it just searches Bing for "Mini test foo". How can I avoid that?
You might not be taking a "deferral", which signals to the OS that your app shouldn't be terminated just yet. Remember to call taskInstance.getDeferral(), and hold on to the resulting object until your app finishes handling the Cortana request.

Mule - How to send SOAP Web Service Request?

Hi i am doing simple POC in mule.
I have a web service and i want to make it's Client.
It is SOAP web service and i want to send request to it but i am not getting wayout. Please give me some idea.
Following is code:
MULE:
<cxf:configuration name="CXF_Configuration" enableMuleSoapHeaders="true" initializeStaticBusInstance="true" doc:name="CXF Configuration"/>
<flow name="prjvm1" doc:name="prjvm1">
<http:inbound-endpoint address="http://localhost:5678/httpHello" contentType="application/x-www-form-urlencoded" doc:name="HTTP">
<http:body-to-parameter-map-transformer />
</http:inbound-endpoint>
<!-- This logger is just set to show the message accepted from the request -->
<logger level="INFO" message="#[payload]" doc:name="Logger"/>
<cxf:jaxws-client doc:name="VimService"
wsdlLocation="file:/C:/Users/gugla/MuleStudio/workspace/prjvm/bin/service/vService.wsdl"
operation="retrieveServiceContent"
clientClass="com.esxclient.VService"
port="VimPort">
<cxf:jaxb-databinding/>
</cxf:jaxws-client>
<outbound-endpoint address="http://localhost:8080/gep-sped/servicos/ServicoDeCadastroEAgendamento"
doc:name="Generic"
exchange-pattern="request-response"/>
<echo-component doc:name="Echo"/>
</flow>
I am getting exception, but operation is there in WSDL
Message : No such operation: retrieveServiceContent. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message payload is of type: ManagedObjectReference
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. No such operation: retrieveServiceContent (java.lang.Exception)
org.mule.module.cxf.CxfOutboundMessageProcessor:282 (null)
2. No such operation: retrieveServiceContent. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message payload is of type: ManagedObjectReference (org.mule.api.transport.DispatchException)
org.mule.module.cxf.CxfOutboundMessageProcessor:150 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transport/DispatchException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.Exception: No such operation: retrieveServiceContent
at org.mule.module.cxf.CxfOutboundMessageProcessor.getOperation(CxfOutboundMessageProcessor.java:282)
at org.mule.module.cxf.CxfOutboundMessageProcessor.getMethodFromOperation(CxfOutboundMessageProcessor.java:322)
at org.mule.module.cxf.CxfOutboundMessageProcessor.getMethod(CxfOutboundMessageProcessor.java:259)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
Following is WSDL in operation: I am confused and around 4 days on it as i am new to mule.
<operation name="RetrieveServiceContent">
<input message="vim2:RetrieveServiceContentRequestMsg" />
<output message="vim2:RetrieveServiceContentResponseMsg" />
<fault name="RuntimeFault" message="vim2:RuntimeFaultFaultMsg"/>
</operation>
There are a couple of ways to do this. I prefer to NOT us the way MuleStudio wants you to do it since I never really got that to work. Basically, whenever I create a webservice client my mule-config looks something like this:
<custom-transformer class="nl.thorax.someprogram.transformers.SomeRequestTransformer
<https:outbound-endpoint ref="someEndpoint" >
<cxf:jaxws-client
clientClass="nl.thorax.someprogram.someclass"
wsdlLocation="http://somedomain?wsdl
port="somePort"
operation="someOperation"/>
</https:outbound-endpoint>
<custom-transformer class="nl.thorax.someprogram.transformers.SomeResponseTransformer
Where:
SomeRequestTransformer: a transformer to create your request.
someEndpoint: some endpoint defined in your MuleConfig. In my example, this is https but it could also be plain http.
someclass: Important! This is your client class. It can be generated from a WSDL by free tools like Apache's WSDL2Java. Google is your friend on this.
somePort: The port in your webservice to use. It can usually be found in the WSDL itself or in the client class you generated. The port more or less specifies what operations you can use.
someOperation: The operation you want to use. Make sure it is typed EXACTLY the same as it's definition in the client class. Wrong use of cApItAlS will cause errors!
SomeResponseTransformer: a transformer to do something with your response.
Now, the way I configure the call (and parse the response for that matter) is to use POJOs. My first transformer, the SomeRequestTransformer (based on the AbstractMessageTransformer in the Mule library) has a bit of code looking like this:
public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException
{
RequestObject request = new RequestObject();
request.setText("Hello!");
message.setPayload(request);
return message;
}
I create the request, set the variables and return it to Mule. The RequestObject is a class generated by WSDL2Java and corresponds to some operation in the WSDL. Parsing the response works pretty much the same way.
Now I know from experience that a lot of webservices do not quite work in the same way. Try to implement my example yourself. If that doesn't work, please provide your Mule-Config and any and all Java classes you may be using.
EDIT:
I've created an example of my method that actually works. The files can be downloaded at our website. Please see the comments in the files. You have to manually create the Mule project, of course.
Points of note for the example:
The XML-representation of the Mule-config can be found in the 'resources' folder in the archive.
The 'nl.example.example' folder contains all the generated JAX-WS files.
The WSDL location in Mule-config has to be changed since it contains an absolute path.
The example creates an endpoint at http://localhost:8088 for you to call. The flow contains a transformer which creates an example call using pre-defined parameters. Then it tries to connect to the webservice. I've used the default address used by SOAPUI when you create a mock service, but this could of course be changed into anything you want. The webservice (supposedly) returns something which is echoed into the user's browser.
In this example, the parameters are actually Strings, since the WSDL-request doesn't contain anything. To figure out what object to pass to the cxf:jaxws-client look at the operation definition which can be found in the Port definition in your generated files.

ActiveSync Sync message not supporting all properties

I'm implementing an ActiveSync Java client. I can already communicate with the server and perform the protocol sequence to Sync emails, as defined in the documentation.
However, when I try and send a Sync command it seems I can only use a subset of the available commands in the specification. When I use certain property tags in the Sync XML message I receive a Status 4 ('Protocol Error') code, even though these should be valid according to the specification.
When I use only the GetChanges property I do get a proper response, however I'd like to be able to specify how many items to return etc.
I've included the XML snippet that I'm sending: the commented out lines are lines that were attempted but caused a Status 4.
<?xml version="1.0" ?>
<Sync xmlns="AirSync:">
<Collections>
<Collection>
<Class>Email</Class>
<SyncKey>{23423972324}</SyncKey>
<CollectionId>{23423sdfsdfsdfsf972324}</CollectionId>
<GetChanges/>
<!--<GetChanges>0</GetChanges>-->
<!--<WindowSize>512</WindowSize>-->
<!--<Options>-->
<!--<Class>Email</Class>-->
<!--<FilterType>3</FilterType>-->
<!--<MaxItems>10</MaxItems>-->
<!--</Options>-->
<!--<Commands>-->
<!-- <Fetch>-->
<!-- <ServerId>1:323</ServerId>-->
<!-- </Fetch>-->
<!--</Commands>-->
</Collection>
</Collections>
<!--<WindowSize>512</WindowSize>-->
</Sync>
Is there any reason why these properties shouldn't be supported? Or is there something I've left out of the message?
The GetOptions command for the server returns the following (truncated):
Server: Microsoft-IIS/6.0,
X-Powered-By: ASP.NET,
Pragma: no-cache,
Public: OPTIONS, POST, Allow: OPTIONS, POST,
MS-Server-ActiveSync: 6.5.7653.19,
MS-ASProtocolVersions: 1.0,2.0,2.1,2.5,
MS-ASProtocolCommands:Sync,SendMail,SmartForward,SmartReply,GetAttachment,GetHierarchy,CreateCollection,DeleteCollection,MoveCollection,FolderSync,FolderCreate,FolderDelete,FolderUpdate,MoveItems,GetItemEstimate,MeetingResponse,ResolveRecipients,ValidateCert,Provision,Search,Notify,Ping
It turns out that the WBXML encode/decoder I was using wasn't working correctly. I figured this out by comparing the byte code generated by two different WBXML encoders and saw a difference. The encoder I was using didn't process empty elements like properly. I fixed it and now the server acts as expected.

Resources