After doing a lot of Googling.....
Is there an "easy way" of converting XMLSlurper results (GPathResult) to JSON?
I have added a sample XML file which I want to fetch server side, store it in a DB (JSON) and dump to a browser page for javascript processing...
Thanks!
Sander
See the following XML file.....:
<OpenSearchDescription xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
<opensearch:Query searchTerms="tt0137523"/>
<opensearch:totalResults>1</opensearch:totalResults>
<movies>
<movie>
<popularity>3</popularity>
<translated>true</translated>
<language>en</language>
<original_name>Fight Club</original_name>
<name>Fight Club</name>
<alternative_name>El club de la lucha</alternative_name>
<type>movie</type>
<id>550</id>
<imdb_id>tt0137523</imdb_id>
<url>http://www.themoviedb.org/movie/550</url>
<overview>A lonely, isolated thirty-something young professional seeks an escape from his mundane existence with the help of a devious soap salesman. They find their release from the prison of reality through underground fight clubs, where men can be what the world now denies them. Their boxing matches and harmless pranks soon lead to an out-of-control spiral towards oblivion.</overview>
<votes>15</votes>
<rating>8.2</rating>
<certification>R</certification>
<released>1999-09-16</released>
<runtime>138</runtime>
<categories>
<category type="genre" name="Crime" url="http://themoviedb.org/genre/crime" id="80"/>
<category type="genre" name="Drama" url="http://themoviedb.org/genre/drama" id="18"/>
<category type="genre" name="Thriller" url="http://themoviedb.org/genre/thriller" id="53"/>
</categories>
<images>
<image type="poster" url="http://hwcdn.themoviedb.org/posters/f84/4bc908ae017a3c57fe002f84/fight-club-mid.jpg" size="mid" id="4bc908ae017a3c57fe002f84"/>
<image type="poster" url="http://hwcdn.themoviedb.org/posters/f84/4bc908ae017a3c57fe002f84/fight-club-cover.jpg" size="cover" id="4bc908ae017a3c57fe002f84"/>
<image type="poster" url="http://hwcdn.themoviedb.org/posters/f84/4bc908ae017a3c57fe002f84/fight-club-thumb.jpg" size="thumb" id="4bc908ae017a3c57fe002f84"/>
<image type="backdrop" url="http://hwcdn.themoviedb.org/backdrops/f55/4bc908a8017a3c57fe002f55/fight-club-original.jpg" size="original" id="4bc908a8017a3c57fe002f55"/>
<image type="backdrop" url="http://hwcdn.themoviedb.org/backdrops/f55/4bc908a8017a3c57fe002f55/fight-club-poster.jpg" size="poster" id="4bc908a8017a3c57fe002f55"/>
<image type="backdrop" url="http://hwcdn.themoviedb.org/backdrops/f55/4bc908a8017a3c57fe002f55/fight-club-thumb.jpg" size="thumb" id="4bc908a8017a3c57fe002f55"/>
<image type="backdrop" url="http://hwcdn.themoviedb.org/backdrops/f51/4bc908a6017a3c57fe002f51/fight-club-original.jpg" size="original" id="4bc908a6017a3c57fe002f51"/>
<image type="backdrop" url="http://hwcdn.themoviedb.org/backdrops/f51/4bc908a6017a3c57fe002f51/fight-club-poster.jpg" size="poster" id="4bc908a6017a3c57fe002f51"/>
<image type="backdrop" url="http://hwcdn.themoviedb.org/backdrops/f51/4bc908a6017a3c57fe002f51/fight-club-thumb.jpg" size="thumb" id="4bc908a6017a3c57fe002f51"/>
<image type="backdrop" url="http://hwcdn.themoviedb.org/backdrops/f4d/4bc908a5017a3c57fe002f4d/fight-club-original.jpg" size="original" id="4bc908a5017a3c57fe002f4d"/>
<image type="backdrop" url="http://hwcdn.themoviedb.org/backdrops/f4d/4bc908a5017a3c57fe002f4d/fight-club-poster.jpg" size="poster" id="4bc908a5017a3c57fe002f4d"/>
<image type="backdrop" url="http://hwcdn.themoviedb.org/backdrops/f4d/4bc908a5017a3c57fe002f4d/fight-club-thumb.jpg" size="thumb" id="4bc908a5017a3c57fe002f4d"/>
</images>
<version>8</version>
<last_modified_at>2010-04-26 23:08:53</last_modified_at>
</movie>
</movies>
</OpenSearchDescription>
If you are already using Grails, you might take a look at Grails Converters.
Grails Converters
They offer a quick way of consuming api XMLs and converting them to JSON.
Related
I have custom claims in my sign-up page register_header and password_header and I want to localize them to Japanese.
Here is my custom policy:
Claims
<ClaimType Id="register_heading">
<DataType>string</DataType>
<AdminHelpText>A claim responsible for holding response messages to send to the relying party</AdminHelpText>
<UserHelpText>A claim responsible for holding response messages to send to the relying party</UserHelpText>
<UserInputType>Paragraph</UserInputType>
</ClaimType>
<ClaimType Id="password_header">
<DataType>string</DataType>
<AdminHelpText>A claim responsible for holding response messages to send to the relying party</AdminHelpText>
<UserHelpText>A claim responsible for holding response messages to send to the relying party</UserHelpText>
<UserInputType>Paragraph</UserInputType>
</ClaimType>
Technical Profile
<TechnicalProfile Id="LocalAccountSignUpWithreadOnlyEmail">
<DisplayName>Email signup</DisplayName>
<Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.SelfAssertedAttributeProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Metadata>
<Item Key="IpAddressClaimReferenceId">IpAddress</Item>
<Item Key="ContentDefinitionReferenceId">api.localaccountsignup</Item>
<Item Key="language.button_continue">Continue</Item>
<Item Key="setting.showCancelButton">false</Item>
<!-- Sample: Remove sign-up email verification -->
<Item Key="EnforceEmailVerification">False</Item>
</Metadata>
<InputClaims>
<InputClaim ClaimTypeReferenceId="email" />
<InputClaim ClaimTypeReferenceId="readOnlyEmail" />
<InputClaim ClaimTypeReferenceId="givenName" />
<InputClaim ClaimTypeReferenceId="surName" />
<!-- claims needed for localization -->
<InputClaim ClaimTypeReferenceId="register_header" DefaultValue="Register account" />
<InputClaim ClaimTypeReferenceId="password_header" DefaultValue="Register password" />
</InputClaims>
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="objectId" />
<!-- Sample: Display the readOnlyEmail claim type (instead of email claim type)-->
<OutputClaim ClaimTypeReferenceId="readOnlyEmail" Required="true" />
<OutputClaim ClaimTypeReferenceId="newPassword" Required="true" />
<OutputClaim ClaimTypeReferenceId="reenterPassword" Required="true" />
<OutputClaim ClaimTypeReferenceId="executed-SelfAsserted-Input" DefaultValue="true" />
<OutputClaim ClaimTypeReferenceId="authenticationSource" />
<OutputClaim ClaimTypeReferenceId="newUser" />
<!-- Optional claims, to be collected from the user -->
<OutputClaim ClaimTypeReferenceId="givenName" Required="true" />
<OutputClaim ClaimTypeReferenceId="surName" Required="true" />
<OutputClaim ClaimTypeReferenceId="TnC" Required="true" />
<!-- claims for localization -->
<OutputClaim ClaimTypeReferenceId="register_header" />
<OutputClaim ClaimTypeReferenceId="password_header" />
</OutputClaims>
<ValidationTechnicalProfiles>
<ValidationTechnicalProfile ReferenceId="AAD-UserWriteUsingLogonEmail" />
</ValidationTechnicalProfiles>
<!-- Sample: Disable session management for sign-up page -->
<UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
Content Definition
<ContentDefinition Id="api.localaccountsignup">
<LoadUri>Insert URL here</LoadUri>
<RecoveryUri>~/common/default_page_error.html</RecoveryUri>
<DataUri>urn:com:microsoft:aad:b2c:elements:contract:selfasserted:1.2.0</DataUri>
<LocalizedResourcesReferences MergeBehavior="ReplaceAll">
<LocalizedResourcesReference Language="en" LocalizedResourcesReferenceId="api.localaccountsignup.en" />
<LocalizedResourcesReference Language="ja" LocalizedResourcesReferenceId="api.localaccountsignup.ja" />
</LocalizedResourcesReferences>
Localized Resources
<LocalizedResources Id="api.localaccountsignup.ja">
<LocalizedStrings>
<LocalizedString ElementType="ClaimType" ElementId="register_header" StringId="DisplayName">アカウントを登録</LocalizedString>
<LocalizedString ElementType="ClaimType" ElementId="password_header" StringId="DisplayName">パスワードを登録</LocalizedString>
</LocalizedStrings>
My problem is the Japanese translation are returned as <label> in the HTML.
But their English counterpart is returned as <p> with the id attribute
I want to use the id but it is only available to the English translation.
Is there a way for the custom policy to change the text in <p> to Japanese and keep the id instead of creating a <label> element? If possible I don't want to use Javascript.
• I would suggest you to please try configuring the localization string ids in the custom policy regarding the two custom claims that you want to be translated in Japanese. Since you have already done the same as posted in your localization strings claims, I would suggest you to please modify your custom policy to also include the details below in it: -
<Localization Enabled="true">
<SupportedLanguages DefaultLanguage="en" MergeBehavior="ReplaceAll">
<SupportedLanguage>en</SupportedLanguage>
<SupportedLanguage>jp</SupportedLanguage>
</SupportedLanguages>
<LocalizedResources Id="api.localaccountsignup.en">
<LocalizedCollections>
<LocalizedCollection ElementType="ClaimType" ElementId="register_header" TargetCollection="Restriction">
<Item Text="StringId" Value="DisplayName" />
</LocalizedCollection>
<LocalizedCollection ElementType="ClaimType" ElementId="password_header" TargetCollection="Restriction">
<Item Text=”StringId” Value=”DisplayName”>
</LocalizedCollection>
</LocalizedCollections>
</LocalizedResources>
<LocalizedResources Id="api.localaccountsignup.jp">
<LocalizedCollections>
<LocalizedCollection ElementType="ClaimType" ElementId="<register_header in japanese" TargetCollection="Restriction">
<Item Text="StringId" Value="DisplayName" />
</LocalizedCollection>
<LocalizedCollection ElementType="ClaimType" ElementId="password_header in japanese" TargetCollection="Restriction">
<Item Text=”StringId” Value=”DisplayName”>
</LocalizedCollection>
</LocalizedCollections>
</LocalizedResources>
</Localization>
Might be when you edit your custom policy to include the display results as above, then you might be able to resolve the issue as desired. Also, do refer to the link below for more details about editing the custom policy as above.
Localised message for RestAPI error response in B2C custom policy
Good Evening,
im geting the following error
{
"Usage": "0.55849504470825",
"Resource": "/file",
"Error": {
"code": "14",
"msg": "Specified values are invalid"
}
}
im trying to post a survey file to to the photo scene - following this documentation the file i have given the extension type .gcp and formatted it as a xml as shown on the example
<?xml version="1.0" encoding="UTF-8"?>
<surveydata coordinatesystem="LL84" description="Local coordinatesystem; meters" epsgcode="27700">
<markers>
<marker id="1" name="C2">
<images>
<image name="I100_0413_0027.jpg" xpixel="452" ypixel="401"/>
<image name="I100_0413_0028.jpg" xpixel="454" ypixel="1105"/>
<image name="I100_0413_0029.jpg" xpixel="464" ypixel="1840"/>
<image name="I100_0413_0030.jpg" xpixel="455" ypixel="2564"/>
</images>
<gcp x="539840.423" y="263277.897" z="16.097" checkpoint="false"/>
</marker>
<marker id="2" name="C3">
<images>
<image name="I100_0413_0009.jpg" xpixel="1887" ypixel="488"/>
<image name="I100_0413_0010.jpg" xpixel="1877" ypixel="1236"/>
<image name="I100_0413_0011.jpg" xpixel="1868" ypixel="1958"/>
<image name="I100_0413_0012.jpg" xpixel="1860" ypixel="2681"/>
<image name="I100_0413_0013.jpg" xpixel="1850" ypixel="3400"/>
</images>
<gcp x="539783" y="263219.485" z="16.511" checkpoint="false"/>
</marker>
<marker id="3" name="C4">
<images>
<image name="I100_0413_0036.jpg" xpixel="4255" ypixel="348"/>
<image name="I100_0413_0037.jpg" xpixel="4211" ypixel="1049"/>
<image name="I100_0413_0038.jpg" xpixel="4167" ypixel="1758"/>
<image name="I100_0413_0039.jpg" xpixel="4125" ypixel="2460"/>
<image name="I100_0413_0040.jpg" xpixel="4063" ypixel="3168"/>
</images>
<gcp x="539845.368" y="263230.711" z="15.852" checkpoint="false"/>
</marker>
</markers>
</surveydata>
on the creation of the scene i have set format=rcs-scenetype=aerial
this is the first time i have tried a survey file and i'm unsure what 'values' are invalid, could anyone help?
According to Survey File Example in documentation, when you specify coordinate system as "LL84":
<surveydata coordinatesystem="LL84" ...
it expects in gcp the long, lat and alt:
<gcp long="38.014125" lat="-122.540530" alt="2010.200000" checkpoint="false"/>
In your case, you specify the gcp as x,y,z:
<gcp x="539840.423" y="263277.897" z="16.097" checkpoint="false"/>
Thus, try to change the coordinate system as "XYZ":
<surveydata coordinatesystem=“XYZ” ...
Although documentation states that "only LL84 is supported for now.", this should do the trick.
I have made a small REST based webservice in Flask by reading http://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask and now I wanted to fuzz the JSON using Peach framework. I know it's uses a pit file(XML) for fuzzing but my small brain is not able to make the pit file that can serve my purpose. I googled a lot for peach pit file but all goes in vain.
I need a pit file or anyone can tell how to create a pit file for fuzzing payload.
There is a nice tutorial about peach available there.
Several elements need to be defined:
a data model describing the format of the data you want to send.
a state model describing the behavior of the fuzzer.
an agent runnning and monitoring the applications under fuzzing.
a test bringing all definitions together.
Here is an example of a Peach Pit file from the tutorial.
<Peach xmlns="http://peachfuzzer.com/2012/Peach" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://peachfuzzer.com/2012/Peach ../peach.xsd">
<DataModel name="DataHTER">
<String value="HTER " mutable="false" token="true"/>
<String value=""/>
<String value="\r\n" mutable="false" token="true"/>
</DataModel>
<StateModel name="StateHTER" initialState="Initial">
<State name="Initial">
<Action type="input" ><DataModel ref="DataResponse"/></Action>
<Action type="output"><DataModel ref="DataHTER"/></Action>
<Action type="input" ><DataModel ref="DataResponse"/></Action>
</State>
</StateModel>
<DataModel name="DataResponse">
<String value=""/>
</DataModel>
<Agent name="RemoteAgent" location="tcp://127.0.0.1:9001">
<!-- Run and attach windbg to a vulnerable server. -->
<Monitor class="WindowsDebugger">
<Param name="CommandLine" value="C:\Documents and Settings\Administrator\Desktop\vulnserver\vulnserver.exe"/>
<Param name="WinDbgPath" value="C:\Program Files\Debugging Tools for Windows (x86)" />
</Monitor>
</Agent>
<Test name="TestHTER">
<Agent ref="RemoteAgent"/>
<StateModel ref="StateHTER"/>
<Publisher class="TcpClient">
<Param name="Host" value="127.0.0.1"/>
<Param name="Port" value="9999"/>
</Publisher>
<Logger class="File">
<Param name="Path" value="Logs"/>
</Logger>
</Test>
If you want to use a JSON data model, you can follow the recommendation of one of the peach architect.
1)Define a data model corresponding to the JSON.
JSON Object
{
"name":"John Smith",
"address":{
"address1":"555 Main St.",
"city":"Seattle"
}
}
Data model
<DataModel>
<String name="name" value="John Smith" />
<Block name="address">
<String name="address1" value="555 Main St." />
<String name="city" value="Seattle" />
</Block>
</DataModel>
You then have to write your own custom publisher in C#. Here is a tutorial for this.
I can't seem to figure out how to accomplish a fairly simple task: I have a simple graphic and I'd like to apply an "orbiting" effect to it - so that the graphic moves in a circle around an arbitrary point (without rotating around its own center).
<s:Ellipse id="circle" width="100" height="100">
<s:fill>
<s:SolidColor color="0x000000" />
</s:fill>
</s:Ellipse>
I was trying to do something using spark.effects.Animate but couldn't figure out how to configure motion paths - I started thinking about Cartesian vs Polar coordinate systems and appropriate circle equations for each and then realized I was probably over-thinking it. Although I consider this to be a fairly common problem searching the Web yielded no results.
P.S.
I'd like to use Flex 4 as much as possible, so I'd appreciate it if the answers reused Flex 4 classes.
I realize that this is a very old question. However, considering that a google search for flex 4 circular motion returns this thread as the very first result, I figured it may be worthwhile to make a small contribution.
Robusto's solution does work - if you don't mind handling the animation updates yourself. If, on the other hand, you'd like to use spark.effects.Animate, then using a Sine easer can accomplish the same thing.
<s:Sine id="cosine" easeInFraction="0.0" />
<s:Sine id="sine" easeInFraction="1.0" />
The easeInFraction property specifies what portion of the easing is spent accelerating. For the Sine easer, this is the portion spent climbing up the Sine curve. By setting this fraction to 0.0, the easer begins at the top of the curve, becoming a Cosine.
A small example (I realize that the main Sequence is a bit verbose. You'd likely want make a new component extending the spark.effects.Sequence class instead of having this all in your main application, but this is just to give the general idea):
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600"
applicationComplete="move_circle.play([circle])">
<fx:Declarations>
<fx:int id="mid_x">500</fx:int>
<fx:int id="mid_y">300</fx:int>
<fx:int id="radius">200</fx:int>
<s:Sine id="cosine" easeInFraction="0.0" />
<s:Sine id="sine" easeInFraction="1.0" />
<s:Sequence id="move_circle" repeatCount="0">
<s:Parallel>
<s:Animate easer="{cosine}">
<s:SimpleMotionPath property="x" valueTo="{mid_x + radius}" />
</s:Animate>
<s:Animate easer="{sine}">
<s:SimpleMotionPath property="y" valueTo="{mid_y}" />
</s:Animate>
</s:Parallel>
<s:Parallel>
<s:Animate easer="{sine}">
<s:SimpleMotionPath property="x" valueTo="{mid_x}" />
</s:Animate>
<s:Animate easer="{cosine}">
<s:SimpleMotionPath property="y" valueTo="{mid_y + radius}" />
</s:Animate>
</s:Parallel>
<s:Parallel>
<s:Animate easer="{cosine}">
<s:SimpleMotionPath property="x" valueTo="{mid_x - radius}" />
</s:Animate>
<s:Animate easer="{sine}">
<s:SimpleMotionPath property="y" valueTo="{mid_y}" />
</s:Animate>
</s:Parallel>
<s:Parallel>
<s:Animate easer="{sine}">
<s:SimpleMotionPath property="x" valueTo="{mid_x}" />
</s:Animate>
<s:Animate easer="{cosine}">
<s:SimpleMotionPath property="y" valueTo="{mid_y - radius}" />
</s:Animate>
</s:Parallel>
</s:Sequence>
</fx:Declarations>
<s:Ellipse id="circle"
x="{mid_x}" y="{mid_y - radius}"
width="100" height="100">
<s:fill>
<s:SolidColor color="#000000" />
</s:fill>
</s:Ellipse>
</s:Application>
You can use trig to find the circumference:
var radius = 50;
for (var i:int = 0, imax:int = 359) : void {
var radians:Number = i * (Math.PI/180);
pointX = radius * Math.cos(radians);
pointY = radius * Math.sin(radians);
// position something at pointX,pointY
}
This goes once around a circle and plots a point for each degree. You would probably want to figure out the offsets from x,y for your orbiting and orbited elements so that the former's center would appear to orbit around the latter's.
Does anyone know, or better yet have an example, of a WCF service that will accept a form post encoded multipart/form-data ie. a file upload from a web page?
I have come up empty on google.
Ta, Ant
So, here goes...
Create your service contract which an operation which accepts a stream for its only parameter, decorate with WebInvoke as below
[ServiceContract]
public interface IService1 {
[OperationContract]
[WebInvoke(
Method = "POST",
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "/Upload")]
void Upload(Stream data);
}
Create the class...
public class Service1 : IService1 {
public void Upload(Stream data) {
// Get header info from WebOperationContext.Current.IncomingRequest.Headers
// open and decode the multipart data, save to the desired place
}
And the config, to accept streamed data, and the maximum size
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="WebConfiguration"
maxBufferSize="65536"
maxReceivedMessageSize="2000000000"
transferMode="Streamed">
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Sandbox.WCFUpload.Web.Service1Behavior">
<serviceMetadata httpGetEnabled="true" httpGetUrl="" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Sandbox.WCFUpload.Web.Service1" behaviorConfiguration="Sandbox.WCFUpload.Web.Service1Behavior">
<endpoint
address=""
binding="webHttpBinding"
behaviorConfiguration="WebBehavior"
bindingConfiguration="WebConfiguration"
contract="Sandbox.WCFUpload.Web.IService1" />
</service>
</services>
</system.serviceModel>
Also in the System.Web increase the amount of data allowed in System.Web
<system.web>
<otherStuff>...</otherStuff>
<httpRuntime maxRequestLength="2000000"/>
</system.web>
This is just the basics, but allows for the addition of a Progress method to show an ajax progress bar and you may want to add some security.
I don't exactly know what you're trying to accomplish here, but there's no built-in support in "classic" SOAP-based WCF to capture and handle form post data. You'll have to do that yourself.
On the other hand, if you're talking about REST-based WCF with the webHttpBinding, you could certainly have a service methods that is decorated with the [WebInvoke()] attribute which would be called with a HTTP POST method.
[WebInvoke(Method="POST", UriTemplate="....")]
public string PostHandler(int value)
The URI template would define the URI to use where the HTTP POST should go. You'd have to hook that up to your ASP.NET form (or whatever you're using to actually do the post).
For a great introduction to REST style WCF, check out Aaron Skonnard's screen cast series on the WCF REST Starter Kit and how to use it.
Marc