How to inject EntityManager in non-EJB based WebService?

Hi,
I want to know how we can inject EntityManager in non-EJB based WebService?
Regards,
imran

I think the way to go would be to actually do use an EJB for the persistence stuff and use that EJB in your webservice. Use the right tool for the job and all that.

Similar Messages

  • Closing ejb based webservice created http sessions

    I have few ejb based web services deployed on netweaver application server 7.0.As per my understanding nw deploys a web service as a web application which means its gonna get hosted by a web container.Now as this is a web app when an external system makes a call to this service a httpsession is opened up .I would like to monitor these httpsessions which get opened up on receving requests for these services from different clients.I went to web container option inside sap mmc but no luck.There is one option called currenthttpsessions but this always remains greyed out.Also i want to make sure that this http session should get closed once that request is processed.I doubt this is not happening right now on the setup which i have.

    I am also having the same problem... trying to revive this thread? any solutions out there?

  • How to inject EntityManager dynamically

    I have a class in which I want to inject a EntityManager based on not compile time known persistence unit name.
    In an EE environment you would normally do something like
    @PersistenceContext(unitName="pu1") private EntityManager em;
    Now the problem is that I want this "pu1" to be dynamic based based upon a parameter.
    In an SE environment (or also EE) I could create a
    emf = Persistence.createEntityManagerFactory(name);
    manually and pass in a dynamic persistence unit name.
    But creating the emf is exepensive.
    What is best way to do this in an EE environment?

    If there will only be one persistence unit in scope then you can just leave the unitName out altogether :
    @PersistenceContext private EntityManager em;
    In this case the container will just consider the one persistence unit defined at the module or application level as the default and inject it.
    If there might be more than one, you can define the dependency in your web.xml or ejb-jar.xml file.
    That will allow you to set the unit-name without having to recompile the code.
    persistence-context-ref is the analog of @PersistenceContext within the deployment descriptor :
    <persistence-context-ref>
    <persistence-context-ref-name>persistence/myemref</persistence-context-ref-name>
    <persistence-unit-name>pu1</persistence-unit-name>
    </persistence-conetxt-ref>
    Then you could look it up via java:comp/env :
    (EntityManager) initialContext.lookup("java:comp/env/persistence/myemfref");
    If you want to get a little fancier, you can use the .xml elements to cause the injection to happen.
    <persistence-context-ref>
    <persistence-context-ref-name>persistence/myemref</persistence-context-ref-name>
    <persistence-unit-name>pu1</persistence-unit-name>
    <injection-target>
    <injection-target-class>com.acme.Foo</injection-target-class>
    <injection-target-name>em</injection-target-name>
    </injection-target>
    </persistence-conetxt-ref>
    Then your java code would look like :
    // dependency and injection declared via deployment descriptor
    private EntityManager em;
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to use UserTransaction in non-EJB code

    This is in a class that is called from within a Stateless Session bean. In this class, I'm trying to use a UserTransaction object that is created as follows (taken from Zuffoletto's book):
    ========================================
    env.put(Context.INITIAL_CONTEXT_FACTORY,
    "weblogic.jndi.WLInitialContextFactory");
    ctx = new InitialContext(env);
    tx = (UserTransaction) ctx.lookup("javax.transaction.UserTransaction");
    ========================================
    However, when I call tx.begin(), it throws an exception as follows:
    ========================================
    javax.transaction.NotSupportedException: Another transaction is associated with this thread. Existing transaction Name=[EJB com.bea.wlw.runtime.core.bean.SyncDispatcherBean.invoke
    (com.bea.wlw.runtime.core.request.Request)],Xid=BEA1-001123C02690(16658514),Status=Ac
    tive,numRepliesOwedMe=0,numRepliesOwedOthers=0,seconds since begin=13,seconds left=43187,activeThread=Thread[ExecuteThread: '12' for
    queue: 'weblogic.kernel.Default',5,Thread Group for Queue: 'weblogic.kernel.Default'],SCInfo[workshop+cgServer]=
    (state=active),properties=({weblogic.transaction.name=
    [EJB com.bea.wlw.runtime.core.bean.SyncDispatcherBean.invoke
    (com.bea.wlw.runtime.core.request.Request)]}),OwnerTransactionManager=ServerTM[ServerCoordinatorDescriptor=
    (CoordinatorURL=cgServer+192.168.0.73:7001+workshop+t3+, XAResources={},NonXAResources={})])
    ========================================
    Any ideas/suggestions/hints??
    Why would this explicitly created tx, being used by one single call be colliding with an existing transaction?
    Thanks for your comments.

    Hello,
    As I understand, you would like to setup a watch folder which will be getting pdf files in arbitrary intervals. You then want each pdf to be converted to ps in a separate folder.
    You could achieve this with the help of a script by polling for pdf files present in the watch folder. When you find pdf files, convert them to ps, save the ps file in another folder and then move the pdf to another folder.
    In any case, once the process of conversion of pdf to ps is over, acroread will quit.
    There is no way to keep the acroread process running in background and convert pdfs as and when they are available.
    Please let me know if this answers your query.
    Regards,
    Rishi

  • How to register non-wsdl based URL in OEG

    How do we register a non-wsdl based URL endpoint in OEG? We had no problem registering a simple WSDL based endpoint on an OEG server. However we cannot find documentation on how to secure/register a RESTful or JSON – URL based service (SOAP, XML over HTTP type service).
    Does this functionality exist? Or are there best practices on what to do with OEG for these types of services?
    Our use case looks like:
    Akamai - - > OEG - -> OSB (WSDL, RESTful, JSON type web services) - -> .Net service (WSDL, RESTful, JSON type web services)

    In case of REST and other non-WSDL type services, there is no SOAP/WSDL based web service like registration process, you'd use OEG as the proxy. You can receive REST based requests at OEG, retrieve parameters (there are convenience filters available for retrieval of attribute values and other types of REST related functions in OEG, as part of the Policy library, "Extract REST Request Attribute", "Validate REST filter", "Create REST Request" etc. - search for REST at the top using Policy Studio, drag it on to canvas and click help for docs on these filters) and do the routing to actual REST end point services. You have the option to receive and use the SOAP message as a basis of generation of the REST url.
    REST to SOAP - http://www.soatothecloud.com/2008/11/how-to-convert-from-rest-to-soap.html
    SOAP to REST - http://markoneill.sys-con.com/node/1989916
    On use with JSON: you can convert XML to JSON on the outbound side to serve mobile clients etc. using script based(standard XSLT) conversions at the gateway. Conversions to Java using google gson library is also an option.
    To register a REST service, simply map the path (e.g. "/MyRESTService") to the policy you're using to process the REST request.
    Let's say you want to simply route a REST request through OEG (e.g. - to OSB). You would create a policy (right-click on "Policies" and add it). Drag in a "Static Router" filter and place in it the hostname and port of the host you want to route to (e.g. - to OSB). Then right-click on it and choose "Set as start" so that it is the first thing which is processed for this REST request. Then drag in a "Connection" filter, and chain it (using a green arrow) after the Static Router filter. The "Connection" filter actually makes the connection to the backend host.
    Now, map the path (using "Add Relative Path") to the service so that if a REST request to "/MyRESTService" or "/MyRESTService/something" comes into OEG, it is routed on to the backend host.
    Deploy your policy (using F6 or the "deploy" button on the Policy Studio toolbar). Then send in your REST request.
    There is actually already a simple REST service setup on OEG, called "healthcheck". If you point a browser to http://<OEG_IP_ADDRESS:8080/healthcheck" then this is run.
    If the backend REST service returns JSON, the response JSON will simply be sent back through OEG.

  • Identity SSO API with non-web based appilcations

    hi,
    i can appreciate hwo this works with cookies etc for web based applications that use the api or one of the agents on apache etc.
    but how does it go with non web based java and say windows applications?
    can anyone point me to some docs?
    thanks

    I don't work for Sun but here are my thoughts
    1. Yes, if you don't want to use the AM SDK then the
    XML auth service is the way to go.
    2 & 3. dunno
    4. I think if you pass around the SSOToken ID
    generated by AM then any application can issue a SAML
    query to see if the session is still valid and get
    identity/auth attributes back
    5. I think SAML 2.0 supports authentication and
    single signoff
    6. If you are doing a lot of thick client apps you
    should use kerberos instead of AM web based
    Authentication. AM supports kerberos authentication,
    most modern browsers support SPEGNO for passing
    credentials to web server, AD supports Kerberos, and
    even Solaris 10 comes with a free KDC built into the
    OS. There is plenty of documentation around kerberos
    and the JDK out of the box supports GSS-API for
    Kerberos authenticationThank you for your feedback.
    We looked at the use of kerberos as well, but this is not really an option as we are dealing with fat clients installed on desktops of clients. So these desktops do not fall within our span control (multiple domain controllers etc.).
    Regards,
    Thomas

  • REST BASED  WEBSERVICES

    Hi,
    We Have a Legacy System based  on  REST BASED  WEBSERVICES, that  legacy  system  can  understand  only  HTTP  format(it does n't  support  SOAP ) our scenario  is  HTTP TO  RFC  SYNCHRONOUS.
    And   we  have  to  connect PI   with  REST BASED  WEBSERVICES     ?
    1---->How  can  we connect  PI  with  REST BASED  WEBSERVICES ?
    2---->and  how  to test  those    REST BASED  WEBSERVICES ?any  tool  for  that?
    Thanks,
    Nagaraju.

    Hi Nagaraju,
    you can sent message from PI via [http receiver adapter|http://help.sap.com/saphelp_nw2004s/helpdata/en/43/64dbb0af9f30b4e10000000a11466f/content.htm].
    For message from legacy to PI use a simple address, what is explained in [SAP help http sender adapter|http://help.sap.com/saphelp_nw2004s/helpdata/en/43/64db4daf9f30b4e10000000a11466f/content.htm]
    You can test http messages with Microsoft's tool [Wfetch|http://www.microsoft.com/download/en/details.aspx?id=21625] (in the net are hundreds of free ware http test tool available).
    Regards,
    Udo

  • How to inject a POJO into an EJB

    This question relates to EJB 3.0
    I have a POJO in a non-ejb jarfile that I want to inject into an EJB. Is this possible? If so, how do I go about making it work?
    Thanks,
    Dave.

    daver wrote:
    This question relates to EJB 3.0
    I have a POJO in a non-ejb jarfile that I want to inject into an EJB. Is this possible? If so, how do I go about making it work?Why must you inject a POJO class? There is nothing for the server to manage here so there really is no benefit of using an injection mechanism. Simply create an instance in the EJB method that needs the object.

  • How to inject ejb in servlet

    hi all
    How to inject ejb in servlet ?
    please explain how to config my servlet and my paroject
    I have an ear file with two jar files
    Thanks in advance

    hi
    I have this error in my project
    I have an ear file ,two war file and three jar file in it
    and I did configuration
    but there was this error
    14:19:45,398 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[conference-servlet].[enterLet]] Allocate exception for servlet enterLet: javax.naming.NameNotFoundException: ITrmnlAuthenticationBL not bound
    @Remote
    public interface ITrmnlAuthenticationBL{
    @Stateless
    public class TrmnlAuthenticationBL implements ITrmnlAuthenticationBL{
    public class EnterLet extends HttpServlet {
         @EJB(mappedName = "ITrmnlAuthenticationBL")
         private ITrmnlAuthenticationBL trmnlMg;
    please explain my mistake

  • Interceptors for non EJB

    Hi,
    does the jee standard covers interceptors for non EJB classes? I'm using Glassfish and it worked for a plain java classes e.g.:
    @Interceptors(TraceInterceptor.class)
    public class PlainClass {
         public String doSomething() {
              return "somthing";
    Hoever when I use the intercepter with a DAO class that's depending an an EntityManager e.g.:
    @Interceptors(TraceInterceptor.class)
    public class PersonDao implements IPersonDao {
         @PersistenceContext
         private EntityManager em;
         @Override
         public Person getById(Integer id) {
              return em.find(Person.class, id);
    I get a NullPointer exeption because the Entity Manger is not injected.
    so my question is: does the jee standard covers interceptors for non EJB classes?
    Regards
    Sebastian

    Hi,
    thanks for your response.
    When I remove the @Interceptors annotation from the PersonDao everything works fine including the injection of the entity manager. When I add the @Interceptors annotation I get a null pointer at em.find(Person.class, id).
    I’m new to JEE6 because I have worked with Spring the last 6 years. Accidently I never used the @Named annotation. Surprisingly that is no problem (at least in Glassfish).
    Anyhow I added the @Named annotation to the DAO but that not changed anything, I still got a null pointer. What’s wrong?
    @Interceptors(TraceInterceptor.class)
    @Named
    public class PersonDao implements IPersonDao {
         @PersistenceContext
         private EntityManager em;
         @Override
         public Person getById(Integer id) {
              return em.find(Person.class, id);
    @Stateless
    @Interceptors(TraceInterceptor.class)
    public class TestSrv implements ITestSrv {
         @Inject
         private IPersonDao personDao;
         @Override
         public Person getPerson(Integer id) {
              return personDao.getById(id);
    Best regards
    Sebastian

  • JTA/JTS for non-EJB & non-J2EE server used

    I have a standalone java program which calls methods on 2 java classes (c1, c2) These are Non-EJB/non-RMI/non-CORBA plain java classes.
    the method in c1 updates table t1 in database db1
    the method in c2 updates table t2 in database db2
    I would like to use JTA for conducting a 2PC based transaction. I know this can be done in an application/server or a J2EE container environment because they have built-in Transaction Managers (TM). and one just has to use JNDI to look up the UserTransaction object and then define the transaction boundaries. However, how do I all the above if I don't have access to a J2EE server and an EJB server?
    It seems like I would have to use a standalone Transaction Manager (not bundled with the app-server).

    Hi,
    My company has just released a (beta!) version of a generic java transaction manager. Although it offers some lightweight beans as standard development model, this does not have to be the case: the core idea is an extensible and very advanced transaction kernel. JTA comptable.
    This software is server-oriented: the transactional kernel (which also does recovery) startup and shutdown events trigger the start (initialization) and shutdown of your 'extension' classes. This is necessary because otherwise your resources will not be recoverable: if the transaction manager starts up, then it will first do recovery, and therefore your resources need to be available.
    You can ask for a beta version through our website:
    http://www.atomikos.com
    Note, however: we did not yet implement the XA DataSources. Rather, we have a kind of 'external' stored procedures that allow distributed transactions over regular JDBC connections. You would have to implement your solution along this line, or wait for the XA datasources.
    If there proves to be a lot of demand,
    we can of course speed up development on XA. It is not a very big effort.
    Best regards,
    Guy
    Guy Pardon ( [email protected] )
    Atomikos Software Technology: Transactioning the Net
    http://www.atomikos.com/

  • Passing Job ID, Job instance from Agent to EJB-based action in OBIEE 11g?

    We would like to ZIP compress Agent-scheduled report output, according to documentation using "Java Jobs" is an option but not recommended in 11g (only upgraded from 10g). Instead EJB-based java actions should be used.
    Documentation has explanation of EJB-based Java action, however there's a problem when an Agent invokes the EJB-based action how can it pass out Job ID and Instance ID, etc so the custom action can refer to the related job information? When using "Java job" approach it offers public interfaces to do so. In EJB-based action there seems no information provided, the example in the documentation only demonstrates user to enter parameter values manually without any way to pass out parameter from the invoker (e.g. an Agent).
    In this case, is there any public interface or any other way that an Agent can pass out Job ID related values when invoking an Java method? This seems also true for other actions like invoking web services, HTTP service, etc that no Job parameter can be passed out.
    Thanks.
    geoff

    998365 wrote:
    [OracleBISchedulerComponent] [NOTIFICATION:1] [] [] [ecid: 004rSLEMUx3AtH4pzSt1iW000119000000] [tid: 871b810] [68013] Scheduler service started.
    [OracleBISchedulerComponent] [NOTIFICATION:1] [] [] [ecid: 004rSLEMUx3AtH4pzSt1iW000119000000] [tid: 871b810] Scheduler service started.
    [OracleBISchedulerComponent] [NOTIFICATION:1] [] [] [ecid: 004rSLEMUx3AtH4pzSt1iW000119000000] [tid: 871b810] [71076] Oracle BI Scheduler crmtest6:9705 has been changed to an Inactive state.
    [OracleBISchedulerComponent] [NOTIFICATION:1] [] [] [ecid: 004rSLEMUx3AtH4pzSt1iW000119000000] [tid: 41222940] [43071] A connection with Cluster Controller CRMTEST6:9706 was established.
    [OracleBISchedulerComponent] [NOTIFICATION:1] [] [] [ecid: 004rSLEMUx3AtH4pzSt1iW000119000000] [tid: 41222940] [71075] Oracle BI Scheduler crmtest6:9705 has been changed to an Active state.*
    [OracleBISchedulerComponent] [WARNING:1] [] [] [ecid: 004rSLEMUx3AtH4pzSt1iW000119000000] [tid: 41222940] [43065]from the log it looks like its started as it changed the state to active. are you able to connect to database using biplatform schema details?

  • Update Excise base value in MRP based and Non-MRP based billing

    Hi Gurus,
    We need to update Excise Base Value for Statistical Condition type. How to configure the same ?
    Sl.No  Pricing Condition Type      Active   Statistical           Passed to Accounting        
    1        MRP Price (Statistical)                                                                               
    2        Abatement (Statistical)                                                                               
    3       Surcharge  (Active&Passed to Accounting)
    4      Assessabel value (Statistical)
    (No:4 This is the base for calculating Excise duties i.e Excise Base Value)
    5       List Price (Statistical)                                              
    6       Customer Discount(Statistical)                             
    7      Surcharge(Active&Passed to Accounting)                                                                 
    8      Net Price (Active&Passed to Accounting)                                                                     
    9      BED   (Active&Passed to Accounting)                                                                          
    10    ECess  (Active&Passed to Accounting)                                                                       
    11   SECess  (Active&Passed to Accounting)
    12   Total collected from Customer(Statistical)              
    Issue: When there is MRP Price higher than the List Price, then the Cutomer will be charged on the basis of Net Price only, but the duties amount to be paid to the government on MRP Price. so in this case I can not calculate Excise Duties on the Actual Net Price condition which is active and passed on to accounting. And always the Excise duties to be calculated on Assessable value(no:4). But that condition type if I make activate then it will pass to accounting and also getting added to the Net Value(KOMP-NETWR). How to come out of this situation.(as per the customer requirement both MRP based materials and non-MRP based materials are also considered in the same sale order i.e with the same pricing procedure).
    Becasue of this EXBAS is not getting updated in the J_1IEXCDTL.
    Gurus, Share your valuable experiences and suggestions.
    Thanks &Regards
    Sreekanth
    09611147585

    Dear Lakshmipathi,
    As per your suggestion, I have maintained Material Assessable Value and then also the duty values are calculating on the basis of Assessable value maintained in the Pricing Procedure. It is not taking the Material Assessable Value into consideration. And it is not getting updated the Excise Base Value.
    In which case Material Assessable value will be taken into consideration?
    How to update the Excise Base Value in J_1IEXCDTL tables?
    Thanks&Regards
    Sreekanth

  • PO Release Strategy - Only for non material based

    Experts,
    I have a requirement to implement a release strategy for a single plant for POs for NON material based purchases ( only for using account assignments, cost centers etc).
    The release strategy I configured is working only for the specific plant I want... However, it works whether its a material based PO or a non material based PO.
    How do i get the strategy to work for only the service based purchases, and not the material ones?

    Thanks for the replies but I'm not sure if they are applicable...
    I did create a characterstic for item categories and added the one's I wanted to have... I did NOT include a blank because i thought that would make the difference between the material based PO and non PO. When we I create Po with material (even with no account assignment) it still goes through release.
    Any reason why that is?
    I dont believe the material group solution will not work either because we require material group for material and non material based POs..
    Side note - when i try to use CEKKO with KTTNP, i get a "KTTNP does not exist error." So i used EKPO - KTTNP... hopefully thats ok, but please let me know if its not.
    Edited by: farmerj3 on Jan 30, 2012 3:36 PM
    Edited by: farmerj3 on Jan 30, 2012 3:39 PM
    Edited by: farmerj3 on Jan 30, 2012 3:48 PM

  • How to enable/disable the input fields based on the data entered/user action in the web dynpro abap?

    How to enable/disable the input fields based on the data entered in the web dynpro application abap?  If the user enters data in one input field then only the next input field should be enabled else it should be in disabled state. Please guide.

    Hi,
    Try this code.
    First create a attribute with the name readonly of type wdy_boolean and bind it read_only property of input field of which is you want to enable or disable.
    Next go to Init method.
    Set the readonly value as 'X'.
    DATA lo_el_context TYPE REF TO if_wd_context_element.
         DATA ls_context TYPE wd_this->element_context.
         DATA lv_visible TYPE wd_this->element_context-visible.
    *   get element via lead selection
         lo_el_context = wd_context->get_element( ).
    *   @TODO handle not set lead selection
         IF lo_el_context IS INITIAL.
         ENDIF.
    *   @TODO fill attribute
    *   lv_visible = 1.
    *   set single attribute
         lo_el_context->set_attribute(
           name =  `READONLY`
           value = 'X').
    After that Go to the Action  ENTER.
    First read the input field ( first input field, which is value entered field) , next give a condition
    if input value is not initial  then set the readonly value is '  '.
    DATA lo_nd_input TYPE REF TO if_wd_context_node.
         DATA lo_el_input TYPE REF TO if_wd_context_element.
         DATA ls_input TYPE wd_this->element_input.
         DATA lv_vbeln TYPE wd_this->element_input-vbeln.
    *   navigate from <CONTEXT> to <INPUT> via lead selection
         lo_nd_input = wd_context->get_child_node( name = wd_this->wdctx_input ).
    *   @TODO handle non existant child
    *   IF lo_nd_input IS INITIAL.
    *   ENDIF.
    *   get element via lead selection
         lo_el_input = lo_nd_input->get_element( ).
    *   @TODO handle not set lead selection
         IF lo_el_input IS INITIAL.
         ENDIF.
    *   get single attribute
         lo_el_input->get_attribute(
           EXPORTING
             name =  `VBELN`
           IMPORTING
             value = lv_vbeln ).
    if lv_vbeln IS not INITIAL.
        DATA lo_el_context TYPE REF TO if_wd_context_element.
        DATA ls_context TYPE wd_this->element_context.
        DATA lv_visible TYPE wd_this->element_context-visible.
    *  get element via lead selection
        lo_el_context = wd_context->get_element( ).
    *  @TODO handle not set lead selection
        IF lo_el_context IS INITIAL.
        ENDIF.
    *  @TODO fill attribute
    *  lv_visible = 1.
    *  set single attribute
        lo_el_context->set_attribute(
          name =  `READONLY`
          value = ' ' ).

Maybe you are looking for