Bug 235306 - [API Request] add setContextRoot() to WebUtilities
Summary: [API Request] add setContextRoot() to WebUtilities
Status: RESOLVED FIXED
Alias: None
Product: WTP Java EE Tools
Classification: WebTools
Component: jst.j2ee (show other bugs)
Version: 2.0.2   Edit
Hardware: PC Windows XP
: P1 enhancement (vote)
Target Milestone: 3.2 M6   Edit
Assignee: Carl Anderson CLA
QA Contact: Chuck Bridgham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-03 07:26 EDT by Udo Walker CLA
Modified: 2010-02-19 03:22 EST (History)
2 users (show)

See Also:


Attachments
A public API to set the context root (1.40 KB, patch)
2010-02-18 14:55 EST, Carl Anderson CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Udo Walker CLA 2008-06-03 07:26:47 EDT
Build ID: M20071023-1652

Steps To Reproduce:
1. IProgressMonitor monitor = new NullProgressMonitor();
2. IProject project = ... some web project.
3. EARArtifactEdit edit = new EARArtifactEdit(project,false);
4. edit.setWebContextRoot(project,"test");
->NPE


More information:
The variable edit contains after line 3 a not null reference value.
Line 4 creates a null pointer exception.

I also do not understand why I need a project to create the EARArtifactEdit and when I want to set the web context root I need the project again?

I don't know how to set the web context root otherwise.
Comment 1 Carl Anderson CLA 2008-06-03 12:13:30 EDT
Udo, do you just have a standalone Web project, that you want to set the Context Root for?  Or is this Web project a member of an EAR?  And is it a Servlet 2.5 Web module?  Or Servlet 2.4 or earlier?
Comment 2 Carl Anderson CLA 2008-06-03 12:15:39 EDT
Also, if the project in step 2 is a web project, it should not be passed into EARArtifactEdit's constructor - that is for EAR projects.  (So this would appear to be a usage problem.)
Comment 3 Udo Walker CLA 2008-06-04 06:02:19 EDT
The project facets are:

Dynamic Web Module 2.5
Java 6.0
Comment 4 Udo Walker CLA 2008-06-04 06:03:12 EDT
How can I change the context path of a "not EAR" web project?
Comment 5 Carl Anderson CLA 2008-08-06 09:30:18 EDT
The appropriate way to set the context root for a Web project is via

J2EEProjectUtilities.setServerContextRoot(webProject, contextRoot);

While J2EEProjectUtilities is an internal class, it is used extensively by both WTP code and adopters.  If requested, an API can be created to access this.

I am lowering the severity of this bug for now.
Comment 6 Udo Walker CLA 2008-08-06 10:28:34 EDT
Hi Carl,

a public API for setting the context root would be great!

Comment 7 Carl Anderson CLA 2008-08-06 10:46:16 EDT
The proper place to put this would be in WebUtilities.
Comment 8 Carl Anderson CLA 2010-02-18 14:55:24 EST
Created attachment 159476 [details]
A public API to set the context root
Comment 9 Carl Anderson CLA 2010-02-18 14:56:46 EST
Committed to HEAD for WTP 3.2 M6
Comment 10 Udo Walker CLA 2010-02-19 03:22:26 EST
Thanks, I will try in one of our next releases.