Announcement Announcement Module
Collapse
No announcement yet.
Runtime configuration of JaxWsPortProxyFactoryBean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Runtime configuration of JaxWsPortProxyFactoryBean

    I am going to need to make several JaxWsPortProxyFactoryBeans to access soap services but I will not know their base url for the wsdlDocumentUrl and endpointAddress until runtime. I am thinking that possibly I could use Spring Configuration class(es), but I can't get the syntax right. What would be the syntax to translate this xml based config into a Spring Configuration class? or any other suggestions on how I could provide the base url at runtime? or other suggestions on best way to access soap services when getting the base url at runtime?

    Working with just static xml configuration as a test. I was able to get that to work and included it below. But, I have tried making an @Configuration class but I am stomped on JaxWsPortProxyFactoryBean becomes a Lineup (my soap service) type (included below) In Java Configuration, I can't cast it. Suggestions?

    applicationContext.xml

    Code:
       <bean id="lineupRetriever" class="com.lineupaggregator.service.LineupRetriever">
            <property name="lineupWebClients">
                <map>
                    <entry key="dev01">
                        <bean id="lineupWebClient1" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
                                <property name="serviceInterface" value="com.server.ws.lineup.Lineup"/>
                                <property name="wsdlDocumentUrl" value="http://xxx:8788/LineupService/LineupImpl?wsdl"/>
                                <property name="namespaceUri" value="http://lineup.ws.server.com/"/>
                                <property name="serviceName" value="LineupService"/>
                                <property name="portName" value="LineupPort"/>
                                <property name="endpointAddress" value="http://xxx:8788/LineupService/LineupImpl"/>
                            </bean>
                    </entry>
                    <entry key="dev07">
                        <bean id="lineupWebClient2" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
                               <property name="serviceInterface" value="com.server.ws.lineup.Lineup"/>
                               <property name="wsdlDocumentUrl" value="http://yyy:8788/LineupService/LineupImpl?wsdl"/>
                               <property name="namespaceUri" value="http://lineup.ws.com/"/>
                               <property name="serviceName" value="LineupService"/>
                               <property name="portName" value="LineupPort"/>
                               <property name="endpointAddress" value="http://yyy:8788/LineupService/LineupImpl"/>
                           </bean>
    
                    </entry>
                </map>
            </property>
        </bean>
    LineupRetriever.class

    Code:
    public class LineupRetriever
    {
       private static final Logger log = LoggerFactory.getLogger(LineupRetriever.class);
       private Map<String, Lineup> lineupWebClients;
    
    
       public Map<String, Lineup> getLineupWebClients()
       {
          return lineupWebClients;
       }
    
       public void setLineupWebClients(Map<String, Lineup> lineupWebClients)
       {
          this.lineupWebClients = lineupWebClients;
       }
    
       public
       @NotNull
       List<RegionalLineup> getAllLineupsInHeadEnd(String masId)
       {
          if (StringUtils.isEmpty(masId))
          {
             throw new IllegalArgumentException("Param masId cannot be empty");
          }
    
          List<RegionalLineup> retList = new ArrayList<RegionalLineup>();
          final Lineup lineupWebClient = lineupWebClients.get(masId);
          if (lineupWebClient == null)
          {
             throw new IllegalArgumentException("lineupWebClient for masId = " + masId + " is null");
          }
          try
          {
             List<LineupData> list = lineupWebClient.getAllLineupsInHeadEnd();
             retList = Lists.transform(list, LineupTransformer.LINEUP_DATA_TO_REGIONAL_LINEUP);
          }
          catch (OperationFailedException_Exception e)
          {
             log.error("Caught ex=", e);
          }
          return retList;
       }
    }

    Doesn't work.


    Code:
    @Configuration
    public class LineupWebClientConfig
    {
    public
       @Bean
       Map<String, String> masEndpoints()
       {
          
          Map<String, String> m = new HashMap<String, String>();
          m.put("dev01", "http://10.254.0.1:8788/LineupService/LineupImpl");
          m.put("dev04", "http://10.254.0.47:8788/LineupService/LineupImpl");
          m.put("dev07", "http://10.254.0.29:8788/LineupService/LineupImpl");
          return m;
       }
    
    
       public JaxWsPortProxyFactoryBean lineup(String masEndpoint)
       {
          final URL wsdlDocumentUrl;
          try
          {
             wsdlDocumentUrl = new URL(masEndpoint + "?wsdl");
          }
          catch (MalformedURLException e)
          {
             throw new IllegalArgumentException("WsdlDocumentUrl derived from masEndpoint = " + masEndpoint + " was malformed");
          }
    
          JaxWsPortProxyFactoryBean lineup = new org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean();
          lineup.setServiceInterface(com.twc.atgw.server.ws.lineup.Lineup.class);
          lineup.setNamespaceUri("http://lineup.ws.server.atgw.twc.com/");
          lineup.setServiceName("LineupService");
          lineup.setPortName("LineupPort");
          lineup.setEndpointAddress(masEndpoint);
          lineup.setWsdlDocumentUrl(wsdlDocumentUrl);
    
          return lineup;
       }
    
    
       public
       @Bean
       LineupRetriever lineupRetriever()
       {
          LineupRetriever lr = new LineupRetriever();
          lr.setLineupWebClients(lineupWebClients());
          return lr;
       }
    
       public
       @Bean(name = "lineupWebClients")
       Map<String, JaxWsPortProxyFactoryBean> lineupWebClients()
       {
          Map<String, JaxWsPortProxyFactoryBean> lineupWebClients = new HashMap<String, JaxWsPortProxyFactoryBean>();
          Iterator it = masEndpoints().entrySet().iterator();
          while (it.hasNext())
          {
             Map.Entry<String, String> entry = (Map.Entry<String, String>) it.next();
             final String masId = entry.getValue();
             final JaxWsPortProxyFactoryBean lineupWebClient = lineup(masId);
             if (lineupWebClient == null)
             {
                throw new IllegalStateException("lineupWebClient constructed for masId = " + masId + " is null");
             }
             lineupWebClients.put(entry.getKey(), lineupWebClient);
          }
          return lineupWebClients;
       }
    }

  • #2
    Solved: Answer the bean has a getObject method that is the proxy object to the webservice. Cast that object.
    Example:
    Code:
     public com.twc.atgw.server.ws.lineup.Lineup lineup(String masEndpoint)
       {
          if (StringUtils.isEmpty(masEndpoint))
          {
             throw new IllegalArgumentException("Parameter masEndpoint cannot be null or empty");
          }
          final URL wsdlDocumentUrl;
          try
          {
             wsdlDocumentUrl = new URL(masEndpoint + "?wsdl");
          }
          catch (MalformedURLException e)
          {
             throw new IllegalArgumentException("WsdlDocumentUrl derived from masEndpoint = " + masEndpoint + " was malformed");
          }
    
          JaxWsPortProxyFactoryBean lineup = new org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean();
          if (lineup == null)
          {
             throw new IllegalStateException("JaxWsPortProxyFactoryBean constructed for endpoint = " + masEndpoint + "  and wsdlDocumentURL = " + wsdlDocumentUrl + " is null");
          }
          lineup.setServiceInterface(com.twc.atgw.server.ws.lineup.Lineup.class);
          lineup.setNamespaceUri("http://lineup.ws.server.atgw.twc.com/");
          lineup.setServiceName("LineupService");
          lineup.setPortName("LineupPort");
          lineup.setEndpointAddress(masEndpoint);
          lineup.setWsdlDocumentUrl(wsdlDocumentUrl);
          lineup.afterPropertiesSet();
    
          Lineup l = (Lineup) lineup.getObject();
          if (l == null)
          {
             throw new IllegalStateException("JaxWsPortProxyFactoryBean proxy object is null for endpoint = " + masEndpoint + "  and wsdlDocumentURL = " + wsdlDocumentUrl);
          }
    
          return l;
       }

    Comment

    Working...
    X