Web Services using Java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #1

    Web Services using Java

    Hi,
    I need to build up a web service using java. I am using,
    Netbeans 5.5.1
    JDK 1.5

    is there any thing else that i should plug in to my project environment apart from this to build up a web service.

    and i am very new to java web services. so please help by providing any tutorial that i can start over, with Netbeans.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by ajaxrand
    Hi,
    I need to build up a web service using java. I am using,
    Netbeans 5.5.1
    JDK 1.5

    is there any thing else that i should plug in to my project environment apart from this to build up a web service.

    and i am very new to java web services. so please help by providing any tutorial that i can start over, with Netbeans.
    Yep, you need at least a Servlet container such as Tomcat. Servlets handle
    http requests and supply dynamically created html responses.

    good luck and

    kind regards,

    Jos

    Comment

    • sumittyagi
      Recognized Expert New Member
      • Mar 2007
      • 202

      #3
      Originally posted by ajaxrand
      Hi,
      I need to build up a web service using java. I am using,
      Netbeans 5.5.1
      JDK 1.5

      is there any thing else that i should plug in to my project environment apart from this to build up a web service.

      and i am very new to java web services. so please help by providing any tutorial that i can start over, with Netbeans.
      If that's ur urgent requirement then I won't comment anything.
      But if you are doing it for learning purpose, then I would rather say, first expertize on web applications. Web services is quite a broad term, and if u are new to java, then u will be lost.

      The sequence of learning should be (according to me),
      1. Expertize core java field.
      2. Expertize Web applications field.
      3. Get introduced to (very basic) Web Component development field (EJBs) (optional, but will help in understanding many things.) (I myself am not much introduced to this field).
      4. Then come to Web services field.

      See wikipedia Link for web services.

      Comment

      • ak1dnar
        Recognized Expert Top Contributor
        • Jan 2007
        • 1584

        #4
        Originally posted by JosAH
        Yep, you need at least a Servlet container such as Tomcat. Servlets handle
        http requests and supply dynamically created html responses.

        good luck and

        kind regards,

        Jos
        Thank you so much jos.
        Both these application servers available in my machine.
        Tom cat 5.5.17
        Sun java system application server 9

        I am sorry I didn't mention it in my original post.

        I went through this tutorial sample application.

        and build the sample application as they have mentioned.

        Web service is here.

        package org.netbeans.en d2end.hellosamp le;

        Code:
        import javax.jws.HandlerChain;
        import javax.jws.WebMethod;
        import javax.jws.WebService;
        import javax.jws.WebParam;
        
        @WebService(serviceName="GreeterWs")
        @HandlerChain(name = "HelloWebService_handlerChain", file = "HelloWebService_handler.xml")
        public class HelloWebService
        {
            /**
             * Web service operation
             */
            @WebMethod(operationName="sayHi")
            public String operation(@WebParam(name="name")String param)
            {
                // TODO implement operation 
                return "Hi"+ param;
            }
              @WebMethod()
            public String sayHello(String s)
            {
                // TODO implement operation 
                return "Hello"+ s;
            }
            
        }
        message handler is here with some errors.

        Code:
        package org.netbeans.end2end.hellosample;
        
        import java.util.Collections;
        import java.util.Set;
        import javax.xml.namespace.QName;
        import javax.xml.soap.SOAPMessage;
        import javax.xml.ws.handler.MessageContext;
        import javax.xml.ws.handler.soap.SOAPHandler;
        import javax.xml.ws.handler.soap.SOAPMessageContext;
        
        
        public class MessageHandler implements SOAPHandler<SOAPMessageContext>
        {
            
            public boolean handleMessage(SOAPMessageContext messageContext)
            {
                //SOAPMessage msg = messageContext.getMessage();
                log(messageContext);
                return true;
            }
            
           private void log(SOAPMessageContext messageContext)
           {
               Boolean outcoming = (Boolean)
               messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
               if(outcoming.booleanValue())
               {
                   System.out.println("\nOutcoming Message:");
               }else
               {
                   System.out.println("\nIncoming Message:");
               }
               SOAPMessage message= messageContext.getMessage();
               try{
                   message.writeTo(System.out);
                   System.out.println("\n");
               }catch(Exception e)
               {
                   System.out.println("Exception "+e);
               }
           }
            
        }

        C:\Sun\SDK\samp les\javaee5\web services\HelloW s\src\java\org\ netbeans\end2en d\hellosample\M essageHandler.j ava:12: org.netbeans.en d2end.hellosamp le.MessageHandl er is not abstract and does not override abstract method getHeaders() in javax.xml.ws.ha ndler.soap.SOAP Handler
        public class MessageHandler implements SOAPHandler<SOA PMessageContext >

        What is the reason here.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by ajaxrand
          C:\Sun\SDK\samp les\javaee5\web services\HelloW s\src\java\org\ netbeans\end2en d\hellosample\M essageHandler.j ava:12: org.netbeans.en d2end.hellosamp le.MessageHandl er is not abstract and does not override abstract method getHeaders() in javax.xml.ws.ha ndler.soap.SOAP Handler
          public class MessageHandler implements SOAPHandler<SOA PMessageContext >

          What is the reason here.
          Exactly what the compiler whines about: your class implements the interface
          SOAPHandler; that implies that your class is either abstract or not. If your
          class is abstract your class doesn't need to implement all methods declared
          in that interface. Your class isn't abstract so it should implement all methods
          declared in the interface but it doesn't: method getHeaders() is a method from
          that interface but your class doesn't implement it.

          kind regards,

          Jos

          Comment

          • ak1dnar
            Recognized Expert Top Contributor
            • Jan 2007
            • 1584

            #6
            Fantastic jos. Now i got a clear idea.Thanks.

            Comment

            • ak1dnar
              Recognized Expert Top Contributor
              • Jan 2007
              • 1584

              #7
              oops But I failed to solve the problem.

              I used the netbeans wizard to create this message handler.

              File -> new file -> web services -> message Handler

              and add the coding as in the tutorial that i used.



              Did i missed something in my coding.

              Code:
              package org.netbeans.end2end.hellosample;
               
              import java.util.Collections;
              import java.util.Set;
              import javax.xml.namespace.QName;
              import javax.xml.soap.SOAPMessage;
              import javax.xml.ws.handler.MessageContext;
              import javax.xml.ws.handler.soap.SOAPHandler;
              import javax.xml.ws.handler.soap.SOAPMessageContext;
               
               
              public class MessageHandler implements SOAPHandler<SOAPMessageContext>
              {
                  
                  public boolean handleMessage(SOAPMessageContext messageContext)
                  {
                      log(messageContext);
                      return true;
                  }
                  
                 private void log(SOAPMessageContext messageContext)
                 {
                     Boolean outcoming = (Boolean)
                     messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
                     if(outcoming.booleanValue())
                     {
                         System.out.println("\nOutcoming Message:");
                     }else
                     {
                         System.out.println("\nIncoming Message:");
                     }
                     SOAPMessage message= messageContext.getMessage();
                     try{
                         message.writeTo(System.out);
                         System.out.println("\n");
                     }catch(Exception e)
                     {
                         System.out.println("Exception "+e);
                     }
                 }
                  
              }

              Comment

              • ak1dnar
                Recognized Expert Top Contributor
                • Jan 2007
                • 1584

                #8

                Let me know whether this sample is working or not.
                I failed with first one now second one also not working.

                i made it as they mentioned but getting this error.

                Code:
                init:
                deps-module-jar:
                deps-ear-jar:
                deps-jar:
                library-inclusion-in-archive:
                library-inclusion-in-manifest:
                compile:
                compile-jsps:
                do-dist:
                dist:
                In-place deployment at D:\NetBeans\WS\CalculatorWSApplication\build\web
                Start registering the project's server resources
                Finished registering server resources
                moduleID=CalculatorWSApplication
                deployment started : 0%
                Deploying application in domain failed; com.sun.tools.apt.Main.process(Lcom/sun/mirror/apt/AnnotationProcessorFactory;[Ljava/lang/String;)I
                D:\NetBeans\WS\CalculatorWSApplication\nbproject\build-impl.xml:453: Deployment error:
                The module has not been deployed.
                See the server log for details.
                BUILD FAILED (total time: 1 second)
                line number 453 under build-impl.xml as like this.

                Code:
                    <target name="-run-deploy-nb" if="netbeans.home">
                        <nbdeploy debugmode="false" clientUrlPart="${client.urlPart}" forceRedeploy="${forceRedeploy}"/>
                    </target>

                Comment

                • ak1dnar
                  Recognized Expert Top Contributor
                  • Jan 2007
                  • 1584

                  #9
                  Hi Guys,
                  Sorry for struggling with this. I really need your help.
                  I tried lots of tutorial all over the net. but only thing what i can do with them,

                  I can build the project with Netbeans 5.5.
                  Once i tried to deploy it to the web container deployment error appears.

                  Code:
                  Deploying application in domain failed; com.sun.tools.apt.Main.process(Lcom/sun/mirror/apt/AnnotationProcessorFactory;[Ljava/lang/String;)I
                  D:\NetBeans\firstcup-dukes-age\nbproject\build-impl.xml:453: Deployment error:
                  The module has not been deployed.
                  See the server log for details.
                  BUILD FAILED (total time: 5 seconds)
                  And the server log is here:

                  Code:
                  Exception occured in J2EEC Phase
                  java.lang.NoSuchMethodError: com.sun.tools.apt.Main.process(Lcom/sun/mirror/apt/AnnotationProcessorFactory;[Ljava/lang/String;)I
                          at com.sun.tools.ws.wscompile.CompileTool.buildModel(CompileTool.java:605)
                          at com.sun.tools.ws.wscompile.CompileTool.run(CompileTool.java:538)
                          at com.sun.tools.ws.util.ToolBase.run(ToolBase.java:56)
                          at com.sun.tools.ws.util.WSToolsObjectFactoryImpl.wsgen(WSToolsObjectFactoryImpl.java:44)
                          at com.sun.enterprise.webservice.WsUtil.runWsGen(WsUtil.java:1820)
                          at com.sun.enterprise.webservice.WsUtil.genWSInfo(WsUtil.java:2089)
                          at com.sun.enterprise.deployment.backend.ModuleDeployer.loadDescriptors(ModuleDeployer.java:396)
                          at com.sun.enterprise.deployment.backend.WebModuleDeployer.deploy(WebModuleDeployer.java:155)
                          at com.sun.enterprise.deployment.backend.ModuleDeployer.doRequestFinish(ModuleDeployer.java:160)
                          at com.sun.enterprise.deployment.phasing.J2EECPhase.runPhase(J2EECPhase.java:169)
                          at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:95)
                          at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:871)
                          at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:266)
                          at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:739)
                          at com.sun.enterprise.management.deploy.DeployThread.deploy(DeployThread.java:174)
                          at com.sun.enterprise.management.deploy.DeployThread.run(DeployThread.java:210)
                  What is this com.sun.tools.a pt.Main.process () why i am getting same error for all the web services samples.?

                  Comment

                  • JosAH
                    Recognized Expert MVP
                    • Mar 2007
                    • 11453

                    #10
                    I'm no web/servlet guru by any means but those exceptions smell like an
                    installation/configuration error. When the system can't find one of its own
                    components something is rotten in the state of Denmark.

                    I apologize for not having a pre-cooked solution for you but if I were you I'd
                    check the installation of it all. I had to do that once, using Tomcat, and it was
                    a mess, I can tell you that.

                    best of luck and

                    kind regards,

                    Jos

                    Comment

                    • r035198x
                      MVP
                      • Sep 2006
                      • 13225

                      #11
                      Originally posted by ajaxrand
                      Hi Guys,
                      Sorry for struggling with this. I really need your help.
                      I tried lots of tutorial all over the net. but only thing what i can do with them,

                      I can build the project with Netbeans 5.5.
                      Once i tried to deploy it to the web container deployment error appears.

                      Code:
                      Deploying application in domain failed; com.sun.tools.apt.Main.process(Lcom/sun/mirror/apt/AnnotationProcessorFactory;[Ljava/lang/String;)I
                      D:\NetBeans\firstcup-dukes-age\nbproject\build-impl.xml:453: Deployment error:
                      The module has not been deployed.
                      See the server log for details.
                      BUILD FAILED (total time: 5 seconds)
                      And the server log is here:

                      Code:
                      Exception occured in J2EEC Phase
                      java.lang.NoSuchMethodError: com.sun.tools.apt.Main.process(Lcom/sun/mirror/apt/AnnotationProcessorFactory;[Ljava/lang/String;)I
                              at com.sun.tools.ws.wscompile.CompileTool.buildModel(CompileTool.java:605)
                              at com.sun.tools.ws.wscompile.CompileTool.run(CompileTool.java:538)
                              at com.sun.tools.ws.util.ToolBase.run(ToolBase.java:56)
                              at com.sun.tools.ws.util.WSToolsObjectFactoryImpl.wsgen(WSToolsObjectFactoryImpl.java:44)
                              at com.sun.enterprise.webservice.WsUtil.runWsGen(WsUtil.java:1820)
                              at com.sun.enterprise.webservice.WsUtil.genWSInfo(WsUtil.java:2089)
                              at com.sun.enterprise.deployment.backend.ModuleDeployer.loadDescriptors(ModuleDeployer.java:396)
                              at com.sun.enterprise.deployment.backend.WebModuleDeployer.deploy(WebModuleDeployer.java:155)
                              at com.sun.enterprise.deployment.backend.ModuleDeployer.doRequestFinish(ModuleDeployer.java:160)
                              at com.sun.enterprise.deployment.phasing.J2EECPhase.runPhase(J2EECPhase.java:169)
                              at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:95)
                              at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:871)
                              at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:266)
                              at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:739)
                              at com.sun.enterprise.management.deploy.DeployThread.deploy(DeployThread.java:174)
                              at com.sun.enterprise.management.deploy.DeployThread.run(DeployThread.java:210)
                      What is this com.sun.tools.a pt.Main.process () why i am getting same error for all the web services samples.?
                      It's usually advisable to test the installation using one of their test projects that they provide with their programs. Have you been able to deploy the project before?

                      Comment

                      • ak1dnar
                        Recognized Expert Top Contributor
                        • Jan 2007
                        • 1584

                        #12
                        Thank you guys,

                        When I build other web Application (Not web services), Netbeans allows me to build, deploy projects successfully.

                        And i used the tutorial samples under sun/netbeans for Web sevices.

                        Ok I'll remove the J2SE and J2EE from the system and NB also.
                        Will be right back after a fresh installation.

                        Comment

                        • ak1dnar
                          Recognized Expert Top Contributor
                          • Jan 2007
                          • 1584

                          #13
                          Hi,
                          I reinstalled JDK and netbeans.

                          Current configurations:

                          [CODE=text]
                          C:\>java -version
                          java version "1.5.0"
                          Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
                          Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)[/CODE]

                          Netbeans 5.5.1 under this location:



                          And I didn't update the IDE for any other add-ons using update manager.

                          Now the problem is different than previous one.

                          I tried this sample application.


                          Again once i come up with deploy it getting this error.

                          under Output-HelloWs window:
                          Code:
                          init:
                          deps-module-jar:
                          deps-ear-jar:
                          deps-jar:
                          library-inclusion-in-archive:
                          library-inclusion-in-manifest:
                          wsgen-init-nonJSR109:
                          wsgen-HelloWebService-nonJSR109:
                          Exception in thread "main" java.lang.NoSuchMethodError: com.sun.tools.apt.Main.process(Lcom/sun/mirror/apt/AnnotationProcessorFactory;[Ljava/lang/String;)I
                                  at com.sun.tools.ws.wscompile.WsgenTool.buildModel(WsgenTool.java:175)
                                  at com.sun.tools.ws.wscompile.WsgenTool.run(WsgenTool.java:102)
                                  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                  at java.lang.reflect.Method.invoke(Method.java:585)
                                  at com.sun.tools.ws.Invoker.invoke(Invoker.java:100)
                                  at com.sun.tools.ws.WsGen.main(WsGen.java:38)
                          Command invoked: wsgen "C:\Program Files\Java\jdk1.5.0\jre\bin\java.exe" -Djava.endorsed.dirs=${jaxws.endorsed.dir} -classpath "C:\Program Files\Java\jdk1.5.0\lib\tools.jar;D:\NetBeans\HelloWs\build\web\WEB-INF\classes;C:\Program Files\netbeans-5.5.1\ide7\modules\ext\jaxws21\activation.jar;C:\Program Files\netbeans-5.5.1\ide7\modules\ext\jaxws21\FastInfoset.jar;C:\Program Files\netbeans-5.5.1\ide7\modules\ext\jaxws21\http.jar;C:\Program Files\netbeans-5.5.1\ide7\modules\ext\jaxws21\api\jaxb-api.jar;C:\Program Files\netbeans-5.5.1\ide7\modules\ext\jaxws21\jaxb-impl.jar;C:\Program Files\netbeans-5.5.1\ide7\modules\ext\jaxws21\jaxb-xjc.jar;C:\Program Files\netbeans-5.5.1\ide7\modules\ext\jaxws21\api\jaxws-api.jar;C:\Program Files\netbeans-5.5.1\ide7\modules\ext\jaxws21\jaxws-rt.jar;C:\Program Files\netbeans-5.5.1\ide7\modules\ext\jaxws21\jaxws-tools.jar;C:\Program Files\netbeans-5.5.1\ide7\modules\ext\jaxws21\api\jsr173_api.jar;C:\Program Files\netbeans-5.5.1\ide7\modules\ext\jaxws21\api\jsr181-api.jar;C:\Program Files\netbeans-5.5.1\ide7\modules\ext\jaxws21\jsr250-api.jar;C:\Program Files\netbeans-5.5.1\ide7\modules\ext\jaxws21\api\saaj-api.jar;C:\Program Files\netbeans-5.5.1\ide7\modules\ext\jaxws21\saaj-impl.jar;C:\Program Files\netbeans-5.5.1\ide7\modules\ext\jaxws21\sjsxp.jar;C:\Program Files\netbeans-5.5.1\ide7\modules\ext\jaxws21\stax-ex.jar;C:\Program Files\netbeans-5.5.1\ide7\modules\ext\jaxws21\streambuffer.jar" com.sun.tools.ws.WsGen -d D:\NetBeans\HelloWs\build\web\WEB-INF\classes -keep -wsdl -r D:\NetBeans\HelloWs\build\generated\wsgen\service -s D:\NetBeans\HelloWs\build\generated\wsgen\service org.netbeans.end2end.hellosample.HelloWebService
                          D:\NetBeans\HelloWs\nbproject\build-impl.xml:303: wsgen failed
                          BUILD FAILED (total time: 0 seconds)
                          web service
                          [CODE=java]
                          package org.netbeans.en d2end.hellosamp le;

                          import javax.jws.Handl erChain;
                          import javax.jws.WebMe thod;
                          import javax.jws.WebPa ram;
                          import javax.jws.WebSe rvice;

                          @WebService(ser viceName="Greet erWs")
                          @HandlerChain(n ame = "HelloWebServic e_handlerChain" , file = "HelloWebServic e_handler.xml")
                          public class HelloWebService
                          {
                          @WebMethod(oper ationName="sayH i")
                          public String operation(@WebP aram(name="name ")String param)
                          {
                          return "Hi" + param;
                          }

                          @WebMethod
                          public String sayHello(String s)
                          {
                          return "Hello" +s;
                          }


                          }
                          [/CODE]

                          Message Handler
                          [CODE=java]package org.netbeans.en d2end.hellosamp le;

                          import java.util.Colle ctions;
                          import java.util.Set;
                          import javax.xml.names pace.QName;
                          import javax.xml.soap. SOAPMessage;
                          import javax.xml.ws.ha ndler.MessageCo ntext;
                          import javax.xml.ws.ha ndler.soap.SOAP Handler;
                          import javax.xml.ws.ha ndler.soap.SOAP MessageContext;


                          public class MessageHandler implements SOAPHandler<SOA PMessageContext >
                          {


                          public boolean handleMessage(S OAPMessageConte xt messageContext)
                          {
                          //SOAPMessage msg = messageContext. getMessage();
                          log(messageCont ext);
                          return true;
                          }
                          private void log(SOAPMessage Context messageContext)
                          {
                          Boolean outcoming = (Boolean)
                          messageContext. get(MessageCont ext.MESSAGE_OUT BOUND_PROPERTY) ;
                          if(outcoming.bo oleanValue())
                          {
                          System.out.prin tln("\nOutcomin g Message:");
                          }else
                          {
                          System.out.prin tln("\nIncoming Message:");
                          }
                          SOAPMessage message= messageContext. getMessage();
                          try{
                          message.writeTo (System.out);
                          System.out.prin tln("\n");
                          }catch(Exceptio n e)
                          {
                          System.out.prin tln("Exception "+e);
                          }
                          }

                          public Set<QName> getHeaders()
                          {
                          return Collections.EMP TY_SET;
                          }

                          public boolean handleFault(SOA PMessageContext messageContext)
                          {
                          return true;
                          }

                          public void close(MessageCo ntext context)
                          {
                          }

                          }
                          [/CODE]

                          Comment

                          Working...