Stateless Spring Security usage - web-services

I need your help with stateless Spring Security. I wrote service that authorize user, my security.xml:
<http use-expressions="true" create-session="stateless" entry-point-ref="restAuthenticationEntryPoint">
<intercept-url pattern="/auth/**" access="permitAll" />
<intercept-url pattern="/**" access="isAuthenticated()" />
<custom-filter ref="myFilter" position="FORM_LOGIN_FILTER"/>
</http>
<beans:bean id="myFilter" class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter">
<beans:property name="authenticationManager" ref="authenticationManager"/>
</beans:bean>
<authentication-manager alias="authenticationManager">
<authentication-provider user-service-ref="userDetailsService" />
</authentication-manager>
It hasn't state, thats why after my authentication, when I want get anything via another URL, it takes me 401 Unauthorized. I heard about token but I don't know how achieve this.

Maximus,
This is what I did in similar scenario:
Used OAuth - http://oauth.net/
There are multiple libraries that implement OAuth specifications
http://tools.ietf.org/html/rfc6749
Spring has an implementation that is easy to configure. There are two sample applications (server and client) from Spring for this. Tutorials are available at:
https://github.com/SpringSource/spring-security-oauth/wiki/tutorial
Sample working config:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oauth="http://www.springframework.org/schema/security/oauth2"
xmlns:ss="http://www.springframework.org/schema/security" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/security/oauth2
http://www.springframework.org/schema/security/spring-security-oauth2-1.0.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
">
<ss:http pattern="/test/customer/**" create-session="stateless"
access-decision-manager-ref="accessDecisionManager"
entry-point-ref="oauthAuthenticationEntryPoint"
xmlns="http://www.springframework.org/schema/security">
<ss:anonymous enabled="false" />
<ss:intercept-url pattern="/test/customer/welcome*"
access="ROLE_USER" />
<ss:custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" />
<ss:access-denied-handler ref="oauth2AccessDeniedHandler" />
</ss:http>
<ss:http pattern="/oauth/token" create-session="stateless"
entry-point-ref="oauthAuthenticationEntryPoint"
authentication-manager-ref="authenticationManager">
<ss:intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_FULLY" />
<ss:anonymous enabled="false" />
<ss:custom-filter ref="clientCredentialsTokenEndpointFilter"
before="BASIC_AUTH_FILTER" />
<ss:access-denied-handler ref="oauth2AccessDeniedHandler" />
</ss:http>
<ss:authentication-manager alias="authenticationManager">
<ss:authentication-provider ref="myAuthenticationProvider" />
</ss:authentication-manager>
<oauth:resource-server id="resourceServerFilter" token-services-ref="tokenServices" />
<bean id="myAuthenticationProvider" class="com.sachin.test.ws.user.MyUserAuthenticationProvider" />
<bean id="oauthAuthenticationEntryPoint"
class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
<property name="realmName" value="myCustomerAppRealm" />
</bean>
<bean id="clientDetailsUserService"
class="org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService">
<constructor-arg ref="clientDetailsService" />
</bean>
<oauth:authorization-server
client-details-service-ref="clientDetailsService" token-services-ref="tokenServices">
<oauth:authorization-code />
<oauth:implicit />
<oauth:refresh-token />
<oauth:client-credentials />
<oauth:password />
</oauth:authorization-server>
<oauth:client-details-service id="clientDetailsService">
<oauth:client client-id="admin"
authorized-grant-types="password,authorization_code,refresh_token,implicit,client_credentials"
authorities="ROLE_USER, ROLE_TRUSTED_CLIENT" scope="read,write,trust"
access-token-validity="60" />
</oauth:client-details-service>
<bean id="oauth2AccessDeniedHandler"
class="org.springframework.security.web.access.AccessDeniedHandlerImpl" />
<bean id="clientCredentialsTokenEndpointFilter"
class="org.springframework.security.oauth2.provider.client.ClientCredentialsTokenEndpointFilter">
<property name="authenticationManager" ref="authenticationManager" />
</bean>
<bean id="accessDecisionManager" class="org.springframework.security.access.vote.UnanimousBased"
xmlns="http://www.springframework.org/schema/beans">
<constructor-arg>
<list>
<bean class="org.springframework.security.oauth2.provider.vote.ScopeVoter" />
<bean class="org.springframework.security.access.vote.RoleVoter" />
<bean class="org.springframework.security.access.vote.AuthenticatedVoter" />
</list>
</constructor-arg>
</bean>
<bean id="tokenStore"
class="org.springframework.security.oauth2.provider.token.InMemoryTokenStore" />
<bean id="tokenServices"
class="org.springframework.security.oauth2.provider.token.DefaultTokenServices">
<property name="tokenStore" ref="tokenStore" />
<property name="supportRefreshToken" value="true" />
</bean>
</beans>
Add this to web.xml:
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
You'll need to read the specs for OAuth and Spring security to understand what I did. You may extend this code to use your DB for authentication and token sharing across multiple servers.
Hope this helps.

Related

Servlet filter invoke not on default port [duplicate]

I'm running embedded jetty inside of a spring ioc container. The spring ioc contains also an embedded hsqldb which makes the whole configuration a nice and complete web application development environment (on a single JVM). Now I'm trying to add apache CXF to this environment to make the jetty host not only servlets but also web services.
Unfortunately I'm getting NullPointerException when attempting to access http://127.0.0.1:8080/cxf/* (servlets and static content are served ok). Any idea what's wrong?
2010-09-17 15:37:20,099 [btpool0-1 - /cxf/] DEBUG org.mortbay.log - REQUEST /cxf/ on org.mortbay.jetty.HttpConnection#2d14d18f
2010-09-17 15:37:20,100 [btpool0-1 - /cxf/] DEBUG org.mortbay.log - servlet=cxf-servlet-holder
2010-09-17 15:37:20,100 [btpool0-1 - /cxf/] DEBUG org.mortbay.log - chain=null
2010-09-17 15:37:20,100 [btpool0-1 - /cxf/] DEBUG org.mortbay.log - servelet holder=cxf-servlet-holder
2010-09-17 15:37:20,101 [btpool0-1 - /cxf/] ERROR org.mortbay.log - /cxf/
java.lang.NullPointerException
at org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:142)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:179)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:108)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:159)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:367)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
at org.mortbay.jetty.Server.handle(Server.java:281)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:502)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:821)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:208)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:378)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:368)
at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)
I'm initializing spring with:
public static void main(String[] args) throws Exception {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[] { "jetty-beans.xml" , "cxf-beans.xml" });
applicationContext.getBean("web-server", Server.class).join();
}
jetty-beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean name="web-server" class="org.mortbay.jetty.Server"
init-method="start">
<property name="connectors">
<list>
<bean class="org.mortbay.jetty.nio.SelectChannelConnector">
<property name="host" value="localhost" />
<property name="port" value="8080" />
</bean>
</list>
</property>
<property name="handlers">
<list>
<ref bean="web-server-context-static" />
<ref bean="web-server-context-servlet" />
<ref bean="web-server-context-cxf" />
</list>
</property>
</bean>
<bean name="web-server-context-static" class="org.mortbay.jetty.servlet.Context">
<property name="contextPath" value="/static" />
<property name="handler">
<bean class="org.mortbay.jetty.handler.ResourceHandler">
<property name="resourceBase" value="static" />
</bean>
</property>
</bean>
<bean name="web-server-context-servlet" class="org.mortbay.jetty.servlet.Context">
<property name="contextPath" value="/servlet" />
<property name="handler">
<bean class="org.mortbay.jetty.servlet.ServletHandler">
<property name="servlets">
<list>
<bean class="org.mortbay.jetty.servlet.ServletHolder">
<property name="name" value="servlet-holder" />
<property name="servlet">
<bean class="test.TestServlet" />
</property>
</bean>
</list>
</property>
<property name="servletMappings">
<list>
<bean class="org.mortbay.jetty.servlet.ServletMapping">
<property name="servletName" value="servlet-holder" />
<property name="pathSpec" value="/*" />
</bean>
</list>
</property>
</bean>
</property>
</bean>
<bean name="web-server-context-cxf" class="org.mortbay.jetty.servlet.Context">
<property name="contextPath" value="/cxf" />
<property name="handler">
<bean class="org.mortbay.jetty.servlet.ServletHandler">
<property name="servlets">
<list>
<bean class="org.mortbay.jetty.servlet.ServletHolder">
<property name="name" value="cxf-servlet-holder" />
<property name="servlet">
<bean class="org.apache.cxf.transport.servlet.CXFServlet">
</bean>
</property>
</bean>
</list>
</property>
<property name="servletMappings">
<list>
<bean class="org.mortbay.jetty.servlet.ServletMapping">
<property name="servletName" value="cxf-servlet-holder" />
<property name="pathSpec" value="/*" />
</bean>
</list>
</property>
</bean>
</property>
</bean>
</beans>
cxf-beans.xml:
<?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:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<bean id="test-ws-impl" class="test.TestWSImpl" />
<jaxws:endpoint id="test-ws-endpoint" implementor="#test-ws-impl"
address="/testWS" />
</beans>
classpath:
activation-1.1.jar
commons-logging-1.1.1.jar
cxf-2.2.10.jar
jaxb-api-2.1.jar
jaxb-impl-2.1.13.jar
jcl-over-slf4j-1.6.1.jar
jetty-6.1.3.jar
jetty-annotations-6.1.3.jar
jetty-util-6.1.3.jar
log4j-1.2.16.jar
neethi-2.0.4.jar
org.springframework.aop-3.0.3.RELEASE.jar
org.springframework.asm-3.0.3.RELEASE.jar
org.springframework.beans-3.0.3.RELEASE.jar
org.springframework.context-3.0.3.RELEASE.jar
org.springframework.context.support-3.0.3.RELEASE.jar
org.springframework.core-3.0.3.RELEASE.jar
org.springframework.expression-3.0.3.RELEASE.jar
servlet-api-2.5-6.1.3.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
wsdl4j-1.6.2.jar
XmlSchema-1.4.5.jar
TestWSImpl.java:
package test;
import javax.jws.WebService;
#WebService(endpointInterface = "test.TestWSInterface")
public class TestWSImpl implements TestWSInterface {
#Override
public String doTest(String testSubject) {
return "successfully tested:" + testSubject;
}
}
TestWSInterface.java
package test;
import javax.jws.WebParam;
import javax.jws.WebService;
#WebService
public interface TestWSInterface {
String doTest(#WebParam String testSubject);
}
I've found out that the above configuration was wrong:
I did not use any WebApplicationContext with has to be initialized prior to the CXFServlet. The simple solution is to use the non-spring version of CXFServlet - it does not require any ApplicationContext (I don't want to create a separate ApplicationContext for the Web Services since I need to have shared DataSource between them) but it has too be initialized (Web Services must be published in the code).
After solving the Context issue I've found out that jetty 6.1 does not initialize the servlet context in proper way, everything works fine after updating to 7.x.
After writing custom WebApplicationContext I was able to use the main/root ApplicationContext as the WebApplicationContext allowing me to use the spring version of CXFServlet with about 6 lines of glue code.

HistoryLevel mismatch on Camunda 7.2

I deployed camunda.war (7.2) into my vanilla tomcat7 following the guide on official web-site.
Now when i starting tomcat i have the following error:
GRAVE: Error while closing command context
org.camunda.bpm.engine.ProcessEngineException: historyLevel mismatch: configuration says org.camunda.bpm.engine.impl.history.HistoryLevelAudit#21 and database says 3
In the database (ACT_GE_PROPERTY table) the historyLevel is set to 3
this is my bpm-platform.xml file
<?xml version="1.0" encoding="UTF-8"?>
<bpm-platform xmlns="http://www.camunda.org/schema/1.0/BpmPlatform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.camunda.org/schema/1.0/BpmPlatform http://www.camunda.org/schema/1.0/BpmPlatform ">
<job-executor>
<job-acquisition name="default" />
</job-executor>
<process-engine name="default">
<job-acquisition>default</job-acquisition>
<configuration>org.camunda.bpm.engine.impl.cfg.StandaloneProcessEngineConfiguration</configuration>
<datasource>java:jdbc/solve</datasource>
<properties>
<property name="history">full</property>
<property name="databaseSchemaUpdate">true</property>
<property name="authorizationEnabled">true</property>
<property name="jobExecutorDeploymentAware">true</property>
</properties>
<plugins>
<!-- plugin enabling Process Application event listener support -->
<plugin>
<class>org.camunda.bpm.application.impl.event.ProcessApplicationEventListenerPlugin</class>
</plugin>
<!-- plugin enabling integration of camunda Spin -->
<plugin>
<class>org.camunda.spin.plugin.impl.SpinProcessEnginePlugin</class>
</plugin>
<!-- plugin enabling connect support -->
<plugin>
<class>org.camunda.connect.plugin.impl.ConnectProcessEnginePlugin</class>
</plugin>
</plugins>
</process-engine>
</bpm-platform>
EDIT
Processes.xml
<?xml version="1.0" encoding="UTF-8" ?>
<process-application
xmlns="http://www.camunda.org/schema/1.0/ProcessApplication"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<process-archive name="MyProcess">
<process-engine>myEngine</process-engine>
<properties>
<property name="isDeleteUponUndeploy">false</property>
<property name="isScanForProcessDefinitions">true</property>
</properties>
</process-archive>
</process-application>
applicationContext.xml
<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd">
<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/my_process" />
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="processEngineConfiguration" class="org.camunda.bpm.engine.spring.SpringProcessEngineConfiguration">
<property name="processEngineName" value="myEngine" />
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="databaseSchemaUpdate" value="true" />
<property name="jobExecutorActivate" value="false" />
<property name="deploymentResources" value="classpath*:*.bpmn" />
<property name="processEnginePlugins">
<list>
<bean id="spinPlugin" class="org.camunda.spin.plugin.impl.SpinProcessEnginePlugin" />
</list>
</property>
</bean>
<bean id="processEngine" class="org.camunda.bpm.engine.spring.container.ManagedProcessEngineFactoryBean" destroy-method="destroy">
<property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>
<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
<bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
<bean id="MyProcess" class="org.camunda.bpm.engine.spring.application.SpringServletProcessApplication" />
<context:annotation-config />
<bean class="it.processes.Starter" />
<bean id="cudOnProcessVariableService" class="it.services.CUDonProcessVariableService" />
</beans>
Did you download the 'camunda standalone webapp' WAR for Tomcat from camunda.org/download?
If so, you should adjust the history level inside the 'application-context.xml' file by adding <property name="history" value="full"/> to the process engine configuration bean <bean id="processEngineConfiguration" class="org.camunda.bpm.engine.spring.SpringProcessEngineConfiguration>.
Otherwise it is strange that you write you install camunda.war to a vanilla Tomcat but post a reference to your bpm-platform.xml file which is not used at all when you are not using the shared process engine approach.

Handling multiple Rest web services using Spring and Castor

Would anyone be able to advise me on the best way of handling access to multiple Rest web services using Springs RestTemplate?
I know that the RestTemplate object has a message converter reference (MarshallingHttpMessageConverter) which in turn has a reference to an unmarshaller. In my case I am using the Spring Frameworks CastorMarshaller object with associated mapping file.
Normally I could have just added all my mappings to one Castor mapping file. However in my case all the web services are of this format (block below) with the < rows ... /> holding different entities depending on the service called.
<data>
<output>
<dataset>
<row id="" .... />
<row id="" .... />
<row id="" .... />
<row id="" .... />
<row id="" .... />
</dataset>
</output>
<nextUpdate><nextUpdate/>
</data>
The CastorMarshaller is injected into the MessageConverter which itself is injected into the RestTemplate in the application context configuration file.
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
<property name="marshaller" ref="castorMarshaller"/>
<property name="unmarshaller" ref="castorMarshaller"/>
<property name="supportedMediaTypes">
<list>
<bean class="org.springframework.http.MediaType">
<constructor-arg index="0" value="application"/>
<constructor-arg index="1" value="xml"/>
</bean>
<bean class="org.springframework.http.MediaType">
<constructor-arg index="0" value="text"/>
<constructor-arg index="1" value="xml"/>
</bean>
</list>
</property>
</bean>
</list>
</property>
</bean>
<bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller">
<property name="mappingLocation" value="classpath:oxm-mapping-worldweather.xml"/>
</bean>
Possible options that I have been thinking about:
1 Create multiple RestTemplates for each Rest service.
2 Create multiple MessageConverters for the different services and change the message converters on the template when accessing a different service.
3 Create multiple CasterMarshaller objects for the different services and update the message converter with the new unmarshaller
What is the best way to approach handling multiple services like this with the same root and sub elements?
Thanks in advance
Sman UK
If specifying multiple mapping files is the issue then below is the solution.
Use mappingLocations property instead of mappingLocation as given below,
<bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller">
<property name="mappingLocations">
<list>
<value>classpath:oxm-mapping-worldweather.xml</value>
<value>classpath:sample-mapping.xml</value>
</list>
</property>
</bean>

Spring - WEB services Problem in Instantiation

HI ALL
I am trying to expose spring webservice i am facing one problem My Service Object is not getting initialized
---------------End point Class--------------
import org.springframework.ws.server.endpoint.AbstractMarshallingPayloadEndpoint;
import com.mt.service.CalculatorService;
public abstract class AbstractCalculatorEndpoint extends AbstractMarshallingPayloadEndpoint {
protected CalculatorService calculatorService;
public void setCalcService(CalculatorService calculatorService) {
this.calculatorService = calculatorService;
}
protected abstract Object invokeInternal(Object request) throws Exception;
}
-----------AddNumberEndpoint Class------------
package com.mt.endpoint;
import com.mt.calculator.schema.AddNumberRequest;
public class AddNumberEndpoint extends AbstractCalculatorEndpoint {
#Override
protected Object invokeInternal(Object request) throws Exception {
AddNumberRequest addNumberRequest = (AddNumberRequest) request;
if( calculatorService==null )
System.out.println("------------------- I AM NULL ------- :( ");
return calculatorService.addTwoNumber(addNumberRequest.getFirstNumber(),
addNumberRequest.getSecondNumber());
}
}
My Servlet Configuration
<?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:oxm="http://www.springframework.org/schema/oxm"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/oxm
http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd">
<bean id="calculatorService" class="com.mt.service.CalculatorServiceImpl"
init-method="initialize" />
<bean id="Calculator"
class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
<property name="schema" ref="schema" />
<property name="portTypeName" value="Calculator" />
<property name="locationUri" value="/services" />
<property name="targetNamespace" value="http://www.mt.com/calculator/schema" />
</bean>
<bean id="schema" class="org.springframework.xml.xsd.SimpleXsdSchema">
<property name="xsd" value="/WEB-INF/calculator.xsd" />
</bean>
<bean id="validatingInterceptor"
class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
<property name="xsdSchema" ref="schema" />
<property name="validateRequest" value="true" />
<property name="validateResponse" value="true" />
</bean>
<bean id="loggingInterceptor"
class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor" />
<oxm:jaxb2-marshaller id="marshaller"
contextPath="com.mt.calculator.schema" />
<oxm:jaxb2-marshaller id="unmarshaller"
contextPath="com.mt.calculator.schema" />
<bean id="addNumberEndpoint" class=" com.mt.endpoint.AddNumberEndpoint"
autowire="byName" />
<bean name="endpointMapping"
class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
<property name="interceptors">
<list>
<ref local="loggingInterceptor" />
<ref local="validatingInterceptor" />
</list>
</property>
<property name="mappings">
<props>
<prop key="{http://www.mt.com/calculator/schema}AddNumberRequest">
addNumberEndpoint</prop>
</props>
</property>
</bean>
<bean id="exceptionResolver"
class="org.springframework.ws.soap.server.endpoint.SoapFaultMappingExceptionResolver">
<property name="defaultFault" value="SERVER" />
<property name="exceptionMappings">
<props>
<prop key="org.springframework.oxm.ValidationFailureException">CLIENT,Invalid request</prop>
<prop key="com.mt.service.CalculatorException">SERVER</prop>
</props>
</property>
</bean>
</beans>
Plese Let me know if you need any other information
Thanks A Lot
Thanks A Lot Previous Exception gone Now I Am Getting --------
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring xml:lang="en">JAXB marshalling exception; nested exception is javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.SAXException2: unable to marshal type "java.lang.Integer" as an element because it is missing an #XmlRootElement annotation]</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
You are autowiring addNumberEndpoint by name so Spring will look for calcService to bind to it (because of the setter name) but the id of CalculatorService is calculatorService.
Change setCalcService(...) to setCalculatorService(...) in AbstractCalculatorEndpoint

Spring, Apache CXF and Embedded Jetty

I'm trying create a web service capable server using Apache CXF, Spring and an embedded Jetty server. When I run my project the server seems to initialize correctly, however when I navigate to http://localhost:8080/SomeService expecting to see the service WSDL, instead I get the following exception:
SEVERE: /SomeService
java.lang.NullPointerException
at org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:163)
at org.apache.cxf.transport.servlet.AbstractCXFServlet.doGet(AbstractCXFServlet.java:145)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:502)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:389)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:535)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:865)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:539)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:520)
Any ideas?
Here's the Java main()
public static void main(String[] args) throws Exception {
new ClassPathXmlApplicationContext(new String[] {"beans-jetty.xml"});
}
beans-jetty.xml
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="file:conf/server.properties" />
</bean>
<bean id="server"
class="org.mortbay.jetty.Server"
init-method="start"
destroy-method="stop">
<property name="connectors">
<list>
<bean id="connector" class="org.mortbay.jetty.nio.SelectChannelConnector">
<property name="host" value="${server.address}"/>
<property name="port" value="${server.port}"/>
</bean>
</list>
</property>
<property name="handlers">
<list>
<ref bean="context-cxf"/>
</list>
</property>
</bean>
<bean name="context-cxf" class="org.mortbay.jetty.servlet.Context">
<property name="contextPath" value="/" />
<property name="handler">
<bean class="org.mortbay.jetty.servlet.ServletHandler">
<property name="servlets">
<list>
<bean class="org.mortbay.jetty.servlet.ServletHolder">
<property name="name" value="cxf-servlet-holder" />
<property name="servlet">
<bean class="org.apache.cxf.transport.servlet.CXFServlet" />
</property>
</bean>
</list>
</property>
<property name="servletMappings">
<list>
<bean class="org.mortbay.jetty.servlet.ServletMapping">
<property name="servletName" value="cxf-servlet-holder" />
<property name="pathSpec" value="/*" />
</bean>
</list>
</property>
</bean>
</property>
</bean>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<import resource="classpath:/beans-cxf.xml" />
beans-cxf.xml
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<jaxws:endpoint
id="someService"
implementor="com.awebster.gitta.services.SomeServiceImpl"
address="${server.address}" />
I should mention that I'm using the Maven one-jar plugin, although I doubt that makes any difference to this problem.
Many Thanks in advance!
Anthony