Bean Validation Made Simple With JSR 303

http://java.dzone.com/articles/bean-validation-made-simple   The URL above explains clearly and concisely how to avoid checking that a value meets a constraint without the need for an if(isStringValueNull?) code block.

Advertisements

No adapter for endpoint

“Is your endpoint annotated with @Endpoint, or does it implement a supported interface like MessageHandler or PayloadEndpoint?”

I spent more time* figuring out the cause of this exception than Sylvinho spent marauding down the left wing for Arsenal.

For a long time I thout it was due to the fact that I was trying to declare two methods in one endpoint class. I knew it wasnt the problem as I had seen it done.

I read elsewhere that the problem may have been a dependency clash / maven issue, again this was not the case.

 

The issue was that I was not consistent from my xsd right through to the service method. A simple example of what I was doing:

 

My xsd:

<xsd:element name=”CreateAccountRequest”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=”AccountDetails” type=”account:Account”/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name=”CreateAccountResponse“>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=”accountID” type=”xsd:string“/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

my service endpoint was:

@PayloadRoot(localPart = “CreateAccountRequest”, namespace = TARGET_NAMESPACE)
public @ResponsePayload
String createAccount(
@RequestPayload CreateAccountRequest request) {

return (“31”);
}

 

my endpoint needed to be:

@PayloadRoot(localPart = “CreateAccountRequest”, namespace = TARGET_NAMESPACE)
public @ResponsePayload
CreateAccountResponse createAccount(
@RequestPayload CreateAccountRequest request) {

CreateAccountResponse response = new CreateAccountResponse();

response.setAccountID(“31”);
return response;
}

ie – my xsd was calling for a CreateAccountResponse object to be returned containing a String, I was simply trying to return a String.

 

 

 

Sylvinho.jpg

*he was at Arsenal for 2 years, I didnt spend quite two years figuring this out.

Spring Exceptions and Errors

I am learning how spring works so as a reference for myself here are some errors and or exceptions that have had me wondering whats going on. While working through Brians excellent Java Blog for Spring novices, I tried setting up his Service but customised to my own applications needs.

 

  1. Endpoint mapping [org.springframework.ws.soap.server.endpoint.mapping.SoapActionAnnotationMethodEndpointMapping@25dad8eb] has no mapping for request  – Cause by having the wrong payload root localpart set in the endpoint java class.

Deploy the Spring application, reading from different properties files.

From the good person over at MyThinkPond, here is how I deployed the same WAR file, into the same webapps directory of Tomcat, but had it read from different properties files. The reason for my need to do this was that I wanted the application, depending on its URL (the war file name) to pick up its relevant properties file.

Therefore, I needed the app to be able to know its name.

Just like my buddy over at  MyThinkPond I created the following class with a static method to get my context:

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class ApplicationContextProvider implements ApplicationContextAware{
 private static ApplicationContext ctx = null;
 public static ApplicationContext getApplicationContext() {
return ctx;
 }
 public void setApplicationContext(ApplicationContext ctx) throws BeansException {
this.ctx = ctx;
 }
}

and in my spring bean configuration xml file I added the following:

 <bean id="applicationContextProvider" class="com.mydomain.myappname.ApplicationContextProvider"></bean>

and then in my classes, I was able to do the following:

ApplicationContext ctx = ApplicationContextProvider.getApplicationContext();

step-up-your-context-path

Igor Stepanovs was famous for changing his property files depending on his application name.