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/]

Similar Messages

  • 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/]

  • 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

  • How to use application params in .EAR files

    When we build an ear file , Weblogic-application.xml provides application-param
    tag?
    are they similar to env-entry in ejb-jar.xml.
    Can I use application-param tag to define a configurable params
    say myName and value as "Harshad"
    How do i read it in the application say a simple java class that is included in
    a jar inside the ear file.

    application-param tag in weblogic-application.xml may be used to define parameters:
    webapp.encoding.default
    webapp.encoding.usevmdefault
    webapp.getrealpath.accept_context_path
    http://e-docs.bea.com/wls/docs81/programming/app_xml.html#1034632
    "Harshad Nanal" <[email protected]> wrote:
    >
    When we build an ear file , Weblogic-application.xml provides application-param
    tag?
    are they similar to env-entry in ejb-jar.xml.
    Can I use application-param tag to define a configurable params
    say myName and value as "Harshad"
    How do i read it in the application say a simple java class that is included
    in
    a jar inside the ear file.

  • 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

  • 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>

  • 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*)>

  • (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

  • 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

  • [svn:bz-trunk] 21273: Fix an issue in MXMLServlet where we use context real path to locate sdk home .

    Revision: 21273
    Revision: 21273
    Author:   [email protected]
    Date:     2011-05-17 12:53:10 -0700 (Tue, 17 May 2011)
    Log Message:
    Fix an issue in MXMLServlet where we use context real path to locate sdk home.
    Modified Paths:
        blazeds/trunk/qa/resources/webtier/qa/src/qa/utils/mxml/MXMLCServlet.java

    Remember that Arch Arm is a different distribution, but we try to bend the rules and provide limited support for them.  This may or may not be unique to Arch Arm, so you might try asking on their forums as well.

  • Create Separate Master Rep for DEV, QA & PROD or just use Contexts

    In line with a previous question I posed on the usage of Contexts for the "ODI touted" one set of code for various environments, I'm wondering in implementation, how many architects have actually used Contexts in the place of different environments (and hence code sets) for DEV, QA and PROD.
    Example, I could have an ODI Master/Work for a DEV environment and then when I move to QA/TEST, I'll have another ODI Master/Work and another ODI Master/Work for PROD. This way, I have true change management and ODI Object Code will be locked from after it leaves the DEV environment. Export from the DEV Master/Work and Import into the QA Master/Work; as well import from QA to PROD Master/Work.
    I've been in an ODI application environment where we did just as above in order to ensure the integrity of the code set (i.e. locked after DEV).
    The other approach is to have just one Master/Work (or multiple Works for Execution or such) and then use the Contexts in the Topology to point to different physical servers. Although this allows for 1 set of code (in the previous approach when Export/Import from DEV to QA you still have to change the physical data server in QA), there's less integrity in the code set.
    So long story short, I'm just wondering what you all have done from an architecture standpoint; pros/cons and etc. Thanks for the input.

    1. One master for DEV & QA ( Multiple Work repository), One Master for prod (Execution work repository)
    Merits:
    -Easier to maintain.
    -If you need the complete project in QA without export/import of each object, solution will be the best approach to implement it. Just restore the solution in QA environment.
    -No need to take special care about the logical schema as you are using the same master repository that was in QA.
    -It will take less time to test each objects.
    -Once the testing is done promote scenarios to production.
    -The very common issue regarding id conflict will not occur frequently.
    Demerits:
    -Sharing the same topology between dev & qa will create unnecessary issues like a developer can have the privilege to change the physical dataserver details. Even if you restrict from editing/deleting, the number of logical schema will goes on increasing day by day. So here you have to have a dedicated admin who will take care of this topology part. But if I would have been there I must have given full privileges to the developers in dev env.
    -If QA env will be a work repository then you have to restrict all testers from modifying the objects or else you can only promote scenarios to QA.
    -If you have different physical connection for QA env, then security concerns may arise as the connection details going to shared between one master repository.
    2. Multiple master and work for each environment.
    Merits:
    -All teams are independent as you have different env.
    -There is nothing to be concerned about security related issues as you have different topology for different env.
    -Once the DEV team is done with the project, promote only scenarios/loadplans to PROD through QA.
    -Easier to maintain the versions as you have separate env.
    Demerits:
    -Chances of getting id conflict issues.
    -Difficult to maintain.
    -Special care must be taken to keep the logical schema name same across all env.
    Other experts also can share their experience. But the common thing for each of us is to keep production completely different in terms of work and master repository.
    Bhabani
    http://dwteam.in

  • Using jsp:param

    hi,
    i am new to java and jsp programming and i am trying to use jsp:param nested in my
    jsp:forward statement.
    if i specify a value in jsp:param my page would display properly. however when i passed a variable in my jsp:param i get the error:
    Generated servlet error:
    [javac] Compiling 1 source file
    C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\star\jsp\Meeting_CreateMinutes_jsp.java:135: cannot resolve symbol
    symbol : method encode (long)
    location: class java.net.URLEncoder
    pageContext.forward("Meeting_ActionItems.jsp" + "?" + "docno=" + java.net.URLEncoder.encode( carno ) + "&" + "formmode=" + "Add");
    ^
    1 error
    this is the snippet in my jsp page that (i suspect) caused the error:
    <% long carno = newcar.getDocno(); %>
    <jsp:forward page="Meeting_ActionItems.jsp">
    <jsp:param name="docno" value="<%= carno %>"/>
         <jsp:param name="formmode" value="Add"/>
    </jsp:forward>
    my question is : does jsp:param do not accept variables as values?
    thanks in advance.
    best regards,
    noynoy

    <% long carno = newcar.getDocno(); %>Change this part as
    <% String carno = ""+newcar.getDocno(); %>
    Hafizur Rahman
    SCJPhi Hafizur,
    Thanks a lot. It solved my problem on the jsp:param error
    More power!!!
    rgds,
    noynoy

  • I am a teacher with 7 iPads for my room with no VPP or Apple Configurator.  May I use the same Apple ID for each of the devices with a separate password for each device?

    Who can help me with the above question?  Multiple iPads in one classroom:  may I use the same Apple ID (which is my work email) for each iPad, and construct a separate password for each device?  My school does not have VPP or Apple Configurator

    Password to what, exactly? If you're referring to the screen lock, each iPad can have a separate passcode, since that's not tied to an Apple ID. If that's not what you mean, please post back and clarify what password you're referring to and what you wish to accomplish.
    Regards.

  • How many computers may i use aperture on

    hi
    purchased a copy of aperture - I like many people have several computers - how many computers may I use my copy of aperture on? i.e. I plan to use it on one laptop and one desktop.

    If you really wanted to access the same library on both laptop and desktop, you could keep the library on an external drive that you plug into one or the other.
    For traveling, what I do is keep a more limited version of the library, with offline masters, on my laptop. If you were willing to give up enough disk space you could keep your whole library this way.
    Or, you can just export projects and keep those on your laptops library by importing them. When on the road I create libraries on my laptop and then re-import them into the desktop library when I get home.

Maybe you are looking for

  • ITunes Match is duplicating files on hard drive

    Almost every song/album I have ever purchased and downloaded will not play from the local file, but instead insists or 'redownloading' from the Music Match Cloud. Eg: The album "Communards" by "The communards". As you can see iTunes is under the impr

  • Call to a remote object in the same JVM

    Hi, I want to implement a logging mechanism in my system. I'm planning to write an rmi object and make it a start up class. I wud like to know whether the calls to this start up class made by the ejb instances and from the servlet engine in the same

  • How do I resize a photo to attach it to someone else's web site

    I want to add photo attachments to someone else's web site. my files are raw, off the camera i.e. big.  I can easily resize if I email. but why can't find an easy way to downsize in iPhoto?  what should I do?

  • Check for db change

    hi guyz, I have a requirment where i need to write a program to check db(row data change) change for particular table for regular intervals of time. I need code or atleast an idea how to do this. Thanks in advance, -manjunath

  • Linking IMAC to Samsung Series 8 tv wireless

    Hi Everyone Trying to link my mac to tv using eyeconnect. I have managed to link tv to router (3 com) and it displays RSS feeds but I cannot get it to link to mac. I have shared files on mac (i photo and i tunes) and enabled sharing in eyeconnect but