1 2 3 Previous Next 32 Replies Latest reply on Jul 7, 2011 3:25 PM by Luke Samad

    httprouter issues with GET/POST WADL Services and Web Routing

    Dave Siracusa Newbie

      I ran into two issues when using the httprouter (new):

      1) Using this router one must specify the method (get,post,delete, etc) in the configuration tree.  If you route to an external server that supports both GET and POST you are stuck because the method factory is created at init time forcing you to use only one.  I've run into this with a RESTful service I'm pointing to.

       

      2) Say you point the router to a web server that serves up a page.  This page contains relative links to images.  The text/html content comes back however the images/other content does not.  As a matter of fact you can't specify anything after the base url, its ignored.

       

      And my router as such:

      <action name="httprouter">  

      <property name="endpointUrl" value="http://localhost">  

      <http-client-property name="max-total-connections" value="100" />  

      <http-client-property name="max-connections-per-host" value="50" />  

      </property>  

      <property name="method" value="GET" /> 

      <property name="responseType" value="STRING" />

      </action>

       

      Urls like this succeed (partially):

      - http://localhost:8080/Quickstart_async/http/test (returns text/html only).

       

      Urls like this fail (even though they exist):

      - http://localhost:8080/Quickstart_async/http/test/index.htm

      - http://localhost:8080/Quickstart_async/http/test/welcome.png

       

      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

      I changed the httprouter source:

      1) I added support for comma separated method value (GET,POST,DELETE).  It creates factories in the init() method, caching it as the original author intended.

      2) I added a call to method.setPath in the process method to initialize the path and all is good.

       

      I've attached the source. 

       

      BTW - I'm having problems signing the CLA.  I've opened discussions on this. 

      I'd like to create a JIRA and check in my changes.

        • 1. Re: httprouter issues with GET/POST WADL Services and Web Routing
          Dave Siracusa Newbie

          I added a patch. Sorry this may be premature, I'll look in the issue tracking system.

          • 3. Re: httprouter issues with GET/POST WADL Services and Web Routing
            jack lista Newbie

            Hi Dave,  saw your post and have been looking for similar facilities.  I want to consume (what would be along the lines of message enhancing) RESTful services (*not* built with RESTEasy, essentially just HTTP calls that return XML) from within my action pipeline.  I was looking for something *similar* to SOAPCLient, maybe called HTTPClient, but didn't find it.  What is the best practice for consuming RESTful services from an action pipeline, can you shed some light here?  Also, I'm curious about what happened to your HTTPRouter src, I don't really need a router but if there's nothing else perhaps I can make due.  Also, I saw posts talking about abstracting an HTTPClient and making it a parent of SOAPCLient, has anything happened on that?  Should I do it?  Sorry to pelt you with questions, I've been having a hard time finding ino on this... thx!

            • 4. Re: httprouter issues with GET/POST WADL Services and Web Routing
              Dave Siracusa Newbie

              Hi Jack

               

              I ended up using jersey v1.2.  It made it far easier to deal with request / response types.

              I used a http-gateway specified like this (INVM and maxThreads for concurrency / speed):

              <service category="Business Profile Services"  name="BusinessProfile REST Proxy" 

                              description="BusinessProfile REST WebService Proxy" invmScope="GLOBAL">

               

              <property name="maxThreads" value="50"/>

              <listeners>

                 <http-gateway name="Index-bprest" urlPattern="businessprofile/rest/*" />

              </listeners>

               

              I created a custom action where I process the request (fragment attached - you'll have to edit it).

              I also attached a jersey singleton class.

               

              You should be able to call non jersey services.

               

              Let me know if you have any other questions.

               

              Best,

              Dave

               

               

               

               

               

               

               

               

               

              • 5. Re: httprouter issues with GET/POST WADL Services and Web Routing
                jack lista Newbie

                Hi, thanks a lot, I'll check that out and see.  So this code is an action of yours that interacts with the HTTP response to a jersey jax-rs client?  That sounds like something along the lines of what I need, I want to consume (not necessarily compliant) RESTful (or RESTlike) services from within an Action pipeline as a client and may well want to be able to route messages to RESTlike/ful endpoints too.  Anyway, I'm kind of a newbie to jboss esb, but I'll check this out, but I might have some questions if you don't mind, thanks.

                 

                --j

                • 6. Re: httprouter issues with GET/POST WADL Services and Web Routing
                  jack lista Newbie

                  Hi, Dave, so it looks like there is some stuff missing, processWADLDocRequest(), processWADLRequest(), processXSDRequest(), do I need this stuff?  Or should I chop out those branches of code and make them throw exceptions or something?  I'm not totally sure of your context as haven't done much work with JBossESB yet, but what I did was to tale your (I'm assuming this is for an Action class, right?) "process(Message msg)" method and slap it in another custom class, from simple_cbr quiclkstart.  So I'm guessing that the action that you chopped this out of does more stuff (like WADL stuff, or XSD stuff... true?) than make REST requests, so you only sent me part of it, is that right?  So, for ex., here:

                   

                  if (requestInfo.getQueryParams().containsKey("doc"))
                          return processWADLDocRequest(message, null);

                   

                  Does it need to handle these cases?  I think there are 3 of them... or can I make them throw exceptions instead and I won't hit them?

                   

                  THe other thing I wanted to ask you about was configuration of this.  I put the method fragment in one of the quickstart MyFooAction classes and renamed it WADLAction.java and slapped your process method in there (please fill me in about the missing methods above, I'm not at all familiar with Jersey).  I also put the JerseyClientSingleton class in the same package as the rest of the simple_cbr quickstart.  Do I need any configuration in jboss-esb.xml?  I think I see what your code is doing for the most part, now let's see if I can get it to work.  Thanks too, BTW!

                  • 7. Re: httprouter issues with GET/POST WADL Services and Web Routing
                    Dave Siracusa Newbie

                    Delete logic/calls to processWADLDocRequest(), processWADLRequest(), processXSDRequest().

                    As far as what they did:

                    -  processWADLDocRequest - return HTML Doc based on WADL + XSL

                    -  processWADLRequest - return patched WADL

                    -  processXSDRequest - return XSDs embedded in the WADL

                     

                    The process method will be called by default in an action class.

                    As far as configuration call JerseyClientSingleton.init as such:

                    public void initialise() throws ActionLifecycleException {
                         JerseyClientSingleton.init();
                    }

                    Also include jersey1.2 jars in the lib directory.

                     

                    If you construct the http request the logic should figure things out.

                    • 8. Re: httprouter issues with GET/POST WADL Services and Web Routing
                      jack lista Newbie

                      Hi Dave, thanks for the info.  I'm trying to build the stuff now, but I'm getting an error on the HTTPClient:

                       

                      [javac] /home/jack/java/jboss/jboss-soa-p.5.0.0/jboss-as/samples/quickstarts/simple_cbr/src/org/jboss/soa/esb/samples/quickstart/simplecbr/JerseyClientSingleton.java:9: package com.sun.jersey.client.apache does not exist
                      [javac] import com.sun.jersey.client.apache.ApacheHttpClient;

                       

                      from this import in JerseyClientSingleton.java (line 9):

                       

                      import com.sun.jersey.client.apache.ApacheHttpClient;

                       

                      I took your advice (perhaps incorrectly) and put these 3 jars in my project lib folder but am still getting the compilation error:

                       

                      asm-3.1.jar

                      jersey-bundle-1.3.jar

                      jsr311-api-1.1.jar

                       

                      I put these in the lib directory of the project, which is the "simple_cbr" jboss quickstart which I'm using to test this stuff.  Am I missing a jar?  Or does it need to go in a different lib dir?  I was looking at this link for dependencies, I'm using ant (the quickstarts all use ant), so I'm following the instructions for non-maven developers:

                       

                      https://jersey.dev.java.net/nonav/documentation/latest/user-guide.html#chapter_deps

                       

                       

                      Whoops, I looked through the zip file for jersey (I'm using 1.3, hope that's ok) and found the apache client jar and threw it in my project lib dir and now it built...  wooo!

                       

                      OK, no need to respond here, I'm mostly posting this to help the next poor sap to come along

                       

                      So the jars needed are:

                       

                      asm-3.1.jar

                      jersey-bundle-1.3.jar

                      jsr311-api-1.1.jar

                      jersey-apache-client-1.3.jar

                       

                      I'm sure I'll have more to say but thanks loads Dave, really appreciate your help!!

                       

                      -=j=-

                       

                       

                      --j

                      • 9. Re: httprouter issues with GET/POST WADL Services and Web Routing
                        Dave Siracusa Newbie

                        I ran into many runtime problems with Jersey 1.3 in most of my http-based services (have many).

                         

                        Likely due to conflicting httpclient.

                         

                        I use maven, here are my dependancies:

                        Note: I used the SOA-P 5.X supplied httpclient.

                        <dependency

                         

                         

                         

                             <groupId>${jboss.groupid}</groupId

                         

                         

                             <artifactId>commons-httpclient</artifactId

                         

                         

                             <version>${jboss.as}</version

                         

                         

                             <scope>provided</scope

                         

                         

                        </dependency>

                         

                         

                        <!-- jersey 1.2 -->

                        <dependency> 

                             <artifactId>asm</artifactId>

                             <groupId>asm</groupId>

                             <version>3.1</version>

                             </dependency>

                        <dependency>

                             <groupId>org.codehaus.jackson</groupId>

                             <artifactId>jackson</artifactId>

                             <version>1.1.1</version>

                        </dependency>

                         

                        <dependency>

                             <groupId>org.codehaus.jettison</groupId>

                             <artifactId>jettison</artifactId>

                             <version>1.1</version>

                        </dependency>

                         

                        <dependency>

                             <groupId>javax.ws.rs</groupId>

                             <artifactId>jsr311-api</artifactId>

                             <version>1.1</version>

                        </dependency>

                         

                        <dependency>

                             <groupId>jersey</groupId>

                             <artifactId>jersey-apache-client</artifactId>

                             <version>1.2</version>

                        </dependency>

                        <dependency>

                             <groupId>jersey</groupId> 

                             <artifactId>jersey-client</artifactId>

                             <version>1.2</version>

                        </dependency>

                         

                        <dependency>

                             <groupId>jersey</groupId>

                             <artifactId>jersey-core</artifactId>

                             <version>1.2</version>

                        </dependency>

                         

                         

                        • 10. Re: httprouter issues with GET/POST WADL Services and Web Routing
                          jack lista Newbie

                          Hmm, some how I loaded stuff that wasn't properly compiled, I did an "ant clean" and found I don't have an import for "HttpResponse", do you have the import for that?  It doesn't seem to be in those jars, (I had assumed this to be Jersey stuff, is it?  Or maybe 3rd party?).  It's from this snippet of code:

                           

                          HttpResponse httpResponse = new HttpResponse(response.getStatus());
                          httpResponse.setContentType(response.getType().toString());
                          message.getBody().add(entityResponse);
                          httpResponse.setResponse(message);

                           

                           

                          I also started looking at this code and it looks like it's processing an incoming request, is that true?  That's cool, but I don't want to do that at the moment., I just want to make an oiutgoing request and then probably enhance a message with the data.  Do I still use this same JerseyClientSingleton to create a brand new request I want to make from my WADLAction class?  Also, if you have a pointer to docs on this client that would be cool too, thanks.

                           

                          --j

                          • 11. Re: httprouter issues with GET/POST WADL Services and Web Routing
                            jack lista Newbie

                            [DIdn't see this] You had problems with Jersey 1.3 eh?  I can back off to 1.2, though, as long as they're still serving the download.

                             

                            Hey, do you have the import for that HttpResponse class?  I found a class of the same name in an "spi" package for RESTEasy but it doesn't look right, it looks internal.  If you would fling me that package import for your WADLAction.java file for that I'd be muhjc obliged... thx

                             

                            --j

                            • 12. Re: httprouter issues with GET/POST WADL Services and Web Routing
                              jack lista Newbie

                              [light goes on] This is all RESTEasy stuff?  Found several of the missing imports in resteasy packages, looks likely... pls conmfirm if you get a chance...

                              • 13. Re: httprouter issues with GET/POST WADL Services and Web Routing
                                Dave Siracusa Newbie

                                import org.jboss.soa.esb.actions.AbstractActionPipelineProcessor;

                                import org.jboss.soa.esb.actions.ActionLifecycleException;

                                import org.jboss.soa.esb.actions.ActionProcessingException;

                                import org.jboss.soa.esb.helpers.ConfigTree;

                                import org.jboss.soa.esb.message.Message;

                                import org.jboss.soa.esb.http.HttpResponse;


                                import org.apache.commons.httpclient.HttpStatus;

                                import org.apache.log4j.Logger;

                                 

                                import java.io.DataInputStream;

                                import java.io.File;

                                import java.io.StringReader;

                                import java.net.InetAddress;

                                import java.net.URL;

                                import java.net.URLConnection;

                                 

                                import javax.ws.rs.core.MediaType;

                                import javax.xml.transform.Source;

                                 

                                import org.jboss.soa.esb.http.HttpRequest;

                                import org.w3c.dom.*;

                                 

                                import net.sf.saxon.s9api.*;

                                 

                                import com.sun.jersey.api.client.ClientResponse;

                                import com.yellowbook.soa.esb.actions.proxy.IConfigChangeEvent;

                                import com.yellowbook.soa.esb.util.file.Resource;

                                import com.yellowbook.soa.esb.util.jersey.JerseyClientSingleton;

                                import com.yellowbook.soa.esb.util.reflection.ReflectionHelper;

                                import com.yellowbook.soa.esb.util.xml.XMLHelper;

                                • 14. Re: httprouter issues with GET/POST WADL Services and Web Routing
                                  jack lista Newbie

                                  awesome, thanks, will sort it out, that makes it *much* easier

                                  1 2 3 Previous Next