<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Paco Saucedo&#039;s blog</title>
	<atom:link href="http://fcosfc.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://fcosfc.wordpress.com</link>
	<description>Cool stuff about computing</description>
	<lastBuildDate>Tue, 19 Mar 2013 15:43:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='fcosfc.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Paco Saucedo&#039;s blog</title>
		<link>http://fcosfc.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://fcosfc.wordpress.com/osd.xml" title="Paco Saucedo&#039;s blog" />
	<atom:link rel='hub' href='http://fcosfc.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Working with Oracle XMLType and JPA over Weblogic</title>
		<link>http://fcosfc.wordpress.com/2013/03/11/working-with-oracle-xmltype-and-jpa-over-weblogic/</link>
		<comments>http://fcosfc.wordpress.com/2013/03/11/working-with-oracle-xmltype-and-jpa-over-weblogic/#comments</comments>
		<pubDate>Mon, 11 Mar 2013 19:28:24 +0000</pubDate>
		<dc:creator>fcosfc</dc:creator>
				<category><![CDATA[EE]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[Weblogic]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[JDeveloper]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[Oracle Database]]></category>
		<category><![CDATA[XMLType]]></category>

		<guid isPermaLink="false">http://fcosfc.wordpress.com/?p=536</guid>
		<description><![CDATA[I&#8217;ve been working with the object type of Oracle databases for XML for a long time, but always in the context of PL/SQL programming. Last week,  I developed a Java EE module that made use of JPA entities, supported by tables with SYS.XMLType columns, so I&#8217;d like to share my findings with an example. First [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fcosfc.wordpress.com&#038;blog=23277319&#038;post=536&#038;subd=fcosfc&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been working with the object type of Oracle databases for XML for a long time, but always in the context of PL/SQL programming. Last week,  I developed a Java EE module that made use of JPA entities, supported by tables with SYS.XMLType columns, so I&#8217;d like to share my findings with an example.</p>
<p>First of all, here you have the creation sentence of a table that offers persistence to a simple messaging interface:</p>
<pre><code>
create table messages
  (
    message_id     number  constraint message_pk primary key,
    reception_date date    not null,
    msg_content    xmltype not null 
                           constraint message_msg_content_ck check(
                              xmlisvalid(msg_content) = 1)
  )
  xmltype column msg_content store as clob xmlschema
  "http://testdomain.com/Messages.xsd"
  element "Messages";
</code></pre>
<p>This is an excerpt of a JPA entity that could represent the former table:</p>
<pre><code>
package com.wordpress.fcosfc.test.messaging;

...

import org.eclipse.persistence.annotations.Customizer;

@Entity
@Table(name = "MESSAGES")
@Customizer(XMLTypeAttributeCustomizer.class)
public class Messages implements Serializable {

    @Id
    @Column(name = "MESSAGE_ID", nullable = false)
    private BigDecimal messageId;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "RECEPTION_DATE", nullable = false)
    private Date receptionDate;

    @Lob
    @Column(nullable = false)    
    private String msgContent;

    ...
}

</code></pre>
<p>I&#8217;m sure you&#8217;ve realized that there is an special annotation <em>Customizer</em>, which makes reference to this class:</p>
<pre><code>
package com.wordpress.fcosfc.test.messaging;

import org.eclipse.persistence.config.DescriptorCustomizer;
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.mappings.xdb.DirectToXMLTypeMapping;

public class XMLTypeAttributeCustomizer implements DescriptorCustomizer {

    @Override
    public void customize(final ClassDescriptor descriptor) throws Exception {
        descriptor.removeMappingForAttributeName("msg_content");
        final DirectToXMLTypeMapping mapping = new DirectToXMLTypeMapping();
        mapping.setAttributeName("msg_content");
        mapping.setFieldName("MSG_CONTENT");
        mapping.getField().setColumnDefinition("sys.XMLTYPE");
        descriptor.addMapping(mapping);
    }

}
</code></pre>
<p>This class has a <a title="EclipseLink JPA Description Customizer" href="http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Customizers#DescriptorCustomizer" target="_blank">method </a>that changes the default mapping of the EclipseLink JPA provider in order to use the proper type from Oracle: SYS.XMLType.</p>
<p>Finally, I&#8217;d like to point out that the first time I deployed my module over an Oracle Weblogic 10.3.5 application server I got a ClassNotFoundException: oracle/xdb/xmltype , so I had to extend my Weblogic domain in order to support Oracle XMType. <a title="Oracle Database Extensions with TopLink" href="http://docs.oracle.com/cd/E12839_01/relnotes.1111/e10133/toplink.htm#CHDGIHIF" target="_blank">Here you have my reference about how to do it</a>, I just followed the instructions to support Oracle XDB.</p>
<hr />
<p>References</p>
<ul>
<li><a title="EclipseLink JPA Description Customizer" href="http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Customizers#DescriptorCustomizer" target="_blank">EclipseLink JPA Description Customizer</a></li>
<li><a title="Oracle Database Extensions with TopLink" href="http://docs.oracle.com/cd/E12839_01/relnotes.1111/e10133/toplink.htm#CHDGIHIF" target="_blank">Oracle Database Extensions with TopLink</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fcosfc.wordpress.com/536/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fcosfc.wordpress.com/536/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fcosfc.wordpress.com&#038;blog=23277319&#038;post=536&#038;subd=fcosfc&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fcosfc.wordpress.com/2013/03/11/working-with-oracle-xmltype-and-jpa-over-weblogic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/246c8ae49665d2d03381f0667408e410?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fcosfc</media:title>
		</media:content>
	</item>
		<item>
		<title>Weblogic: Interoperating with Oracle AQ JMS. A tip for sending messages</title>
		<link>http://fcosfc.wordpress.com/2013/02/08/weblogic-interoperating-with-oracle-aq-jms-a-tip-for-sending-messages/</link>
		<comments>http://fcosfc.wordpress.com/2013/02/08/weblogic-interoperating-with-oracle-aq-jms-a-tip-for-sending-messages/#comments</comments>
		<pubDate>Fri, 08 Feb 2013 19:00:59 +0000</pubDate>
		<dc:creator>fcosfc</dc:creator>
				<category><![CDATA[Advanced Queuing]]></category>
		<category><![CDATA[EE]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[Weblogic]]></category>
		<category><![CDATA[AQ]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[JMS]]></category>
		<category><![CDATA[Oracle Database]]></category>

		<guid isPermaLink="false">http://fcosfc.wordpress.com/?p=532</guid>
		<description><![CDATA[I usually work with Oracle Streams Advanced Queuing (AQ) integrated with Weblogic. In PL/SQL programs you can set the exception queue where you want to move the messages that couldn&#8217;t be delivered to their destinations, when you send a message, for example: declare enq_msgid raw(16) ; eopt dbms_aq.enqueue_options_t; mprop dbms_aq.message_properties_t; message sys.aq$_jms_text_message; begin mprop.priority := [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fcosfc.wordpress.com&#038;blog=23277319&#038;post=532&#038;subd=fcosfc&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I usually work with <a title="Interoperating with Oracle AQ JMS" href="http://docs.oracle.com/cd/E14571_01/web.1111/e13738/aq_jms.htm" target="_blank">Oracle Streams Advanced Queuing (AQ) integrated with Weblogic</a>. In PL/SQL programs you can set the exception queue where you want to move the messages that couldn&#8217;t be delivered to their destinations, when you send a message, for example:</p>
<pre><code>
declare
  enq_msgid raw(16) ;
  eopt      dbms_aq.enqueue_options_t;
  mprop     dbms_aq.message_properties_t;
  message   sys.aq$_jms_text_message;
begin
  mprop.priority        := 1;
  <strong>mprop.exception_queue := 'test_exception_q';</strong>
  message               := sys.aq$_jms_text_message.construct() ;
  message.set_text('This is a Test') ;
  dbms_aq.enqueue(queue_name =&gt; 'test_q', 
                  enqueue_options =&gt; eopt,
                  message_properties =&gt; mprop, 
                  payload =&gt; message, 
                  msgid =&gt; enq_msgid) ;

  commit;
end;
</code></pre>
<p>But, how to set the exception queue when you&#8217;re programming in Java, in the context of an integration between Oracle AQ and Weblogic? The solution I&#8217;ve found is to set the string property called <strong>JMS_OracleExcpQ</strong> to the message with the name of the Oracle AQ exception queue, for example:</p>
<pre><code>
...
javax.jms.TextMessage msg = jmsSession.createTextMessage();
msg.setStringProperty("JMS_OracleExcpQ", "TEST.TEST_EXCEPTION_Q");
msg.setText("This is a Test");
jmsProducer.send(msg);
...
</code></pre>
<p>An important advice: put the name in uppercase and preceded by the name of the schema.</p>
<p>Finally, I&#8217;d like to point out that this is a good solution in the context of an integration between Oracle AQ and Weblogic, but makes the code non portable, if you want to change the messaging provider of your Weblogic Application Server.</p>
<hr />
<p>References</p>
<ul>
<li><a title="Interoperating with Oracle AQ JMS" href="http://docs.oracle.com/cd/E14571_01/web.1111/e13738/aq_jms.htm" target="_blank">Oracle Streams Advanced Queuing (AQ) integrated with Weblogic</a></li>
<li><b></b><a title="Oracle Streams Advanced Queuing User's Guide" href="http://docs.oracle.com/cd/E11882_01/server.112/e11013/jm_create.htm#autoId18" target="_blank">Oracle Streams Advanced Queuing User&#8217;s Guide</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fcosfc.wordpress.com/532/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fcosfc.wordpress.com/532/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fcosfc.wordpress.com&#038;blog=23277319&#038;post=532&#038;subd=fcosfc&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fcosfc.wordpress.com/2013/02/08/weblogic-interoperating-with-oracle-aq-jms-a-tip-for-sending-messages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/246c8ae49665d2d03381f0667408e410?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fcosfc</media:title>
		</media:content>
	</item>
		<item>
		<title>A .NET class library for accessing to the HornetQ REST interface</title>
		<link>http://fcosfc.wordpress.com/2013/02/07/a-net-class-library-for-accessing-to-the-hornetq-rest-interface/</link>
		<comments>http://fcosfc.wordpress.com/2013/02/07/a-net-class-library-for-accessing-to-the-hornetq-rest-interface/#comments</comments>
		<pubDate>Thu, 07 Feb 2013 19:11:59 +0000</pubDate>
		<dc:creator>fcosfc</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[HornetQ]]></category>
		<category><![CDATA[JBoss]]></category>
		<category><![CDATA[Microsoft .NET]]></category>
		<category><![CDATA[Microsoft ASP.net Web API]]></category>
		<category><![CDATA[Microsoft Visual Web Developer Express]]></category>
		<category><![CDATA[NuGet]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Visual Basic .NET]]></category>

		<guid isPermaLink="false">http://fcosfc.wordpress.com/?p=524</guid>
		<description><![CDATA[This is the third article of my series about the HornetQ REST interface, in the first post I wrote about the building and deployment of a customized version of the Web application that implements the interface, in the second post I talked about the development of a Java class library for accessing to the HornetQ REST interface, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fcosfc.wordpress.com&#038;blog=23277319&#038;post=524&#038;subd=fcosfc&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This is the third article of my series about the HornetQ REST interface, in <a title="Researching the HornetQ REST interface" href="http://fcosfc.wordpress.com/2012/11/18/researching-the-hornetq-rest-interface/" target="_blank">the first post</a> I wrote about the building and deployment of a customized version of the Web application that implements the interface, in <a title="A Java class library for accessing to the HornetQ REST interface" href="http://fcosfc.wordpress.com/2012/12/31/a-java-class-library-for-accessing-to-the-hornetq-rest-interface/" target="_blank">the second post</a> I talked about the development of a Java class library for accessing to the HornetQ REST interface, this time I want to develop a .NET API with the same goal.</p>
<p>I was an enthusiastic VB6 programmer long, long time ago. I also participated in some projects that made use of Visual Basic .NET and I even made some things in ASP.NET, but, to be perfectly honest, I&#8217;ve been focused in Java based technologies last years, so I&#8217;ve had to bring myself up to date on .NET!</p>
<p>The first task was to setup a development environment. I decided to use the free tool <a title="Microsoft Visual Web Developer 2010 Express" href="http://www.microsoft.com/visualstudio/eng/products/visual-studio-2010-express" target="_blank">Microsoft Visual Web Developer 2010 Express</a> and I also installed the extension <a title="NuGet Package Manager" href="http://visualstudiogallery.msdn.microsoft.com/27077b70-9dad-4c64-adcf-c7cf6bc9970c" target="_blank">NuGet Package Manager</a>, which made the setup of <a title="Microsoft ASP.NET Web API Client Libraries" href="http://nuget.org/packages/Microsoft.AspNet.WebApi.Client/4.0.20710.0" target="_blank">Microsoft ASP.NET Web API Client Libraries</a> easier. These libraries helped me to access to the HornetQ REST interface, like <a title="RESTEasy" href="http://www.jboss.org/resteasy" target="_blank">RESTEasy</a> helped me in Java. <a title="Calling a Web API From a .NET Client (C#)" href="http://www.asp.net/web-api/overview/web-api-clients/calling-a-web-api-from-a-net-client" target="_blank">This post of Mike Wasson</a> was very useful to get a quick introduction, although he programs in C#!</p>
<p>My idea was to rewrite the library I created in Java using Visual Basic .NET, as simple as that. The first thing I realized is that nowadays both languages have similar capacities, a quick proof, this is the messaging interface in Java:</p>
<pre><code>
public interface MessagingInterface {

    void start() throws MessagingException;

    &lt;T&gt; void sendMessage(T message) throws MessagingException;

    &lt;T&gt; T receiveNextMessage(Class&lt;T&gt; type) throws MessagingException;

    void ackLastMessageReceived() throws MessagingException;

    void stop() throws MessagingException;
}
</code></pre>
<p>And this .NET:</p>
<pre><code>
Public Interface MessagingInterface(Of T)

    Sub ClientStart()

    Sub SendMessage(ByRef Mensaje As T)

    Function ReceiveNextMessage() As T

    Sub AckLastMessageReceived()

    Sub ClientStop()

End Interface
</code></pre>
<p>The HTTP messages to send in each case are determined by the <a title="HornetQ REST Interface user's manual" href="http://docs.jboss.org/hornetq/2.2.5.Final/rest-interface-manual/html_single/" target="_blank">HornetQ REST Interface user&#8217;s manual</a>, so the algorithms are the same in Java and in Visual Basic .NET, I just had to adapt the code to the language and the special features of .NET<br />
Another interesting comparison, this the Java method to send a message:</p>
<pre><code>
@Override
public &lt;T&gt; void sendMessage(T message) throws MessagingException {
    ClientResponse response;

    try {
        if (!this.isStarted) {
            throw new IllegalStateException("The client is not started");
        }

        response = this.msgCreateLink.request().body(MediaType.APPLICATION_XML, message).post();

        if (response.getStatus() == 307) {
            this.msgCreateLink = response.getLocation();

            response = this.msgCreateLink.request().body(MediaType.APPLICATION_XML, message).post();
        }

        if (response.getResponseStatus().equals(Response.Status.CREATED)) {
            this.msgCreateLink = response.getHeaderAsLink("msg-create-next");
        } else {
            throw new MessagingException("Response code  " + response.getStatus() + " not supported");
        }
    } catch (MessagingException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new MessagingException(ex);
    }
}
</code></pre>
<p>And this is the .NET one:</p>
<pre><code>
Public Sub SendMessage(ByRef Message As T) Implements MessagingInterface(Of T).SendMessage
    Dim Response As HttpResponseMessage
    Dim XmlFormatter As XmlMediaTypeFormatter

    Try
        If Not Me.IsStarted Then
            Throw New InvalidOperationException("The client is not started")
        End If

        XmlFormatter = New XmlMediaTypeFormatter
        XmlFormatter.UseXmlSerializer = True

        Response = Me.HornetQHttpClient.PostAsync(Me.MsgCreateUri, 
                                                  Message, 
                                                  XmlFormatter).Result

        If Response.StatusCode = HttpStatusCode.RedirectKeepVerb Then
            Me.MsgCreateUri = Response.Headers.GetValues("Location").First
            Response = Me.HornetQHttpClient.PostAsync(Me.MsgCreateUri, 
                                                      Message, 
                                                      XmlFormatter).Result
        End If

        If Response.StatusCode = HttpStatusCode.Created Then
            Me.MsgCreateUri = Response.Headers.GetValues("msg-create-next").First
        Else
            Throw New MessagingException("Response code " + Response.StatusCode + " not supported")
        End If
    Catch ex As MessagingException
        Throw ex
    Catch ex As Exception
        Throw New MessagingException(ex.Message, ex)
    End Try
End Sub
</code></pre>
<hr />
<p>References</p>
<ul>
<li><a title="HornetQ REST Interface User's Manual" href="http://docs.jboss.org/hornetq/2.2.5.Final/rest-interface-manual/html_single/" target="_blank">HornetQ REST interface user&#8217;s manual</a></li>
<li><a title="HornetQ REST Interface Web Application" href="https://github.com/fcosfc/HornetQRESTInterface" target="_blank">HornetQ REST Interface Web Application</a></li>
<li><a title="Microsoft Visual Web Developer 2010 Express" href="http://www.microsoft.com/visualstudio/eng/products/visual-studio-2010-express" target="_blank">Microsoft Visual Web Developer 2010 Express</a></li>
<li><a title="NuGet Package Manager" href="http://visualstudiogallery.msdn.microsoft.com/27077b70-9dad-4c64-adcf-c7cf6bc9970c" target="_blank">NuGet Package Manager</a></li>
<li><a title="Microsoft ASP.NET Web API Client Libraries" href="http://nuget.org/packages/Microsoft.AspNet.WebApi.Client/4.0.20710.0" target="_blank">Microsoft ASP.NET Web API Client Libraries</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fcosfc.wordpress.com/524/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fcosfc.wordpress.com/524/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fcosfc.wordpress.com&#038;blog=23277319&#038;post=524&#038;subd=fcosfc&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fcosfc.wordpress.com/2013/02/07/a-net-class-library-for-accessing-to-the-hornetq-rest-interface/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/246c8ae49665d2d03381f0667408e410?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fcosfc</media:title>
		</media:content>
	</item>
		<item>
		<title>A Java class library for accessing to the HornetQ REST interface</title>
		<link>http://fcosfc.wordpress.com/2012/12/31/a-java-class-library-for-accessing-to-the-hornetq-rest-interface/</link>
		<comments>http://fcosfc.wordpress.com/2012/12/31/a-java-class-library-for-accessing-to-the-hornetq-rest-interface/#comments</comments>
		<pubDate>Mon, 31 Dec 2012 15:20:34 +0000</pubDate>
		<dc:creator>fcosfc</dc:creator>
				<category><![CDATA[EE]]></category>
		<category><![CDATA[HornetQ]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JBoss]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[NetBeans]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://fcosfc.wordpress.com/?p=480</guid>
		<description><![CDATA[This is the second post of the series about the HornetQ REST interface, which I started to write last month. This time I&#8217;ve developed a Java class library that pretends to simplify the access to the HornetQ REST interface. You may be wondering, why not to use JMS if you&#8217;re programming in Java language? The main [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fcosfc.wordpress.com&#038;blog=23277319&#038;post=480&#038;subd=fcosfc&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This is the second post of the series about the HornetQ REST interface, which I started to write <a title="Researching the HornetQ REST interface" href="http://fcosfc.wordpress.com/2012/11/18/researching-the-hornetq-rest-interface/" target="_blank">last month</a>. This time I&#8217;ve developed a Java class library that pretends to simplify the access to the HornetQ REST interface. You may be wondering, why not to use JMS if you&#8217;re programming in Java language? The main reason is that it&#8217;s difficult to communicate through firewalls using JMS in JBoss 4.2.1, which it&#8217;s a requisite in my case. You might implement HTTP tunnelling, but this could be inefficient and not scalable, so I think that an architecture that mixes JMS and REST may be a good solution when you have to send/receive messages to/from multiple partners. For example, a provider can send you a message through the REST interface and you can consume with JMS, and vice versa.</p>
<p>First of all, I&#8217;d like to point out two additional requisites of my case:</p>
<ul>
<li><span style="line-height:13px;">All messages must be persistent.</span></li>
<li>Messages must not be duplicated.</li>
</ul>
<p>These goals can be achieved by setting up the elements <em>default-durable-send</em> and <em>dups-ok</em> of the <a title="HornetQ REST Interface Web Application" href="https://github.com/fcosfc/HornetQRESTInterface" target="_blank">HornetQ REST Interface Web Application</a> configuration file (<em>rest-config.xml</em>) to the values <em>true</em> and <em>false </em>respectively.</p>
<p>The <a title="HornetQ REST Interface user's manual" href="http://docs.jboss.org/hornetq/2.2.5.Final/rest-interface-manual/html_single/" target="_blank">HornetQ REST Interface user&#8217;s manual</a> define a protocol for sending and receiving messages, where you have to send several HTTP messages, read different HTTP headers, interpret return codes and so on. The idea is to write a class library that hides this complexity and offers a simple interface that allows sending and receiving messages:</p>
<pre><code>
public interface MessagingInterface {

    void start() throws MessagingException;

    &lt;T&gt; void sendMessage(T message) throws MessagingException;

    &lt;T&gt; T receiveNextMessage(Class&lt;T&gt; type) throws MessagingException;

    void ackLastMessageReceived() throws MessagingException;

    void stop() throws MessagingException;
}
</code></pre>
<p>The class <em>HornetQRESTClient</em> implements the former interface. It uses the <a title="RESTEasy" href="http://www.jboss.org/resteasy" target="_blank">RESTEasy</a> supporting library in order to simplify the REST calls and has three main properties:</p>
<ul>
<li><em>serverURL</em>: URL where is deployed the <a title="HornetQ REST Interface Web Application" href="https://github.com/fcosfc/HornetQRESTInterface" target="_blank">HornetQ REST Interface Web Application</a></li>
<li><em>queue</em>: the queue or topic where you want to send messages or receive from.</li>
<li><em>msgSubscriberId</em>: the id of the subscriber for the case of the topics.</li>
</ul>
<p>The <em>start</em> method setup the environment and send an HTTP HEAD request, which returns the headers you need for sending and receiving messages. Here you have an excerpt of the most interesting code:</p>
<pre><code>
    ...
    request = new ClientRequest(this.serverURL + (this.isTopic ? "/topics/" : "/queues/") + this.queue);

    response = request.head();
    if (response.getResponseStatus().equals(Response.Status.OK)) {
        this.msgCreateLink = response.getHeaderAsLink("msg-create");                
        this.msgPullConsumerCreationLink = response.getHeaderAsLink(this.isTopic ? 
                                                                        "msg-pull-subscriptions" : 
                                                                        "msg-pull-consumers");
    } else if (response.getResponseStatus().equals(Response.Status.NOT_FOUND)) {
        throw new MessagingException("The queue " + queue + " is not registered");
    } else {
        throw new MessagingException("Response code  " + response.getStatus() + " not supported");
    }
    ...
</code></pre>
<p>The method <em>sendMessage</em> allows you to send a message encapsulated on an object susceptible to be marshalled with JAXB:</p>
<pre><code>
@Override
public &lt;T&gt; void sendMessage(T message) throws MessagingException {
    ClientResponse response;

    try {
        if (!this.isStarted) {
            throw new IllegalStateException("The client is not started");
        }

        response = this.msgCreateLink.request().body(MediaType.APPLICATION_XML, message).post();

        if (response.getStatus() == 307) {
            this.msgCreateLink = response.getLocation();

            response = this.msgCreateLink.request().body(MediaType.APPLICATION_XML, message).post();
        }

        if (response.getResponseStatus().equals(Response.Status.CREATED)) {
            this.msgCreateLink = response.getHeaderAsLink("msg-create-next");
        } else {
            throw new MessagingException("Response code  " + response.getStatus() + " not supported");
        }
    } catch (MessagingException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new MessagingException(ex);
    }
}
</code></pre>
<p>On the other hand, I&#8217;ve decided to implement the manual acknowledgement method for receiving messages via pull, so I&#8217;m continuously polling the server to see if messages are available by calling the method <em>receiveNextMessage</em> and I call the method <em>ackLastMessageReceived</em>, once I&#8217;ve processed a received message.  I&#8217;ll analyse consuming messages via push in a forthcoming post. Here you have the code of both methods:</p>
<pre><code>
@Override
public &lt;T&gt; T receiveNextMessage(Class&lt;T&gt; type) throws MessagingException {
    T message = null;
    ClientResponse response;

    try {
        if (!this.isStarted) {
            throw new IllegalStateException("The client is not started");
        }

        if (this.msgAcknowledgementLink != null) {
            throw new IllegalStateException("There is a message waiting for acknowledgement");
        }

        // Creates the consumer, if needed
        if (this.msgPullConsumerLink == null) {
            if (this.isTopic) {
                response = this.msgPullConsumerCreationLink.request()
                        .formParameter("autoAck", "false")
                        .formParameter("durable", "true")
                        .formParameter("name", this.msgSubscriberId)
                        .post();
            } else {
                response = this.msgPullConsumerCreationLink.request().formParameter("autoAck",
                                                                                    "false").post();
            }

            if (response.getResponseStatus().equals(Response.Status.CREATED)) {
                this.msgPullConsumerLink = response.getLocation();                    
                this.nextMsgLink = response.getHeaderAsLink("msg-acknowledge-next");
            } else if (response.getResponseStatus().equals(Response.Status.NO_CONTENT)) {
                this.nextMsgLink = response.getHeaderAsLink("msg-acknowledge-next");              
            } else {
                throw new MessagingException("Response code  " + response.getStatus() + " not supported");
            }
        }

        response = this.nextMsgLink.request()
                .header("Accept-Wait", SECONDS_WAITING)
                .header("Accept", MediaType.APPLICATION_XML)
                .post();

        if (response.getResponseStatus().equals(Response.Status.OK)) {
            message = (T) response.getEntity(type);
            this.msgAcknowledgementLink = response.getHeaderAsLink("msg-acknowledgement");
        } else if (response.getResponseStatus().equals(Response.Status.SERVICE_UNAVAILABLE)) {
            this.nextMsgLink = response.getHeaderAsLink("msg-acknowledge-next");
        } else if (response.getResponseStatus().equals(Response.Status.PRECONDITION_FAILED)) {
            this.nextMsgLink = response.getHeaderAsLink("msg-acknowledge-next");
        } else {
            throw new MessagingException("Response code  " + response.getStatus() + " not supported");
        }
    } catch (MessagingException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new MessagingException(ex);
    }

    return message;
}

@Override
public void ackLastMessageReceived() throws MessagingException {
    ClientResponse response;

    try {
        if (!this.isStarted) {
            throw new IllegalStateException("The client is not started");
        }

        if (this.msgAcknowledgementLink == null) {
            throw new MessagingException("No messages waiting for acknowledgement");
        }

        response = this.msgAcknowledgementLink.request().formParameter("acknowledge", "true").post();

        if (response.getResponseStatus().equals(Response.Status.NO_CONTENT)) {
            this.nextMsgLink = response.getHeaderAsLink("msg-acknowledge-next");                
            this.msgAcknowledgementLink = null;
        } else {
            throw new MessagingException("Response code  " + response.getStatus() + " not supported");
        }
    } catch (MessagingException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new MessagingException(ex);
    }
}
</code></pre>
<p>The method <em>stop</em> cleans up the consumer created for consuming messages just in the case of queues. I&#8217;ve decided not to do it for topics, because I need durable subscriptions and I&#8217;ve realized through testing that if you delete the consumer, the subscription is deleted too, and the manual says:</p>
<p><em>&#8220;&#8230;A consumer timeout for durable subscriptions will not delete the underlying durable JMS subscription though, only the server-side consumer resource (and underlying JMS session)&#8230;&#8221;</em></p>
<p>So, I just wait for the timeout. Here you have the code:</p>
<pre><code>
@Override
public void stop() throws MessagingException {
    ClientResponse response;

    try {
        if (!this.isStarted) {
            throw new IllegalStateException("The client is not started");
        }

        if (this.msgPullConsumerLink != null &amp;&amp; (!this.isTopic)) {
            response = this.msgPullConsumerLink.request().delete();

            if (!response.getResponseStatus().equals(Response.Status.NO_CONTENT)) {
                throw new MessagingException("Response code  " + response.getStatus() + " not supported");
            }
        }

        this.isStarted = false;
        this.initLinks();
    } catch (MessagingException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new MessagingException(ex);
    }
}
</code></pre>
<p>Finally, I&#8217;d like to show the code of a simple unit test:</p>
<pre><code>
@Test
public void queueTest() throws MessagingException {
    MessagingInterface messaging;
    Order orderToSend, orderReceived;

    messaging = RESTMessagingClientFactory.getHornetQRESTClient(SERVER_URL, QUEUE);

    messaging.start();

    // Purge the queue
    while((orderReceived = messaging.receiveNextMessage(Order.class)) != null) {
        messaging.ackLastMessageReceived();
    }

    orderToSend = new Order("Test item", 5, 10.2f);        
    messaging.sendMessage(orderToSend);

    orderReceived = messaging.receiveNextMessage(Order.class);        
    messaging.ackLastMessageReceived();

    messaging.stop();

    assertNotNull(orderReceived);
    assertEquals(orderToSend, orderReceived);                
}
</code></pre>
<p>In order to run the test, I had to deploy the following queue and topic by adding this configuration to my hornetq-jms.xml file:</p>
<pre><code>
   &lt;queue name="orders"&gt;
      &lt;entry name="/queues/orders"/&gt;
   &lt;/queue&gt;
   &lt;topic name="orders"&gt;
      &lt;entry name="/topics/orders"/&gt;
   &lt;/topic&gt;
</code></pre>
<hr />
<p>References</p>
<ul>
<li><a title="HornetQ REST Interface User's Manual" href="http://docs.jboss.org/hornetq/2.2.5.Final/rest-interface-manual/html_single/" target="_blank">HornetQ REST interface user&#8217;s manual</a></li>
<li><a title="HornetQ REST Interface Web Application" href="https://github.com/fcosfc/HornetQRESTInterface" target="_blank">HornetQ REST Interface Web Application</a></li>
<li><a title="RESTEasy" href="http://www.jboss.org/resteasy" target="_blank">RESTEasy</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fcosfc.wordpress.com/480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fcosfc.wordpress.com/480/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fcosfc.wordpress.com&#038;blog=23277319&#038;post=480&#038;subd=fcosfc&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fcosfc.wordpress.com/2012/12/31/a-java-class-library-for-accessing-to-the-hornetq-rest-interface/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/246c8ae49665d2d03381f0667408e410?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fcosfc</media:title>
		</media:content>
	</item>
		<item>
		<title>Researching the HornetQ REST interface</title>
		<link>http://fcosfc.wordpress.com/2012/11/18/researching-the-hornetq-rest-interface/</link>
		<comments>http://fcosfc.wordpress.com/2012/11/18/researching-the-hornetq-rest-interface/#comments</comments>
		<pubDate>Sun, 18 Nov 2012 19:11:56 +0000</pubDate>
		<dc:creator>fcosfc</dc:creator>
				<category><![CDATA[EE]]></category>
		<category><![CDATA[HornetQ]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JBoss]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[JMS]]></category>
		<category><![CDATA[NetBeans]]></category>

		<guid isPermaLink="false">http://fcosfc.wordpress.com/?p=455</guid>
		<description><![CDATA[I&#8217;ve been studying the HornetQ REST interface during the last weeks, because I consider it&#8217;s a very good solution if you have an application that uses JMS and you want to integrate messages from a third party that doesn&#8217;t use Java language. This is the first post of the ones I&#8217;ve decided to write about [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fcosfc.wordpress.com&#038;blog=23277319&#038;post=455&#038;subd=fcosfc&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been studying the HornetQ REST interface during the last weeks, because I consider it&#8217;s a very good solution if you have an application that uses JMS and you want to integrate messages from a third party that doesn&#8217;t use Java language. This is the first post of the ones I&#8217;ve decided to write about this issue and, in this case, the first task is to configure and install the interface.</p>
<p>As usual, it&#8217;s important to review the user&#8217;s manual of the technology, this time the <a title="HornetQ REST Interface user's manual" href="http://docs.jboss.org/hornetq/2.2.5.Final/rest-interface-manual/html_single/" target="_blank">HornetQ REST interface</a> one.  One important restriction in my case was that I had to use the version 4.2.1 GA of the JBoss Application Server, with HornetQ 2.2.5 as its messaging provider. Therefore, <a title="HornetQ user's manual. Installing Within Pre-configured Environment" href="http://docs.jboss.org/hornetq/2.2.5.Final/rest-interface-manual/html_single/#d0e57" target="_blank">the pom.xml file proposed by the manual</a> had to be changed, in order to add the dependency on the RESTEasy libraries and the 1.5 Java version for both the source and target code:</p>
<pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;

  &lt;groupId&gt;com.wordpress.fcosfc.hornetq&lt;/groupId&gt;
  &lt;artifactId&gt;HornetQRESTInterface&lt;/artifactId&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  &lt;version&gt;1.0&lt;/version&gt;
  &lt;name&gt;HornetQRESTInterface&lt;/name&gt;
  &lt;repositories&gt;
    &lt;repository&gt;
      &lt;id&gt;jboss&lt;/id&gt;
      &lt;url&gt;http://repository.jboss.org/nexus/content/groups/public/&lt;/url&gt;
    &lt;/repository&gt;
  &lt;/repositories&gt;

  &lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.hornetq.rest&lt;/groupId&gt;
      &lt;artifactId&gt;hornetq-rest&lt;/artifactId&gt;
      &lt;version&gt;2.2.2.Final&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
      &lt;artifactId&gt;resteasy-jaxrs&lt;/artifactId&gt;
      &lt;version&gt;2.2.2.GA&lt;/version&gt;
      &lt;exclusions&gt;
        &lt;exclusion&gt;
          &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
          &lt;groupId&gt;commons-logging&lt;/groupId&gt;
        &lt;/exclusion&gt;
      &lt;/exclusions&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
      &lt;artifactId&gt;resteasy-jaxb-provider&lt;/artifactId&gt;
      &lt;version&gt;2.2.2.GA&lt;/version&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;

  &lt;build&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.0.2&lt;/version&gt;
        &lt;configuration&gt;
          &lt;source&gt;1.5&lt;/source&gt;
          &lt;target&gt;1.5&lt;/target&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;
&lt;/project&gt;
</code></pre>
<p>Here you have a <a title="HornetQ REST Interface Web Application" href="https://github.com/fcosfc/HornetQRESTInterface" target="_blank">link</a> to my <a title="Apache Maven" href="http://maven.apache.org/" target="_blank">Maven</a> project, I hope it will be useful for you.</p>
<hr />
<p>References</p>
<ul>
<li><a title="HornetQ REST Interface User's Manual" href="http://docs.jboss.org/hornetq/2.2.5.Final/rest-interface-manual/html_single/" target="_blank">HornetQ REST interface user&#8217;s manual</a></li>
<li><a title="Apache Maven Project" href="http://maven.apache.org/" target="_blank">Apache Maven Project</a></li>
<li><a title="HornetQ REST Interface Web Application" href="https://github.com/fcosfc/HornetQRESTInterface" target="_blank">HornetQ REST Interface Web Application</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fcosfc.wordpress.com/455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fcosfc.wordpress.com/455/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fcosfc.wordpress.com&#038;blog=23277319&#038;post=455&#038;subd=fcosfc&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fcosfc.wordpress.com/2012/11/18/researching-the-hornetq-rest-interface/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/246c8ae49665d2d03381f0667408e410?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fcosfc</media:title>
		</media:content>
	</item>
		<item>
		<title>Fighting with sockets!</title>
		<link>http://fcosfc.wordpress.com/2012/08/23/fighting-with-sockets/</link>
		<comments>http://fcosfc.wordpress.com/2012/08/23/fighting-with-sockets/#comments</comments>
		<pubDate>Thu, 23 Aug 2012 20:00:49 +0000</pubDate>
		<dc:creator>fcosfc</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[SE]]></category>
		<category><![CDATA[Debug]]></category>
		<category><![CDATA[Java SE]]></category>
		<category><![CDATA[JDeveloper]]></category>
		<category><![CDATA[Microsoft .NET]]></category>
		<category><![CDATA[Oracle Database]]></category>
		<category><![CDATA[Sockets]]></category>

		<guid isPermaLink="false">http://fcosfc.wordpress.com/?p=433</guid>
		<description><![CDATA[Last week, I was appointed to develop a Java program that should connect to an external secure socket, in order to get data provided by a partner company. Another requisite was that the module should be stored on an Oracle 11g Database, so I must use a 1.5 JDK. Easy, I thought! First of all, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fcosfc.wordpress.com&#038;blog=23277319&#038;post=433&#038;subd=fcosfc&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Last week, I was appointed to develop a Java program that should connect to an external secure socket, in order to get data provided by a partner company. Another requisite was that the module should be stored on an Oracle 11g Database, so I must use a 1.5 JDK. Easy, I thought!</p>
<p>First of all, I review <a title="Java Secure Socket Extension (JSSE) Reference Guide" href="http://docs.oracle.com/javase/1.5.0/docs/guide/security/jsse/JSSERefGuide.html" target="_blank">Java Secure Socket Extension (JSSE) Reference Guide</a>. Our company partner IT team provided me with the key store containing the certificate I should trust and I decide to program a custom SSL context:</p>
<pre>   ...
   KeyStore keyStoreTrust = KeyStore.getInstance("PKCS12");
   keyStoreTrust.load(this.getClass().getResourceAsStream("KeyStoreTrust.pfx"),
                      "password".toCharArray());
   TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("PKIX");
   trustManagerFactory.init(keyStoreTrust);

   SSLContext sslContext = SSLContext.getInstance("SSL");
   sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
   ...</pre>
<p>The first problem arose when the server socket (developed in Microsoft .NET C#) unexpectedly closed the connection during the handshake, the support guy of my partner company said me that they got the following error message: “The client and server cannot communicate, because they do not possess a common algorithm”. Therefore, I delved into the problem and finally I realized that the server wanted to use a TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA cipher suite, which wasn&#8217;t supported by the security providers shipped with the JDK 1.5 I&#8217;d like to point out that a key point to find out the source of the error was to activate the debug of the SSL connection:</p>
<pre>System.setProperty("javax.net.debug", "ssl");</pre>
<p>Hence, I decided to add to my program the well-known <a title="http://www.bouncycastle.org/java.html" href="Bouncy Castle security provider" target="_blank">Bouncy Castle security provider,</a> which supports the required cipher suite and it&#8217;s 1.5 compliant:</p>
<pre>Security.addProvider(new BouncyCastleProvider());</pre>
<p>Once I sorted out the problem, everything started to work properly, at least as an stand-alone client! So, I created a &#8220;Loadjava and Java Stored Procedures&#8221; profile in my JDeveloper IDE, in order to deploy the software to the Oracle Database 11.2, but when I tried to do it I got the following errors:</p>
<pre>Invoking loadjava on connection 'Test11g_Paco' with arguments:
 -order -resolve -definer -thin -resolver ((* TEST) (* PUBLIC) (* -)) -synonym
 errors   : class org/bouncycastle/jcajce/provider/asymmetric/ec/BCECPrivateKey
 ORA-29552: verification warning: java.lang.NoClassDefFoundError: java/security/interfaces/ECPrivateKey

 errors   : class org/bouncycastle/jcajce/provider/asymmetric/ec/BCECPublicKey
 ORA-29552: verification warning: java.lang.NoClassDefFoundError: java/security/interfaces/ECPublicKey

 errors   : class org/bouncycastle/jcajce/provider/asymmetric/ecgost/BCECGOST3410PrivateKey
 ORA-29552: verification warning: java.lang.NoClassDefFoundError: java/security/interfaces/ECPrivateKey

 errors   : class org/bouncycastle/jcajce/provider/asymmetric/ecgost/BCECGOST3410PublicKey
 ORA-29552: verification warning: java.lang.NoClassDefFoundError: java/security/interfaces/ECPublicKey

 errors   : class org/bouncycastle/jce/provider/JCEECPrivateKey
 ORA-29552: verification warning: java.lang.NoClassDefFoundError: java/security/interfaces/ECPrivateKey

 errors   : class org/bouncycastle/jce/provider/JCEECPublicKey
 ORA-29552: verification warning: java.lang.NoClassDefFoundError: java/security/interfaces/ECPublicKey

 Loadjava finished.</pre>
<p>I can&#8217;t understand the problem because the interfaces java.security.interfaces.ECPublicKey and java.security.interfaces.ECPrivateKey are available in 1.5 and the Oracle Database 11.2 JVM is supposed to be 1.5 compliant, but I couldn&#8217;t find any satisfactory solution.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fcosfc.wordpress.com/433/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fcosfc.wordpress.com/433/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fcosfc.wordpress.com&#038;blog=23277319&#038;post=433&#038;subd=fcosfc&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fcosfc.wordpress.com/2012/08/23/fighting-with-sockets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/246c8ae49665d2d03381f0667408e410?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fcosfc</media:title>
		</media:content>
	</item>
		<item>
		<title>Trying to set up a JMS bridge between HornetQ and Oracle AQ</title>
		<link>http://fcosfc.wordpress.com/2012/07/08/trying-to-set-up-a-jms-bridge-between-hornetq-and-oracle-aq/</link>
		<comments>http://fcosfc.wordpress.com/2012/07/08/trying-to-set-up-a-jms-bridge-between-hornetq-and-oracle-aq/#comments</comments>
		<pubDate>Sun, 08 Jul 2012 09:27:21 +0000</pubDate>
		<dc:creator>fcosfc</dc:creator>
				<category><![CDATA[Advanced Queuing]]></category>
		<category><![CDATA[EE]]></category>
		<category><![CDATA[HornetQ]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JBoss]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Weblogic]]></category>
		<category><![CDATA[AQ]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[JMS]]></category>

		<guid isPermaLink="false">http://fcosfc.wordpress.com/?p=404</guid>
		<description><![CDATA[I&#8217;ve been interested in setting up a JMS bridge between HornetQ and Oracle Advanced Queuing (AQ) for a while, even I wrote about this issue in a response to a question of the HornetQ user&#8217;s forum. I resume the matter in this post with some improvements, although, to be perfectly honest, I am not happy with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fcosfc.wordpress.com&#038;blog=23277319&#038;post=404&#038;subd=fcosfc&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been interested in setting up a JMS bridge between HornetQ and Oracle Advanced Queuing (AQ) for a while, even I wrote about this issue in a <a title="Connect to Oracle AQ" href="https://community.jboss.org/message/645184?tstart=0#645184" target="_blank">response to a question of the HornetQ user&#8217;s forum</a>. I resume the matter in this post with some improvements, although, to be perfectly honest, I am not happy with the configuration.</p>
<p>In theory, the bridge is possible because both systems are JMS 1.1. compliant. If you use a HornetQ 2.2.5 standalone installation, you simply have to add some managed beans to the hornetq-beans.xml file, as is described in the <a title="HornetQ user manual. The JMS bridge" href="http://docs.jboss.org/hornetq/2.2.5.Final/user-manual/en/html_single/index.html#jms-bridge" target="_blank">user manual</a>. The key point here is to use <a title="Configure Foreign Server Connection Factories" href="http://docs.oracle.com/cd/E14571_01/web.1111/e13738/aq_jms.htm#CJAFEJCB" target="_blank">the proper connection factory</a> and set up the destination following <a title="Configure AQ JMS Foreign Server destinations" href="http://docs.oracle.com/cd/E14571_01/web.1111/e13738/aq_jms.htm#CJABAGCH" target="_blank">the rules of the Weblogic manual</a>: <a title="Interoperating with Oracle AQ JMS" href="http://docs.oracle.com/cd/E14571_01/web.1111/e13738/aq_jms.htm" target="_blank">&#8220;Interoperating with Oracle AQ JMS&#8221;</a>. Here you have an excerpt of the hornetq-beans.xml file:</p>
<pre>&lt;bean name="JMSBridge"&gt;
  &lt;constructor&gt;
  ...
    &lt;!-- concatenate JMS messageID to the target's message header --&gt;
    &lt;parameter&gt;true&lt;/parameter&gt;
  ...
&lt;/bean&gt;
...
&lt;!-- TargetCFF describes the ConnectionFactory used to connect to the target destination --&gt;
&lt;bean name="TargetCFF"&gt;
  &lt;constructor&gt;
    &lt;parameter&gt;
      &lt;inject bean="TargetJNDI" /&gt;
    &lt;/parameter&gt;
    &lt;parameter&gt;<strong>QueueConnectionFactory</strong>&lt;/parameter&gt;
  &lt;/constructor&gt;
&lt;/bean&gt;
...
&lt;!-- TargetDestinationFactory describes the Destination used as the target --&gt;
&lt;bean name="TargetDestinationFactory"&gt;
  &lt;constructor&gt;
    &lt;parameter&gt;
      &lt;inject bean="TargetJNDI" /&gt;
    &lt;/parameter&gt;
    &lt;parameter&gt;<strong>Queues/testQueue</strong>&lt;/parameter&gt;
  &lt;/constructor&gt;
&lt;/bean&gt;
...
&lt;!-- JNDI is a Hashtable containing the JNDI properties required --&gt;
&lt;!-- to connect to the *target* JMS resources                    --&gt;
&lt;bean name="TargetJNDI"&gt;
  &lt;constructor&gt;
    &lt;map keyClass="java.lang.String" valueClass="java.lang.String"&gt;
      &lt;entry&gt;
        &lt;key&gt;java.naming.factory.initial&lt;/key&gt;
        &lt;value&gt;<strong>oracle.jms.AQjmsInitialContextFactory</strong>&lt;/value&gt;
      &lt;/entry&gt;
      &lt;entry&gt;
        &lt;key&gt;<strong>db_url</strong>&lt;/key&gt;
        &lt;value&gt;jdbc:oracle:thin:@oraclehost:1521:test&lt;/value&gt;
      &lt;/entry&gt;
      &lt;entry&gt;
        &lt;key&gt;<strong>java.naming.security.principal</strong>&lt;/key&gt;
        &lt;value&gt;test&lt;/value&gt;
      &lt;/entry&gt;
      &lt;entry&gt;
        &lt;key&gt;<strong>java.naming.security.credentials</strong>&lt;/key&gt;
        &lt;value&gt;secret&lt;/value&gt;
      &lt;/entry&gt;
    &lt;/map&gt;
  &lt;/constructor&gt;
&lt;/bean&gt;</pre>
<p>The former configuration runs properly with the <em>DUPLICATES_OK</em> quality of service, but when you moves to a <em>ONCE_AND_ONLY_ONCE</em> one, changing the <em>TargetCFF</em> to <em>XAQueueConnectionFactory</em>, you get a <em>NullPointerException</em>:</p>
<pre>  oracle.jms.AQjmsException: Error creating the db_connection
    at oracle.jms.AQjmsDBConnMgr.getConnection
    at oracle.jms.AQjmsDBConnMgr.
    at oracle.jms.AQjmsXAConnection.
    at oracle.jms.AQjmsXAQueueConnectionFactory.createAllXAConnection
    at oracle.jms.AQjmsXAQueueConnectionFactory.createXAQueueConnection</pre>
<p>After a research on Oracle Support notes, I found that the Oracle API has a bug (10102373) that it will be fixed on the future release 12.1 There are workarounds for not receiving duplicate messages, for example: to save the <em>JMS Message ID</em> in a Oracle table and implement a unique index on that column, you have to take into account that the<em> JMS Messege ID</em> sent by HornetQ is a property that can be recovered with the method <em>get_string_property</em> of the Oracle type <em>aq$_jms_messag</em>e.</p>
<p>But, why Weblogic can interoperate with Oracle AQ in XA configurations? I suspect that the reason is because uses datasources with pre-created database connections. So, I&#8217;ve tried to deploy the bridge within JBoss AS 6.0.0, with HornetQ as its default JMS provider. First of all, I created an Oracle XA datasource. After that, I set up the configuration file jms-bridge-jboss-beans.xml in a similar way as before, the only change is to change the <em>db_url</em> parameter by the parameter <em>datasource</em>:</p>
<pre>&lt;bean name="TargetJNDI"&gt;
  &lt;constructor&gt;
    &lt;map keyClass="java.lang.String" valueClass="java.lang.String"&gt;
      &lt;entry&gt;
        &lt;key&gt;java.naming.factory.initial&lt;/key&gt;
        &lt;value&gt;<strong>oracle.jms.AQjmsInitialContextFactory</strong>&lt;/value&gt;
      &lt;/entry&gt;
      &lt;entry&gt;
        &lt;key&gt;<strong>datasource</strong>&lt;/key&gt;
        &lt;value&gt;jdbc/testOracleXA&lt;/value&gt;
      &lt;/entry&gt;
    &lt;/map&gt;
  &lt;/constructor&gt;
&lt;/bean&gt;</pre>
<p>But, when I tried to run the former configuration, the bridge didn&#8217;t start. Another <a title="JMS Bridge FailureStartupHandler" href="https://issues.jboss.org/browse/HORNETQ-496" target="_blank">bug</a>, a HornetQ one in this case, prevented me from reaching my goal. To be perfectly honest, I didn&#8217;t patch the installation, but I restart the managed bean through the JMX console and I got another exception, a <em>ClassCastException</em>, because JBoss pass a wrapped Oracle connection to the class <em>AQjmsInitialContextFactory</em>, which is waiting for an native internal connection. I really felt powerless!</p>
<p>Finally, I adopted the solution of setting up an Oracle Weblogic server as a mediator,  the guru Edwin Biemond describes this configuration in this <a title="WebLogic JMS / AQ bridge with JBoss AS 7" href="http://biemond.blogspot.com.es/2012/06/weblogic-jms-aq-bridge-with-jboss-as-7.html" target="_blank">article</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fcosfc.wordpress.com/404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fcosfc.wordpress.com/404/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fcosfc.wordpress.com&#038;blog=23277319&#038;post=404&#038;subd=fcosfc&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fcosfc.wordpress.com/2012/07/08/trying-to-set-up-a-jms-bridge-between-hornetq-and-oracle-aq/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/246c8ae49665d2d03381f0667408e410?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fcosfc</media:title>
		</media:content>
	</item>
		<item>
		<title>JasperServer: workarounds for small problems</title>
		<link>http://fcosfc.wordpress.com/2012/05/24/jasperserver-workarounds-for-small-problems/</link>
		<comments>http://fcosfc.wordpress.com/2012/05/24/jasperserver-workarounds-for-small-problems/#comments</comments>
		<pubDate>Thu, 24 May 2012 19:57:50 +0000</pubDate>
		<dc:creator>fcosfc</dc:creator>
				<category><![CDATA[JasperReports]]></category>
		<category><![CDATA[iReport]]></category>
		<category><![CDATA[JasperServer]]></category>

		<guid isPermaLink="false">http://fcosfc.wordpress.com/?p=366</guid>
		<description><![CDATA[I wrote about the integration between JasperServer and Microsoft Active Directory last October. One of the readers of the post, Andrés Arenas, drew my attention to a problem: if an person input its user name one time in lowercases, another in uppercases, Jasper Reports Server creates two users in its repository. Here you have an [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fcosfc.wordpress.com&#038;blog=23277319&#038;post=366&#038;subd=fcosfc&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I wrote about the <a title="JasperServer user authentication with Microsoft Active Directory" href="http://fcosfc.wordpress.com/2011/10/31/jasperserver-user-authentication-with-microsoft-active-directory/" target="_blank">integration between JasperServer and Microsoft Active Directory</a> last October. One of the readers of the post, <a title="Andrés Arenas' personal website" href="http://www.arenasa.com" target="_blank">Andrés Arenas</a>, drew my attention to a problem: if an person input its user name one time in lowercases, another in uppercases, Jasper Reports Server creates two users in its repository. Here you have an excerpt of a screenshot that shows the problem clearly:</p>
<p style="text-align:center;"><a href="http://fcosfc.files.wordpress.com/2012/05/jasperserverscreenshotduplicatedusers1.jpg" target="_blank"><img class="aligncenter size-full wp-image-372" title="JasperServer Screenshot" src="http://fcosfc.files.wordpress.com/2012/05/jasperserverscreenshotduplicatedusers1.jpg?w=590&#038;h=222" alt="JasperServer Screenshot" width="590" height="222" /></a></p>
<p>Fortunately, if you follow the best practice of assigning permissions to the Active Directory groups imported, you won&#8217;t have problems. I&#8217;m sure that the solution to this issue would be to patch the source code that imports the users, but for a systems administrator this isn&#8217;t practical. A quick way to avoid this problem is to edit the file $JASPERSERVER_HOME/apache-tomcat/webapps/jasperserver/WEB-INF/jsp/templates/login.jsp and change the line:</p>
<pre><code>  &lt;input id="j_username" name="j_username" type="text"/&gt;</code></pre>
<p>for</p>
<pre><code>  &lt;input id="j_username" name="j_username" type="text" 
    style="text-transform:lowercase;" onkeyup="javascript:this.value=this.value.toLowerCase();"/&gt;</code></pre>
<p>On the other hand, I recently had to design a report for a tracking system where each user just could see its own data, not those saved by others. Therefore, the SQL statement must include the user name within the WHERE clause. My first option was to create a parameter named LoggedInUser of the class com.jaspersoft.jasperserver.api.metadata.user.domain.User and put this clause:</p>
<pre><code> where username = $P{LoggedInUser}.getFullName()</code></pre>
<p>But I got the following exception:</p>
<pre><code>  com.jaspersoft.jasperserver.api.JSExceptionWrapper: Report design not valid : 
    1. Parameter type not supported in query : LoggedInUser class 
    com.jaspersoft.jasperserver.api.metadata.user.domain.User</code></pre>
<p>A workaround to this problem is to create another string parameter, LoggedInUserName, and assign the expression $P{LoggedInUser}.getFullName() as its default value.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fcosfc.wordpress.com/366/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fcosfc.wordpress.com/366/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fcosfc.wordpress.com&#038;blog=23277319&#038;post=366&#038;subd=fcosfc&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fcosfc.wordpress.com/2012/05/24/jasperserver-workarounds-for-small-problems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/246c8ae49665d2d03381f0667408e410?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fcosfc</media:title>
		</media:content>

		<media:content url="http://fcosfc.files.wordpress.com/2012/05/jasperserverscreenshotduplicatedusers1.jpg" medium="image">
			<media:title type="html">JasperServer Screenshot</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL statement to get the weeks before the current date</title>
		<link>http://fcosfc.wordpress.com/2012/04/28/sql-statement-to-get-the-weeks-before-the-current-day/</link>
		<comments>http://fcosfc.wordpress.com/2012/04/28/sql-statement-to-get-the-weeks-before-the-current-day/#comments</comments>
		<pubDate>Sat, 28 Apr 2012 19:08:49 +0000</pubDate>
		<dc:creator>fcosfc</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Oracle Database]]></category>

		<guid isPermaLink="false">http://fcosfc.wordpress.com/?p=352</guid>
		<description><![CDATA[I recently had to design a report to analyze the data of a week, so the user had to select that week using an input control. The data source of the combo box was the following SQL statement that runs in an Oracle Database: select to_char(next_day(trunc(sysdate, 'DAY'), 'SATURDAY') - (level * 7) - 6, 'mm/dd/yyyy') [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fcosfc.wordpress.com&#038;blog=23277319&#038;post=352&#038;subd=fcosfc&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I recently had to design a report to analyze the data of a week, so the user had to select that week using an input control. The data source of the combo box was the following SQL statement that runs in an Oracle Database:</p>
<pre>select to_char(next_day(trunc(sysdate, 'DAY'), 'SATURDAY') - (level * 7) - 6, 
                    'mm/dd/yyyy')
  || ' - '
  || to_char(next_day(trunc(sysdate, 'DAY'), 'SATURDAY') - (level * 7), 
             'mm/dd/yyyy') week
from dual
  connect by level &lt;= 52
order by level</pre>
<p>This code employs the hierarchical query clause CONNECT BY to select the initial and the final day of the weeks before the current date, a period of a year more or less.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fcosfc.wordpress.com/352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fcosfc.wordpress.com/352/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fcosfc.wordpress.com&#038;blog=23277319&#038;post=352&#038;subd=fcosfc&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fcosfc.wordpress.com/2012/04/28/sql-statement-to-get-the-weeks-before-the-current-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/246c8ae49665d2d03381f0667408e410?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fcosfc</media:title>
		</media:content>
	</item>
		<item>
		<title>Security notes about Hornetq as a JBoss JMS provider</title>
		<link>http://fcosfc.wordpress.com/2012/03/12/security-notes-about-hornetq-as-a-jboss-jms-provider/</link>
		<comments>http://fcosfc.wordpress.com/2012/03/12/security-notes-about-hornetq-as-a-jboss-jms-provider/#comments</comments>
		<pubDate>Mon, 12 Mar 2012 19:19:53 +0000</pubDate>
		<dc:creator>fcosfc</dc:creator>
				<category><![CDATA[EE]]></category>
		<category><![CDATA[HornetQ]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JBoss]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Weblogic]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[JMS]]></category>

		<guid isPermaLink="false">http://fcosfc.wordpress.com/?p=313</guid>
		<description><![CDATA[I&#8217;ve been recently involved in a project where my client had to share information with some partners, using HornetQ 2.2.5 queues deployed on a JBoss 4.2.1 GA application server, and I had to face up to a security problem. Here you have the case: the first step that a remote client has to perform when [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fcosfc.wordpress.com&#038;blog=23277319&#038;post=313&#038;subd=fcosfc&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been recently involved in a project where my client had to share information with some partners, using HornetQ 2.2.5 queues deployed on a JBoss 4.2.1 GA application server, and I had to face up to a security problem. Here you have the case: the first step that a remote client has to perform when it tries to send a message to a queue is to lookup for a connection factory and the queue in a JNDI tree; at this point, you should not simply open your JBoss JNDI port (1099 by default), even having configured your firewall to open the port just to your partners&#8217; servers and having an user authentication process for JNDI, because they might list all the names of your global JNDI namespace and exploit any security bug you may have. On the other hand, although I would have opened the port, our JBoss application server runs into a demilitarized zone (DMZ) with a NAT (Network Address Translation) standard configuration, <a title="OTN forum entry where Esmond Pitt says that RMI can't be used within a NAT configuration" href="https://forums.oracle.com/forums/thread.jspa?messageID=9960861" target="_blank">in this situation you can&#8217;t use RMI</a>.</p>
<p>The solution to my problem was to force the partners to <a title="Accessing JNDI over HTTP" href="http://docs.jboss.org/jbossas/docs/Server_Configuration_Guide/4/html/JNDI_over_HTTP-Accessing_JNDI_over_HTTP.html" target="_blank">access JNDI over HTTP</a> an secure that access in a manner that they  just could perform lookup operations over a controlled <a title="Securing Access to JNDI with a Read-Only Unsecured Context" href="http://docs.jboss.org/jbossas/docs/Server_Configuration_Guide/4/html/JNDI_over_HTTP-Securing_Access_to_JNDI_with_a_Read_Only_Unsecured_Context.html" target="_blank">read-only context</a>, so they got their connection factories and queues from that context and, later on, opened their JMS sessions, through a HTTPS tunnel, after an user authentication process.</p>
<p>In order to run a basic test case,  the first step is to create a role for the remote users (named remoteRole in this example) and another for local ones (localRole) on JBoss. On the other hand, I created one key store for the SSL connection:</p>
<pre>keytool -genkeypair -alias test -keyalg RSA -keysize 1024 -dname OU=TEST,CN=TEST,CN=LOCAL
        -keypass test1234 -keystore hornetq.test.keystore -storepass test1234</pre>
<p>The following task is to deploy the <a title="HornetQ User's manual: Configuring Netty Servlet" href="http://docs.jboss.org/hornetq/2.2.5.Final/user-manual/en/html/configuring-transports.html#d0e3531" target="_blank">netty servlet</a> that provide the HTTP transport, please follow <a title="HornetQServlet WAR file" href="https://docs.google.com/open?id=0BxIsXB00A5yPVkVaTTVmMkYxWEk" target="_blank">this link</a> where you have the WAR file I setup.  The next step is to edit the file  hornetq-configuration.xml file  of the HornetQ installation and to add a servlet connector (please, notice that the path to the test keystore is referred to the client file system and you have to provide it with the keystore) and its corresponding acceptor :</p>
<pre>&lt;connectors&gt;
...  
   &lt;connector name="netty-servlet"&gt;
      &lt;factory-class&gt;org.hornetq.core.remoting.impl.netty.NettyConnectorFactory&lt;/factory-class&gt;
      &lt;param key="host" value="${jboss.bind.address:localhost}"/&gt;
      &lt;param key="port" value="8443"/&gt;
      &lt;param key="use-servlet" value="true"/&gt;
      &lt;param key="servlet-path" value="/messaging/HornetQServlet"/&gt;
      &lt;param key="ssl-enabled" value="true"/&gt;
      &lt;param key="key-store-path" value="C:\\Software\\KeyStores\\hornetq.test.keystore"/&gt;
      &lt;param key="key-store-password" value="test1234"/&gt;
 &lt;/connector&gt;
...
&lt;/connectors&gt;

&lt;acceptors&gt;
..  
   &lt;acceptor name="netty-invm"&gt;
      &lt;factory-class&gt;org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory&lt;/factory-class&gt;
      &lt;param key="use-invm" value="true"/&gt;
      &lt;param key="host" value="org.hornetq"/&gt;
   &lt;/acceptor&gt;
...
&lt;/acceptors&gt;</pre>
<p>The following task is to be sure that the HTTPS connector of the JBoss 4.2.1 AS is running, if not you have to edit the file server.xml located in the folder \deploy\jboss-web.deployer</p>
<p>I also add a security constraint to this  hornetq-configuration.xml configuration file, so the remote users just can send messages to our queues:</p>
<pre>...
&lt;security-settings&gt;
...
  &lt;security-setting match="jms.queue.ReadOnly.#"&gt;
    &lt;permission type="consume" roles="localRole"/&gt;
    &lt;permission type="send" roles="remoteRole"/&gt;
  &lt;/security-setting&gt;
...
&lt;/security-settings&gt;
...</pre>
<p>The following task is to edit the hornetq-jms.xml file and add a connection factory and a queue, deployed under the <em>readonly</em> context:</p>
<pre>...
&lt;connection-factory name="ReadOnly.NettyConnectionFactory"&gt;
  &lt;xa&gt;true&lt;/xa&gt;
  &lt;connectors&gt;
    &lt;connector-ref connector-name="netty-servlet"/&gt;
  &lt;/connectors&gt;
  &lt;entries&gt;
    &lt;entry name="readonly/XAConnectionFactory"/&gt;
  &lt;/entries&gt;
&lt;/connection-factory&gt;
...
&lt;queue name="ReadOnly.TestQueue"&gt;
  &lt;entry name="readonly/TestQueue"/&gt;
&lt;/queue&gt;
...</pre>
<p>The next step is to code a basic messages producer, in order to be used by the remote part:</p>
<pre>public class RemoteJMSProducer {

    public void sendMessages() {
        ConnectionFactory connectionFactory;
        Connection connection = null;
        Session session = null;
        Queue queue;
        MessageProducer producer;
        TextMessage message;
        Context initialContext;
        Properties jndiConfig;

        try {
            jndiConfig = new Properties();
            jndiConfig.put(Context.INITIAL_CONTEXT_FACTORY,
                           "org.jboss.naming.HttpNamingContextFactory");
            jndiConfig.put(Context.PROVIDER_URL,
                           "http://remote-jboss-server/invoker/ReadOnlyJNDIFactory");
            initialContext = new InitialContext(jndiConfig);

            connectionFactory = (ConnectionFactory)
                                 initialContext.lookup("readonly/XAConnectionFactory");
            connection = connectionFactory.createConnection("remoteUser", "test");
            queue = (Queue) initialContext.lookup("readonly/TestQueue");

            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            producer = session.createProducer(queue);
            message = session.createTextMessage();

            for (int i = 0; i &lt; 10; i++) {
                message.setText("This is the test message number " + i);
                producer.send(message);
            }

            System.out.println("Messages sent!");
        } catch (NamingException ex) {
            System.err.println("JNDI exception: " + ex.getMessage());
        } catch (JMSException ex) {
            System.err.println("JMS exception: " + ex.getMessage());
        } finally {
            try {
                session.close();
            } catch (Exception ignore) {
            }
            try {
                connection.close();
            } catch (Exception ignore) {
            }
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        RemoteJMSProducer remoteJMSProducer;

        remoteJMSProducer = new RemoteJMSProducer();
        remoteJMSProducer.sendMessages();
    }
}</pre>
<p>The former class doesn&#8217;t use the typical org.jnp.interfaces.NamingContextFactory, but the org.jboss.naming.HttpNamingContextFactory as the initial context factory. On the other hand, I&#8217;d like to point out that the provider URL is <a href="http://remote-jboss-server/invoker/ReadOnlyJNDIFactory" rel="nofollow">http://remote-jboss-server/invoker/ReadOnlyJNDIFactory</a>. In order to run the example, you need to put the following libraries on your classpath:</p>
<ul>
<li>hornetq-core-client.jar</li>
<li>hornetq-jms-client.jar</li>
<li>netty.jar</li>
<li>concurrent.jar</li>
<li>jboss-client.jar</li>
<li>jboss-common-client.jar</li>
<li>jboss-j2ee.jar</li>
<li>jboss-remoting.jar</li>
<li>jboss-serialization.jar</li>
<li>jbosssx-client.jar</li>
</ul>
<p>Please, realize that if you try to perform a list or a rename operation, you get an exception.</p>
<hr />
<p>References</p>
<ul>
<li><a title="Configuring Netty Servlet" href="http://docs.jboss.org/hornetq/2.2.5.Final/user-manual/en/html/configuring-transports.html#d0e3531" target="_blank">Configuring Netty Servlet</a></li>
<li><a title="Naming on JBoss" href="http://docs.jboss.org/jbossas/docs/Server_Configuration_Guide/4/html/Naming_on_JBoss.html" target="_blank">Naming on JBoss</a></li>
<li><a title="HornetQ Security" href="http://docs.jboss.org/hornetq/2.2.5.Final/user-manual/en/html/security.html" target="_blank">HornetQ Security</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fcosfc.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fcosfc.wordpress.com/313/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fcosfc.wordpress.com&#038;blog=23277319&#038;post=313&#038;subd=fcosfc&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fcosfc.wordpress.com/2012/03/12/security-notes-about-hornetq-as-a-jboss-jms-provider/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/246c8ae49665d2d03381f0667408e410?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fcosfc</media:title>
		</media:content>
	</item>
	</channel>
</rss>
