Reading context-param in JAX-WS

I have created a JAX-WS using netbeans. How can I read the context-param values added in web.xml, in the web service (it could be any thing like database conneciton string)

Yes, you can configure database acceess information in property file and read using [java.util.Properties|http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html] Or [Apache commons configuration|http://commons.apache.org/configuration/]

Similar Messages

  • May i use context-param in jax-ws?

    I have a web service with jax-ws & jaxb. after deploied it to glassfish. i found it exposed to a servlet.
    so, may i read the context-param elements from web.xml to jax-ws classes? if i can , how wil i do?
    Edited by: Kepeng on Jan 14, 2008 7:44 AM

    Yes, you can configure database acceess information in property file and read using [java.util.Properties|http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html] Or [Apache commons configuration|http://commons.apache.org/configuration/]

  • How to read Standard JSR Portlet Web.xml's context-param

    Hi
    I am completely new to Java.
    I want to keep some configuration in Web.xml in Context param. My Web.xml looks like
    <context-param>
    <param-name>ConfigUrl</param-name>
    <param-value>http://localhost:8083/</param-value>
    </context-param>
    How can I read these values? Can I read these values directly in my JSP file or will I have to read it in my Portlet Class in some function.
    Thanks

    As soon as I use portletConfig, it gives me NullPointerException. I am definitely using <portlet:defineObjects/>
    My Jsp looks as :
    <%@ page contentType = "text/html; charset=windows-1252"
    pageEncoding = "windows-1252"
    import = "javax.portlet.*, java.util.*, port.Port, port.resource.PortBundle,javax.portlet.PortletContext"%>
    <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
    <portlet:defineObjects/>
    <%
    PortletContext ctx = portletConfig.getPortletContext();
    String configpath = "Hello";
    %>
    <label>Welcome</label>
    <label><%=configpath%></label>

  • (SJAS9) Reading a context param in a web service

    Platform - SJAS9, NB5.5
    I am trying to add a web service to a small web project and I need database access for it.
    My web.xml defines 2 different resource-refs for my databases, jdbc/development and jdbc/production. There is also a global context-param named database with values of development or production that defines which database the web app should be using.
    I have two database pools set up under SJAS9 for these resource names, and the servlets can access these just fine using :
        protected Connection getConnection() {
            Connection conn = null;
            try {
                String datasourceName = "jdbc/" + getServletContext().getInitParameter("database");
                Context initCtx = new InitialContext();
                Context envCtx = (Context)initCtx.lookup("java:comp/env");
                DataSource ds = (DataSource)envCtx.lookup(datasourceName);
                log.debug("retrieving database connection for " + datasourceName);
                conn = ds.getConnection();
                log.debug("done");
                conn.setAutoCommit(false);
                return conn;
            catch (SQLException ex) {
                log.error("error getting a connection", ex);
                return null;
            catch (NamingException ex) {
                log.error("error finding the datasource", ex);
                return null;
        }I have just added a web service to the project, and I can't find a way to get the context param. When I created the web service, Netbeans added some annotation around it, and it is not extended any class or implementing any interface (that I can see).
    For the web service, there is no appropriate method equivalent for the call
                String datasourceName = "jdbc/" + getServletContext().getInitParameter("database");so how do I retrieve the context param database so I can know which resource pool to obtain the connection from inside the web service?
    Thanks
    Chris

    Here's how to invoke getServletContext() from a web service:
    First you'll need to add "ServiceLifecycle" to the list of implmentations of your class:
    public class MyService implements WebServices.MyServiceSoap, Remote, ServiceLifecycle {}Next you'll need to add the following:
    private ServletContext servletContext;
    public void destroy(){}  
    public void init(Object context) throws javax.xml.rpc.ServiceException {
       ServletEndpointContext soapContext = (ServletEndpointContext) context;
       servletContext = soapContext.getServletContext();
    Hope this helps!
    Peter

  • Access custom variable value in web.xml context-param?

    My requirement or need is to access a variable value either in a class in my Model project or a backing bean in my View project. For example, one variable I need to access is an application server I am integrating with - 'testserver' or 'productionserver' - I want to be able to configure this within an external file so that I do not have to re-compile my application to change the variable.
    I was thinking about placing this variable in the web.xml <context-param> section as:
    <context-param>
    <param-name>servername</param-name>
    <param-value>testserver</param-value>
    </context-param>
    I need to access this value within a class (not a servlet) on an Application Module service method, though if needed, I could access it from a backing bean and pass it to the service method (less desirable.) Is this a good approach and how do access this variable from within a Java class including any imports I need to do (code example)?
    Thanks and Happy New Year!
    Hopefully most everyone is out spending time with friends and family versus stuck trying to complete a project like me...

    I found an example from SRDemo that provides what I was looking for:
    String serverhostaddress =
    FacesContext.getCurrentInstance().getExternalContext().getInitParameter("param-name-var-in-webxml");

  • Significance of context param in web.xml to initialize any variable?servlet

    I am writing a standalone web appplication for rss (xml) creation where i am having jsp servlets class etc.
    Now to write rss.xml and read it back in application i have temporarily used c:\\rss.xml but to make it capable working in web application which can be uploaded in website i need to make it configurable i need to kep it in context param of web.xml and in init() method of servlet of my application what exactly i should do there.what i have tried is this :
    public class Startup extends HttpServlet {
    private static String rssFeed;
    private ServletContext ctx;
    Logger log = Logger.getLogger(Startup.class);
    public void init(){
    log.debug("Initializing APPLICATION CONTEXT Variables");
    ctx = getServletContext();
    rssFeed = (String)ctx.getInitParameter("RssFeed");
    log.debug("Rss : " + rssFeed);
    String rssFile = this.getServletContext().getRealPath("") + File.separator + "WEB-INF" + File.separator + "rss.properties";
    Properties property = new Properties();
    try{
    InputStream propertiesFile = new FileInputStream(rssFile);
    property.load(propertiesFile);
    catch (IOException e) {
    log.error("IOException during domainValuesList file Reading");
    e.printStackTrace();
    log.error("Exception while loading AllowedDomainValues file");
    log.debug("Domain Values Lists Updated");
    /** Get Host Name (Server Name) where application is hosted on
    public static String getRssFeed(){
    return rssFeed;
    after that i called this startup servlet class in other servlet taken this getRssFeed()
    stored it as string passed as parametr to other class where i need to call it but there i am getting null pointer exception which says not initialized.
    even what i have written in web.xml is here:
    <context-param>
    <param-name>RssFeed</param-name>
    <param-value>c:\\rsshandler.xml</param-value>
    </context-param>
    <servlet>
    <servlet-name>Startup</servlet-name>
    <servlet-class>src.Startup</servlet-class>
    <init-param>
    <param-name>RssFeedConfig</param-name>
    <param-value>/WEB-INF/rss-config.xml</param-value>
    </init-param>
    </servlet>
    <servlet-mapping>
    <servlet-name>Startup</servlet-name>
    <url-pattern>/Startup</url-pattern>
    <load-on-startup>1</load-on-startup>
    </servlet-mapping>
    i tried what i know or understood but its not working.
    one more thing i have doneis:created rss.properties files in web-inf
    lines added are
    rssfeed=c:\\rsshandler.xml
    but even i am not getting this why
    or what sholud i do here.
    this thing needs to be configurablewhich we can change later easily.
    any suggestions.
    thanks
    vijendra

    Ben -
    There can be init params for the servlet or for the servlet context. For the servlet, this looks like:
    <servlet>
    <servlet-name>InitServlet</servlet-name>
    <servlet-class>package1.InitServlet</servlet-class>
    <init-param>
    <param-name>message</param-name>
    <param-value>Hello From Initialization Parameter</param-value>
    </init-param>
    </servlet>
    in the web.xml file, and is accessed using:
    public void init(ServletConfig config) throws ServletException
    super.init(config);
    message = config.getInitParameter("message");
    For a servlet context init param, you define it as you did using the web.xml settings editor:
    <context-param>
    <param-name>hello</param-name>
    <param-value>hi</param-value>
    </context-param>
    This is accessed using:
    public void init(ServletConfig config) throws ServletException
    super.init(config);
    message1 = config.getServletContext().getInitParameter("hello");
    Hope this helps,
    Lynn
    Java Tools Team

  • Problem in using context param for storing database connection information

    Hello Friends,
    I am new to struts & jsp.I am developing a project in struts.I have 1 jsp page called editProfile.jsp.On submitting this page it will call 1 action class.The action class in turn will call the Plain old java class where I have written the logic for updating User Profile.
    I have created context-param in web.xml for database connection information like dbURL , dbUserName , dbPassword , jdbcDriver.Now I want to use these connection information in my Business logic(Plain Old Java Class).As we can use context parameter only in jsp & servlets , I am setting the variables of my business logic class with these context param in jsp itself.
    now when I am calling the updateProfile method of Business logic class from Action class it is giving error as all the connection variables which I set in jsp for my business logic class has become null again.
    I am not getting.If once I have set those variables how come they are becoming null again???Please help me.Any Help will be highly appreciated.Thanx in advance.

    This is the code I have written
    web.xml file
    <context-param>
    <param-name>jdbcDriver</param-name>
    <param-value>oracle.jdbc.driver.OracleDriver</param-value>
    </context-param>
    <context-param>
    <param-name>dbUrl</param-name>
    <param-value>jdbc:oracle:thin:@localhost:1521:gd</param-value>
    </context-param>
    <context-param>
    <param-name>dbUserName</param-name>
    <param-value>system</param-value>
    </context-param>
    <context-param>
    <param-name>dbPassword</param-name>
    <param-value>password</param-value>
    </context-param>
    EditProfile.jsp
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@ page import="java.sql.*" %>
    <jsp:useBean id="EditProfile" scope="application"
    class="com.myapp.struts.EditProfile"/>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Edit My Profile</title>
    </head>
    <body>
    <form action="submitEditProfileForm.do" focus="txt_FirstName" method="post">
    <%
    EditProfile.setjdbcDriver(application.getInitParameter("jdbcDriver"));
    EditProfile.setdbURL(application.getInitParameter("dbURL"));
    EditProfile.setdbUserName(application.getInitParameter("dbUserName"));
    EditProfile.setdbPassword(application.getInitParameter("dbPassword"));
    -----------more code goes here------------
    EditActionProfile.java
    package com.myapp.struts;
    import javax.servlet.jsp.jstl.core.Config;
    import org.apache.struts.action.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.sql.*;
    public class EditProfileAction extends Action {
    public EditProfileAction()
    public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) throws Exception
    try
    if (isCancelled(request))
    return mapping.findForward("mainpage");
    EditProfileForm epf = (EditProfileForm)form;
    EditProfile ep = new EditProfile();
    String temp = ep.updateProfile(epf.getTxt_FirstName(),epf.getTxt_MiddleName() , epf.getTxt_LastName() , epf.getTxt_Address() , epf.getTxt_Email() );
    if(temp.equals("SUCCESS"))
    return mapping.findForward("success");
    else
    return mapping.findForward("failure");
    catch(SQLException e)
    System.out.println("error" + e.getMessage());
    return mapping.findForward("failure");
    EditProfile.java class (My Business Logic Class)
    package com.myapp.struts;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.sql.*;
    public class EditProfile {
    private String dbURL;
    private String dbUserName , jdbcDriver;
    private String dbPassword;
    private Connection con;
    private Statement stmt;
    public EditProfile()
    public void setdbURL(String s )
    this.dbURL = s;
    public void setdbUserName(String s )
    this.dbUserName = s;
    public void setdbPassword(String s )
    this.dbPassword = s;
    public void setjdbcDriver(String s )
    this.jdbcDriver = s;
    public String updateProfile(String firstname , String middlename , String lastname , String address , String email)
    throws SQLException, ClassNotFoundException , java.lang.InstantiationException , IllegalAccessException
    try
    String s1 = new String("update usr set first_name='" + firstname + "' , middle_name='" + middlename + "' , last_name='" + lastname +"' , address='" + address + "' , email_id='" + email + "' where usr_key=1" );
    con = this.init();
    System.out.println("after init");
    stmt = con.createStatement();
    int rslt = stmt.executeUpdate(s1);
    System.out.println("after excute update");
    stmt.close();
    if(rslt>=1)
    return "SUCCESS";
    else
    return "Failure";
    finally
    if (null != con)
    con.close();
    public Connection init() throws SQLException, ClassNotFoundException
    Class.forName(jdbcDriver);
    con = DriverManager.getConnection(dbURL, dbUserName, dbPassword);
    return con;
    public void close(Connection connection) throws SQLException
    if (!connection.isClosed())
    connection.close();
    }

  • Use combination context param, EL of databinding in a EL.

    Hi. I have a image tag(ADF Faces.General Controls). I add into source attribute at common of property palette a EL #{resource['images:bakery.jpg']} with bakery.jpg is a image locate directy in images directory. Now, I want to change images directory by a context param that i added and bakery.jpg by a EL of databinding, as #{bindings.Name.inputValue}. Purpose is to change dynamically image displayed. How to do that? Thanks.

    Hi,
    using Google to search for : EL JSF context parameter brings up
    http://stackoverflow.com/questions/6523193/jsf-2-how-can-i-get-a-context-param-value-from-web-xml-using-jsf-el
    For the image name, if it is in an ADF attribute you use
    #{bindings.attributeName.inputValue}
    So concatenating it
    #{initparam El as in link above}/#{bindings.attributeName.inputValue}
    or, to read it from HTTP and not through the faces servlet
    /#{initparam El as in link above}/#{bindings.attributeName.inputValue}
    Frank

  • 9.0.3, web.xml, context-param

    Using documentation found on oracle's website, where I needed to have a specific initialization parameter, I setup a context-param in web.xml. In 9.0.2, I got a warning (and posted here but got no response) but was able to continue. In 9.0.3 I can't run my project when I include this parameter.
    Here's what I add to web.xml
    <context-param>
    <param-name>ReportServerURL</param-name>
    <param-value>http://localhost:8888/reports/rwservlet</param-value>
    </context-param>
    when trying to compile, I get:
    Error(76,18): Invalid element 'context-param' in content of 'web-app', expected elements '[taglib, resource-ref, security-constraint, login-config, security-role, env-entry, ejb-ref]'.
    Any ideas?
    Thanks,
    Jeff

    If only you would see web-app.dtd you could know that context-param must be enclosed in web-app and be at certain place. See that (from web-app.dtd):
    <!ELEMENT web-app (icon?, display-name?, description?, distributable?,
    context-param*, filter*, filter-mapping*, listener*, servlet*,
    servlet-mapping*, session-config?, mime-mapping*, welcome-file-list?,
    error-page*, taglib*, resource-env-ref*, resource-ref*, security-constraint*,
    login-config?, security-role*, env-entry*, ejb-ref*, ejb-local-ref*)>

  • Generated JSP reports and context-param in web.xml

    I have what I believe to be a problem when using .jsp files generated from reports builder (actually, it looks as if the problem is in the reports tag library. When adding a context-param to web.xml, I get an error when compiling the following line:
    <%@ taglib uri="/WEB-INF/lib/reports_tld.jar" prefix="rw" %>
    Error(1): oracle.xml.parser.v2.XMLParseException: Invalid element 'context-param' in content of 'web-app', expected elements '[taglib, resource-ref, security-constraint, login-config, security-role, env-entry, ejb-ref]'.
    Note that I can read the context param and no other JSP pages seem to care, just those with the Reports Tag library.
    Regards,
    Jeff

    Ben -
    There can be init params for the servlet or for the servlet context. For the servlet, this looks like:
    <servlet>
    <servlet-name>InitServlet</servlet-name>
    <servlet-class>package1.InitServlet</servlet-class>
    <init-param>
    <param-name>message</param-name>
    <param-value>Hello From Initialization Parameter</param-value>
    </init-param>
    </servlet>
    in the web.xml file, and is accessed using:
    public void init(ServletConfig config) throws ServletException
    super.init(config);
    message = config.getInitParameter("message");
    For a servlet context init param, you define it as you did using the web.xml settings editor:
    <context-param>
    <param-name>hello</param-name>
    <param-value>hi</param-value>
    </context-param>
    This is accessed using:
    public void init(ServletConfig config) throws ServletException
    super.init(config);
    message1 = config.getServletContext().getInitParameter("hello");
    Hope this helps,
    Lynn
    Java Tools Team

  • Read Context  Node/Attribute option in webdynpro code wizard not available

    Hi Expets,
    I am new to webdynpro Abap, i have developed a small application to set default values for two fields. i want to use code wizard to implement the code. When i click on code wizard icon  in application tool bar, i have found lot of option like Method call in current controller, method call in used controller, Instantiate used component ... etc. But i didn't find the option Read Context Node/Attribute. Do i need to do any settings to get that. Kindly suggest. Your help will be greatly appreciated.
    Venkat

    Hi,
    Check the NW release,
    I checked with NW 7.02 - 2 tabs were available.
    with NW 7 - only 1 tab was available which you mentioned.
    Additional tab (Context ) might have been added after NW release 7.0.
    Regards
    Manas Dua

  • Web.xml context-param problem...

    Hi all,
    Thoes anyone know how to set CHECK_FILE_MODIFICATION in web.xml param permanently, because whenever I set it on true, after few moments it's back on false?
        <context-param>
            <param-name>org.apache.myfaces.trinidad.CHECK_FILE_MODIFICATION</param-name>
            <param-value>true</param-value>
        </context-param>Regards,
    s o v i e t

    Hi Soviet,
    We suffer from the same bug (which is very annoying) on our project too. One of the exasperated team member fixed it by saving the value to true then removing the write right on that file at OS level... It's a hardcore fix, but it works.
    Regards,
    ~ Simon

  • "Read context" radio button  not found in ECCEHP4 version

    Hello friends,
                         I am new to webdynpro abap.
                         In SE80 when i click on "webdynpro wizard" button in menubar, i can not see the "Read Context" radio button. We are using ECCEHP4 version. So anyone can please tell what to do.
    Regards,
    Mihir

    Hi Mihir,
    When you open the Code wizard there will be two tabs 1- Context 2-General.
    In context there will be a field Node, by using F4 you can choose your context node and Read it by selecting the Read Radio button under this Input field.
    Please revert us if you are still not able to read the context node.

  • Read applet param with unknown name

    To read an applet param, there's the method "String getParameter(String name). For using this method I need to know the parameters name.
    Does anybody know a way to read all params, without knowing all possible
    param names?
    Thanks for any help.
    Marko M�ller

    Yikes ... not sure. Perhaps you could try to indicate what you are doing and implement it an alternate way. I have gotten around this in the past using various tricks. One of them (briefly) is to use a generic parameter accumulator:
    <param NAME="keyValue0" VALUE="pieWedge1|15.43">
    <param NAME="keyValue1" VALUE="pieWedge2|10.57">
    <param NAME="keyValue2" VALUE="pieWedge3|12.00">
    <param NAME="keyValue3" VALUE="pieWedge4|12.00">
    <param NAME="keyValue4" VALUE="pieWedge5|25.00">
    <param NAME="keyValue5" VALUE="pieWedge6|50.00">
    Then you can just loop through and do
    .getParameter("keyValue" + String.ValueOf(i));
    and pick out all of the parameters. I pass each of the key value parameters to a decoupler, which parses out based on my "|" delimeter, and adds the parameters to a hashtable keyed on the key portion of the keyvalue pair, for easy access.
    In essense, you can do this with ALL of your dynamic parameters. I tend to use logical groupings myself. That is you can separate them by using keyValue#, option#, etc so that you can differentiate various sets of dynamic parameters to your applet.
    Hope this helps. If you find another way of grabbing all parameters, I would like to see what you come up with.

  • How to read the param in an URL with an applet???

    I will like to read the in an URL with an applet param (after the ?)
    I need the equivalent of: String parm1 = request.getParameter("param"); but for applet
    I think the HttpServletResponse doesn't work in an applet ???
    Tell me if I'am right
    Thanks for your help
    Benoit

    Hi
    What you can do is, just get that URL in the web page. Like as we can get in the ASP. Store the required information in the variables and pass this information as parameters to the applet.
    Hope this helps!

Maybe you are looking for

  • Re: [iPlanet-JATO] Re: Href click & tiled view display

    Srinivas-- Remember, attachments don't come through on the forum. Please send them to the jatoteam@e... alias. Todd ----- Original Message ----- From: "Srinivas Chikkam" <srinivas.chikkam@w...> Sent: Thursday, July 19, 2001 5:26 AM Subject: [iPlanet-

  • HOW TO Change behaviour of attendance type

    Hi guys, I have a question for you: - I have an attendance "9500 Extra Time", for overtime, introduced through IT 2002, which belongs to attendance type "O" (Overtime). When time schema is executed, attendances of this type are added to table TIP (6t

  • Regarding file content conversion

    Re: regarding file content conversion   Posted: Sep 25, 2008 11:30 AM    in response to: kummari     Edit      E-mail this message      Reply  i tried.but m getting this error Message processing failed. Cause: com.sap.aii.af.ra.ms.api.RecoverableExce

  • What video format is needed to play videos in an iPhoto slideshow?

    I would like to use pictures and video to play throughout the slideshow however, the pictures play fine but the video just shows a blank black screen when I play. Is there a certain format that the videos must be in for them to register in a slidesho

  • 10.7 share to 10.6?

    Hi, i'm trying to share a calendar I've created in iCal in lion with a friend running snow leopard, but he is being asked to upgrade to iCloud. Does he have to do this? Thanks, Andrew.