From c786c19edff2f90f7d4f0cb8346a5bfa77480e09 Mon Sep 17 00:00:00 2001 From: Thomas Diesler Date: Thu, 3 Nov 2011 09:32:45 +0100 Subject: [PATCH] Add juddi.properties for registry configuration --- .../jboss/as/jaxr/scout/SaajTransport.java | 12 ++--- .../as/jaxr/service/JAXRConfiguration.java | 2 +- .../as/jaxr/service/JUDDIContextService.java | 54 ++++++++++++++++--- .../jboss/as/jaxr/service/JUDDIServlet.java | 26 +++------ .../main/resources/WEB-INF/juddi.properties | 54 +++++++++++++++++++ .../integration/jaxr/scout/JaxrTestBase.java | 3 -- 6 files changed, 117 insertions(+), 34 deletions(-) create mode 100644 jaxr/src/main/resources/WEB-INF/juddi.properties diff --git a/jaxr/src/main/java/org/jboss/as/jaxr/scout/SaajTransport.java b/jaxr/src/main/java/org/jboss/as/jaxr/scout/SaajTransport.java index ecb73bdd8c1b..48df1e841d50 100644 --- a/jaxr/src/main/java/org/jboss/as/jaxr/scout/SaajTransport.java +++ b/jaxr/src/main/java/org/jboss/as/jaxr/scout/SaajTransport.java @@ -62,7 +62,7 @@ public class SaajTransport implements Transport { public Element send(Element request, URI endpointURL) throws RegistryException { String requestMessage = DOMWriter.printNode(request, true); - log.debug("Request message:" + requestMessage); + log.debugf("Request message: %s\n%s", endpointURL, requestMessage); Element response = null; try { @@ -81,11 +81,11 @@ public Element send(Element request, URI endpointURL) throws RegistryException { } response = getFirstChildElement(soapBody); } catch (Exception ex) { - log.error("Exception::", ex); + log.errorf(ex, "Exception::"); throw new RegistryException(ex); } - log.debug("Response message:" + DOMWriter.printNode(response, true)); + log.debugf("Response message: %s", DOMWriter.printNode(response, true)); return response; } @@ -164,8 +164,8 @@ private static Element getElement(String xmlFrag) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); doc = factory.newDocumentBuilder().parse(new InputSource(new StringReader(xmlFrag))); reqElement = doc.getDocumentElement(); - } catch (Exception e) { - log.error("Exception:", e); + } catch (Exception ex) { + log.errorf(ex, "Exception:"); } return reqElement; @@ -187,7 +187,7 @@ private Element getFirstChildElement(Element el, String tagName) { } } String responseObtained = DOMWriter.printNode(childEl, true); - log.debug("Response obtained=" + responseObtained); + log.debugf("Response obtained: %s", responseObtained); return childEl; } } diff --git a/jaxr/src/main/java/org/jboss/as/jaxr/service/JAXRConfiguration.java b/jaxr/src/main/java/org/jboss/as/jaxr/service/JAXRConfiguration.java index 4faae5db62c5..bd4807639ad3 100644 --- a/jaxr/src/main/java/org/jboss/as/jaxr/service/JAXRConfiguration.java +++ b/jaxr/src/main/java/org/jboss/as/jaxr/service/JAXRConfiguration.java @@ -42,7 +42,7 @@ public class JAXRConfiguration { // Should all tables be created on Start private boolean createOnStart=true; // Should all tables be dropped on Stop - private boolean dropOnStop=true; + private boolean dropOnStop=false; // Should all tables be dropped on Start private boolean dropOnStart=true; // Datasource to Database diff --git a/jaxr/src/main/java/org/jboss/as/jaxr/service/JUDDIContextService.java b/jaxr/src/main/java/org/jboss/as/jaxr/service/JUDDIContextService.java index 97a8de69a417..775e3329316b 100644 --- a/jaxr/src/main/java/org/jboss/as/jaxr/service/JUDDIContextService.java +++ b/jaxr/src/main/java/org/jboss/as/jaxr/service/JUDDIContextService.java @@ -29,6 +29,8 @@ import org.apache.catalina.core.StandardContext; import org.apache.catalina.startup.ContextConfig; import org.apache.juddi.registry.RegistryServlet; +import org.apache.naming.resources.ProxyDirContext; +import org.apache.naming.resources.Resource; import org.apache.tomcat.InstanceManager; import org.jboss.as.server.mgmt.HttpManagementService; import org.jboss.as.server.mgmt.domain.HttpManagement; @@ -47,10 +49,22 @@ import org.jboss.msc.service.StopContext; import org.jboss.msc.value.InjectedValue; +import javax.naming.Binding; +import javax.naming.Name; +import javax.naming.NameClassPair; +import javax.naming.NameParser; +import javax.naming.NamingEnumeration; import javax.naming.NamingException; +import javax.naming.directory.Attributes; +import javax.naming.directory.DirContext; +import javax.naming.directory.ModificationItem; +import javax.naming.directory.SearchControls; +import javax.naming.directory.SearchResult; import javax.servlet.http.HttpServlet; import java.io.File; +import java.io.InputStream; import java.lang.reflect.InvocationTargetException; +import java.util.Hashtable; /** * A service starting a welcome web context driven by simple static content. @@ -79,7 +93,19 @@ public static ServiceController addService(final ServiceTarget target, final } private JUDDIContextService(final JAXRConfiguration config) { - this.context = new StandardContext(); + context = new StandardContext() { + private DirContext resources; + // [TODO] AS7-2499 Remove DirContext hack to load juddi.properties + public DirContext getResources() { + if (resources == null) { + DirContext orgdirctx = super.getResources(); + if (orgdirctx != null) { + resources = new JAXRDirContext(new Hashtable(), orgdirctx); + } + } + return resources; + } + }; } @Override @@ -111,12 +137,13 @@ public synchronized void start(StartContext startContext) throws StartException context.addServletMapping("/publish", "JUDDIServlet"); context.addServletMapping("/inquiry", "JUDDIServlet"); - // Add the JUDDIServlet + // Add the RegistryServlet servlet = new RegistryServlet(); wrapper = context.createWrapper(); wrapper.setName("JUDDIRegistryServlet"); wrapper.setServlet(servlet); wrapper.setServletClass(servlet.getClass().getName()); + wrapper.setLoadOnStartup(1); context.addChild(wrapper); host.addChild(context); @@ -148,10 +175,6 @@ public synchronized void stop(StopContext stopContext) { @Override public synchronized Context getValue() throws IllegalStateException { - final Context context = this.context; - if (context == null) { - throw new IllegalStateException(); - } return context; } @@ -190,4 +213,23 @@ public void newInstance(Object o) throws IllegalAccessException, InvocationTarge public void destroyInstance(Object o) throws IllegalAccessException, InvocationTargetException { } } + + private static class JAXRDirContext extends ProxyDirContext { + public JAXRDirContext(Hashtable env, DirContext dircontext) { + super(env, dircontext); + } + + @Override + // [TODO] AS7-2499 Remove DirContext hack to load juddi.properties + public Object lookup(String name) throws NamingException { + try { + return super.lookup(name); + } catch (NamingException namingExeption) { + InputStream stream = getClass().getClassLoader().getResourceAsStream(name); + if (stream == null) + throw namingExeption; + return new Resource(stream); + } + } + } } diff --git a/jaxr/src/main/java/org/jboss/as/jaxr/service/JUDDIServlet.java b/jaxr/src/main/java/org/jboss/as/jaxr/service/JUDDIServlet.java index 90f4e34fe1ce..dae7f58d9172 100644 --- a/jaxr/src/main/java/org/jboss/as/jaxr/service/JUDDIServlet.java +++ b/jaxr/src/main/java/org/jboss/as/jaxr/service/JUDDIServlet.java @@ -86,15 +86,12 @@ public class JUDDIServlet extends HttpServlet { private static Logger log = Logger.getLogger(JUDDIServlet.class); - public void doGet(HttpServletRequest req, HttpServletResponse res) - throws ServletException, IOException { + public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setHeader("Allow", "POST"); - res.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The request " + - "method 'GET' is not allowed by UDDI API."); + res.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The request method 'GET' is not allowed by UDDI API."); } - public void doPost(HttpServletRequest req, HttpServletResponse res) - throws ServletException, IOException { + public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/xml; charset=utf-8"); SOAPMessage soapReq = null; @@ -121,13 +118,11 @@ public void doPost(HttpServletRequest req, HttpServletResponse res) } if (uddiReq == null) - throw new FatalErrorException("A UDDI request was not " + - "found in the SOAP message."); + throw new FatalErrorException("A UDDI request was not found in the SOAP message."); String function = uddiReq.getLocalName(); if ((function == null) || (function.trim().length() == 0)) - throw new FatalErrorException("The name of the UDDI request " + - "could not be identified."); + throw new FatalErrorException("The name of the UDDI request could not be identified."); IHandler requestHandler = maker.lookup(function); if (requestHandler == null) throw new UnsupportedException("The UDDI request " + @@ -135,13 +130,9 @@ public void doPost(HttpServletRequest req, HttpServletResponse res) String generic = uddiReq.getAttribute("generic"); if (generic == null) - throw new FatalErrorException("A UDDI generic attribute " + - "value was not found for UDDI request: " + function + " (The " + - "'generic' attribute must be present)"); + throw new FatalErrorException("A UDDI generic attribute value was not found for UDDI request: " + function + " (The 'generic' attribute must be present)"); else if (!generic.equals(IRegistry.UDDI_V2_GENERIC)) - throw new UnsupportedException("Currently only UDDI v2 " + - "requests are supported. The generic attribute value " + - "received was: " + generic); + throw new UnsupportedException("Currently only UDDI v2 requests are supported. The generic attribute value received was: " + generic); // Unmarshal the raw xml into the appropriate jUDDI // request object. @@ -167,8 +158,7 @@ else if (!generic.equals(IRegistry.UDDI_V2_GENERIC)) IHandler responseHandler = maker.lookup(uddiResObj.getClass().getName()); if (responseHandler == null) - throw new FatalErrorException("The response object " + - "type is unknown: " + uddiResObj.getClass().getName()); + throw new FatalErrorException("The response object type is unknown: " + uddiResObj.getClass().getName()); // Create a new 'temp' XML element to use as a container // in which to marshal the UDDI response data into. diff --git a/jaxr/src/main/resources/WEB-INF/juddi.properties b/jaxr/src/main/resources/WEB-INF/juddi.properties new file mode 100644 index 000000000000..f6500a9ffe09 --- /dev/null +++ b/jaxr/src/main/resources/WEB-INF/juddi.properties @@ -0,0 +1,54 @@ +# jUDDI Registry Properties (used by RegistryServer) +# see http://www.juddi.org for more information + +# The UDDI Operator Name +juddi.operatorName = jUDDI.org + +# The maximum name size and maximum number +# of name elements allows in several of the +# FindXxxx and SaveXxxx UDDI functions. +juddi.maxNameLength=255 +juddi.maxNameElementsAllowed=5 +juddi.maxBusinessEntitiesPerUser=25 +juddi.maxBusinessServicesPerBusiness=20 +juddi.maxBindingTemplatesPerService=10 +juddi.maxTModelsPerUser=100 +juddi.maxRowsLimit=10 + +# jUDDI Authentication module to use +juddi.auth = org.apache.juddi.auth.DefaultAuthenticator + +# jUDDI DataStore module currently to use +juddi.dataStore = org.apache.juddi.datastore.jdbc.JDBCDataStore + + +# jUDDI UUIDGen implementation to use +juddi.uuidgen = org.apache.juddi.uuidgen.DefaultUUIDGen + +# jUDDI Monitor implementation to use +#juddi.monitor = org.apache.juddi.monitor.jdbc.JDBCMonitor + +# jUDDI Cryptor implementation to use +juddi.cryptor = org.apache.juddi.cryptor.DefaultCryptor + +# jUDDI Validator to use +juddi.validator=org.apache.juddi.validator.DefaultValidator + +# jUDDI DataSource to use +juddi.dataSource=java:jboss/datasources/ExampleDS + + +# jUDDI Proxy Properties (used by RegistryProxy) +juddi.proxy.adminURL = http://localhost:8080/juddi/admin +juddi.proxy.inquiryURL = http://localhost:8080/juddi/inquiry +juddi.proxy.publishURL = http://localhost:8080/juddi/publish +juddi.proxy.transportClass = org.apache.juddi.proxy.AxisTransport +juddi.proxy.securityProvider = com.sun.net.ssl.internal.ssl.Provider +juddi.proxy.protocolHandler = com.sun.net.ssl.internal.www.protocol + +# jUDDI HTTP Proxy Properties +juddi.httpProxySet = true +juddi.httpProxyHost = proxy.viens.net +juddi.httpProxyPort = 8000 +juddi.httpProxyUserName = sviens +juddi.httpProxyPassword = password \ No newline at end of file diff --git a/testsuite/integration/src/test/java/org/jboss/as/test/integration/jaxr/scout/JaxrTestBase.java b/testsuite/integration/src/test/java/org/jboss/as/test/integration/jaxr/scout/JaxrTestBase.java index 804b006226d8..9ee51aac5b36 100644 --- a/testsuite/integration/src/test/java/org/jboss/as/test/integration/jaxr/scout/JaxrTestBase.java +++ b/testsuite/integration/src/test/java/org/jboss/as/test/integration/jaxr/scout/JaxrTestBase.java @@ -116,9 +116,6 @@ public void tearDown() throws Exception { if (connection != null) connection.close(); } - /** - * Does authentication with the uddi registry - */ protected void login() { PasswordAuthentication passwdAuth = new PasswordAuthentication(userid, passwd.toCharArray()); Set creds = new HashSet();