how to invoke http method using dp:url-open function - xslt

question : how to invoke http method (GET,POST,CREATE & DELETE) using IBM Datapower dp:url-open function in XSLT language
requirement : code in xslt and step by step process theory in short ?

It's going to be tedious if you don't learn to read the documentation... Your question has the clear answer in the docs, here: https://www.ibm.com/docs/en/datapower-gateways/10.0.1?topic=elements-dpurl-open
However, trying to explain what's going on in a bit more detail as for the command:
<dp:url-open
target="URL"
response="xml | binaryNode | ignore | responsecode | responsecode-binary | responsecode-ignore"
resolve-mode="xml | swa"
base-uri-node="nodeset"
data-type="xml | base64 | filename"
http-headers="nodeset"
content-type="contentType"
ssl-proxy="client:profile"
timeout="seconds"
http-method="get | patch | post | put | delete | head"
options="options">
</dp:url-open>
The first thing you need is obviously the URL. This can be a string or a variable:
target="https://google.com"
target="{$url_variable}"
The default method is GET but for any other you'd need to set the http-method parameter. To post data and fetch the response in a variable you'd use:
<xsl:variable name="jsp-response">
<dp:url-open target="http://www.datapower.com/application.jsp">
<xsl:copy-of select="$some-nodes">
</dp:url-open>
</xsl:variable>
This would make a HTTP POST request sending the data (body) found in the $some-nodes variable.

Related

Wiremock withQueryParam not matching regex

I'm trying to do this:
stubFor(get("/my/path")
.withQueryParam("paramName", matching(format("^(%s)|(%s)|(%s)$", v1, v2, v3)))
.willReturn(okJson(RESPONSE)));
and I get this error:
GET | GET
/my/path | /my/path?paramName=v1Value <<<<< URL does not match
|
Query: paramName [matches] ^(v1Value)|(v2Value)|(v3Value)$ | paramName: v1Value
I have tested the regex and it works. I also debugged and I saw that the RegexPattern also matches. But for some reason, I still get this error. I believe I'm using it wrongly.
I tried a simpler version that also didn't work:
stubFor(get("/my/path")
.withQueryParam("paramName", equalTo("v1Value"))
.willReturn(okJson(RESPONSE)));
Any ideas? Thanks in advance.
WireMock documentation recommends matching on url path only and matching on query parameters separately.
That would look something like...
stubFor(get(urlPathEqualTo("/my/path"))
.withQueryParam("paramName", matching(format("^(%s)|(%s)|(%s)$", v1, v2, v3)))
.willReturn(okJson(RESPONSE)));
If I recall correctly, just using stubFor(get("my/url")) defaults to using urlEqualTo, which checks equality matching on path and query parameters

What is the purpose of the composite flow(from Sink and Source)?

I am trying the understand composite flow (from Sink and Source) from the website and they represent as the following:
Could someone please provide an example for the usage of composite flow.
And when should I use it?
Flow.fromSinkAndSource provides a convenient way to assemble a flow composed with a sink as its input and a source as its output that are not connected, which can be best illustrated with the following diagram (available in the API link):
+----------------------------------------------+
| Resulting Flow[I, O, NotUsed] |
| |
| +---------+ +-----------+ |
| | | | | |
I ~~>| Sink[I] | [no-connection!] | Source[O] | ~~> O
| | | | | |
| +---------+ +-----------+ |
+----------------------------------------------+
As shown in #gabrielgiussi's answer, it's often used in cases where one wants to "switch" the output of an existing source( or flow) to some different output - for testing purposes or what-not. Here's a trivialized example:
import akka.actor.ActorSystem
import akka.stream.scaladsl._
implicit val system = ActorSystem("system")
implicit val materializer = ActorMaterializer()
val switchFlow = Flow.fromSinkAndSource( Sink.ignore, Source(List("a", "b", "c")) )
Source(1 to 5).via(switchFlow).runForeach(println)
// res1: scala.concurrent.Future[akka.Done] = Future(Success(Done))
// a
// b
// c
It's also worth noting that the method's "Mat" version, fromSinkAndSourceMat, has some interesting use cases. An example is to use it to keep half-closed WebSockets open by using Source.maybe[T] to maintain a Promise[Option[T]] as the materialized value which will be completed when one wants to close the connection. Below is the sample code from the relevant section in the Akka-http WebSockets client support document:
// using Source.maybe materializes into a promise
// which will allow us to complete the source later
val flow: Flow[Message, Message, Promise[Option[Message]]] =
Flow.fromSinkAndSourceMat(
Sink.foreach[Message](println),
Source.maybe[Message])(Keep.right)
val (upgradeResponse, promise) =
Http().singleWebSocketRequest(
WebSocketRequest("ws://example.com:8080/some/path"),
flow)
// at some later time we want to disconnect
promise.success(None)
Maybe in some scenario you just need to provide the Flow and for certain cases you need a NoOp Flow.
Then you could do
Flow.fromSinkAndSource(Sink.ignore,Source.empty)
Or ignore every element from the Source and use another one
Flow.fromSinkAndSource(Sink.ignore,Source.tick(1.second,1.second,"something"))
I got understanding from here
object SingleWebSocketRequest {
def main(args: Array[String]) = {
// print each incoming strict text message
val printSink: Sink[Message, Future[Done]] =
Sink.foreach {
case message: TextMessage.Strict =>
println(message.text)
}
val helloSource: Source[Message, NotUsed] =
Source.single(TextMessage("hello world!"))
// the Future[Done] is the materialized value of Sink.foreach
// and it is completed when the stream completes
val flow: Flow[Message, Message, Future[Done]] =
Flow.fromSinkAndSourceMat(printSink, helloSource)(Keep.left)
// upgradeResponse is a Future[WebSocketUpgradeResponse] that
// completes or fails when the connection succeeds or fails
// and closed is a Future[Done] representing the stream completion from above
val (upgradeResponse, closed) =
Http().singleWebSocketRequest(WebSocketRequest("ws://echo.websocket.org"), flow)
val connected = upgradeResponse.map { upgrade =>
// just like a regular http request we can access response status which is available via upgrade.response.status
// status code 101 (Switching Protocols) indicates that server support WebSockets
if (upgrade.response.status == StatusCodes.SwitchingProtocols) {
Done
} else {
throw new RuntimeException(s"Connection failed: ${upgrade.response.status}")
}
}
// in a real application you would not side effect here
// and handle errors more carefully
connected.onComplete(println)
closed.foreach(_ => println("closed"))
}
}
I used this in an actual situation, and it is convenient. Websocket is a two-way connection and Akka-HTTP WebSocket provides SingleWebSocketRequest function which takes a flow in argument and uses it in joinMat function as a parameter. With this configuration, your source plays a key role here to send a message to WebSocket and your sink is for receiving a message from WebSocket. So this is not just like:
Source ~> Sink
its is like
Other Source(WebSocket) ~> Sink
Other Source(WebSocket) <~ Source ( ex: ping message every 15 seconds)

How to print table data using print statement in Karate API?

I need to understand how the Table concept is working in Karate API. So I just tried with the following example. I have created a feature file like this.
Feature: RCI Webservices Testing
Background:
* url 'test-something-url'
Scenario: JavaAPI Handler
Given request read('test.xml')
When method post
Then status 200
xmlstring xmlVar = response
* table xmlResponse
| xmlData | filename | statuscode |
| xmlVar | 'Customers.xml' | responseStatus |
* print 'Table Data :', <xmldata> (**tried without < > also** )
When I run this script through a java class i.e. JUnit Test, I'm not seeing anything in the print statement except Table Data:
Even I read the documentation, I'm not able to understand how does it work?
It will be helpful if you provide an example.
Thanks
You need an example, here you go: xml.feature just cut and paste from this and experiment.

Getting an empty list of services from a valid OWLS document

I'm struggling with an abandoned java library (with a down maven repository) to work with OWLS called owls-api. I'm trying to get the list of services from an OWLS document:
OWLKnowledgeBase kb = OWLFactory.createKB();
OWLIndividualList<Service> services = kb.readAllServices("http://127.0.0.1/services/1.1/BookPrice.owls");
System.out.println(services.toString());
I keep getting an empty services list, Why ?
<?xml version="1.0" encoding="WINDOWS-1252"?>
<rdf:RDF xmlns:owl = "http://www.w3.org/2002/07/owl#"
xmlns:rdfs = "http://www.w3.org/2000/01/rdf-schema#"
xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:service = "http://www.daml.org/services/owl-s/1.1/Service.owl#"
xmlns:process = "http://www.daml.org/services/owl-s/1.1/Process.owl#"
xmlns:profile = "http://www.daml.org/services/owl-s/1.1/Profile.owl#"
xmlns:grounding = "http://www.daml.org/services/owl-s/1.1/Grounding.owl#"
xml:base = "http://127.0.0.1/services/1.1/BookFinder.owls">
<owl:Ontology rdf:about="">
<owl:imports rdf:resource="http://127.0.0.1/ontology/Service.owl" />
<owl:imports rdf:resource="http://127.0.0.1/ontology/Process.owl" />
<owl:imports rdf:resource="http://127.0.0.1/ontology/Profile.owl" />
<owl:imports rdf:resource="http://127.0.0.1/ontology/Grounding.owl" />
<owl:imports rdf:resource="http://127.0.0.1/ontology/books.owl" />
</owl:Ontology>
<service:Service rdf:ID="TITLE_BOOK_SERVICE">
<service:presents rdf:resource="#TITLE_BOOK_PROFILE"/>
<service:describedBy rdf:resource="#TITLE_BOOK_PROCESS"/>
<service:supports rdf:resource="#TITLE_BOOK_GROUNDING"/>
</service:Service>
<profile:Profile rdf:ID="TITLE_BOOK_PROFILE">
<service:isPresentedBy rdf:resource="#TITLE_BOOK_SERVICE"/>
<profile:serviceName xml:lang="en">
BookFinder
</profile:serviceName>
<profile:textDescription xml:lang="en">
This service returns the information of a book whose title best matches the given string.
</profile:textDescription>
<profile:hasInput rdf:resource="#_TITLE"/>
<profile:hasOutput rdf:resource="#_BOOK"/>
<profile:has_process rdf:resource="TITLE_BOOK_PROCESS" /></profile:Profile>
<!--<process:ProcessModel rdf:ID="TITLE_BOOK_PROCESS_MODEL">
<service:describes rdf:resource="#TITLE_BOOK_SERVICE"/>
<process:hasProcess rdf:resource="#TITLE_BOOK_PROCESS"/>
</process:ProcessModel>-->
<process:AtomicProcess rdf:ID="TITLE_BOOK_PROCESS">
<service:describes rdf:resource="#TITLE_BOOK_SERVICE"/>
<process:hasInput rdf:resource="#_TITLE"/>
<process:hasOutput rdf:resource="#_BOOK"/>
</process:AtomicProcess>
<process:Input rdf:ID="_TITLE">
<process:parameterType rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI">http://127.0.0.1/ontology/books.owl#Title</process:parameterType>
</process:Input>
<process:Output rdf:ID="_BOOK">
<process:parameterType rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI">http://127.0.0.1/ontology/books.owl#Book</process:parameterType>
</process:Output >
<grounding:WsdlGrounding rdf:ID="TITLE_BOOK_GROUNDING">
<service:supportedBy rdf:resource="#TITLE_BOOK_SERVICE"/>
<grounding:hasAtomicProcessGrounding>
<grounding:WsdlAtomicProcessGrounding rdf:ID="TITLE_BOOK_AtomicProcessGrounding"/>
</grounding:hasAtomicProcessGrounding>
</grounding:WsdlGrounding>
<grounding:WsdlAtomicProcessGrounding rdf:about="#TITLE_BOOK_AtomicProcessGrounding">
<grounding:wsdlDocument rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI"
>http://127.0.0.1/wsdl/TitleBook.wsdl</grounding:wsdlDocument>
<grounding:owlsProcess rdf:resource="#TITLE_BOOK_PROCESS"/>
<grounding:wsdlOperation>
<grounding:WsdlOperationRef>
<grounding:operation rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI"
>http://127.0.0.1/wsdl/TitleBook#get_BOOK</grounding:operation>
<grounding:portType rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI"
>http://127.0.0.1/wsdl/TitleBook#TitleBookSoap</grounding:portType>
</grounding:WsdlOperationRef>
</grounding:wsdlOperation>
<grounding:wsdlInputMessage rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI"
>http://127.0.0.1/wsdl/TitleBook#get_BOOKRequest</grounding:wsdlInputMessage>
<grounding:wsdlOutputMessage rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI"
>http://127.0.0.1/wsdl/TitleBook#get_BOOKResponse</grounding:wsdlOutputMessage>
<grounding:wsdlInput>
<grounding:WsdlInputMessageMap>
<grounding:owlsParameter rdf:resource="#_TITLE"/>
<grounding:wsdlMessagePart rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI"
>http://127.0.0.1/wsdl/TitleBook#_TITLE</grounding:wsdlMessagePart>
<grounding:xsltTransformationString>None (XSL)</grounding:xsltTransformationString>
</grounding:WsdlInputMessageMap>
</grounding:wsdlInput>
<grounding:wsdlOutput>
<grounding:WsdlOutputMessageMap>
<grounding:owlsParameter rdf:resource="#_BOOK"/>
<grounding:wsdlMessagePart rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI"
>http://127.0.0.1/wsdl/TitleBook#_BOOK</grounding:wsdlMessagePart>
<grounding:xsltTransformationString>None (XSL)</grounding:xsltTransformationString>
</grounding:WsdlOutputMessageMap>
</grounding:wsdlOutput>
</grounding:WsdlAtomicProcessGrounding>
</rdf:RDF>
(* all static files are well server using grizzly java web server)
Is there any alternative to this buggy library to work with owls files ?
Update
https://github.com/tarrsalah/owls-example/issues/1
The RDF data here isn't all that complex, so it's not too hard to get what you're looking for by using a SPARQL query. E.g., you can use the following query to get the following results:
prefix service: <http://www.daml.org/services/owl-s/1.1/Service.owl#>
select ?service { ?service a service:Service }
----------------------------------------------------------------------
| service |
======================================================================
| <http://127.0.0.1/services/1.1/BookFinder.owls#TITLE_BOOK_SERVICE> |
----------------------------------------------------------------------
If you want to do this a bit more programmatically, it's just listing instances of the class
http://www.daml.org/services/owl-s/1.1/Service.owl#Service, so you could get that class as an OWLClass, and use getIndividuals to retrieve the set of its instances.

XHTML5 and HTML4 character entities

Does XHTML5 support character entities such as and —. At work we can require specific software to access the admin side of the site, and people are demanding multi-file-upload. For me this is an easy justification to require migrating to FF 3.6+, so I'll be doing it soonish. We currently use XHTML 1.1, and upon moving to HTML5, I'm only having issues with character entity names... Does anyone have a doc on this?
I see there is a list on the WHATWG spec but I'm not sure if it affects files served as application/xhtml+xml. By any means the two mentioned trigger errors in both Chromium nightly and FF 3.6.
There is no DTD for XHTML5, so an XML parser will see no entity definitions (other than the predefined ones). If you wanted to use an entity you would have to define it for yourself in the internal subset.
<!DOCTYPE html [
<!ENTITY mdash "—">
]>
<html xmlns="http://www.w3.org/1999/xhtml">
... — ...
</html>
(Of course using the internal subset is likely to trip browsers up if you serve it to them as text/html. Sending an internal subset in a non-XHTML HTML5 document is disallowed.)
The HTML5 wiki currently recommends:
Do not use entity references in XHTML (except for the 5 predefined entities: &, <, >, " and &apos;)
And I agree with this advice not just for XHTML5 but for XML and HTML in general. There's little reason to be using the HTML entities for anything today. Unicode characters typed directly are far more readable for everyone, and &#...; character references are available for those sad cases when you can't guarantee a 8-bit/encoding-clean transport. (Since HTML entities are not defined for the majority of Unicode characters, you are going to need those anyway.)
I needed an XML validation of potentially HTML 5. HTML 4 and XHTML only had a mediocre 250 or so entities, while the current draft (January 2012) has more than 2000.
GET 'http://www.w3.org/TR/html5-author/named-character-references.html' |
xmllint --html --xmlout --format --noent - |
egrep '<code|<span.*glyph' | # get only the bits we're interested in
sed -e 's/.*">/__/' | # Add some "__" markers to make e.g. whitespace
sed -e 's/<.*/__/' | # entities work with xargs
sed 's/"/\"/' | # xmllint output contains " which messes up xargs
sed "s/'/\&apos;/" | # ditto apostrophes. Make them HTML entities instead.
xargs -n 2 echo | # Put the entity names and values on one line
sed 's/__/<!ENTITY /' | # Make a DTD
sed 's/;__/ /' |
sed 's/ __/"/' |
sed 's/__$/">/' |
egrep -v '\bapos\b|\bquot\b|\blt\b|\bgt\b|\bamp\b' # remove XML entities.
You end up with a file containing 2114 entities.
<!ENTITY AElig "Æ">
<!ENTITY Aacute "Á">
<!ENTITY Abreve "Ă">
<!ENTITY Acirc "Â">
<!ENTITY Acy "А">
<!ENTITY Afr "𝔄">
Plugging this into an XML parser should allow the XML parser to resolve these character entities.
Update October 2012: Since the working draft now has a JSON file (yes, I'm still using regular expressions) I worked it down to a single sed:
curl -s 'http://www.w3.org/TR/html5-author/entities.json' |
sed -n '/^ "&/s/"&\([^;"]*\)[^0-9]*\[\([0-9]*\)\].*/<!ENTITY \1 "\&#\2;">/p' |
uniq
Of course a javascript equivalent would be a lot more robust, but not everyone has node installed. Everyone has sed, right? Random sample output:
<!ENTITY subsetneqq "⫋">
<!ENTITY subsim "⫇">
<!ENTITY subsub "⫕">
<!ENTITY subsup "⫓">
<!ENTITY succapprox "⪸">
<!ENTITY succ "≻">
My best advice is to not upgrade to HTML5 or XHTML5 until support for character entity names is provided.
Anyone who thinks that 〹 makes more sense than — needs a brain upgrade. Most people can't remember huge tables of numbers.
Those of us who have to remain with older operating systems to be compatible with existing scientific, real-time, or point-of-sale hardware (or government networks) can't just type the character or pick it from a list. It won't save correctly in the file.
The reason this has been imposed on us is that w3c no longer wants the expense of serving DTD files, so we must go back to the stone age.
Nothing like this that has been provided should ever be deprecated.
The right answer (the modern way)
I asked this question five years ago. Now every browser supports UTF-8. And, every inception of UTF-8 includes glyph support for all named character entities. The rightmost current solution to this problem is not to use named entities at all but to serve only UTF-8 (strict) and to use actually characters in that.
This is a list of all XML entities. All of these have UTF-8 character alternatives -- and that's how they'd normally be rendered anyway.
For instance, take
U+1D6D8, MATHEMATICAL BOLD SMALL CHI , b.chi
I suppose in some variant of xml you could have &b.chi or something, searching for MATHEMATICAL BOLD SMALL CHI you'll find some page on fileformat.info, which has the 𝛘 character listed.
Alternatively, in Windows you can type Alt + 1 D 6 D 8 (the 1d68d comes from the table of XML entities), or in Linux Ctrl + Shift + u 1 D 6 D 8.
This will put the character into your document the right way.
Using the following answer: https://stackoverflow.com/a/9003931/689044 , I created the file and posted it as a Gist on GitHub: https://gist.github.com/cerkit/c2814d677854308cef57 for those of you who need the Entities in a file.
I used it successfully with ASP.NET MVC by loading the text file into the Application object and using that value with my (well-formed) HTML to parse a System.Xml.XmlDocument.
XmlDocument doc = new XmlDocument();
// load the HTML entities into the document and add a root element so it will load
// The HTML entities are required or it won't load the document if it uses any entities (ex: –)
doc.LoadXml(string.Format("{0}<root>{1}</root>", Globals.HTML_ENTITIES, control.HtmlText));
var childNodes = doc.SelectSingleNode("//root").ChildNodes;
// do your work here
foreach(XmlNode node in childNodes)
{
// or here
}
Globals.HTML_ENTITIES is a static property that loads the entities from the text file and stores them in the Application object, or it uses the values if they're already loaded in the Application object.
public static class Globals
{
public static readonly string APPLICATION_KEY_HTML_ENTITIES = "HTML_ENTITIES";
public static string HTML_ENTITIES
{
get
{
string retVal = null;
// load the HTML entities from a text file if they're not in the Application object
if(HttpContext.Current.Application[APPLICATION_KEY_HTML_ENTITIES] != null)
{
retVal = HttpContext.Current.Application[APPLICATION_KEY_HTML_ENTITIES].ToString();
}
else
{
using (StreamReader sr = File.OpenText(HttpContext.Current.Server.MapPath("~/Content/HtmlEntities/RootHtmlEntities.txt")))
{
retVal = sr.ReadToEnd();
HttpContext.Current.Application[APPLICATION_KEY_HTML_ENTITIES] = retVal;
}
}
return retVal;
}
}
}
I tried creating a long string to hold the values, but it kept crashing Visual Studio, so I decided that the best route would be to load the text file at runtime and store it in the Application object.