12 Replies Latest reply on Jan 4, 2011 10:33 AM by andreas_back

    WebServiceContext injection. Was it fixed or not?

    ggary

      I have this piece of code in my web service:

      @Resource
      private WebServiceContext context;

      However it is not being injected. The value is always null.
      I found a bug on JIRA and it is in the resolved state with the intended release JBossWS 2.0.
      Now I am on JBoss 4.2.1 with JBossWS 2.0.1 and still have this problem.
      Can someone answer on the state of this problem

        • 1. Re: WebServiceContext injection. Was it fixed or not?
          richard_opalka

          Could you share your service code with us?

          Richard

          • 2. Re: WebServiceContext injection. Was it fixed or not?
            ggary

             

            "richard_opalka" wrote:
            Could you share your service code with us?

            Richard

            Sure, here it is:
            package com.rsys.rsystools.ws;
            
            import javax.annotation.Resource;
            import javax.jws.WebMethod;
            import javax.jws.WebParam;
            import javax.jws.WebResult;
            import javax.jws.WebService;
            import javax.jws.soap.SOAPBinding;
            import javax.jws.soap.SOAPBinding.Style;
            import javax.servlet.ServletContext;
            import javax.xml.ws.ResponseWrapper;
            import javax.xml.ws.WebServiceContext;
            import javax.xml.ws.handler.MessageContext;
            import org.springframework.web.context.support.WebApplicationContextUtils;
            
            
            @WebService(targetNamespace="http://service.responsys.com/rsystools/ws/SpamComplaintWS/1.0")
            @SOAPBinding(style = Style.DOCUMENT)
            public class SpamComplaintWS implements SpamComplaint
            {
             @Resource
             private WebServiceContext context;
            
             ServletContext servletCtx;
             /** Creates a new instance of SpamComplaintWS */
             public SpamComplaintWS()
             {
             }
            
             /**
             * Web service operation
             */
             @WebMethod(operationName="processSpamComplaints")
             @WebResult(name="SpamResult", targetNamespace="http://service.responsys.com/rsystools/ws/SpamComplaintWS/1.0")
             @ResponseWrapper(className="com.rsys.rsystools.ws.SpamResult",
             targetNamespace="http://service.responsys.com/rsystools/ws/SpamComplaintWS/1.0")
             public SpamResult processSpamComplaints(
             @WebParam(name = "email") String email,
             @WebParam(name = "fromAddress") String fromAddress,
             @WebParam(name = "mailDate") String mailDate,
             @WebParam(name = "complaintDate") String complaintDate,
             @WebParam(name = "mailbox") String mailbox,
             @WebParam(name = "complainer") String complainer,
             @WebParam(name = "xRext") String xRext,
             @WebParam(name = "accountName") String accountName)
             {
             ServletContext servletCtx = (ServletContext) context.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
             Object appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletCtx);
             responsys.prodtools.SpammerTables st = new responsys.prodtools.SpammerTables();
             java.lang.String[] res = st.processSpamRecord(email, fromAddress, mailDate, complaintDate, mailbox, complainer, xRext, accountName);
             return (new SpamResult(res[0],res[1],res[2],res[3],res[4],res[5],res[6],res[7],res[8],res[9],res[10],res[11],res[12],res[13]));
             }
            
            
            }
            


            • 3. Re: WebServiceContext injection. Was it fixed or not?
              richard_opalka

              Your service looks OK,

              could you create minimalistic version of your problem and report a JIRA issue with the sources reproducing the problem?

              Richard

              • 4. Re: WebServiceContext injection. Was it fixed or not?
                ggary

                 

                "richard_opalka" wrote:
                Your service looks OK,

                could you create minimalistic version of your problem and report a JIRA issue with the sources reproducing the problem?

                Richard

                It is already quite minimalistic. I am sorry, I am in the time crunch at the moment. I have to find a solution for my problems before the end of the week.

                • 5. Re: WebServiceContext injection. Was it fixed or not?
                  thomas.diesler

                  Your field cannot be private, use

                   @Resource
                   WebServiceContext context;
                  



                  • 6. Re: WebServiceContext injection. Was it fixed or not?

                    ggary so did it work for you finally then ???
                    I am using jboss423 on java 5 and cant seem to get it to work.
                    Then because of the hug u mentioned, i also tried using 421 and jbossws 201 but still it does not work.


                    @WebService(name = "CreditCard", serviceName = "CreditCard",
                     wsdlLocation = "/WEB-INF/wsdl/CreditCard.wsdl",
                     targetNamespace = "http://aig.al.com/APCWebServices/CreditCardService/",
                     endpointInterface = "com.al.aig.apc.ws.creditcard.server.generated.CreditCard")
                    @SOAPBinding(style = Style.DOCUMENT)
                    public class CreditCardService_Impl implements CreditCard{
                    
                     @Resource
                     WebServiceContext wsContext;
                    
                     Logger log = Logger.getLogger(CreditCardService_Impl.class);
                    
                     @WebMethod(operationName = "createCreditCard")
                     public CreateCreditCardResponse createCreditCard(
                     @WebParam(name = "parameters") CreateCreditCardInput parameters) {
                    
                     log.debug("createCreditCard:entering.");
                     CreateCreditCardResponse drResp = new CreateCreditCardResponse();
                     System.out.println("addSecondaryMsisdn() called..................");
                    
                     if (wsContext == null) {
                     System.out.println("its NULLL..");
                     } else {
                     System.out.println("ITS NOT NULL");
                     }
                    
                     log.debug("createCreditCard:exiting.");
                     return drResp;
                     }
                    

                    This is the code that i ahve got, nothing special here. I have handwritten the WSDL for this webservice.
                    Does the WebServiceContext injection depend on the binding type or something.

                    • 7. Re: WebServiceContext injection. Was it fixed or not?
                      jnorris10

                       

                      "thomas.diesler@jboss.com" wrote:
                      Your field cannot be private, use

                       @Resource
                       WebServiceContext context;
                      



                      Why does this restriction exist?

                      • 8. Re: WebServiceContext injection. Was it fixed or not?
                        ropalka

                         

                        "jnorris10" wrote:
                        Why does this restriction exist?

                        According to javax.annotation.Resource javadoc you can use private qualifier as well.

                        • 9. Re: WebServiceContext injection. Was it fixed or not?
                          dhanushgopinath

                          Hi,

                          I am using JBOSS 4.2.3 with JBOSS WS 3.1.0 and I am also getting the same problem. The web service context is getting null. Here is my service

                          
                          @WebService(serviceName = "AWFUtilityService", targetNamespace = "http://www.test.com/WF/Framework/AWFUtilityService", endpointInterface = "com.test.wf.framework.awfutilityservice.AWFUtilityServicePortType",portName="AWFUtilityServicePort",wsdlLocation="WEB-INF/wsdl/AWFUtilityService.wsdl")
                          public class AWFUtilityServiceImpl implements AWFUtilityServicePortType {
                          
                           @Resource
                           WebServiceContext context;
                          
                           @WebMethod
                           public String getCorrelationID(String CorrelationID)
                           throws GetCorrelationIDFault
                           {
                           SOAPMessageContext soapMsgContext = (SOAPMessageContext) context.getMessageContext();
                           try {
                           boolean login = ParseAndValidateSoapHeader(soapMsgContext);
                           } catch (EPMAuthenticationFailureException e) {
                           // TODO Auto-generated catch block
                           e.printStackTrace();
                           }
                           String strCorrValue = EPMUtils.GetGloballyUniqueID();
                           return CorrelationID + "_" + strCorrValue;
                           }
                          


                          Is this still a bug in JBOSS WS or am I doing some thing wrong.

                          Thanks
                          DHanush

                          • 10. Re: WebServiceContext injection. Was it fixed or not?

                            I'm having the same problem. Does anyone have a solution or workaround? I'm using JBoss 4.2.3 and JBossWS 3.1.1.GA.

                            @Resource
                            WebServiceContext wsCtx;

                            always returns null.

                            • 11. Re: WebServiceContext injection. Was it fixed or not?
                              ropalka

                              This is fixed since JBossWS 3.1.2

                              • 12. Re: WebServiceContext injection. Was it fixed or not?
                                andreas_back

                                Hello,

                                 

                                on Java 6 and JBoss 4.2.3 and JBossWS 3.1.1.GA

                                 

                                     @Resource WebServiceContext webServiceContext;

                                 

                                workes for me.

                                 

                                Greetings,

                                 

                                Andreas