Sharing session (JSP) in 2 different project - eclipse

is there anyway of sharing the Session data across two different JSP (i mean two dynamic web project)
projects
in the 1st project i test like that
<%if(session.getAttribute("UserName") != null ){%>
.
.
do something
.
<% } %>
it's ok
but when i do that in the 2nd project i got this exception
Etat HTTP 404 - /myEbookSearchClient/myEBook/WebContent/JSP/session/index.jsp
--------------------------------------------------------------------------------
type Rapport d''état
message /myEbookSearchClient/myEBook/WebContent/JSP/session/index.jsp
description La ressource demandée (/myEbookSearchClient/myEBook/WebContent/JSP/session/index.jsp) n'est pas disponible.
--------------------------------------------------------------------------------
Apache Tomcat/7.0.5
Basically, I'm jumping from a page in one to a page in another
any idea how to Shar the session of the 1st project with the 2 project ?

You cant. Attempting to share sessions is discouraged for a variety of reasons primarily related to security.
Servlet contexxt methods that retreieve a session by id or return an enumeration of all now all do nothing for precisely this reason.
You will need to share data in some other manner such as a cache or via a database.

Related

Can't retrieve crawling errors using Python client

A while ago (around 3 months) I used gsc api to retrieve crawl errors, but it does not work right now. Here is the code:
# oauth2flow <--- function implementing authorization
service = oauth2flow(name='webmasters', fname='path_to_client_secret', scope='https://www.googleapis.com/auth/webmasters', version='v3')
self.service.urlcrawlerrorssamples().list(
siteUrl=siteUrl,
category=category,
platform=platform
).execute()
The problem is that urlcrawlerrorsamples is not recognized (AttributeError: 'Resource' object has no attribute 'urlcrawlerrorssamples'). All other things like seachanalytics, sites work just fine. I have problem only with crawling errors.
Here is my package list:
google-api-core==1.11.1
google-api-python-client==1.7.9
google-auth==1.6.3
google-auth-httplib2==0.0.3
google-auth-oauthlib==0.2.0
google-cloud-core==1.0.1
google-cloud-storage==1.16.1
google-resumable-media==0.3.2

Need Yii2 Equivalent of Zend_Session_Namespace

I am currently migrating an old Zend 1.1 website and need a replacement for the uses of Zend_Session_Namespace.
Does one exist for Yii2? Or alternatively is there a plugin or something to add this functionality?
-Edit:
Specifically the ability to set expiry timeouts and hop limits like Zend has.
Thank you.
UPDATE
The info you have added in the edit was never mentioned earlier and makes your question too broad you might create a separate question for that.
By default session data are stored in files. The implementation is locking a file from opening a session to the point it's closed either by session_write_close() (in Yii it could be done as Yii::$app->session->close()) or at the end of request. While session file is locked all other requests which are trying to use the same session are blocked i.e. waiting for the initial request to release the session file. this can work for dev or small projects. But when it comes to handling massive concurrent requests, it is better to use more sophisticated storage, such as a database.
Zend_Session_Namespace instances provide the primary API for manipulating session data in the Zend Framework. Namespaces are used to segregate all session data, if you are converting the script to Yii2 framework you might need to look into https://www.yiiframework.com/doc/api/2.0/yii-web-session
A simple example to compare both of the functionalities by example are
Zend Framework 1.1 Counting Page Views
$defaultNamespace = new Zend_Session_Namespace('Default');
if (isset($defaultNamespace->numberOfPageRequests)) {
// this will increment for each page load.
$defaultNamespace->numberOfPageRequests++;
} else {
$defaultNamespace->numberOfPageRequests = 1; // first time
}
echo "Page requests this session: ",
$defaultNamespace->numberOfPageRequests;
Yii2 Framework Counting Page Views
public function actionIndex()
{
$session = new \yii\web\Session();
$session->open();
$visits = $session->get('visits', 0);
$visits = $visits+1;
$session->set('visits', $visits);
return "Total visits $visits";
}

Sammy.js working fine one localhost but not when calling from remote computer

I'm working one SPA with sammy.js and jquery.tmpl.
It's kind of huge project what the company want to work as an SPA.
The issue is that there are few different states for the app (used to be three different pages and now it is all in one, add, edit and add for a non registered client).
When i am developing from my own station (IIS6.1 for windows 7, not VS IIS) and using both localhost of my IP address every thing is working great, but when trying to connect with a domain name (changes the host in my station) or from a remote computer both with ip or domain name i'm getting an 404 from sammy:
body 404 Not Found get /employer/newemployers/index.aspx#/edit/2354478 Error {message: "404 Not Found get /employer/newemployers/index.aspx#/edit/2354478 ", stack: "Error↵ at Object.n.Application.e.extend.error (…oyers/javascript/lib/jquery-1.7.2.min.js:3:17273)"} sammy-0.7.4.min.js:8
My Sammy.js code:
$.sammy('body', function () {
this.get('#/', index);
this.get('#/index', index); //For Non registered Employer
this.get('#/indexPageAdd', indexPageAdd); //For Registered Employer
this.get('#/Edit/:JobID', MainEdit); // For Job Edit
this.get('#/firstStage', firstStage);
this.get('#/secondStage', secondStage);
this.get('#/thirdStage', thirdStage);
}).run('#');
Any one encountered this type or issue? Couldn't find this anywhere..
Thank you
Found the answer,
When calling from my own computer( localhost or ip), Sammy.js is case insensitive, but when trying to use real urls (on my own computer or from remote computer) need to use case sensitive urls, the edit is with capital E and i used lowercase e and didn't notice.... added a record for lowercase and every thing is working great now.
Hope this helped anyone with the same problem

Can I add multiple servlets to a WebAppContext?

I have the following Scala code to setup a Jetty server with Scalatra.
val server = new Server(8080)
val context = new WebAppContext()
context.setResourceBase("visualization")
context.addServlet(new ServletHolder(new CallTreeServlet(dataProvider)), "/*")
context.addServlet(new ServletHolder(new DataLoadingServlet(dataProvider)), "/*")
server.setHandler(context)
My problem is that it seems to work only if I register a single servlet.
If I register more than one, like I do in the code I posted, it loads only one of them.
Is it possible to load multiple servlets? I guess it is, but I can't figure out how.
If I try to load a page from the first servlet I got this error message that references only pages belonging to the second servlet:
Requesting "GET /callTrees" on servlet "" but only have:
GET /components
POST /load
POST /searchCallTrees
POST /selectPlugIn
To troubleshoot this, you should verify the servlet lifecycle. One convenient way to do this is to peruse the servlet container's logs to see what it reports while starting up the web application. It should tell you about each web app ( servlet context ) and each servlet . . .
However, I think I see what your problem is. Your servlet path mappings are kind of funky. It looks to me that you are mapping both servlets to receive ALL requests. This can't work, from a practical point of view, and might not work in terms of the servlet rules. From the servlet specification:
SRV.11.2
Specification of Mappings
In the Web application deployment descriptor, the following syntax is used to define
mappings:
• A string beginning with a ‘/’ character and ending with a ‘/*’ suffix is used
for path mapping.
• A string beginning with a ‘*.’ prefix is used as an extension mapping.
• A string containing only the ’/’ character indicates the "default" servlet of
the application. In this case the servlet path is the request URI minus the con-
text path and the path info is null.
• All other strings are used for exact matches only.
I suggest you make them both unique. As it looks now, you have them both at "/*" which is kind of like the "default servlet", but not . . .
Why not try "/first/" and "/second/" as a sanity check. Then move from there toward getting the configuration how you like.

What is the best way to log errors in Zend Framework 1?

We built an app in Zend Framework (v1) and have not worked a lot in setting up error reporting and logging. Is there any way we could get some level or error reporting without too much change in the code? Is there a ErrorHandler plugin available?
The basic requirement is to log errors that happens within the controller, missing controllers, malformed URLs, etc.
I also want to be able to log errors within my controllers. Will using error controller here, help me identify and log errors within my controllers? How best to do this with minimal changes?
I would use Zend_Log and use the following strategy.
If you are using Zend_Application in your app, there is a resource for logging. You can read more about the resource here
My advice would be to choose between writing to a db or log file stream. Write your log to a db if you plan on having some sort of web interface to it, if not a flat file will do just fine.
You can setup the logging to a file with this simple example
resources.log.stream.writerName = "Stream"
resources.log.stream.writerParams.stream = APPLICATION_PATH "/../data/logs/application.log"
resources.log.stream.writerParams.mode = "a"
resources.log.stream.filterName = "Priority"
resources.log.stream.filterParams.priority = 4
Also, I would suggest sending Critical errors to an email account that is checked regularly by your development team. The company I work for sends them to errors#companyname.com and that forwards to all of the developers from production sites.
From what I understand, you can't setup a Mail writer via a factory, so the resource won't do you any good, but you can probably set it up in your ErrorController or Bootstrap.
$mail = new Zend_Mail();
$mail->setFrom('errors#example.org')
->addTo('project_developers#example.org');
$writer = new Zend_Log_Writer_Mail($mail);
// Set subject text for use; summary of number of errors is appended to the
// subject line before sending the message.
$writer->setSubjectPrependText('Errors with script foo.php');
// Only email warning level entries and higher.
$writer->addFilter(Zend_Log::WARN);
$log = new Zend_Log();
$log->addWriter($writer);
// Something bad happened!
$log->error('unable to connect to database');
// On writer shutdown, Zend_Mail::send() is triggered to send an email with
// all log entries at or above the Zend_Log filter level.
You will need to do a little work to the above example but the optimal solution would be to grab the log resource in your bootstrap file, and add the email writer to it, instead of creating a second log instance.
You can use Zend_Controller_Plugin_ErrorHandler . As you can see on the documentation page there is an example that checks for missing controller/action and shows you how to set the appropriate headers.
You can then use Zend_Log to log your error messages to disk/db/mail.