Posting XML content to a REST Service

hanymorcos's picture
Good Evening, I'm attempting to post RDF (XML) content to sesame's REST services. Request I'm attempting to create: POST /openrdf-sesame/repositories/mem-rdf/statements HTTP/1.1 Host: localhost Content-Type: application/rdf+xml;charset=UTF-8 [RDF/XML ENCODED RDF DATA] Response I should get back: HTTP/1.1 204 NO CONTENT My first attempt was to use the scraper. But, I was not able to post xml content as part of the tag. My second attempt was to use the WSRequest. I'm getting this: "Fault: org.apache.axis2.AxisFault: Transport error: 415 Error: Unsupported Media Type". sesameRDF.documentation = "Given an address returns a specific latitude and longitude" ; sesameRDF.safe = true;geocode.inputTypes = {"RDF_INPUT":"any"}; // I tried xml and string sesameRDF.outputType = ""; function sesameRDF(RDF_INPUT){ var sesame = new WSRequest(); var options = new Array(); options["useSOAP"] = "false"; options["HTTPMethod"] = "post"; sesame.open(options, 'http://localhost:8080/sesame/repositories/mysql', false); var request = RDF_INPUT; yahoo.send(request); } Any ideas?
hanymorcos's picture

woodstox is not able to parse rdf xml?

It seems that payload that is being passed using wsrequest is being parsed. It's unable to read RDF text. My code sample in the previous message was missing /statements in the URL. Is there a way I can tell it to not parse what I'm sending using wsrequest? Fault: com.ctc.wstx.exc.WstxParsingException: String ']]>' not allowed in textual content, except as the end marker of CDATA section at [row,col {unknown-source}]: [63,5] [detail] sesameRDF.documentation = "Given an address returns a specific latitude and longitude" ; sesameRDF.safe = true;geocode.inputTypes = {"RDF_INPUT":"any"}; // I tried xml and string sesameRDF.outputType = ""; function sesameRDF(RDF_INPUT){ var sesame = new WSRequest(); var options = new Array(); options["useSOAP"] = "false"; options["HTTPMethod"] = "post"; sesame.open(options, 'http://localhost:8080/sesame/repositories/mysql/statements', false); var request = RDF_INPUT; yahoo.send(request); }
tyrell's picture

Did you try escaping the

Did you try escaping the special characters mentioned in the log (String ']]>' ) ?
hanymorcos's picture

XML is well-formed

Downloaded XMLspy and xml sent to woodstox is well formed. I'm getting a new error. I have two questions, if someone can shed some light that would be great? 1) Is there a way to make send method on wsrequest not to parse the data but send it? 2) How do I post data using scraper/web-harvest? Here is the latest error, I can't locate that location because I have a large xml file. Fault: org.apache.axis2.AxisFault: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'o' (code 111) in prolog; expected '<' at [row,col {unknown-source}]: [1,1]
tyrell's picture

1) Is there a way to make

1) Is there a way to make send method on wsrequest not to parse the data but send it? You can send a "string" using WSRequest. Ex: (from "yahooGeoCode" sample shipped with the MS)       var key = getApiKey();     if (key == null) throw("You must first provision this service with a valid Yahoo API Key.  See http://developer.yahoo.com/wsregapp/index.php.");     var yahoo = new WSRequest();     var options = new Array();     options["useSOAP"] = "false";     options["HTTPMethod"] = "get";     yahoo.open(options, "http://local.yahooapis.com/MapsService/V1/geocode", false);     var request = "<parameters><appid>" + key + "</appid><street>" + street + "</street><city>" + city + "</city><state>" + state + "</state></parameters>";     yahoo.send(request);     return yahoo.responseXML;   2) How do I post data using scraper/web-harvest? This link should help http://web-harvest.sourceforge.net/manual.php#http.   Tyrell  
hanymorcos's picture

request is a string

The XML passed in the payload in the Yahoo example adheres to a specific XML schema, DTD. I tried changing the code to string. It's not working for me. Fault: com.ctc.wstx.exc.WstxParsingException: String ']]>' not allowed in textual content, except as the end marker of CDATA section at [row,col {unknown-source}]: [15,1212] [detail] sesameRDFLoad.documentation = "I'm using the Yahoo example" ; sesameRDFLoad.safe = true; sesameRDFLoad.inputTypes = {"RDF_INPUT":"string"}; sesameRDFLoad.outputType = "string"; function sesameRDFLoad(RDF_INPUT){ var sesame= new WSRequest(); var options = new Array(); options["useSOAP"] = "false"; options["HTTPMethod"] = "post"; sesame.open(options, 'http://localhost:8080/sesame/repositories/mysql/statements', false); var request = RDF_INPUT; /* RDF_INPUT is a string containing xml */ sesame.send(request); /* the send method is parsing the xml and failing because of library called woodstox is not ingesting RDF XML for some reason How do I tell send not to parse the xml and just pass it along? */ return "done"; }
tyrell's picture

There's no way to bypass the

There's no way to bypass the XML validation by woodstock AFAIK. Is the RDF input valid? You can validate it using http://www.w3.org/RDF/Validator/ Looks like the reserved marker ']]>' is somewhere within the input making the validation to fail.
hanymorcos's picture

RDF Validated on www.w3.org/RDF/Validator

Thanks Tyrell. But, RDF is validated and woodstox is not taking it. Hany Validation Results Your RDF document validated successfully. Fault: com.ctc.wstx.exc.WstxParsingException: String ']]>' not allowed in textual content, except as the end marker of CDATA section at [row,col {unknown-source}]: [25,3] [detail]
hanymorcos's picture

Read Timed Out

I tried a simple RDF file and it seems to be working. For complex RDF files, the parser seems to shoke. I wonder if Woodstox is compliant with the latest RDF schema standards. I'm running into another issue: any ideas? Fault: org.apache.axis2.AxisFault: Read timed out [detail]
tyrell's picture

Fault:

Fault: org.apache.axis2.AxisFault: Read timed out [detail] This is a common fault when the service end point takes a long time to respond. I can't say what's causing it without the detailed log though. Tyrell
hanymorcos's picture

RDF

So we agree that woodstox the xml parser is not taking in RDF data. Is there a workaround? Hany
tyrell's picture

You can use the scraper

You can use the scraper object and the example I linked earlier to post data as well. Tyrell
hanymorcos's picture

Tried Scraper Object

Tyrell, I spent hours trying to get the scraper to use RDF as Var-def or a template. It wouldn't take it. It seems like that sending a binary data or a blob of data to any service is something that would be needed. Hany
tyrell's picture

Hany, It seems like we

Hany, It seems like we need something similar to the plain old XMLHttpRequest. The WSRequest object is similar, but specializes in accessing Web Services. It has been sufficient so far for our users to do REST calls as well. I opened a JIRA at https://wso2.org/jira/browse/MASHUP-1286. Please add additional info which you think would be helpful. Tyrell
jonathan.wso2.com's picture

Is the problem CDATA?

It looks like part of the problem might be wrapping CDATA within another CDATA section. CDATA delimiters aren't recursive. If the RDF used & escaping instead would it avoid the problem?
hanymorcos's picture

CDATA in a CDATA

The RDF sent doesn't have CDATA in a CDATA. Actually wsrequest failed for all RDF files. Hany
tte217.gmail.com's picture

Thanks for a nice share you

Thanks for a nice share you have given to us with such an large collection of information. Great work you have done by sharing them to all. simply superb. regards, http://www.superchinawholesale.com
library project main code
Learn Cloud
Learn
Cloud

The WSO2 Application Server is a reliable application server that can host your enterprise web applications. The WSO2 Application Server as a Service is offered in StratosLive, the WSO2 Platform as a Service. This article explains how a simple web application can be developed and deployed from Carbon Studio to the WSO2 Application Server...

Latest Webinar
Different groups within an organization need to monitor different Key Performance Indicators (KPIs) - An operations team will be interested in the response times of business services and loads of each service,..
Thursday, February 9th 2012, 09.00 AM (PST)

Thursday, February 9th 2012, 10.00 AM (GMT)