We will now run the Chapter6
sample application that demonstrates the use of the HTTP gateway:
jboss-esb.xml
file in Source mode.listener
definition to the <listeners>
tag.<listeners> <jms-listener busidref="chapter6ESBChannel" name="Chapter6ESBListener"/> <jms-listener busidref="chapter6GwChannel" is-gateway="true" name="Chapter6GwListener"/> <http-gateway busidref="chapter6HttpGateway" name="Chapter6HttpGwListener"/> </listeners>
<action name="notificationAction" class="org.jboss.soa.esb.actions.Notifier"> <property name="okMethod" value="notifyOK"/> <property name="notification-details"> <NotificationList type="ok"> <target class="NotifyFiles"> <file append="false" URI="${java.io.tmpdir}/results.log"/> </target> </NotificationList> </property> </action>
src
folder and expand it till the SendHttpMessage.java
file is displayed in the tree. Now click Run | Run As | Java Application.The console will display the following:
Http Gateway says Hello!
We sent a message via the HTTP gateway listener and received a synchronous response, on the same connection which transferred the request.
Here is the listing of the client code for reference:
public static void main(String[] args) throws Exception { String serverURL = "http://localhost:8080/Chapter6/http/Chapter6Sample/Chapter6Service"; HttpURLConnection connection = (HttpURLConnection)new URL(serverURL).openConnection(); connection.setRequestMethod("POST"); connection.setDoOutput(true); connection.setDoInput(true); connection.connect(); PrintWriter out = new PrintWriter(new OutputStreamWriter(connection.getOutputStream())); out.println("Hello Http Gateway!"); out.close(); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { System.out.println(inputLine); } in.close(); }
Go ahead and modify the listener to add asynchronous behavior. Are you able to send a GET request now? What status code does it return by default?
Aspects of the HTTP configuration can be shared between multiple gateways, specified through the <http-provider>
or <http-bus>
elements.
The <http-provider>
element exposes the shared configuration of the HTTP exception mappings. Using the <exception>
element specifies the translations from exceptions into the appropriate HTTP response.
The <http-bus>
element exposes the shared configuration of the HTTP methods that are supported using the <protected-methods>
element, the security roles required to access the endpoint using the <allowed-roles>
element, and any requirement to secure the HTTP transport using the transportGuarantee
attribute.
A typical HTTP provider configuration would look like this:
<http-provider name="http"> <http-bus busid="chapter6HttpGateway" transportGuarantee="CONFIDENTIAL"> <allowed-roles> <role name="friend"> </allowed-roles> <protected-methods> <method name="GET"> <method name="PUT"> <method name="POST"> <method name="DELETE"> </protected-methods> </http-bus> <exception mappingsFile="/http-exception-mappings.properties"/> </http-provider>
Note that the configuration stipulates a requirement to use a CONFIDENTIAL
transport, in other words SSL, and requires the user to authenticate using credentials that include the friend
role.
The exception
element can also be configured directly as shown in the following:
<exception> <mapping class="com.acme.AcmeException" status="503"/> </exception>