ActiveSync Sync message not supporting all properties - activesync

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.

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.

Posting empty payload - inbound-gateway

I have the following config.
<int-http:inbound-gateway request-channel="RequestChannel"
path="/contractName/-/{resource}/**"
supported-methods="POST,PUT,PATCH,DELETE"
request-payload-type="java.util.LinkedHashMap"
error-channel="ErrorChannel"
id="InboundGateway" >
</int-http:inbound-gateway>
When posting json to the server the payload is transformed to a LinkedHashMap as expected, however in certain cases I need to post a request that has no payload, when posting an empty payload the conversion fails with bad request. Just wondering if there is a simple/quick workaround in the config where I could tell it to skip the conversion if payload is empty. Currently I need to post "{}" for it to work.
Thanks a lot.
The only one way I see is about coding some custom HttpMessageConverter. And I guess that you just need to override a bit MappingJackson2HttpMessageConverter to populate an empty Map for empty request body.

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.

Gmail IMAP via php ouath2 Zend_Mail_Protocol_Imap - getting the X-GM-THRID

I'm accessing GMail via IMAP using OAuth2 authentication and Zend_Mail_Protocol_Imap.
It all works great.
What I need to do is present emails in thread form just like the GMail interface. Google make this really easy because they have an X-GM-THRID header that links a conversation with a 64-bit unsigned integer.
My problem is: when presented with a single email, how do I find out what X-GM-THRID it belongs to?
First off Google says that there is a server extension X-GM-EXT-1 which is active. You can check it is there using the CAPABILITY command (and I have).
All the information suggests that if this is active then the X-GM-THRID will simply be returned as a header, but it isn't.
Perhaps I need to ask Google to return it via the fetch command. Google does describe a simple fetch process here:
https://developers.google.com/google-apps/gmail/imap_extensions
My code is sending TAG5 FETCH 3673 (FLAGS RFC822.HEADER X-GM-THRID) but the headers do not include an entry for X-GM-THRID.
I've even simplified it to TAG6 FETCH 3673 (X-GM-THRID) to be exactly as described in the google example. In this case no headers are returned.
I'm not massively familiar with IMAP commands and I'm not sure if Zend_Mail_Protocol_Imap is abstracting some handling which means this header is being removed.
But I do know that this is driving me mad.
Am I missing something? Is it not a header?
Okay, so it looks like it is not a header. It is an attribute in the IMAP command and response.
The standard fetch command sent by Zend_Mail_Protocol_Imap is "TAG5 FETCH 3673 (FLAGS RFC822.HEADER)"
The code that handles the response only expects to be dealing with 'FLAGS' and 'RFC822.HEADER'. It passes this information to a Zend_Mail_Message object which extends Zend_Mail_Part.
Zend_Mail_Part parses information about flag. It also parses the header.
The additional 'X-GM-THRID' attribute that I added does actually get a response. but since it is not passed back to Zend_Mail_Message there is no way for me to use it. It gets lost in the ether (at around line 171 of Zend_Mail_Storage_Imap in my Zend Library to be exact).
So I've hacked the core... Zend_Mail_Storage_Imap::getMessage now expects $data['X-GM-THRID'] and passes it to the constructor Zend_Mail_Part. And I now have a method Zend_Mail_Part::getXGmThrid which solves all my problems. I'll obviously refactor them into my own classes extending Zend_Mail_Storage_Imap and Zend_Mail_Part in the not too distant... but for now I know this works.

Resources