In my scenario UAS receives two Via headers. Using [last_Via:] it replies 183, 200 OK for subsequent PRACK but for 180 Ringing and 200 OK for the original INVITE it needs those two Via headers. How do I store them in a variable so that I can use here ?
Approach that I goggled:
<ereg regexp="[Vv][Ii][Aa][ ]*:[ ](.*)$" search_in="msg" check_it="true" assign_to="1"/>
$1= It has both the Via headers but also the rest of the message including SDP.
<nop>
<action>
<assignstr assign_to="1" value="[last_Via:]" />
</action>
</nop>
Otherwise, using your regex approach, you should be able to consume everything until the next CR LF characters with something like: "[^\r\n]*\r\n".
Do this right before your <send>:
<nop>
<action>
<assignstr assign_to="lvia" value="[last_Via:]" />
<ereg regexp="[Vv][Ii][Aa]: (.*), (.*)" search_in="var" variable="lvia" assign_to="5,6,7"/>
<exec command="echo Via1: [$5], via2: [$6], via3: [$7]"/>
</action>
</nop>
Then use the values store in variables 6 and 7.
This works for 2 Vias, you may need to adapt if you need to handle more.
Related
I make a callout that response is like this:
<ns:return>
<ax2446:contract>
<ax2446:array>variable1</ax2446:array>
<ax2446:array>value1</ax2446:array>
</ax2446:contract>
<ax2446:contract>
<ax2446:array>variable2</ax2446:array>
<ax2446:array>value2</ax2446:array>
</ax2446:contract>
<ax2446:contract>
<ax2446:array>variable3</ax2446:array>
<ax2446:array>value3</ax2446:array>
</ax2446:contract>
<ax2446:documents>
<ax2446:array>attachement1</ax2446:array>
<ax2446:array>D:\AUTO\filename-1.txt</ax2446:array>
</ax2446:documents>
<ax2446:documents>
<ax2446:array>attachment2</ax2446:array>
<ax2446:array>D:\AUTO\filename-2.txt</ax2446:array>
</ax2446:documents>
<ax2446:process>TEST_PROCESS</ax2446:modulo>
</ns:return>
i want to create a new payload with contracts values (the number can change)
<p:instantiateProcess xmlns:p="http://carbon.sample">
<xs:process xmlns:xs="http://carbon.sample">TEST_PROCESS</xs:process>
<ns:contract xmlns:ns="http://carbon.sample">
<xs:array xmlns:xs="http://carbon.sample">variable1</xs:array>
<xs:array xmlns:xs="http://carbon.sample">value1</xs:array>
</ns:contract>
<ns:contract xmlns:ns="http://carbon.sample">
<xs:array xmlns:xs="http://carbon.sample">variable2</xs:array>
<xs:array xmlns:xs="http://carbon.sample">value2</xs:array>
</ns:contract>
<ns:contract xmlns:ns="http://carbon.sample">
<xs:array xmlns:xs="http://carbon.sample">variable3</xs:array>
<xs:array xmlns:xs="http://carbon.sample">value3</xs:array>
</ns:contract>
</p:instantiateProcess>ยด
i get all the contract by:
<property
expression="//ns:return/ax2431:contract"
name="contract" scope="default" type="STRING"
xmlns:ax2431="http://vo.carbon.sample/xsd" xmlns:ns="http://carbon.sample"/>
I try with payloadfactory, by i dont know how to enrinch (if it is correct to use this mediator) the message to make a call to a new web service. or if i have to make the payload with an iterator...
can anybody help me? thanks
You appear to have a few options:
Use a Payload factory
Use XSLT
Use Script meditator
I suspect all 3 could get the result you are after. It is a question of which you feel most comfortable with. Personally, I would head down the Script mediator route, mapping between two XML payloads, here is an example: http://nimbleapi.com/2016/05/javascript-mapping-between-xml-payloads/
Once you get the contract list you can use iterate mediator to iterate the list and inside the iterator you can add payloadFactory mediator to create payload, then, same time you can send the modified payload to a new web service.
Please find the following links which explain in detail how you use iterate mediator.
http://sparkletechthoughts.blogspot.com/2012/08/how-to-use-iterator-mediator-to-iterate.html
In addition to XSLT or Script meditators, ForEach mediator is also an option.
https://docs.wso2.com/display/ESB490/ForEach+Mediator
We have integrated Fedex API in a ruby on rails application .
We need nearest drop off locations . We want to filter locations by DANGEROUS_GOODS_SERVICES.
We have checked the fedex locationService pdf file and we found the following xml request format that we are requesting .
Request
<SearchLocationsRequest xmlns="http://fedex.com/ws/locs/v3">
<UserCredential>
<Key>XXXXXXXXXXXX</Key>
<Password>XXXXXXXXXXXXXX</Password>
</UserCredential>
<WebAuthenticationDetail/>
<ClientDetail>
<AccountNumber>XXXXXXXXXX</AccountNumber>
<MeterNumber>XXXXXXXXX</MeterNumber>
<Region>us</Region>
</ClientDetail>
<Version>
<ServiceId>locs</ServiceId>
<Major>1</Major>
<Intermediate>0</Intermediate>
<Minor>0</Minor>
</Version>
<EffectiveDate>2016-04-13</EffectiveDate>
<LocationsSearchCriterion>ADDRESS</LocationsSearchCriterion>
<Address>
<StreetLines>811 E 1950 N</StreetLines>
<City>Spanish Fork</City>
<StateOrProvinceCode/>
<PostalCode>84660</PostalCode>
<UrbanizationCode/>
<CountryCode>US</CountryCode>
<Residential>0</Residential>
</Address>
<PhoneNumber/>
<GeographicCoordinates/>
<MultipleMatchesAction>RETURN_ALL</MultipleMatchesAction>
<SortDetail>
<Criterion>DISTANCE</Criterion>
<Order>LOWEST_TO_HIGHEST</Order>
</SortDetail>
<Constraints>
<RadiusDistance>
<Value>10.0</Value>
<Units>KM</Units>
</RadiusDistance>
</Constraints>
</SearchLocationsRequest>
Response
{"SearchLocationsReply"=>{"HighestSeverity"=>"ERROR", "Notifications"=>{"Severity"=>"ERROR", "Source"=>"prof", "Code"=>"1000", "Message"=>"Authentication Failed"}, "Version"=>{"ServiceId"=>"locs", "Major"=>"1", "Intermediate"=>"0", "Minor"=>"0"}}}
Authentication failed message we are getting, while the same credentails are working for getting rates and labels.
I had the same problem than you, after several hours I discovered that the problem was some invisible characteres copied from the fedex email confirmation. In a text editor was possible to see them:
Be careful with the strange characters at the begin and at the end of the key/passwords.
The problem was solved after strip those characters.
I would like to write a regular expression that catch Encoded Words parts from email MIME message string (eml). for example, this is part of email:
<div dir=3D"ltr"><br clear=3D"all"><div><div dir=3D"ltr"><div style=3D"dire=
ction:rtl">-------------</div><div style=3D"direction:rtl">=D7=91=D7=91=D7=
=A8=D7=9B=D7=94,</div><div style=3D"direction:rtl">=D7=90=D7=91=D7=99=D7=A2=
=D7=93 =D7=9B=D7=94=D7=9F</div></div></div>
</div>
--20cf3003bc2e044e980500f755dc--
--20cf3003bc2e044e9d0500f755de
Content-Type: text/plain; charset=US-ASCII; name="EhudBanay.txt"
Content-Disposition: attachment; filename="EhudBanay.txt"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_hz0z4us30
aHR0cHM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DI5NDY3JTJG
RWh1ZF9CYW5haV8tX0FuZV9MaV9fMjAwNF8ucmFyJmg9dkFRRWlEWXFu
I didn't manage to do it with regular expression so i tried to use the following line which always start with "--" and ends with "--". notice that before the wanted part there is always an empty line.
I tried: "(\s).*(--)$" but it returns only the following line.
Can someone please help?
It sounds like you're trying to parse multipart/mixed email. There are libraries in most languages to do this already. If you want to write your own I'd suggest following the structure of a multipart message.
Find the boundary defined in the content-type header
Split the message into parts delimited by the boundary (prefixed by --).
For each part seek to the first instance of two consecutive line breaks that denote the end of the headers.
While regular expressions might be helpful for some part of this. I'm not sure its the right tool to parse a structured message.
You can use this regex:
\n\s*\n\K(?:[^-]{2})*.?(?=\n--)
Online demo
I am trying to use logback's replace feature to not have empty values printed in my MDC log pattern.
http://logback.qos.ch/manual/layouts.html#replace
I am trying to follow an example from here
http://logogin.blogspot.com/2013/04/logback-mdc-and-empty-values.html
Some background
For 90% of the time my log pattern prints
2014-08-28 11:30:27,014 emp:Peter org:IT Expense submitted
For 5% of the time it prints
2014-08-28 11:30:27,014 emp: org: Cleanup jobs.
This is because the emp and org do not need to be supplied on MDC in the latter case.
For these cases, I want the emp: and org: to not be present at all in the log line.
Desired
2014-08-28 11:30:27,014 Cleanup jobs.
Possible solution with replace
Here is my variable and the appender I am using. The idea is that the mdcPattern will resolve to an empty string for no emp and org values.
<variable scope="context" name="mdcPattern" value="%replace( emp:%X{empName} org:%X{orgName} ) {'[a-z]+:( |$)', ''}"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d ${mdcPattern} %thread %-5level %logger{25} - %msg%n</pattern>
</encoder>
</appender>
However the replace regex does not work. I see log lines as:
2014-08-28 11:30:27,014 emp: org: {'[a-z]+:( |$
My regex is a bit weak. I can't seem to understand why the replace pattern is appearing as is in my log line. Any help is greatly appreciated.
With help from the author of the original blog post, I've managed to get this to work.
He has provided another example on GitHub.
http://logogin.blogspot.com/2013/04/logback-mdc-and-empty-values.html
https://gist.github.com/logogin/ff44c254f655340b653c
I had extra spaces in the replacement pattern which I've removed.
Eg: {orgName} ) {'[a-z]+
To: {orgName}){'[a-z]+
I have a restful web service that's returning results like this:
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Some Text</string>
However, the people on the receiving end need this text to be terminated w/ a special character such as "\r". How can I add that text to the end of my serialized response?
I'm sending this response from inside of a WCF service in C# like this:
[WebGet(UriTemplate = "/MyMethod?x={myId}"), OperationContract]
string GetSomeText(Guid myId);
I can think of three solutions:
1. Http Module (least code but most confusing for maintenance)
Assuming you're hosting your WCF in ASP.Net, you can create an Http module to add a \r to the end of all responses in your application.
This could be the code of the Http module. I've used 'End' as a suffix here because it's easier to read in a browser than \r, but for \r you would change the "End" in context_PostRequestHandlerExecute to "\r".
public class SuffixModule : IHttpModule
{
private HttpApplication _context;
public void Init(HttpApplication context)
{
_context = context;
_context.PostRequestHandlerExecute += context_PostRequestHandlerExecute;
}
void context_PostRequestHandlerExecute(object sender, EventArgs e)
{
// write the suffix if there is a body to this request
string contentLengthHeaderValue = _context.Response.Headers["Content-length"];
string suffix = "End";
if (!String.IsNullOrEmpty(contentLengthHeaderValue))
{
// Increase the content-length header by the length of the suffix
_context.Response.Headers["Content-length"] =
(int.Parse(contentLengthHeaderValue) + suffix.Length)
.ToString();
// and write the suffix!
_context.Response.Write(suffix);
}
}
public void Dispose()
{
// haven't worked out if I need to do anything here
}
}
Then you need to set up your module up in your web.config. The below assumes you have IIS running in Integrated Pipeline mode. If you haven't, you need to register the modules in the <system.web><httpModules> section.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<!-- 'type' should be the fully-qualified name of the type,
followed by a comma and the name of the assembly-->
<add name="SuffixModule" type="WcfService1.SuffixModule,WcfService1"/>
</modules>
</system.webServer>
This option has the problems that it would affect all requests in your application by default and it would probably fall over if you decided to use chunked encoding.
2. Use ASP.NET MVC (changes technology but good maintainability)
Use MVC instead of WCF. You'd have far better control over your output.
3. Custom Serializer (lots of code, but less hacky than option 1)
You could write your own custom serializer. This StackOverflow question gives you pointers on how to do this. I didn't write a prototype for this because it looked as though there were many, many methods which needed to be overridden. I daresay most of them would be pretty simple delegations to the standard serializer.