10 Replies Latest reply on Oct 15, 2009 8:37 PM by skeener

    Web Service question....

    skeener

      So I have been developing a simple web service based on suggestions from this forum.

       

      I want to return pre-generated XML as a string.  I do not want any other xml wrapping around it.  (It's already pre-generated by a seperate module)

       

      Suggestions on how to accomplish this?  I've got data being returned, but it's wrapped in outgoing XML similar to what's below around a dummy string:

       

      <ns1:getKmlResponse xmlns:ns1="http://jivesoftware.com/clearspace/webservices">
           <return><field1><value1></value1></field1></return>
      </ns1:getKmlResponse>

       

      The string response that I want corresponds to:

       

      <field1><value1></value1></field1>

       

      I'm trying to get rid of the rest of the wrappings.

       

      Thanks!!!

        • Re: Web Service question....

          Hi Steve,

           

          That markup is built into our REST framework; you're not going to get around it.

           

          You could define an action that wraps the web service (or invokes the same APIs) and gives you the output you want.  You can avoid the sitemesh decoration by adding the following annotation to your class:

           

          @Decorate(false)

           

          See this for more info on that:  Struts: Frequently Asked Questions

           

          What's your use case (just curious)?  Normally I'd clean up on the client end with a SAX parse or string manipulation.

            • Re: Web Service question....
              skeener

              Been there did that, got the t-shirt.  :-)

               

              Basically I am creating a translation plugin for data ingestion capabilities.  I load an xml file, translate it, and make it available via URL to a 3rd party javascript tool we are using.  I can't intercept it and repackage it on the consumer side.  So I have to produce what the 3rd party toolkit is expecting to see.

               

              I initially was doing an action.  But Rick your trainer suggested doing a web service instead.  Normally I wouldn't have a problem with the packaging and pulling out the data I need.  Unfortunately that isn't the case with this instance.

               

              ok....guess I'm back to trying to find a hack to make it work.  Lovely.

                • Re: Web Service question....

                  Gotcha.  Like a servlet filter that strips it?   Sounds nasty, sorry about that.  Good luck!

                    • Re: Web Service question....
                      skeener

                      If I go the route of using an Action with no decorator...how would I prevent the redirect to login  (Like by adding te session id to the url)  I'm not terribly familiar with this, so a pointer or three might help out here.

                       

                      Steve

                        • Re: Web Service question....

                          How would you authenticate then, using Basic Auth like Web Services?

                           

                          At that point you want to modify the Spring security filter chain to use a different authentication mechanism for that URL.    Let me know if you need more detail.

                          • Re: Web Service question....

                            You're basically creating a file in jiveHome/etc  that overrides some spring configs:

                             

                            <?xml version="1.0" encoding="UTF-8"?>
                            <beans xmlns="http://www.springframework.org/schema/beans"
                                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                   xmlns:aop="http://www.springframework.org/schema/aop"
                                   xmlns:util="http://www.springframework.org/schema/util"
                                   xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
                                   xsi:schemaLocation="
                            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
                            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
                            http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd"
                                   default-autowire="no" default-init-method="init" default-destroy-method="destroy">



                                <!-- This bean is the main entry point of the Acegi Filter and a critical configuration point.
                                        Filters referenced here are defined below. -->
                                <bean id="filterChainProxy">
                                    <property name="filterInvocationDefinitionSource">
                                        <value>
                                            CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
                                            PATTERN_TYPE_APACHE_ANT
                                            /upgrade/**=httpSessionContextIntegrationFilter, upgradeAuthenticationFilter, upgradeExceptionTranslationFilter,jiveAuthenticationTranslationFilter
                                            /post-upgrade/**=httpSessionContextIntegrationFilter, postUpgradeAuthenticationFilter, postUpgradeExceptionTranslationFilter,jiveAuthenticationTranslationFilter
                                            /admin/**=httpSessionContextIntegrationFilter, sessionTrackingFilter, adminAuthenticationFilter, openfireAuthenticationFilter, adminExceptionTranslationFilter,jiveAuthenticationTranslationFilter
                                            /rpc/xmlrpc=wsRequireSSLFilter, httpSessionContextIntegrationFilter, basicAuthenticationFilter, wsExceptionTranslator, jiveAuthenticationTranslationFilter, wsAccessTypeCheckFilter
                                            /rpc/rest/**=wsRequireSSLFilter, httpSessionContextIntegrationFilter, basicAuthenticationFilter, wsExceptionTranslator, jiveAuthenticationTranslationFilter, wsAccessTypeCheckFilter
                                            /rpc/soap/**=wsRequireSSLFilter, httpSessionContextIntegrationFilter, jiveAuthenticationTranslationFilter
                                            /**=httpSessionContextIntegrationFilter, sessionTrackingFilter, formAuthenticationFilter,  feedBasicAuthenticationFilter,exceptionTranslationFilter,jiveAuthenticationTranslationFilter
                                        </value>
                                    </property>
                                </bean>

                             

                            </beans>

                            Then you add in a new matcher that copies one of rpc matchers above but matches on your new Action's URL.


                            I talked to Len, we  can discuss this further at 4pm Eastern.

                              • Re: Web Service question....
                                skeener

                                So basically I *have* to do the following for my plugin:

                                 

                                1.  Create the file you listed above - spring security configuration that adds a new filter to the /rpc/rest section.

                                2.  Place it in <JIVE_HOME>/etc as a secondary part of my plugin install.  (Or is there a way to do it as part of the plugin???)

                                3.  Implement a filter similar to com.jivesoftware.community.aaa.FeedsBasicProcessingFilter.java - only it would basically create an authentication for a "user" of this specific URL.  (An example being a configurable user/pwd that can be used to authenticate the request automatically.)

                                 

                                Am I going in the right direction?

                                  • Re: Web Service question....

                                    No, you're right you can put it in the spring.xml in your plugin.


                                    You don't have to impelement a new filter.   What I'm talking about is just adding a new line that uses just the filters you want, which I assume uses basic auth, e.g.:

                                     

                                    <!-- This bean is the main entry point of the Acegi Filter and a critical configuration point.

                                                Filters referenced here are defined below. -->

                                        <bean id="filterChainProxy">

                                            <property name="filterInvocationDefinitionSource">

                                                <value>

                                                    CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON

                                                    PATTERN_TYPE_APACHE_ANT

                                                    /upgrade/**=httpSessionContextIntegrationFilter, upgradeAuthenticationFilter, upgradeExceptionTranslationFilter,jiveAuthenticationTranslationFilter

                                                    /post-upgrade/**=httpSessionContextIntegrationFilter, postUpgradeAuthenticationFilter, postUpgradeExceptionTranslationFilter,jiveAuthenticationTranslationFilter

                                                    /admin/**=httpSessionContextIntegrationFilter, sessionTrackingFilter, adminAuthenticationFilter, openfireAuthenticationFilter, adminExceptionTranslationFilter,jiveAuthenticationTranslationFilter

                                                    /rpc/xmlrpc=wsRequireSSLFilter, httpSessionContextIntegrationFilter, basicAuthenticationFilter, wsExceptionTranslator, jiveAuthenticationTranslationFilter, wsAccessTypeCheckFilter

                                                    /rpc/rest/**=wsRequireSSLFilter, httpSessionContextIntegrationFilter, basicAuthenticationFilter, wsExceptionTranslator, jiveAuthenticationTranslationFilter, wsAccessTypeCheckFilter

                                                    /rpc/soap/**=wsRequireSSLFilter, httpSessionContextIntegrationFilter, jiveAuthenticationTranslationFilter

                                                    /steveAction*=wsRequireSSLFilter,feedBasicAuthenticationFilter

                                                   /**=httpSessionContextIntegrationFilter, sessionTrackingFilter, formAuthenticationFilter,  feedBasicAuthenticationFilter,exceptionTranslationFilter,jiveAuthenticationTranslationFilter

                                                </value>

                                            </property>

                                        </bean>

                                     

                                    </beans>

                                      • Re: Web Service question....

                                        So basically all you need is a filter you can plugin to the chain:

                                        public class StevesProcessingFilter implements Filter, InitializingBean {

                                         

                                        . . . .

                                         

                                        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
                                                    throws IOException, ServletException {

                                         

                                             SecurityContextHolder.getContext().setAuthentication(new AnonymousAuthentication());

                                            chain.doFilter(request, response);

                                        }

                                         

                                        . . .

                                        }

                                          • Re: Web Service question....
                                            skeener

                                            Er....I have an authentication filter running now.  I'm watching the log for it.  That works great.  Sadly, it doesn't prevent the redirect of the URL request.

                                             

                                            I did some more poking on the support site here....and came up with this information:

                                             

                                               http://www.jivesoftware.com/jivespace/docs/DOC-3277

                                             

                                             

                                            So I tried adding the jiveAuthenticationTranslationFilter to the filter chain.  No dice.

                                             

                                            Some more poking in the SBS 3.0.4 code produced the JiveAnonymousProcessingFilter. And again....no dice.

                                             

                                             

                                            In the filter I created only the doFilter method is being called.  It's returning exactly what you suggested.