This blog has moved to
http://blog.matthias-reining.com

Die bestehenden Artikel bleiben vorerst alle bei blogspot. Neue Artikel veröffentliche ich allerdings nur noch auf http://blog.matthias-reining.com

Dienstag, 16. März 2010

JBoss WebService Anbindung - DNS kann nicht aufgelöst werden, IP wird benötigt

[Alle hier beschriebenen Merkmale gelten für JBoss 4.2.3GA]

Wenn innerhalb von JBoss verschieden Session Beans als WebService veröffentlicht werden, wird hier per default einfach das entsprechende WSDL erzeugt.

Anbei ein Beispiel für eine entspreche SLSB:

@WebService
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
public interface ExampleService {

      @WebMethod
      Public String getData();
}

@Stateless
@WebContext(contextRoot = "/ExampleWS")
@WebService
@Remote(ExampleService.class)
@Local(ExampleService.class)
public class ExampleServiceBean implements ExampleService {
@Override
      public String getData() {
            return "ExampleData";
      }
}

Dies WSDL kann dann unter foglender Adresse eingesehen werden:


Im unteren Abschnitt der WSDL ist dann folgender Abschnitt:
<service name='ExampleServiceBeanService'>
  <port binding='tns:ExampleServiceBeanBinding' name='ExampleServiceBeanPort'>
    <soap:address location='http://pluto:8080/ExampleWS/ExampleServiceBean'/>
  </port>
</service>

pluto ist mein lokaler Rechnername. Und genau das ist das Problem. Innerhalb des WSDL Files wird der DNS Name des Server herangezogen.

Wenn man nun außerhalb des eigenes Netzes per WebService auf den Rechner zugreifen will, kann „pluto“ natürlich nicht aufgelöst werden. Dies kommt beispielsweise vor, wenn ein Webserver in der DMZ steht und auf einen AppServer, der innerhalb des Firmennetzes steht, per Webservice zugreifen möchte. In der Firewall wurde hierfür extra 1 Port geöffnet, das WSDL File kann noch angezeigt werden, der Service ist dann aber nicht aufrufbar L

Ein Zugriff auf den JBoss Server ist nur per IP Adresse möglich!

Abhilfe schafft hierzu folgender Parameter beim Start des Servers:

-Djboss.bind.address=192.168.15.11

Die 192.168.15.11 ist in diesem Beispiel natürlich meine lokale IP Adresse.

Das WSDL wird anschließend entsprechend angepasst und die soap:address location verwendet dann nicht mehr den Rechnernamen sondern den Wert  für jboss.bind.address.

Der Parameter hat direkt Einfluss auf folgendes Konfigurationsfile:

<JBOSS_HOME>\server\default\deploy\jbossws.sar\jbossws.beans\META-INF\jboss-beans.xml

Folgender Abschnitt ist hier relevant:

<!-- An abstraction of server configuration aspects. --> 
  <bean name="WSServerConfig" class="org.jboss.wsf.stack.jbws.NativeServerConfig">
    <property name="mbeanServer"><inject bean="WSMBeanServerLocator" property="mbeanServer"/></property>
   
    <!--
        The WSDL, that is a required deployment artifact for an endpoint, has a <soap:address>
        element which points to the location of the endpoint. JBoss supports rewriting of that SOAP address.
     
        If the content of <soap:address> is a valid URL, JBossWS will not rewrite it unless 'modifySOAPAddress' is true.
        If the content of <soap:address> is not a valid URL, JBossWS will rewrite it using the attribute values given below.
       
        If 'webServiceHost' is not set, JBossWS uses requesters protocol host when rewriting the <soap:address>.
    -->
    <property name="webServiceHost">${jboss.bind.address}</property>
    <property name="modifySOAPAddress">true</property>
   
    <!--
      Set these properties to explicitly define the ports that will be used for rewriting the SOAP address.
      Otherwise the ports will be identified by querying the list of installed connectors.
      If multiple connectors are found the port of the first connector is used.
      <property name="webServiceSecurePort">8443</property>
      <property name="webServicePort">8080</property>
    -->
  </bean>

Alternativ zu dem Parameter jboss.bind.address kann auch beim Start der Parameter -b eingesetzt werden.