Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Excerpt
  • Define Spring WebServiceTemplate context:

    Code Block
    xml
    xml
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:oxm="http://www.springframework.org/schema/oxm"
        xmlns:p="http://www.springframework.org/schema/p"
        xsi:schemaLocation="http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    
      <!-- contextPath - package where to find request and response classes to marshall / unmarshal
           if request and response are in different packages, declare marshaller and unmarshaller separately -->
      <oxm:jaxb2-marshaller id="jaxb2marshaller" contextPath="eu.geomodel.schema.ws.pvplanner"/>
    
      <bean id="pvPlannerTemplate" class="org.springframework.ws.client.core.WebServiceTemplate"
          p:marshaller-ref="jaxb2marshaller" p:unmarshaller-ref="jaxb2marshaller"
          p:defaultUri="https://solargis.info/ws/soap/pvPlanner"> <!-- web service endpoint uri -->
        <property name="interceptors">
          <list>
            <bean class="org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor"
                p:securementActions="Timestamp UsernameToken"
                p:securementUsername="demo"
                p:securementPassword="demo"/>
          </list>
        </property>
      </bean>
    </beans>
    


  • Define client Spring bean:

    Code Block
    java
    java
    // imports omitted
    public class PvPlannerWsClient {
    
      @Autowired
      @Qualifier("pvPlannerTemplate")
      WebServiceTemplate template;
    
      public CalculateResponse callPvPlanner(/*some args*/) {
        return (CalculateResponse) template.marshalSendAndReceive(prepareRequest(/*some args*/));
      }
    
      private CalclulateRequest prepareRequest(/*some args*/) {
        // just sample request
        CalculateRequest request = new CalculateRequest();
        Location location = new Location();
        location.setLat(48.612590); // location of demo site
        location.setLng(20.827079);
        request.setLocation(location);
        PvSystem system = new PvSystem();
        system.setInstalledPower(1);
        system.setModuleType(ModuleTypeEnum.C_SI);
        Settings settings = new Settings();
        settings.setInverterEfficiency(97.5);
        settings.setDcLosses(5.5);
        settings.setAcLosses(1.5);
        settings.setAvailability(99);
        system.setSettings(settings);
        MountingFixedRoofMounted mounting = new MountingFixedRoofMounted();
        mounting.setAzimuth(175);
        mounting.setInclination(45D);
        system.setMounting(mounting);
        request.setSystem(system);
        return request;
      }
    
    }
    
  •