Results 1 to 13 of 13
  1. #1
    ragnor2004 is offline Member
    Join Date
    Mar 2009
    Posts
    11
    Rep Power
    0

    Default Using a Web Service

    Ok to Start off I havent used java for a while now, but was asked to create a small program that can enter and pull items from a database and send them to a web service. Trouble is I am not familiar with this type of operation. I cant seem to find a good tutorial out there that has helped me so here I go. My WSDL is http://wservicecrt.cerner.com/SRWeb/...SR_INVOKE.wsdl and I will need to take information gathered by the database portion of my program and send it to this web service. There is a class called ProSr that will contain all of the information I need to send to the service.

    Here is the ProSr code.

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package desktopapplication1;
    
    /**
     *
     */
    public class ProSR{
         ProSR(){}
         String sClient;
         String sContactFN;
         String sContactLN;
         String sContactWP;
         String sEnvironment;
         String sMnemonicCern;
         String sOwner;
         String sSeverity;
         String sSolution;
         String sSolutionFam;
         String sSource;
         String sStatus;
         String sSubstatus;
         String sSummary;
         String sTeam;
         String sEntitlement;
         public void setClient(String x){ sClient = x;}
         public void setEntitlement(String x){sEntitlement =x;}
          public void setContactFN(String x){sContactFN =x;}
          public void setContactLN(String x){sContactLN =x;}
          public void setContactWP(String x){sContactWP =x;}
          public void setEnvironment(String x){sEnvironment =x;}
          public void setMnemonicCern(String x){sMnemonicCern =x;}
          public void setOwner(String x){sOwner =x;}
          public void setSeverity(String x){sSeverity =x;}
          public void setSolution(String x){sSolution =x;}
          public void setSolutionFam(String x){sSolutionFam =x;}
          public void setSource(String x){sSource =x;}
          public void setStatus(String x){sStatus =x;}
          public void setSubstatus(String x){sSubstatus =x;}
          public void setSummary(String x){sSummary =x;}
          public void setTeam(String x){sTeam =x;}
          public String getClient(){ return sClient;}
          public String getContactFN(){ return sContactFN ;}
          public String getContactLN(){ return sContactLN ;}
          public String getContactWP(){ return sContactWP ;}
          public String getEnvironment(){ return sEnvironment ;}
          public String getMnemonicCern(){ return sMnemonicCern ;}
          public String getOwner(){ return sOwner ;}
          public String getSeverity(){ return sSeverity ;}
          public String getSolution(){ return sSolution ;}
          public String getSolutionFam(){ return sSolutionFam ;}
          public String getSource(){ return sSource ;}
          public String getStatus(){ return sStatus ;}
          public String getSubstatus(){ return sSubstatus ;}
          public String getSummary(){ return sSummary ;}
          public String getTeam(){ return sTeam ;}
          public String getEntitlement(){return sEntitlement;}
        }
    So if someone could point me to a place or better yet tell me what code I need to implement to be able to send things to this web service you would be helping me out a lot.
    Last edited by ragnor2004; 01-28-2010 at 05:19 PM.

  2. #2
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    364
    Rep Power
    5

    Default

    Your URL with wsdl cannot be reached.

    So, on that URL is server that is exposing some operations.
    If you can understand basics of wsdl you will see what messages are exchanged between client and server and what are parameters for them.

    Easiest way for you is to use wizard in Eclipse, Netbeans...

    Find web services creator in your IDE and you should look for
    "Creating Top Down Web Service".

    Point to *.wsdl file and wizard creates java classes for you.

    Study a liitle bit those classes, specially stub and proxy, and you will recognize how to use them in your own client class to set up
    params for web service methods and invoke server call.

    If you want to check if that server is working at all u can use
    'web service explorer' tool in your IDE, where you just enter params for
    operations in some GUI and send them to server (no coding at all)

    good luck!

  3. #3
    ragnor2004 is offline Member
    Join Date
    Mar 2009
    Posts
    11
    Rep Power
    0

    Default

    Ah well its was early when I posted the WSDL is on our company intranet so you wont be able to see it. Also if it helps I am using netbeans and have already added use the connect to webservice client and added it to my code. Here is the code I get when (in the code for my create button) I click and insert code then add web service operational code.
    Java Code:
    public void Create() {
            System.out.println("create");
            try { // Call Web Service Operation
                desktopapplication1.INVOKEINVOKEHttpService service = new desktopapplication1.INVOKEINVOKEHttpService();
                desktopapplication1.INVOKE port = service.getINVOKEINVOKEHttpPort();
                // TODO initialize WS operation arguments here
                desktopapplication1.SR serviceRequest = new desktopapplication1.SR();
                javax.xml.ws.Holder<java.lang.String> serviceRequestNumber = new javax.xml.ws.Holder<java.lang.String>();
                javax.xml.ws.Holder<java.lang.String> serviceRequestId = new javax.xml.ws.Holder<java.lang.String>();
                javax.xml.ws.Holder<java.lang.String> serviceRequestIntegrationId = new javax.xml.ws.Holder<java.lang.String>();
                port.upsert(serviceRequest, serviceRequestNumber, serviceRequestId, serviceRequestIntegrationId);
                
    
    
            } catch (Exception ex) {
                // TODO handle custom exceptions here
            }
    
        }
    Last edited by ragnor2004; 01-28-2010 at 05:18 PM.

  4. #4
    ragnor2004 is offline Member
    Join Date
    Mar 2009
    Posts
    11
    Rep Power
    0

    Default

    Ok here is my updated code nothing is being created on the test end so I'm not quite sure what I have to use to send the information over.

    XML Code:
    public void Create() {
            System.out.println("create");
            try { // Call Web Service Operation
                desktopapplication1.INVOKEINVOKEHttpService service = new desktopapplication1.INVOKEINVOKEHttpService();
                desktopapplication1.INVOKE port = service.getINVOKEINVOKEHttpPort();
                // TODO initialize WS operation arguments here
                desktopapplication1.SR serviceRequest = new desktopapplication1.SR();
                javax.xml.ws.Holder<java.lang.String> serviceRequestNumber = new javax.xml.ws.Holder<java.lang.String>();
                javax.xml.ws.Holder<java.lang.String> serviceRequestId = new javax.xml.ws.Holder<java.lang.String>();
                javax.xml.ws.Holder<java.lang.String> serviceRequestIntegrationId = new javax.xml.ws.Holder<java.lang.String>();
    
    
                serviceRequest.setSummary("Testing SR Creation");
                serviceRequest.setStatus("Open");
                serviceRequest.setClientMnemonic("UNIV_MO");
                serviceRequest.setSeverity("3: Moderate Impact");
                serviceRequest.setContactLoginId("SW019489");
                serviceRequest.setSource("Proactive Intervention");
                serviceRequest.setSubstatus("Unassigned");
                serviceRequest.setOwner("SW019489");
                serviceRequestNumber.value = "";
                serviceRequestId.value = "";
                serviceRequestIntegrationId.value = "";
                
                ups.setServiceRequest(serviceRequest);
                
                port.upsert(serviceRequest, serviceRequestNumber, serviceRequestId, serviceRequestIntegrationId);
    
            
            } catch (Exception ex) {
                // TODO handle custom exceptions here
            }
    
        }
    Last edited by ragnor2004; 01-28-2010 at 05:18 PM.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default

    Can you use code tags?#It makes it a lot easier to see what's going on.

    Also you are committing a great sin in eatig your exceptions. At the very least do ex.printSTackTrace(), otherwise you'll never know if an exception has been thrown.

  6. #6
    ragnor2004 is offline Member
    Join Date
    Mar 2009
    Posts
    11
    Rep Power
    0

    Default

    Sorry forgot about the code tags, and yeah I forgot all about printStackTrace, like I said I havent done this in a while. Thanks for the help.

  7. #7
    ragnor2004 is offline Member
    Join Date
    Mar 2009
    Posts
    11
    Rep Power
    0

    Default

    So now I am getting the following exception, thanks for the help
    Java Code:
    com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.ConnectException: Connection refused: connect
            at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:121)
            at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:142)
            at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:83)
            at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:105)
            at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:587)
            at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:546)
            at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:531)
            at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:428)
            at com.sun.xml.internal.ws.client.Stub.process(Stub.java:211)
            at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:124)
            at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:98)
            at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
            at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)
            at $Proxy32.upsert(Unknown Source)
            at desktopapplication1.DesktopApplication1View.Create(DesktopApplication1View.java:772)
            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:597)
            at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(ApplicationAction.java:662)
            at org.jdesktop.application.ApplicationAction.actionPerformed(ApplicationAction.java:698)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
            at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
            at java.awt.Component.processMouseEvent(Component.java:6263)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3255)
            at java.awt.Component.processEvent(Component.java:6028)
            at java.awt.Container.processEvent(Container.java:2041)
            at java.awt.Component.dispatchEventImpl(Component.java:4630)
            at java.awt.Container.dispatchEventImpl(Container.java:2099)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
            at java.awt.Container.dispatchEventImpl(Container.java:2085)
            at java.awt.Window.dispatchEventImpl(Window.java:2475)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    Caused by: java.net.ConnectException: Connection refused: connect
            at java.net.PlainSocketImpl.socketConnect(Native Method)
            at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
            at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
            at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
            at java.net.Socket.connect(Socket.java:525)
            at java.net.Socket.connect(Socket.java:475)
            at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
            at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
            at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
            at sun.net.www.http.HttpClient.<init>(HttpClient.java:233)
            at sun.net.www.http.HttpClient.New(HttpClient.java:306)
            at sun.net.www.http.HttpClient.New(HttpClient.java:323)
            at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:860)
            at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:839)
            at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:726)
            at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:904)
            at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:109)
            ... 46 more

  8. #8
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    364
    Rep Power
    5

    Default

    Take a look at wsdl file.

    At bottom there is SERVICE element with the address for invoking the specified service ,some URL like:
    ...
    <soap:address
    location=" http://wservicecrt.cerner.com/SRWeb/..... "/>
    ...

    Try first ping on that machine or telnet from your machine on severs's port
    to see if everything is OK with network.

    That location from wsdl
    must be present in your code. I guess some wizard created it from wsdl
    and put in some class(mine is called ServiceLocator) . While trying to invoke server, use debuger to find
    this line to be 100% sure that URL is OK and you can connect there.

  9. #9
    ragnor2004 is offline Member
    Join Date
    Mar 2009
    Posts
    11
    Rep Power
    0

    Default

    @ Fon, I'm not quite sure what you mean, I cannot ping the WSDL file but i can browse to it and see the xml information.

  10. #10
    johniem is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default

    You have to post your wsdl. You are trying to invoke a non exist service in your code or you are using wrong authentication parameters.

  11. #11
    ragnor2004 is offline Member
    Join Date
    Mar 2009
    Posts
    11
    Rep Power
    0

    Default

    Ok Guys here is my WSDL file
    XML Code:
    <?xml version="1.0" encoding="UTF-8" ?> 
    - <wsdl:definitions name="INVOKE_INVOKEHttp_Service" targetNamespace="http://SR_LIB/INVOKE/Binding" xmlns:Port_0="http://SR_LIB/INVOKE" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:this="http://SR_LIB/INVOKE/Binding" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
      <wsdl:import location="INVOKE.wsdl" namespace="http://SR_LIB/INVOKE" /> 
    - <wsdl:binding name="INVOKE_INVOKEHttpBinding" type="Port_0:INVOKE">
      <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> 
    - <wsdl:operation name="UPSERT">
      <soap:operation soapAction="" /> 
    - <wsdl:input name="UPSERTRequest">
      <soap:body use="literal" /> 
      </wsdl:input>
    - <wsdl:output name="UPSERTResponse">
      <soap:body use="literal" /> 
      </wsdl:output>
    - <wsdl:fault name="Fault">
      <soap:fault name="Fault" use="literal" /> 
      </wsdl:fault>
      </wsdl:operation>
    - <wsdl:operation name="Query">
      <soap:operation soapAction="" /> 
    - <wsdl:input name="QueryRequest">
      <soap:body use="literal" /> 
      </wsdl:input>
    - <wsdl:output name="QueryResponse">
      <soap:body use="literal" /> 
      </wsdl:output>
    - <wsdl:fault name="Fault">
      <soap:fault name="Fault" use="literal" /> 
      </wsdl:fault>
      </wsdl:operation>
      </wsdl:binding>
    - <wsdl:service name="INVOKE_INVOKEHttpService">
    - <wsdl:port binding="this:INVOKE_INVOKEHttpBinding" name="INVOKE_INVOKEHttpPort">
      <soap:address location="http://wservicecrt.cerner.com:9080/SRWeb/sca/INVOKE" /> 
      </wsdl:port>
      </wsdl:service>
      </wsdl:definitions>

  12. #12
    ragnor2004 is offline Member
    Join Date
    Mar 2009
    Posts
    11
    Rep Power
    0

    Default

    Ok Guys anymore help here not the best for with WSDL files, i'm not sure what I need to do to correct my error above?

  13. #13
    ragnor2004 is offline Member
    Join Date
    Mar 2009
    Posts
    11
    Rep Power
    0

    Default

    Is anyone able to help me out on this i'm really at a standstill here.

Similar Threads

  1. Web service
    By mousumidas in forum Advanced Java
    Replies: 3
    Last Post: 01-28-2010, 09:12 AM
  2. how to call service method inside another service
    By kirtichopra2003 in forum Web Frameworks
    Replies: 1
    Last Post: 10-24-2009, 02:19 AM
  3. serialize to web service?
    By theartz in forum Advanced Java
    Replies: 2
    Last Post: 08-16-2008, 01:39 AM
  4. Setup RMI service on Ant
    By vaskarbasak in forum Advanced Java
    Replies: 0
    Last Post: 07-24-2008, 02:25 PM
  5. Web Service from JSP
    By Eric in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 07-02-2007, 05:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •