Expose and access static XSD schema in Spring WS 2 - xsd

I can't reach XSD schema. Here is my configuration:
web.xml
<servlet>
<servlet-name>spring-ws</servlet-name>
<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
<init-param>
<param-name>transformWsdlLocations</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>spring-ws</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
spring-ws-servlet.xml
<sws:annotation-driven/>
<context:component-scan base-package="example.ws.endpoint"/>
<sws:dynamic-wsdl id="boo"
portTypeName="BooResource"
locationUri="/services/">
<sws:xsd location="classpath:example/ws/schema/Boo.xsd"/>
</sws:dynamic-wsdl>
WSDL is accessible on [http://localhost:port/spring-ws-server-0.1-SNAPSHOT/services/boo.wsdl], but how can I expose XSD and what will be the URL?

I've been able to expose my XSD's without using Spring-MVC for it by defining something like this in my #Configuration class:
private ClassPathResource messagesXsdResource = new ClassPathResource("messages.xsd");
#Bean
public SimpleXsdSchema messages() {
return new SimpleXsdSchema(messagesXsdResource);
}
You should take a look at this question as well, that explains how to do this in XML.

I'm afraid this is not possible, at least not automatically like your WSDLs are exposed. Spring WS doesn't intend to make your XSDs available like it does with the static and generated WSDLs. Of course, you can make your XSDs available through a simple servlet or through MVC (if you're using MVC as well).

If you're using Spring Boot, whatever you put under the public folder which you can create under resources, will be publicly available.
You can put your xsd there and point your wsdl to that definition:
<xsd:schema>
<xsd:import namespace="http://jaxws.com.your.ns" schemaLocation="/your.xsd"/>
</xsd:schema>
Now this will make your xsd available at http://localhost:8080/your.xsd

Related

Liferay Vaadin bootstrap Content Encoding Error

I'm trying to convert our Vaadin porlets to serve the theme, widgetset etc from the portlets own web application rather that from the ROOT (Liferay) application but am hitting a content encoding problem.
I've added to the portlet.xml
<init-param>
<name>vaadin.resources.path</name>
<value>PORTLET_CONTEXT</value>
</init-param>
and to the web.xml
<servlet>
<servlet-name>VaadinServlet</servlet-name>
<servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>VaadinServlet</servlet-name>
<url-pattern>/VAADIN/*</url-pattern>
</servlet-mapping>
The portlets wont start as they can't load {WEB_APP}/VAADIN/vaadinBootstrap.js?v.7.7.7
If I try and load the js file manually in Firefox the error I get is
Content Encoding Error
The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression.
Please contact the website owners to inform them of this problem.
If I use wget to load the URL it works perfectly and downloads the bootstrap.js file.
We have Liferay 6.2EE and Vaadin 7.7.7
I've managed to solve this. It appears that VaadinServlet checks for the gzip header, and if found returns the .gz version of the file. This was subsequently getting gzipped again by the HTTP server. The solution was to override the Servlet and disable the gzip code.
<servlet>
<servlet-name>VaadinServlet</servlet-name>
<servlet-class>com.foo.MyVaadinServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>VaadinServlet</servlet-name>
<url-pattern>/VAADIN/*</url-pattern>
</servlet-mapping>
Then created a custom Servlet like this where I always return false for allowServePrecompressedResource.
package com.foo;
import javax.servlet.http.HttpServletRequest;
import com.vaadin.server.VaadinServlet;
public class MyVaadinServlet extends VaadinServlet {
#Override
protected boolean allowServePrecompressedResource(HttpServletRequest request, String url)
{
return false;
}
}

Error 500: javax.servlet.ServletException: Filter [SBTFilter]

I am following the lab manual: Getting started with IBM Connections Cloud. Last updated November 19 2014 by Jan Smolenski.
After I have setup the project and run the server (step 109) and open the mysocial.webapp url I get the message:
Error 500: javax.servlet.ServletException: Filter [SBTFilter]: Could not find required filter class - com.ibm.sbt.util.SBTFilter.class
In the console I read:
[ERROR ] SRVE0321E: The [SBTFilter] filter did not load during start up.
How can I include the sbtfilter during startup? Should I import additional libraries from the SDK or alter my configuration?
I run the samples exactly as declared in the lab manual...
There is a sample project called social.helloworld.webapp. You can look at the following web.xml
https://github.com/OpenNTF/SocialSDK/blob/master/samples/j2ee/templates/social.helloworld.webapp/src/main/webapp/WEB-INF/web.xml
Copy the Following Lines
<servlet>
<description>The service servlet handles requests from the toolkit to access external resources.</description>
<display-name>Social Business Toolkit Service Servlet</display-name>
<servlet-name>ServiceServlet</servlet-name>
<servlet-class>com.ibm.sbt.service.core.servlet.ServiceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServiceServlet</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
<servlet>
<description>This servlet initializes the specified JavaScript library for use by the Social Business Toolkit.</description>
<display-name>Social Business Toolkit Library Servlet</display-name>
<servlet-name>LibraryServlet</servlet-name>
<servlet-class>com.ibm.sbt.jslibrary.servlet.LibraryServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LibraryServlet</servlet-name>
<url-pattern>/library/*</url-pattern>
</servlet-mapping>
<filter>
<description>This filter is responsible for creating the toolkit application and context objects for every servlet within this web application.</description>
<display-name>Social Business Toolkit Filter</display-name>
<filter-name>SBTFilter</filter-name>
<filter-class>com.ibm.sbt.util.SBTFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SBTFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<resource-ref>
<description>Reference to a URL resource which points to the managed bean configuration for the Social Business Toolkit.</description>
<res-ref-name>url/ibmsbt-managedbeansxml</res-ref-name>
<res-type>java.net.URL</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<resource-ref>
<description>Reference to a URL resource which points to the configuration properties for the Social Business Toolkit.</description>
<res-ref-name>url/ibmsbt-sbtproperties</res-ref-name>
<res-type>java.net.URL</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
and then restart your webapp
you can also make sure that the jar files exist.
Another good reference is... https://github.com/OpenNTF/SocialSDK/wiki/Building-your-first-social-enabled-jsp

How do you override a log4j2 configuration file with another log4j2 configuration file?

My current web application uses log4j 1.2, and I'd like to migrate to log4j2, but I haven't been able to figure out how to handle my particular use case.
In my web app's war file, I store a log4j configuration file which has reasonable defaults. My design is to search for a configuration file external to the war file which would override the configuration bundled with the war. That way logging configuration is configured at deployment time and can be different for each server.
Using log4j 1.2, this is accomplished via a ServletContextListener with the following method and it works great:
/**
* Configures system-wide log4j logging system with log4j.xml from the
* class path. This overrides configuration from the default location in
* Tomcat: WEB-INF/classes
*/
private void configureLog4J() {
URL url = ClassLoader.getSystemResource("log4j.xml");
if (url != null) {
DOMConfigurator.configure(url);
log = org.apache.log4j.LogManager.getLogger(LDSContextListener.class);
log.info("log4j.xml loaded from " + url);
}
}
If I'm going to migrate to log4j2, how can I override the internal file with configuration from an external file? log4j2 doesn't have DOMConfigurator in its API.
I found a solution that doesn't exactly replicate what I had before, but comes close enough.
Instead of programmatically configuring log4j, I add log4j-web-2.0.jar to my classpath and add the following to my web.xml:
<context-param>
<param-name>isLog4jAutoInitializationDisabled</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>log4jConfiguration</param-name>
<param-value>file:///usr/jboss/ldsconf/log4j2.xml</param-value>
</context-param>
<listener>
<listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
</listener>
<filter>
<filter-name>log4jServletFilter</filter-name>
<filter-class>org.apache.logging.log4j.web.Log4jServletFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>log4jServletFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
<dispatcher>ASYNC</dispatcher><!-- Servlet 3.0 w/ disabled auto-initialization only; not supported in 2.5 -->
</filter-mapping>
where the log4jConfiguration context-param specifies where my external configuration file is. This isn't the same as the ClassLoader searching the classpath for the configuration file, but it still allows me to reference an external configuration file. Also, if this file isn't present, the system falls back to the internal configuration file, which is exactly what I wanted.
Reference: http://logging.apache.org/log4j/2.x/manual/webapp.html
You can add an environment variable called LOG4J_CONFIGURATION_FILE while you start the application.
I suggest you create a feature request on the Log4j2 Jira issue tracker.

Configure web service in seam ("no active application context")

I am building a web service using seam 2.0.1 and deploying it on jboss 4.2.2 GA. I have my web service class which access another class (updates stuff in data base).
I have standard-jaxws-endpoint-config.xml in META-INF folder.
#Name("pluginHandler")
#Scope(ScopeType.APPLICATION)
#Install(precedence = Install.BUILT_IN)
#Startup(depends = "someclass")
#Stateless
#WebService(name = "Plugin", serviceName = "PluginService")
public class PlugInHandler {
#WebMethod
public int processRequest(Account account)
{
Workbench wb = Component.getInstance("Workbench");
//above line keeps throwing exception "No application context active"
}
}
I have been looking all over different forums, but I cannot find a solution. I tried using Lifecycle.begincall() and Lifecycle.endCall() but nothing worked.
Do I need web.xml as well? If yes what information should web.xml contain?
Any help would be highly appreciated.
I recognize that this is question is rather dated, but to those few poor souls out there that still share your (and, currently my) predicament, here are a few pointers (dragged together from various sources but mainly from https://community.jboss.org/thread/192046):
Java EE WebService
First, using JBoss 4.2.2 likely means using Java EE5. WebServices there (with or without SEAM 2) can only be created on top of Stateless Session Beans. Stateless Session Beans in Java EE 5 need to implement a Service Endpoint Interface annotated with #Local or #Remote. While this has become optional in Java EE6, it is still mandatory here.
So:
#Local
public interface PluginHandlerInterface {
int processRequest(Account account);
}
#WebService
#Stateless
public PluginHandler implements PluginHandlerInterface { }
POJO WebService
If, in seam, you want to use a regular POJO as web-service, your class has to have another special annotation defining a Handler chain:
#WebService
// This here makes all the difference!
#HandlerChain(file = "web-service-handler-chain.xml")
public class PluginHandler {
...
}
This is the handler chain you put in /WEB-INF/classes/web-service-handler-chain.xml:
<?xml version="1.0" encoding="UTF-8"?>
<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
<handler-chain>
<handler>
<description>seam request handler</description>
<!-- probably not necessary
<handler-name>org.jboss.seam.webservice.SOAPRequestHandler</handler-name>
-->
<handler-class>org.jboss.seam.webservice.SOAPRequestHandler</handler-class>
</handler>
</handler-chain>
</handler-chains>
And you have to announce your service class to the war files web.xml like so:
<listener> <!-- this might already be present in your web.xml -->
<listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
</listener>
<servlet> <!-- Which class is to be used? -->
<servlet-name>PluginHandler</servlet-name>
<servlet-class>your.package.name.PluginHandler</servlet-class>
</servlet>
<servlet-mapping>
<!-- you'll find it under http://localhost:8080/your-war/PluginHandler?wsdl-->
<servlet-name>PluginHandler</servlet-name>
<url-pattern>/PluginHandler</url-pattern>
</servlet-mapping>
So these three steps, creating the handler chain, adding the annotation and announcing your service to the web.xml, should do the trick for you in SEAM: You'll have a web-service and the SEAM Context available right in it.

Dispatcher-servlet.xml - not mandatory?

I am working on an assignment that is already built to some extent. It is a Spring 3.0 project with Spring Integration and Spring MVC. I see that in web.xml, the is defined and the name is associated to the DispatcherServlet class. But in /web-inf/ I don't see the Dispatcher-servlet.xml
when I looked at the spring documentation, I read that the Dispatcher-servlet.xml is mandatory.
The app is working fine. The jsp is fetched and the flow is as expected.But without the Dispatcher-servlet.xml, how is it working? Any thoughts?
Thanks,
Jan.
Eg: here is my web.xml definition. Over here my dispatcherservlet name is springController-servlet.xml which is placed in the web-inf folder.
<servlet>
<servlet-name>springController</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springController</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
Check yours and revert back. Spring requires a dispatcher servlet file.

Resources