[opencms-dev] write access to file
Qi Zhang
kksjtu at gmail.com
Thu Oct 27 18:29:01 CEST 2016
Hi Paul,
thank you so much for the help!!
Unfortunately I tested your code and still got HTTP 500 error.
I guess there is some limitation for me in our university system preventing
to switch on/offline.
I could test in my local PC environment. But now I think the issue is
related with the system settings. I'll make an appointment with our
administator.....
Actually my work is set up a download page for a tool our institut want to
publish. And I met another issue which is in real webpage the downloaded
file is polluted. But in online offline projects it works fine... This
system has driven me crazy :(
Maybe I'll just use the webform module.
I'm really appreciated for the help from all of you :)
Best regards,
Qi
2016-10-27 10:17 GMT+02:00 Paul-Inge Flakstad <flakstad at npolar.no>:
> Hi again,
>
>
>
> Sorry it didn't fix your problem. As it turns out, I was half wrong.
>
>
>
> Just tested the following code and it runs without errors Offline, Online
> and logged-out:
>
>
>
> CmsJspActionElement cms = new CmsJspActionElement(pageContext, request,
> response);
>
> CmsObject cmso = cms.getCmsObject();
>
>
>
> // cmso.loginUser("usr", "pwd");
>
>
>
> // NOTE: replace getCurrentProject() with currentProject() on older
> versions
>
> if (cms.getRequestContext().getCurrentProject().isOnlineProject()) {
>
> cms.getRequestContext().setCurrentProject(cmso.readProject("Offline"));
>
> }
>
> out.println("Now in " + cms.getRequestContext().getCurrentProject().getName()
> + " project.");
>
>
>
> HOWEVER: If you wanted to actually *do* something though, like write to a
> file, you'd need to login first. Otherwise, your code would work Offline &
> Online (with your user). But it would not work logged-out (with the Guest
> user) – you'd just get a 500 Server Error. Sound familiar?
>
>
>
> When code runs fine in the Online project, but not when logged-out, that's
> a strong indication of a problem related to the current user and that
> user's privileges.
>
>
>
> I'm not convinced that the project switching is your actual problem. To
> me, it seems likely to be something else.
>
>
>
> To test this, you could try running the code above in a standalone JSP. No
> error means your problem is elsewhere. In that case, you could gradually
> expand the standalone test JSP, in small steps, toward looking like your
> actual problem JSP. First add a small bit (e.g. include the login). Then do
> a test. Then add another bit (e.g. write a file, see
> http://www.opencms-wiki.org/wiki/Modify_file_content_programatically).
> Then test again. And so on. Eventually you should be able to identify the
> culprit.
>
>
>
> PS: If your access to the actual system is limited, have you considered
> testing on a local OpenCms installation?
>
>
>
> HTH :)
>
>
>
> Best regards,
>
> Paul
>
>
>
> *From:* opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces@
> opencms.org] *On Behalf Of *Qi Zhang
> *Sent:* 26. oktober 2016 19:07
> *To:* The OpenCms mailing list <opencms-dev at opencms.org>
>
> *Subject:* Re: [opencms-dev] write access to file
>
>
>
> ahh sorry, it works fine for loging. Just not work when combining with
> switching context code..
>
>
>
> 2016-10-26 19:02 GMT+02:00 Qi Zhang <kksjtu at gmail.com>:
>
> Hi Paul,
>
> I tried:
> CmsObject cmso = cms.getCmsObject();
> cmso.loginUser("myUserName","myPassword");
>
> It still: works fine in offline&online project, but got HTTP500 error in
> actual webpage..(without adding the switching context code yet) :(
>
>
>
> But thanks a lot for help
>
>
>
>
>
> 2016-10-26 17:42 GMT+02:00 Paul-Inge Flakstad <flakstad at npolar.no>:
>
> Hi,
>
>
>
> I may be wrong here, but I'm guessing it's because the Guest user cannot
> switch to the Offline project. (Keep in mind that your CmsObject is
> initialized with a user.) This would explain why it works when you test it
> with your user in the Online project, but fails in the actual online
> version.)
>
>
>
> Try switching to a user with sufficient privileges before you switch to
> the Offline project.
>
>
>
> Best regards,
> Paul
>
>
>
> *From:* opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces@
> opencms.org] *On Behalf Of *Qi Zhang
> *Sent:* 26. oktober 2016 17:29
> *To:* Christoph Kukulies <kuku at physik.rwth-aachen.de>
> *Cc:* The OpenCms mailing list <opencms-dev at opencms.org>
> *Subject:* Re: [opencms-dev] write access to file
>
>
>
> Other pages are all fine. Just this one after clicking submit button..
>
> I have checked,as long as I have these lines of code. I have the error:
>
>
>
>
> *if(curProject.isOnlineProject()){ CmsProject offlineProject =
> cmso.readProject("Offline");
> cmsContext.setCurrentProject(offlineProject); }*
>
> But isn't it the only way to have write access to files? Does it mean we
> can't change to offline context in published webpage?
>
> Here are some related code:
>
>
>
>
> *CmsJspActionElement cms = new CmsJspActionElement(pageContext, request,
> response); CmsObject cmso = cms.getCmsObject(); CmsRequestContext
> cmsContext = cmso.getRequestContext(); CmsProject curProject =
> cmsContext.currentProject();*
>
>
>
> 2016-10-26 14:26 GMT+02:00 Christoph Kukulies <kuku at physik.rwth-aachen.de
> >:
>
> Am 26.10.2016 um 13:09 schrieb Qi Zhang:
>
> Yes, it's a form and the action is a jsp.
>
> Permissions of the jsp?
>
> Do other pages work in www.123.com? Error 500 is "Internal Server Error"
> which indicates a syntax error in jsp sometimes. It's not just a page not
> found (404).
> You gotta gather more information.
>
> Can you invoke the jsp alone in the browser (possibly passing the
> neccessary parameters to it).
>
>
>
> I'm working for a university. So I have limited permissions. I can only
> see server internal error HTTP 500 etc when I visit the page and submit
> form as a guest. Within opencms system all fine.
>
>
>
> On 26 Oct 2016 10:16, "Christoph Kukulies" <kuku at physik.rwth-aachen.de>
> wrote:
>
> what does the log say (opencms.log, tomcat logs)?
> You say, it's a form, right? Is the action a jsp that is invoked?
>
> Am 25.10.2016 um 20:50 schrieb Qi Zhang:
>
> Hi,
>
> the page is visible, just the function doesn't work.There is a webform,
> after clicking the function should be called. And then the page got a HTTP
> 500 error..
>
>
>
> 2016-10-25 19:55 GMT+02:00 Jose Fermin Athie Campollo <
> athiecampollo at gmail.com>:
>
> Hi,
>
> A few questions:
>
> Do you use a balancer or is the server of opencms who resolve the domain?
>
> If it is from opencms you have to set the new domain http://www.opencms-
> wiki.org/wiki/MultiSite_configuration_instructions
>
>
>
> In www.123.com is the only page they can not see?
>
>
>
> Regards
>
>
>
> El mar., 25 de oct. de 2016 a la(s) 11:53, Qi Zhang <kksjtu at gmail.com>
> escribió:
>
> Hi,
>
> thanks for the help!
>
> Yes, I was coding according to the 1st documentation. But my problem is
>
>
>
> http://opencms.123.com/index.html(offline)
> works!
> http://opencms.123.com/index.html(online)
> works!
> http://www.123.com/index.html(online)
> NOT working!
>
> Do you have any idea why it happen?
>
>
>
> 2016-10-25 5:35 GMT+02:00 Jose Fermin Athie Campollo <
> athiecampollo at gmail.com>:
>
> Hi
>
>
>
> Right now i can't see this page. http://www.opencms-wiki.
> org/wiki/Write_a_file_programatically in it you could find a way to
> create a resource and then publish it
>
> Some one else publish the code to create a resource http://opencms.
> 996256.n3.nabble.com/Create-resource-programatically-td15459.html
>
>
>
> You should see the javadoc of CmsObject you can do a lot of thing with
> it.
>
>
>
> Regards
>
>
>
>
>
> --
>
> Best regards,
>
> Qi Zhang
>
>
>
>
>
>
>
> --
> Chris Christoph P. U. Kukulies kukulies (at) rwth-aachen.de
>
>
>
>
> --
>
> Best regards,
>
> Qi Zhang
>
>
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>
>
>
>
>
>
> --
>
> Best regards,
>
> Qi Zhang
>
>
>
>
> --
>
> Best regards,
>
> Qi Zhang
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>
>
>
>
>
--
Best regards,
Qi Zhang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20161027/bd5174d8/attachment.htm>
More information about the opencms-dev
mailing list