Why does StaticFileHandler not server .json? - json

We have a problem downloading .json files via IIS7.5.
MIME type has been set correctly:
<mimeMap fileExtension=".json " mimeType="application/json" />
But still gives error: "HTTP Error 404.3 - Not Found".
To get it to work we have to add a handler mapping:
<handlers>
<add name="JSON" path="*.json" verb="*" modules="IsapiModule" scriptProcessor="C:\WINDOWS\system32\inetsrv\asp.dll" resourceType="Unspecified" />
</handlers>
Why can't json files be handled by the StaticFileHandler like other static content? It seems bizarre we have to install classic asp support to handle json files.

In my case a StaticFileHandler does handle json by itself. The asp.dll handler is not required.
Problem was a sneaky trailing space in the fileExtension property:
<mimeMap fileExtension=".json " mimeType="application/json" />
doh

Recently I ran into this problem too. First I added the .json MIME type. But I had placed my json file in the app_data folder. If you don't give the web application rights to that folder it won't work.
Try putting your json file in the same folder as the html file.
Also, the Mapping Handler won't work unless you have installed the Classic Asp module (in Windows Features). I've written some full directions here.

Related

Extend OTB slingshot search Webscript Alfresco 5.0 C

I want to add a csv response template to the default slingshot/search? web script which is inside in a jar (Alfresco remote api).
Already l have an ant script which build a jar inside Alfresco/tomcat/shared/lib
Inside this jar l have define an extension xml file config/alfresco/site-data/extensions/extension-modules.xml
<extension>
<modules>
<module>
<id>Custom DocumentList Widget</id>
<description>Extend Alfresco Search</description>
<customizations>
<customization>
<targetPackageRoot>org.alfresco.slingshot.search
</targetPackageRoot>
<sourcePackageRoot>webscripts.search</sourcePackageRoot>
</customization>
</customizations>
</module>
</modules>
</extension>
Also lnside config/webscripts/search l have the search.get.csv.ftl file but I never get the csv response. Is this the best way to modify/extend the default web script ?
No this isn't the best way to extend this in your case.
Normally it is, but in your case just use the default override mechanism of Alfresco.
So just place your addition in org/alfresco/slingshot/search, cause Alfresco doesn't has a csv.ftl file, so it will be available.
The extension module is uses to extend/change the default get.js & get.html.ftl file, so I'm not sure if it will accept any addition if you don't specify the one of the above files.

Gradle replace token in a file during build process

I have a web application and I use gradle to build it. In one of the xml files in WEB-INF folder (src/main/webapp/WEB-INF/my.xml) I have a piece of file that needs replacing.
<system-properties>
<property name="clientId" value="#clientId#" />
</system-properties>
When I try to replace the token with some value using:
processResources{
filter(ReplaceTokens, tokens:['clientId': 'test'])
}
Than when I run gradle build the token in the output file (./build/exploded-app/WEB-INF/my.xml) is not replaced. I was wondering which is the correct way to do this?
The problem is that you are configuring the wrong task. processResources only copies files from src/main/resources (or whatever else you define in the main sourceSet as resource), while it is task war which copies / zips your my.xml.
war {
filter(ReplaceTokens, tokens:['clientId': 'test'])
}

Local XSL reference within XML-File

First a short task description:
There is an XML file which references a xsl stylesheet which is within a *.dll.
The beginning of this XML looks as follows:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='res://name_xsl.dll/frameset.xsl'?>
This xml file can be opened and displayed as an HTML within Internet Explorer and only IE.
(The xsl transform the xml to html)
As you can see it references the win32 system folder, in which the dll file is saved.
Referencing with "res://" does work.
But now I do not want to store my dll within the system folder, but under a different folder lets say %ALLUSERSPROFILE% (environment variable) which e.g. on Windows XP is C:\Documents and Settings\All Users or on Win7 C:\Users\Public (Not sure about that one).
How do I reference to the dll lying in that folder?
Is it possible to do this using environment variables, such that it is system independent?
What solution would you recommend.
(All html, xsl data is saved locally within the dll on the local computer.)
So far I have tried to change the reference line to the following:
<?xml-stylesheet type='text/xsl' href='file:///c:/Documents and Settings/All Users/name_xsl.dll/frameset.xsl'?>
I have also tried the same with the root folder c: and even without absolute path having all files (xml and dll) in the same folder.
All attempts without res:// resulted in the following error message:
The system cannot locate the resource specified.
Error processing resource 'file:///C:/Documents and Settings/All Users/name_xsl.dll/...
or 'file:///C:/name_xsl.dll/frameset.xsl'
Could you help me out? Why it does not find the file?
(filenames are fictive)
This is the solution:
<?xml-stylesheet type='text/xsl' href='res://C:%5CDocuments and Settings%5CAll Users%5Cname_xsl.dll/frameset.xsl'?>
Notes:
You MUST use the res:// protocol to access a resource within a file.
File system backslashes can be encoded as %5C . Possibly forward slashes will work as well.
Example:
I tested this example for the file:// protocol, but it should work the same way as the res: protocol. On my system, I have a text file located at:
C:\Program Files\CodeGear\Delphi for PHP\2.0\privacy.txt
I can access this file, by putting into the nav bar of the Windows File Explorer:
file:///%ProgramFiles%/CodeGear/Delphi for PHP/2.0/privacy.txt
Notice backslashes converted to forward slashes, and no need to escape spaces. This has been tested and it works. The equivalent on the res protocol had not been tested, but it should work the same way, except of course that the res protocol is slightly different in that it also includes a resource index number.
Refer http://msdn.microsoft.com/en-us/library/ie/aa767740(v=vs.85).aspx for syntax.

Create jar file that can be executed on any machine

I have simple java app that prints `hello world!' on console. It is packed in app.jar.
Jar structure:
main/Hello.class - my main class with singe println method
META-INF/MANIFEST.MF
Manifest file contains following:
Manifest-Version: 1.0
Main-Class: main.Hello
Everything goes fine.
But when you have a dependency than troubles begin. I'm not sure but think in this case you have to put all libs to jar file. If I put them in META-INF/lib I must specify "Class-Path" in manifest. How "Class-Path" will look?
P.S There are some resembling questions but I haven't found appropriate answer.
I tend to use an ANT build script to package my application and all necessary jar files. I find this makes life much easier once you've got it working properly.
build.xml file looks something like:
<project default="create_run_jar" name="Create Runnable Jar for MyProject">
<!--ANT 1.7 is required -->
<target name="create_run_jar">
<jar destfile="my-runnable-jar.jar">
<manifest>
<attribute name="Main-Class" value="my.MainClass"/>
<attribute name="Class-Path" value="."/>
</manifest>
<fileset dir="E:/path/to/my/project/bin"/>
<fileset dir="E:/path/to/my/project/classes"/>
<zipfileset src="E:/path/to/library/some-library.jar"/>
</jar>
</target>
</project>
Note that if you use Eclipse, you can simplly do File / Export... / Runnable jar file and it will do everything for you (including generating the ANT build.xml).
You don't have to specify anything special if you unpack the libraries and integrate them into your project. If you do this, you should have a "main" folder, and if you have org.apache.foo as an external library, you'll also have an "org" folder at the top level.

Is there any way to add sections to .config files that will not be parsed by ConfigurationManager

I don't want to create separate configuration file for my app but store the data in the web.config.
I just want to put some XML there and manually parse it because current implementation of ConfigurationManager isn't appropriate for my case.
However, without dummy classes and properties I can't add my XML there without getting Configuration Error: Parser Error Message: Unrecognized element XXXXX. Even if I create dummy configuration classes I can't fix this error in all cases...
Is there any way to mark my XML not to be parsed so that I can use System.XML to manually get the data.
Thx.
Use System.Configuration.IgnoreSectionHandler.
Example:
<configuration>
<configSections>
<section
name="myCustomSection"
type="System.Configuration.IgnoreSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowLocation="false" />
</configSections>
...
<myCustomSection>
...
</myCustomSection>
...
</configuration>
I would suggest creating a custom figuration section if you want to store the data in your .configs
www.codeproject.com/KB/cs/CustomConfigurationSectio.aspx
I don't think you can do this - you need to conform to the XML schema for configuration files if you play around in the *.config files - and this means, you need to have your sections according to the specified schema, and if that's the case, ConfigurationManager will be able to parse them (and will do so).
If you need extra config information that doesn't conform to the standard .NET config schema, you'll have to use extra, separate config files - I don't see any other way, sorry.
Marc