The requested resource () is not available. - iframe pdf - html

Inside of iframe I get the error message :
HTTP Status 404 -
type Status report
message
descriptionThe requested resource () is not available.
GlassFish Server Open Source Edition 3.1.2.2
I have placed a pdf in the folder resources/pdf/1.pdf and it does not matter where I place this file, I get this error, what have I done wrong or forgotten to do, it is a page that just shows the user an instruction manual.
<iframe src="/resources/pdf/1.pdf"></iframe>
|
| Gui
| `---- submittedPDF.xhtml
|
|
|resources
`pdf
`1.pdf
Heres a print screen of the structure
http://i1081.photobucket.com/albums/j348/west-wot/directory_zpsf8b3b5aa.png

Update your code in the submittedPDF.xhtml to
<iframe src="../resources/pdf/1.pdf"></iframe>
.. and . have following meanings in file paths:
.. means up one directory and . means current directory.

<iframe src="/resources/pdf/1.pdf"></iframe>
The leading slash brings you to the domain root, skipping the context path.
You need to include the context path:
<iframe src="#{request.contextPath}/resources/pdf/1.pdf"></iframe>
Or, as it's apparently been placed in /resources folder, use the implicit #{resource} map:
<iframe src="#{resource['pdf/1.pdf']}"></iframe>
Either way, it'll autogenerate the proper domain-relative URL, including the context path.

Related

Fatfree routing with PHP built-in web server

I'm learning fatfree's route and found it behaves unexpected.
Here is my code in index.php:
$f3 = require_once(dirname(dirname(__FILE__)). '/lib/base.php');
$f3 = \Base::instance();
echo 'received uri: '.$_SERVER['REQUEST_URI'].'<br>';
$f3->route('GET /brew/#count',
function($f3,$params) {
echo $params['count'].' bottles of beer on the wall.';
}
);
$f3->run();
and here is the URL which I access: http://xx.xx.xx.xx:8090/brew/12
I get a 404 error:
received uri: /brew/12
Not Found
HTTP 404 (GET /12)
the strange thing is that the URI in F3 is now "/12" instead of "/brew/12" and I guess this is the issue.
When I check the base.php (3.6.5), $this->hive['BASE'] = "/brew" and $this->hive['PATH'] = "/12".
But if F3 only uses $this->hive['PATH'] to match the predefined route, it won't be able to match them.
If I change the route to:
$f3->route('GET /brew',
and use the URL: http://xx.xx.xx.xx:8090/brew, then the route matches without issue.
In this case, $this->hive['BASE'] = "" and $this->hive['PATH'] = "/brew". If F3 compares the $this->hive['PATH'] with predefined route, they match each other.
BTW, I'm using PHP's built-in web server and since $_SERVER['REQUEST_URI'] (which is used by base.php) returns the correct URI, I don't think there is anything wrong with the URL rewrite in my .htrouter.php.
Any idea? What did I miss here?
add the content of .htrouter.php here
<?php
#get the relative URL
$uri = urldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
#if request to a real file (such as a html, image, js, css) then leave it as it is
if ($uri !== '/' && file_exists(__DIR__ . $uri)) {
return false;
}
#if request virtual URL then pass it to the bootstrap file - index.php
$_GET['_url'] = $_SERVER['REQUEST_URI'];
require_once __DIR__ . './public/index.php';
Your issue is directly related to the way you're using the PHP built-in web server.
As stated in the PHP docs, here's how the server handles requests:
URI requests are served from the current working directory where PHP was started, unless the -t option is used to specify an explicit document root. If a URI request does not specify a file, then either index.php or index.html in the given directory are returned. If neither file exists, the lookup for index.php and index.html will be continued in the parent directory and so on until one is found or the document root has been reached. If an index.php or index.html is found, it is returned and $_SERVER['PATH_INFO'] is set to the trailing part of the URI. Otherwise a 404 response code is returned.
If a PHP file is given on the command line when the web server is started it is treated as a "router" script. The script is run at the start of each HTTP request. If this script returns FALSE, then the requested resource is returned as-is. Otherwise the script's output is returned to the browser.
That means that, by default (without a router script), the web server is doing a pretty good job for routing unexisting URIs to your document root index.php file.
In other words, provided your file structure is like:
lib/
base.php
template.php
etc.
public/
index.php
The following command is enough to start your server and dispatch the requests properly to the framework:
php -S 0.0.0.0:8090 -t public/
Or if you're running the command directly from the public/ folder:
cd public
php -S 0.0.0.0:8090
Beware that the working directory of your application depends on the folder from which you call the command. In order to leverage this value, I strongly advise you to add chdir(__DIR__); at the top of your public/index.php file. This way, all subsequent require calls will be relative to your public/ folder. For ex: $f3 = require('../lib/base.php');
Routing file-style URIs
The built-in server, by default, won't pass unexisting file URIs to your index.php, as stated in:
If a URI request does not specify a file, then either index.php or index.html in the given directory are returned
So if you plan to define some routes with dots, such as:
$f3->route('GET /brew.json','Brew->json');
$f3->route('GET /brew.html','Brew->html');
Then it won't work because PHP won't pass the request to index.php.
In that case, you need to call a custom router, such as the .htrouter.php you were trying to use. The only thing is that your .htrouter.php has obviously been designed for a different framework (F3 doesn't care about $_GET['url'] but cares about $_SERVER['SCRIPT_NAME'].
Here's an exemple of .htrouter.php that should work with F3:
// public directory definition
$public_dir=__DIR__.'/public';
// serve existing files as-is
if (file_exists($public_dir.$_SERVER['REQUEST_URI']))
return FALSE;
// patch SCRIPT_NAME and pass the request to index.php
$_SERVER['SCRIPT_NAME']='index.php';
require($public_dir.'/index.php');
NB: the $public_dir variable should be set accordingly to the location of the .htrouter.php file.
For example if you call:
php -S 0.0.0.0:8090 -t public/ .htrouter.php
it should be $public_dir=__DIR__.'/public'.
But if you call:
cd public
php -S 0.0.0.0:8090 .htrouter.php
it should be $public_dir=__DIR__.
OK, I checked the base.php and found out when f3 calculates the base URI, it uses $_SERVER['SCRIPT_NAME'].
$base='';
if (!$cli)
$base=rtrim($this->fixslashes(
dirname($_SERVER['SCRIPT_NAME'])),'/');
if we have web server directly forward all requests to index.php, then
_SERVER['SCRIPT_NAME'] = /index.php, and in this this case, base is ''.
if we use URL rewriting via .htrouter.php to index.php, then
_SERVER['SCRIPT_NAME'] = /brew/12, and in this this case, base is '/brew' which causes the issue.
Since I'm going to use the URL rewrite, I have to comment out the if statement and make sure base =''.
Thanks xfra35 for providing the clue.
Apache like php router here:
It can url rewrite.
https://github.com/kyesil/QPHP/blob/master/router.php
Usage:
php -S localhost:8081 router.php

Chrome doesn’t show un-minified code in spite of source map present

I’m using Grunt and UglifyJS to generate source maps for my AngularJS app. It produces a file customDomain.js and customDomain.js.map.
JS file
Last line of customDomain.js looks like this:
//# sourceMappingURL=customDomain.js.map
Map file
I find two references to customDomain.js inside of customDomain.js.map, one at the beginning:
"sources":["../../../.tmp/concat/scripts/customDomain.js"]
I think this looks weird so I trim it to:
"sources":["customDomain.js"]
The second reference is at the end:
"file":"customDomain.js"
...which I leave as it is.
Testing
When I run my app in Chrome I expect to see my development code when I click on customDomain.js, but I do not:
I can see on the console output from my web server that customDomain.js.map is indeed requested from the browser:
200 /js/customDomain.js.map (gzip)
What is missing?
"sources":["customDomain.js"] should be relative to the customDomain.map.js file.
Make sure they are in the same directory on your server if this is the case for you.
"file":"customDomain.js" should be changed to the name of the map file, in your case this would be "file":"customDomain.map.js".
Here's a map file example taken from treehouse (sourceRoot may be unnecessary in your case):
{
version: 3,
file: "script.js.map",
sources: [
"app.js",
"content.js",
"widget.js"
],
sourceRoot: "/",
names: ["slideUp", "slideDown", "save"],
mappings: "AAA0B,kBAAhBA,QAAOC,SACjBD,OAAOC,OAAO..."
}

Google Chrome: DOMException: Registration failed - manifest empty or missing

I am trying to implement Push Notifications on my website (using Pushpad). Therefore I created a "manifest.json" with following content:
{
"gcm_sender_id": "my_gcm_sender_id",
"gcm_user_visible_only": true
}
of course I created a valid GCM-Account and have a sender id
I put the manifest.json into my root directory and I also added this line to my index.php:
<link rel="manifest" href="/manifest.json">
Using Firefox everything works fine and I can send and receive push notifications (so I think the manifest-include works fine), but Chrome won't work...
The console shows following error:
Uncaught (in promise) DOMException: Registration failed - manifest empty or missing
I searched Google for a long time and tried everything I found, but nothing works.
What I tried:
created the manifest.json with "Editor" and saved it as type All Types (so no hidden .txt-file) and also with UTF-8-Encoding.
restarted Chrome
cleared Chrome's cache, history, etc.
I really hope somebody can help me.
For me it was a redirect. The manifest.json must return a 200 status code (must be directly available from the server), without any redirects.
You can check the response via
wget --max-redirect=0 https://example.com/manifest.json
or
curl https://example.com/manifest.json
I faced same issue,added manifest file right after head tag . which worked for me.Cheers!
This may be an issue with your Service Worker scope. I ran into a similar problem when I rearranged my files/directories. Make sure your sw.js is on the same level as your manifest.json, otherwise the service worker won't be able to find your manifest. Try putting them both in the root of your directory. Optionally, you can specify the scope of your service worker by adding it to serviceWorker.register():
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw-test/sw.js', {scope: '/sw-test/'})
.then(function(reg) {
// registration worked
console.log('Registration succeeded. Scope is ' + reg.scope);
}).catch(function(error) {
// registration failed
console.log('Registration failed with ' + error);
});
}
Read more here:
https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers
Was wondering if your "manifest.json" is public accessible ?
If not maybe you can try to set it public accessible to see if that helps or not.
And it seems that the current chrome, when getting the "manifest.json" won't supply the cookies.
Because I didn't find an answer anywhere out there in the WWW, but managed to get it working after some time I want to provide my solution/answer for other users, who probably have the same problem:
In the file where I inlcuded the Pushpad files I wrote some PHP-Code before the <head>-Tag to include some files, e.g. for database connection. After I moved the PHP-Code below the <head>-Tag everything worked fine.
There seem to be three ways to fix this bug:
a) No redirects for "manifest.json" file.
b) Put a link to this file at the top of the tag.
c) Be sure, that there is no other manifest file before this one, cause it seems that web push script will try to import the first one and return an error due to the wrong data.
I have tried all three and finally forced Chrome to behave.
Adding the following block fixed this for me:
self.addEventListener('push', (event) => {
const title = 'Get Started With Workbox';
const options = {
body: event.data.text()
};
event.waitUntil(self.registration.showNotification(title, options));
});

Exit code 1 http error : 1202 - wkhtmltopdf - Google Map (static image)

I have a problem with the generation of a PDF with wkhtmlpdf. Here is my investigation:
1- Generation of PDF with static Google Map image in default mode (default size)
The web page and PDF contain the image.
2- Generation of PDF with static Google Map image with business licence (customize size)
The web page contains the image, the PDF not.
3- In command line
If I run in command line the wkhtmlpdf instruction, I receive this exception code:
Exit with code 1 due to http error: 1202
The only difference between the both is the url parameters &client=XXXXX and &signature=YYY are added for the business call at Google.
I didn't find a description for this http error code on the net and I wonder me if it's really a right http error code.
I am not an expert with wkhtmltopdf.
This is actually issue #1502 and is fixed in the development version, for which you can download a snapshot from the website.
So, the description for this error code is: PDF generated OK, but some request(s) did not return HTTP 200.
In waiting the final version, I decided to load the Google Map image in local and after put a reference in the web page.
With this solution, I don't have any exception while the generation of PDF.
Below is the code to load and save the Google Map image.
String myUrl = "http://www.lesoir.be/sites/default/files/imagecache/475x317/2014/04/02/1670051557_B972392274Z.1_20140402231342_000_GIT27H8H9.2-0.jpg";
URL imageURL = new URL(myUrl);
RenderedImage img = ImageIO.read(imageURL);
File outputfile = new File("C:\\Dev\\Tmp\\Img\\image.jpg");
ImageIO.write(img, "jpg", outputfile);

IBM iWidget Persistent storage of attributes - 404 response when saving in Connections 4.0

I am trying to save a persistent variable for iWidget instances in IBM Connections 4.0
Documentation (link & link) leads me to the following javascript (run with the iWidget in Edit mode):
this.iContext.getiWidgetAttributes().setItemValue("instance","helloWorld");
this.iContext.getiWidgetAttributes().save(); //or .commit(); as save is deprecated
I also tried defined the variable in the widget XML definition:
<iw:itemSet id="attributes" private="false" onItemSetChanged="itemSetChanged">
<iw:item id="instance" value="" readOnly="false"/>
</iw:itemSet>
This sets the value correctly in the local instance, I also see a PUT request to the server to save this value. It returns a 404 Response code. The URL is:
/connections/opensocial/common/repos?st=default%3AcQitETUij2Iqg0A_8mB9A35-pRKmnH_dFUgT4rY-hERIC3ZTNW3hp0OeLr_SYZ2mXWW6OjMtcFPijI_YaIaCDZlduzYgn5FkYQUTiqngHgLqsBMG&type=itemSet&pageId=undefined&widgetId=widget_d785df84b58d4d459707a048014567f6_1369275060798&itemSetId=attributes
The value is no longer stored when I reload the page and try to retrieve it again using:
this.iContext.getiWidgetAttributes().getItemValue("instance");
I notice there is a "pageId=undefined" in the URL.
There are no outputs in the SystemOut.log of the Connections servers.
At the moment this is running in the Homepage "My Widgets" page, but will also be run in Communities application later.
Thanks
For anyone else that comes across this problem, here is what I found;
It turns out that saving through the Homepage refused to work, however I did successfully save Instance Data when the widget is loaded through the Communities mechanism;
JavaScript for saving (.save calls a callback function, but not necessary):
if(this.inCommunity)
{
this.iContext.getiWidgetAttributes().setItemValue("instance",contentToSave);
this.iContext.getiWidgetAttributes().save(dojo.hitch(this,this.dashboardSaved));
}
Loading saved data:
this.instanceData = this.iContext.getiWidgetAttributes().getItemValue("instance");
Widget definition (in widgets-config.xml)
<widgetDef defId="Dashboard" description="MyDash" modes="view edit" url="/Dashboard.xml" uniqueInstance="false">
<itemSet>
<item name="instance" value=""/>
</itemSet>
</widgetDef>
Dashboard.xml
<iw:iwidget xmlns:iw="http://www.ibm.com/xmlns/prod/iWidget" iScope="Dashboard" supportedModes="view edit" mode="view" allowInstanceContent="true">
<iw:resource uri="./dashboard.js"/>
<iw:event id="view" handled="false" onEvent="onView"/>
<iw:event id="edit" handled="false" onEvent="onEdit"/>
<iw:event id="onRefreshNeeded" handled="true" onEvent="onRefresh"/>
<iw:itemSet id="attributes" private="true" onItemSetChanged="itemSetChanged">
<iw:item id="instance" readOnly="false"/>
</iw:itemSet>
<iw:content mode="view">
<![CDATA[<div id="RootWidget"></div>]]>
</iw:content>
<iw:content mode="edit">
<![CDATA[<div id="RootWidget"></div>]]>
</iw:content>
</iw:iwidget>