GWT RequestContext ENum in the request - gwt

If we use enum as one of the attribute in the Request invocation , it throws an UnsupportedOpeationException and does not even invoke the service method on the server.
#Service(value = DesignService.class, locator = DesignServiceLocator.class)
public interface DesignRequest extends RequestContext {
Request<List<DesignProxy>> findDesign(SortEnum sortorder);
}
when we invoke the designRequest.findDesign(sortorderEnum).fire() the UnsupportOperationException is thrown on the javascript console on chrome dev tools/Firebug console.

Looks like it is related to Issue 6504, which will throw an UnsupportedOperationException if it fails to find the type you are using - consider trying to change to class methods in your enum, or wait until 2.4 is released.
If you are not using anonymous enum instances, can you post more info about this error, such as where the exception is thrown from?

Related

Does Crud Repository has saveAll method that works?

I am trying to use CRUDRepository for my development project. I have seen in many posts that CRUD Repository do support saveAll method which allows to save a list of object in the database. But when I am using it, It is giving me an error that saveAll property is not found
Here is the detailed error
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'BinaryPartCRUDRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query method public abstract java.util.List xxx.xxx.xx.xxxx.repository.BinaryPartCRUDRepository.saveAll(java.util.List)! No property saveAll found for type BinaryPart!
Here is my code.
public interface BinaryPartCRUDRepository extends CrudRepository<BinaryPart, Long> {
BinaryPart save(BinaryPart binaryPart);
List<BinaryPart> saveAll(List<BinaryPart> binaryParts);
}
The save Function is working. But saveAll is not.
I have also tried to use the Persistence manager to do the batch save. But having null object while doing JUnit Testing. So I am preferring to stay with CRUD Repository. Appreciate any kind of suggestion.
saveAll already there in CrudRepository, so no need to specify your own method for save all in repository interface.
remove this part:
List<BinaryPart> saveAll(List<BinaryPart> binaryParts);
and in your service class , directly call `saveAll method. Remember this method using iterable as param and return value.
The saveAll method has the following signature:
<S extends T> Iterable<S> saveAll(Iterable<S> entities);
You define an additional method with the same name, but a different signature. Spring Data does not know how to create an implementation for that and throws the exception.
Just change your interface to:
public interface BinaryPartCRUDRepository extends CrudRepository<BinaryPart, Long> {}
And you are good to go.

How to check whether SOAP fault is being handled gracefully?

I'm using JUnit and Mockito in order to test whether my SOAP web service handles SOAP faults gracefully and doesn't throw any unwanted exceptions for example.
So up until now, as you can see from the code below, I'm only testing whether a SOAPFaultException is being thrown (of course it does, I threw it). I wonder how I could check though whether any other exception would be thrown when receiving the SOAP fault.
Also is there any way to mock a SOAP fault without throwing an exception (SOAPFaultException)?
public class SOAPFaultsTest {
private MyObj myObj = (MyObj) mock(IMockClass.class);
#Before
public void create() {
SOAPFault soapFault = null;
try {
soapFault = SOAPFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL).createFault();
soapFault.setFaultString("unable to create new native thread");
soapFault.setFaultCode(QName.valueOf("soap:Server"));
} catch (SOAPException e) {
e.printStackTrace();
}
// Define behaviour of myObj mock object
when(myObj.randomMethod(any(RandomClass.class))).thenThrow(new SOAPFaultException(soapFault));
}
// Here I'm testing whether invoking myObj's randomMethod with a RandomClass object as an argument throws a SOAPFaultException.
// It does because this is how I defined its behaviour.
// What I really want to test is whether receiving a SOAP fault at any time is going to cause any trouble.
#Test(expected=SOAPFaultException.class)
public void testSOAPException() throws SOAPFaultException {
RandomClass rc = new RandomClass();
myObj.randomMethod(rc);
}
}
I suggest you go with a full-stack mock (i.e. spawn an Endpoint on a local socket, point the client there). Then create a soap fault and let the mock throw an appropriate exception over the wire. If you're using CXF, I've created a simple JUnit Rule which does this, see the test method SoapServiceRuleTest.processSoapCallWithException().
As a general strategy, I suggest you make an abstract 'happy case' unit test which you then sabotage one call at a time by doing reset on the mock with each test method and adding thenThrow(..) correspondingly.

Assert.Pass() throwing exception

I have a constructor as follows
public class MyClass
{
public MyClass()
{
}
}
While writing test cases, i used Assert.Pass().
But it throws an exception of type ArguementNullException
The SuccessException is a convenience for a test runner. This allows you to pass a test and record an optional message. The better way to approach this is to just let the test finish without throwing any exceptions or recording failed assertions.
More info here: http://www.nunit.org/index.php?p=utilityAsserts&r=2.5
If you're using NUnit framework,
Assert.Pass<SuccessException>();
when you want to pass a test.

JAX-RS exception handling

I'm relatively new to REST services in Java. I've created one and everything works fine except error handling. If I make a request with incorrectly formed JSON in it, Jackson JSON processor throws an exception which I unable to catch and I get error 500 in client. Exception follows:
javax.ws.rs.InternalServerErrorException: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.HashSet out of VALUE_STRING token
I have no idea how to handle exceptions raised outside my code.
Google suggests using Exception Mappers or Phase Inteceptors. Though I could miss something in search results.
What is the proper way to handle such situations?
Please, advise something. I'm stuck with this problem...
A JAX-RS ExceptionMapper should do the job. Just add a class like below to your code and if you have the exception type right, then you should get the hook to customize the handling.
#Provider
public class MyExceptionMapper implements ExceptionMapper<MyException> {
#Override
public Response toResponse(MyException ex) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
}

Spring MVC calling webservice endpoint from the browser

I want to be able to call my web service directly from the browser. Calling it from a HTTPClient via the web browser is OK, but if i try and call it directly via the browser I get the following error:
SEVERE: [Request processing failed; nested exception is org.springframework.http.converter.HttpMessageConversionException: Could not instantiate JAXBContext for class [class com.mycompanay.MyClass]: 8 counts of IllegalAnnotationExceptions; nested exception is com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 8 counts of IllegalAnnotationExceptions
com.mycompany.MyInterface is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
com.mycompany.myInteface
at private java.util.List com.mycompanay.MyClass.values
at com.mycompanay.myClass
#XmlAttribute/#XmlValue need to reference a Java type that maps to text in XML.
this problem is related to the following location:
I've tried to reference the implmentation class via the #XMLElement annotation but i'm getting the same error:
public MyClass {
#XmlElement(type=MyInterfaceImpl.class, name="values")
private List<MyInterface> values;
#XmlElement(type=MyInterfaceImpl.class, name="values")
public void getValues() {
return values;
}
}
You were correct to use the #XmlElement annotation to specify the implementation type. The problem is still occurring because by default JAXB will treat public properties as mapped. This is why it is still trying to process the interfaces. Since you have annotated tr field you can add XmlAccessorType(XmlAccessType.FIELD) to your class.
For More Information
http://blog.bdoughan.com/2011/06/using-jaxbs-xmlaccessortype-to.html
http://blog.bdoughan.com/2011/05/jaxb-and-interface-fronted-models.html