Calling service list from existing SOAP service












0















I tried to generate some lists from existing SOAP webservice. But the problem is that, I always getting null value when tried to generate it.
Maybe someone can comment why this problem is happening to me?
Thanks!



Steps which I am doing:



I have generated wsdl from WSDL_link



Generated wsdl files with plugin:



<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<!-- Following configuration will pass ${project.basedir}/src/remote-xjc/bindings.xjc
and ${project.basedir}/src/jaxws/bindings-default.xjc to wsimport. -->
<configuration>
<wsdlUrls>
<wsdlUrl>${project.basedir}/src/main/resources/wsdl/FxRates_12.wsdl</wsdlUrl>
</wsdlUrls>
</configuration>
</execution>
</executions>
</plugin>


I used this plugin, because other plugins give me always errors.
And tried to call it with:



@RestController
public class GetRatesController {
private static final String soapEndpointUrl = "http://old.lb.lt/webservices/FxRates/FxRates.asmx";
private static final String soapAction = "http://www.lb.lt/WebServices/FxRates/getCurrencyList";
@RequestMapping(value = "/get", method = RequestMethod.GET, produces = "application/xml")
public ResponseEntity<GetCurrencyListResponse> getIndexView() {
GetCurrencyListResponse response = new GetCurrencyListResponse();
try {
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// Send SOAP Message to SOAP Server
GetCurrencyList getCurrencyList = new GetCurrencyList();
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(soapAction, getCurrencyList), soapEndpointUrl);
JAXBContext jaxbContext = JAXBContext.newInstance(GetCurrencyListResponse.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
response = (GetCurrencyListResponse) unmarshaller.unmarshal(soapResponse.getSOAPBody().extractContentAsDocument());
} catch (Exception e) {
System.err.println("nError occurred while sending SOAP Request to Server!nMake sure you have the correct endpoint URL and SOAPAction!n");
e.printStackTrace();
}
System.out.println(response.getGetCurrencyListResult().getContent());
return new ResponseEntity<>(response, HttpStatus.OK);
}
private static <T> SOAPMessage createSOAPRequest(String soapAction, T requestClass) throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
createSoapEnvelope(soapMessage, requestClass);
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", soapAction);
soapMessage.saveChanges();
return soapMessage;
}
private static <T> void createSoapEnvelope(SOAPMessage soapMessage, T requestClass) throws SOAPException, JAXBException {
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
JAXBContext jaxbContext = JAXBContext.newInstance(requestClass.getClass());
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
StringWriter sw = new StringWriter();
// SOAP Body
SOAPBody soapBody = envelope.getBody();
jaxbMarshaller.marshal(requestClass, sw);
System.out.println(sw.toString());
soapBody.addTextNode(sw.toString());
}
}


But the result I am getting is null.
Which part is wrong? How to get the currency list, which service should return?
XML of currency list service: XML










share|improve this question



























    0















    I tried to generate some lists from existing SOAP webservice. But the problem is that, I always getting null value when tried to generate it.
    Maybe someone can comment why this problem is happening to me?
    Thanks!



    Steps which I am doing:



    I have generated wsdl from WSDL_link



    Generated wsdl files with plugin:



    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>2.5</version>
    <executions>
    <execution>
    <goals>
    <goal>wsimport</goal>
    </goals>
    <!-- Following configuration will pass ${project.basedir}/src/remote-xjc/bindings.xjc
    and ${project.basedir}/src/jaxws/bindings-default.xjc to wsimport. -->
    <configuration>
    <wsdlUrls>
    <wsdlUrl>${project.basedir}/src/main/resources/wsdl/FxRates_12.wsdl</wsdlUrl>
    </wsdlUrls>
    </configuration>
    </execution>
    </executions>
    </plugin>


    I used this plugin, because other plugins give me always errors.
    And tried to call it with:



    @RestController
    public class GetRatesController {
    private static final String soapEndpointUrl = "http://old.lb.lt/webservices/FxRates/FxRates.asmx";
    private static final String soapAction = "http://www.lb.lt/WebServices/FxRates/getCurrencyList";
    @RequestMapping(value = "/get", method = RequestMethod.GET, produces = "application/xml")
    public ResponseEntity<GetCurrencyListResponse> getIndexView() {
    GetCurrencyListResponse response = new GetCurrencyListResponse();
    try {
    // Create SOAP Connection
    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection soapConnection = soapConnectionFactory.createConnection();
    // Send SOAP Message to SOAP Server
    GetCurrencyList getCurrencyList = new GetCurrencyList();
    SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(soapAction, getCurrencyList), soapEndpointUrl);
    JAXBContext jaxbContext = JAXBContext.newInstance(GetCurrencyListResponse.class);
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    response = (GetCurrencyListResponse) unmarshaller.unmarshal(soapResponse.getSOAPBody().extractContentAsDocument());
    } catch (Exception e) {
    System.err.println("nError occurred while sending SOAP Request to Server!nMake sure you have the correct endpoint URL and SOAPAction!n");
    e.printStackTrace();
    }
    System.out.println(response.getGetCurrencyListResult().getContent());
    return new ResponseEntity<>(response, HttpStatus.OK);
    }
    private static <T> SOAPMessage createSOAPRequest(String soapAction, T requestClass) throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    createSoapEnvelope(soapMessage, requestClass);
    MimeHeaders headers = soapMessage.getMimeHeaders();
    headers.addHeader("SOAPAction", soapAction);
    soapMessage.saveChanges();
    return soapMessage;
    }
    private static <T> void createSoapEnvelope(SOAPMessage soapMessage, T requestClass) throws SOAPException, JAXBException {
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPEnvelope envelope = soapPart.getEnvelope();
    JAXBContext jaxbContext = JAXBContext.newInstance(requestClass.getClass());
    Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
    jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
    StringWriter sw = new StringWriter();
    // SOAP Body
    SOAPBody soapBody = envelope.getBody();
    jaxbMarshaller.marshal(requestClass, sw);
    System.out.println(sw.toString());
    soapBody.addTextNode(sw.toString());
    }
    }


    But the result I am getting is null.
    Which part is wrong? How to get the currency list, which service should return?
    XML of currency list service: XML










    share|improve this question

























      0












      0








      0








      I tried to generate some lists from existing SOAP webservice. But the problem is that, I always getting null value when tried to generate it.
      Maybe someone can comment why this problem is happening to me?
      Thanks!



      Steps which I am doing:



      I have generated wsdl from WSDL_link



      Generated wsdl files with plugin:



      <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>jaxws-maven-plugin</artifactId>
      <version>2.5</version>
      <executions>
      <execution>
      <goals>
      <goal>wsimport</goal>
      </goals>
      <!-- Following configuration will pass ${project.basedir}/src/remote-xjc/bindings.xjc
      and ${project.basedir}/src/jaxws/bindings-default.xjc to wsimport. -->
      <configuration>
      <wsdlUrls>
      <wsdlUrl>${project.basedir}/src/main/resources/wsdl/FxRates_12.wsdl</wsdlUrl>
      </wsdlUrls>
      </configuration>
      </execution>
      </executions>
      </plugin>


      I used this plugin, because other plugins give me always errors.
      And tried to call it with:



      @RestController
      public class GetRatesController {
      private static final String soapEndpointUrl = "http://old.lb.lt/webservices/FxRates/FxRates.asmx";
      private static final String soapAction = "http://www.lb.lt/WebServices/FxRates/getCurrencyList";
      @RequestMapping(value = "/get", method = RequestMethod.GET, produces = "application/xml")
      public ResponseEntity<GetCurrencyListResponse> getIndexView() {
      GetCurrencyListResponse response = new GetCurrencyListResponse();
      try {
      // Create SOAP Connection
      SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
      SOAPConnection soapConnection = soapConnectionFactory.createConnection();
      // Send SOAP Message to SOAP Server
      GetCurrencyList getCurrencyList = new GetCurrencyList();
      SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(soapAction, getCurrencyList), soapEndpointUrl);
      JAXBContext jaxbContext = JAXBContext.newInstance(GetCurrencyListResponse.class);
      Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
      response = (GetCurrencyListResponse) unmarshaller.unmarshal(soapResponse.getSOAPBody().extractContentAsDocument());
      } catch (Exception e) {
      System.err.println("nError occurred while sending SOAP Request to Server!nMake sure you have the correct endpoint URL and SOAPAction!n");
      e.printStackTrace();
      }
      System.out.println(response.getGetCurrencyListResult().getContent());
      return new ResponseEntity<>(response, HttpStatus.OK);
      }
      private static <T> SOAPMessage createSOAPRequest(String soapAction, T requestClass) throws Exception {
      MessageFactory messageFactory = MessageFactory.newInstance();
      SOAPMessage soapMessage = messageFactory.createMessage();
      createSoapEnvelope(soapMessage, requestClass);
      MimeHeaders headers = soapMessage.getMimeHeaders();
      headers.addHeader("SOAPAction", soapAction);
      soapMessage.saveChanges();
      return soapMessage;
      }
      private static <T> void createSoapEnvelope(SOAPMessage soapMessage, T requestClass) throws SOAPException, JAXBException {
      SOAPPart soapPart = soapMessage.getSOAPPart();
      SOAPEnvelope envelope = soapPart.getEnvelope();
      JAXBContext jaxbContext = JAXBContext.newInstance(requestClass.getClass());
      Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
      jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
      StringWriter sw = new StringWriter();
      // SOAP Body
      SOAPBody soapBody = envelope.getBody();
      jaxbMarshaller.marshal(requestClass, sw);
      System.out.println(sw.toString());
      soapBody.addTextNode(sw.toString());
      }
      }


      But the result I am getting is null.
      Which part is wrong? How to get the currency list, which service should return?
      XML of currency list service: XML










      share|improve this question














      I tried to generate some lists from existing SOAP webservice. But the problem is that, I always getting null value when tried to generate it.
      Maybe someone can comment why this problem is happening to me?
      Thanks!



      Steps which I am doing:



      I have generated wsdl from WSDL_link



      Generated wsdl files with plugin:



      <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>jaxws-maven-plugin</artifactId>
      <version>2.5</version>
      <executions>
      <execution>
      <goals>
      <goal>wsimport</goal>
      </goals>
      <!-- Following configuration will pass ${project.basedir}/src/remote-xjc/bindings.xjc
      and ${project.basedir}/src/jaxws/bindings-default.xjc to wsimport. -->
      <configuration>
      <wsdlUrls>
      <wsdlUrl>${project.basedir}/src/main/resources/wsdl/FxRates_12.wsdl</wsdlUrl>
      </wsdlUrls>
      </configuration>
      </execution>
      </executions>
      </plugin>


      I used this plugin, because other plugins give me always errors.
      And tried to call it with:



      @RestController
      public class GetRatesController {
      private static final String soapEndpointUrl = "http://old.lb.lt/webservices/FxRates/FxRates.asmx";
      private static final String soapAction = "http://www.lb.lt/WebServices/FxRates/getCurrencyList";
      @RequestMapping(value = "/get", method = RequestMethod.GET, produces = "application/xml")
      public ResponseEntity<GetCurrencyListResponse> getIndexView() {
      GetCurrencyListResponse response = new GetCurrencyListResponse();
      try {
      // Create SOAP Connection
      SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
      SOAPConnection soapConnection = soapConnectionFactory.createConnection();
      // Send SOAP Message to SOAP Server
      GetCurrencyList getCurrencyList = new GetCurrencyList();
      SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(soapAction, getCurrencyList), soapEndpointUrl);
      JAXBContext jaxbContext = JAXBContext.newInstance(GetCurrencyListResponse.class);
      Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
      response = (GetCurrencyListResponse) unmarshaller.unmarshal(soapResponse.getSOAPBody().extractContentAsDocument());
      } catch (Exception e) {
      System.err.println("nError occurred while sending SOAP Request to Server!nMake sure you have the correct endpoint URL and SOAPAction!n");
      e.printStackTrace();
      }
      System.out.println(response.getGetCurrencyListResult().getContent());
      return new ResponseEntity<>(response, HttpStatus.OK);
      }
      private static <T> SOAPMessage createSOAPRequest(String soapAction, T requestClass) throws Exception {
      MessageFactory messageFactory = MessageFactory.newInstance();
      SOAPMessage soapMessage = messageFactory.createMessage();
      createSoapEnvelope(soapMessage, requestClass);
      MimeHeaders headers = soapMessage.getMimeHeaders();
      headers.addHeader("SOAPAction", soapAction);
      soapMessage.saveChanges();
      return soapMessage;
      }
      private static <T> void createSoapEnvelope(SOAPMessage soapMessage, T requestClass) throws SOAPException, JAXBException {
      SOAPPart soapPart = soapMessage.getSOAPPart();
      SOAPEnvelope envelope = soapPart.getEnvelope();
      JAXBContext jaxbContext = JAXBContext.newInstance(requestClass.getClass());
      Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
      jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
      StringWriter sw = new StringWriter();
      // SOAP Body
      SOAPBody soapBody = envelope.getBody();
      jaxbMarshaller.marshal(requestClass, sw);
      System.out.println(sw.toString());
      soapBody.addTextNode(sw.toString());
      }
      }


      But the result I am getting is null.
      Which part is wrong? How to get the currency list, which service should return?
      XML of currency list service: XML







      java web-services soap






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 9:04









      DonatasDonatas

      11




      11
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296406%2fcalling-service-list-from-existing-soap-service%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296406%2fcalling-service-list-from-existing-soap-service%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()