Tuesday, November 24, 2015

Recover Form post from chrome

Recently I am working on writing a requirement spec on my companies wiki page. After I am done with writing all my ideas, questions, requirements, etc, when I tried to save the wiki page, it redirected to the authentication page (as I opened the page long back, the session got time out and when I tried to publish it, it tried to re-authenticate), which didn't surprised me. But after I provided my user name/password and did a submit, to my horror, there is an exception and I lost all I have typed in. Oh sh*t.

From couple of hours I am working on this and the valuable data I have is completely lost! I don't like to think again and do the same writing again (It is just stupid, I don't think I will think about all the points again because I am doing it for the second time I might not fresh or my mind is not interested to do the work again). So I started thinking is there any way to recover the lost post. When I click on the publish button, the app will do a POST data on the server (at that point of time the 'intelligent' server recognized that the authentication got expired and user has to re-login again). Why the hell did it not warned me saying that you no longer connected to the server, please save. It is a big usability issue on the wiki website.

Anyhow I found way to recover the data if you are using Chrome (and didn't closed the window where the post data happened, even if we moved to the next pages or opened another site it is okey. But if *closed* the tab, no one can save :).

Luckly I didn't closed the tab, because I tried to see in the back pages etc to get my content.

Here is way to recover lost form data in chrome.

You can recover it from the process dump file.

1. Get the process id for that tab. Chrome each tab as a different process. Click on the options menu (the  menu in the top right), go to "More tools", "Select Task manager".


It will list all the tabs (tasks) and the corresponding Process Id.

2. Now go "Windows Task manager" and select the process with that Process Id.

Right click the windows toolbar and select "Start Task Manager"

In the Task manager, go to the Process tab. If the table in process tab don't have PID coloumn, you can select it from the view menu item, choose "Select Columns" and select "PID (Process Identifier).


Now select the Process in the Process tab of the Windows Task Manager. Right click on the corresponding process and "Create Dump file".

It will create a dump file in the temp directory.

3. Using string.exe utility (you can download the windows utility from microsoft website) - https://technet.microsoft.com/en-us/sysinternals/strings.aspx, convert the dump file to text file.
In command promt,
system.exe chrome.DMP > output.txt
where chrome.DMP is your dump file.

4. Now use any text editor and search for your specific text in that output file using some keywords that you can remember typing in. I use Notepad++ - https://notepad-plus-plus.org/.

Note: Both the dump file and text file can be huge. Dump file willbe around 500mb to 1gb (but your mileage can vary) and the text file will around 100mb to 250mb.

5. Hurray you recovered your valuable content :) I am able to save couple of hours of my work using this method.






Saturday, March 22, 2008

Generating Sample XML file from Schema

Generating Sample XML files from Schema

Eclipse XML Editor (comes with WTP Editor) has a nice feature to generate a sample xml file from the given schema.


Make sure you have the WTP plugin installed on your Eclipse editor – if not please check this or search in google.


Let us create a sample XML file for the following Schema (this schema file is created using Eclipse Schema editor – more details can be found here.)


<?xml version="1.0" encoding="UTF-8"?>

<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/shiporder" xmlns:tns="http://www.example.org/shiporder" elementFormDefault="qualified">


<element name="shiporder" type="tns:shiporderType"></element>

<complexType name="shiporderType">

<sequence>

<element name="orderperson" type="string"></element>

<element name="shipto" type="tns:shiptoType"></element>

<element name="item" type="tns:itemType" maxOccurs="unbounded" minOccurs="1"></element>

</sequence>

</complexType>


<complexType name="shiptoType">

<sequence>

<element name="street" type="string"></element>

<element name="city" type="string"></element>

<element name="country">

<simpleType>

<restriction base="string">

<enumeration value="INDIA"></enumeration>

<enumeration value="US"></enumeration>

<enumeration value="UK"></enumeration>

<enumeration value="Japan"></enumeration>

</restriction>

</simpleType>

</element>

<element name="pincode">

<simpleType>

<restriction base="int">

<pattern value="[0-9]{5}"></pattern>

</restriction>

</simpleType>

</element>

</sequence>

</complexType>

<complexType name="itemType">

<sequence>

<element name="title" type="string"></element>

<element name="quantity" type="int"></element>

<element name="price" type="double"></element>

</sequence>

</complexType>

</schema>



Assume that the above schema is stored in your project or in your system.


Now, to create a sample XML file for the above schema.


1) Create a New XML file using File -> New -> Others... and select XML and click next.




2) In the next wizard page, give the file name and the location where to create the file and click “Next”




3) Here give select the option “Create XML file from XML Schema” (if you want to create an XML file from DTD, you can select the first option. Click “Next” to choose the schema file.





4) In this wizard page, you need to give the schema file location. If your schema file is present in your workbench select the option “Select file from Workbench”. If your schema file is in your local system (but not in your workbench) you can import these files using “Import” button. However if you want to cretae an xml file from a standard schema file like WSDL or SOAP, you can choose “Select XML Catalog entry” - more on this later. Click “Next” button.




5) In this wizard you need to select the root element of you document. Let us select “shiporder” as our root element. You can check “Create optional attributes” and “Create optional elements” if you want to. However as our schema don't have any option attributes or element, you can simply ignore thos. Click “Finish” to create the XML file.







6) This will create an xml file like this




You can validate this XML file against the schema using the “Validate” option. Right click on the editor and select “Validate” option.


Observe that XML Validate found some errors in pincode tag.








It has an error saying

cvc-pattern-valid: Value '0' is not facet-valid with respect to pattern '[0-9]{5}' for type '#AnonType_pincodeshiptoType'.



This is because in our schema we defined the pincode to follow this pattern.


<element name="pincode">

<simpleType>

<restriction base="int">

<pattern value="[0-9]{5}"></pattern>

</restriction>

</simpleType>

</element>


Eclipse XML editor can't generate sample data based on pattern. It simply generate “0” for intergers, “0.0” for float or double and the tag name for strings. Ofcouse many comercial ides also can't generate data based on pattern restriction.


To fix this error manually give a valid value for pincode (a five digit value), save it and validate it again. The problem marker will go off if it is a valid value!



Working with XML Catalogs

Now we will look at the option “Select XML Catalog entry” to create a xml instead of creating an XML file from a give schema.





If you want to create an xml file from a standand schema like WSDL, SOAP you can select this option and in the XML Catalog you can select the key.


Let us select the key “http://schemas.xmlsoap.org/wsdl” and click Next. Select “definitions” as root element and click Finish. This will generate a file that will confirm to wsdl schema.




You can also add your custom schema to the XML Catalog entry so that whenever you want to create a XML file of that type you don't need to select the schema file again.


Now let us add our shiporder.xsd to XML Catalog.


Select Window > Preferences menu item. Here select Web and XML > XML Catalog as shown in figure.




Scroll down and select the “Add button” and choose either workspace or File system (wherever you schema file is present).




Select the workspace option and give your schema location and click Ok.





This will add you schema to XML Catalog




Click Ok to close the Preference setting dialog.


Now, you can create an XML file using this catalog entry. The first 3 three steps (till “Create XML file from Schema”) option is same. After this step Select “XML Catalog entry” and choose our shiporder.xsd and click next.




Click Next and then Click finish. This will create our require XML file.


The difference between the too files (one generated by directly giving the schema location) is the value of schemocation tag.


xsi:schemaLocation="http://www.example.org/shiporder shiporder.xsd "


xsi:schemaLocation="http://www.example.org/shiporder http://www.example.org/shiporder


In the first one first one the schema file is directly referenced using relative location, so if you schema file “shiporder.xsd” is not present in the directory where the xml file recides validation won't happen propely. However for file generated from XML catalog it is refering to a web location which is not present – but validation occurs fine as it uses the catalog to search for XML Schemas before going to the web address.


Suppose if you have 50 xml files that uses a schema and now if the schema needs to be moved to someother folder you need to update the schemaLocation attribute for all the 50 xml files if you have used the first option, but if you choosen to generate XML files from XML Catalog, only you need to update the catalog by selecting Edit option in your preferences page so all your 50 xml files automatically pick the correct schema – no need to update the xml files.


So, cataloging you XML Schemas is a better way if you what to repeadly use this schema.



Creating XML File from Templates

The New XML file wizard in Eclipse also have an option to generate XML files based on a template.


In the “Create XML File from” page select the “Create XML file from an XML template” option.




And click next, this open up the “Select XML Template” wizard page. Now select the “Use XML Template” option and click “XML Tempaltes” hyperlink.





This will open up the Preferences page




Click on “New...” button to create a new template.




Give a name “shipOrder” and decription. Also select the Context as “New XML” so this template will be used while creating new xml files.


In the pattern file, type (or copy and paste) the XML you want. You can also add variables to the pattern using Inset Variable... button.


Clikc OK once you are done.


Now our shipOrder will be shown in the template list as shown in the figure (note that only templates with context New XML will be displayed here).



Select our newly created template “shipOrder” and click finish.


This will create an XML file using that template.


Thursday, March 20, 2008

Eclipse Schema Editor

Working with schema files in Eclipse


A schema (XSD) is a complex language for describing the structure of your XML data. Writing or modify a schema file is quite difficult, but most the times it is required to write a new schema or understand an existing file because it the only widely used standard for describing xml structure (others are: 1) DTD, which is not used these days as it has lot of short commings including suport for namespaces 2) Relax NG). However schemas are widely used in Web services (for describing the structure of input data a service can accept – specified in wsdl types section). Check this link for more details about different languages for describing XML document http://www.xml.com/pub/a/2001/12/12/schemacompare.html

However Eclipse WTP plugin has a nice graphical Schema (XSD) editor that allows you to create, view and edit a schema file easily, effectively and without much pain in understanding the schema language.


This presentation gives you a basic introduction and features present in schema editor.


1) Configuring Eclipse

If Eclipse is not readily available on your system, you can download it from http://www.eclipse.org/downloads/, download “Eclipse IDE for J2EE development”.

Check and Install Schema editor

Click Help -> About Eclipse platform -> plugin details button





Verify that there is a plugin with name “XML Schema Editor”. If Schema editor is not installed please follow the below steps to install a Schema editor.


Installing a WTP plugin if not installed

The best way to install eclipse plugins is to use “Software updates” instead of manully downloading zip file and extracting it to the eclipse folder. “Software updates” not only downloads the dependent plugins but also downloads the correct version of the plugin based on your current version of Eclipse.

Help -> Software updates -> Find and Install this open up “Install/Update” dialog. “Choose search for new features to install” option and click next, select “Web Tools platform” and click finish. This will download the latest version of WTP plugins for your Eclipse enviroment.


2) Creating a new schema file

Now we try to create a schema file for a shipment notice data (sample data is shown in figure). Even though there are tools that allows to generate schema from a sample xml file (available in XML Spy and Stylus studio), the idea here to familarize with Eclipse schema editor.


<?xml version="1.0" encoding="ISO-8859-1"?>

<shiporder orderid="889923"

xmlns="urn:shiporder">

<orderperson>John Smith</orderperson>

<shipto>

<name>Ola Nordmann</name>

<address>

<street>Langgt 23</street>

<city>4000 Stavanger</city>

<country>Norway</country>

<pincode>35004</pincode>

</address>

</shipto>

<item seq="1">

<title>Empire Burlesque</title>

<note>Special Edition</note>

<quantity>1</quantity>

<price>10.90</price>

</item>

<item seq="2">

<title>Hide your heart</title>

<quantity>1</quantity>

<price>9.90</price>

</item>

</shiporder>


The shiporder is the root tag that has a orderid attribute and it can has detailed about name of the person who ordered the items (orderperson) and his address (address tag). It also contains the items he has order (item tag, he can order different items using same request – hence item tag can be one or more). Address contains an street, city, country and pincode. Let us assume that country is an optional tag and if it is not given the country will be US. Also the country is fixed list like US, UK, India, Japan. Pincode is five digit number. The item has an seq attribute (which is interger and a unique), title, quantity (a positive five digit integer) and price (a positive double value).


Now let us see how we construct a xml schema using the above constaints using Eclipse WST editor.


I assume you don't have in depth knowledge about xml schemas (that is the reason why you and I should use an Editor – a person who wrote the schema spec can easily write schemas using notepad :-). However basic idea about schemas is required – able to identify an Element, Type (complexType or simpleType) and attributes.


1) Create a new project, XMLSamples – using File -> New project and selecting “Project” under the General section




2) Click next, and type “XMLSample” in Project name field and click Finish – This will create a new Eclipse project named “XMLSample”





3) Create a new Schema file, by using new file wizard: File -> New -> Others and selecting “XML Schema” under XML section as shown in figure.



4) Click next and type “shiporder.xsd” and click finish.




This will create a file “shiporder.xsd” in the XMLSamples project and opens in the editor. Go the design view page (if is opened in source page).




The Eclipse schema editor has five section in the Design page

  1. Directives – Other schema files that are included or improted in this schema will be listed here.

  2. Elements – All elements that the defined this schema will be shown here

  3. Types – All types that the defined in this schema will be shown here

  4. Attributes – Attributes defined will be listed in this section

  5. Groups – Goups will be listed here.


In addition to the Design page, you need to know about Outline view and Properties view.

If these views are not visible, you can bring them up by selecting Window -> Show view -> Others and selecting Outline view and clicking ok (same way to bring the Properties view also) – we see later how to use these views.




Now, let us start adding element to our schema file.


The root tag should be shiporder that contains orderperson, shipto and item tags. Also the schema elements should be in the namespace “urn:shiporder”

Right click the Element section and select Add Element menu item. Make the element names as “shiporder”.




You can rename the element name by click on the name text (or using Properties view).


By default XSD Editor creates a element of type string, but as shiporder contains others tags like ordername, so let us change the type of the shiporder.
























This will open up the New type dialog, create a complex type with name “shiporderType”


Now double click the shiporderType item present in the Types section. Right click on the shiporderType and select “Add Element”. This will add a new element of type string. Add three element and name it as “orderperson”, “shipto” and “item” - same names as the element tags we want inside the shiporder tag.




But again our shipto and item tags are of complex type not simple type like string or int. So, right click on the shipto column and select menu item Step type -> New, this open up the “New type” dialog we saw previously. Name it as shiptoType. Similarly do it for item also.



The final output should look like:


Now we need to add street, city, country and pincode for shiptoType and title, quantity and price for itemType.

You can do it by right click on the shiptoType and selecting “Add Element”


To change the type from string to int, you can click on the type and select int as shown in figure.


Adding all the tags the screen will look like:


By now we have created all the require tags.


Adding constraints


item” can occur one or more time in the shiporder. To make this right click on the item and select “Set multiplicity -> 1...*” menu item



Alternatively you can change the Min occurance and max occurance using properties view. If properties view is not visible, can make it appear by selecting the menu item “Window -> Show view -> Others” and select “Properties” in the general section..




This will open the Properties view.


Click on each item will update the properties view to show the properties of that selected item.

When we select the item in Design view the properties will look like:




You can set the minimum occurrence and maximum occurrence of the element.


Also our pincode should be a five digit interger. To apply this contraint, click on the “pincode” and select the “constraints” tab in properties view. In the “Specify constraint values” group choose “Patterns” option and click “Add” button.



This will bring up the “Regular Expression wizard”, type the regualar expression “[0-9]{5}” which specifies any letter from 0 to 9 and should occur five times. Click next to test your regualar expression and then click “Finish”.
































































This will make the pincode to be an integer with only five characters (or digits).


To make the quantity a positive integer, click on the “quantity” tag and in the constraints tab of properties view, give minimum value as “0”.


You can do the same for price also to make it a positive double.




Finally let us make our country tag to accept only a fixed set of values like “US, UK, France, Germany, Japan and India” using the Properties view.


To do this, click on the country item in the Design page and in the properties view select “Constraints” tab and choose “Enumerations” in the “Specific constraint values” group box. Click on Add and give a name “India”, to add one more item to the list, click “Add” button again and give “US” as value this time.




Now save the file (using Ctrl + s keyboard short cut), you can view the source by click on the source tab:




This completes our creating schemas using XML Schema editor.


Copyright (c) 2008 - Suresh