JAX-RS(CXF) JSONProvider - rest

I am new to JAX-RS, I am just starting with apache CXF, I am struck at "No message body writer has been found for response class" while trying to return "application/jason". I know, I can set the JSONProvider using spring context loader file, but I dont want to use spring. Is there any way to set JSONProvider to the application directly?

I made a mistake in my code, instead "application/json" I wrote "application/jason", I corrected it, and it is working. And I found that no need to set JSON Provider explicitly.

Related

MutableMessageBuilderFactory in Spring Integration

I have a spring cloud stream consumer getting messages from Kafka. I want to modify the message headers, but currently the message I get is of type GenericMessage.
I saw this post and this code from spring integration core so I added to my configuration a bean of type MutableMessageBuilderFactory but I'm still getting the message as GenericMessage. Actually, the bean creating code doesn't even seem to get called, the getMessageBuilderFactory(BeanFactory beanFactory) in IntegrationUtils classs gets called multiple times and everytime beanFactory.getBean("messageBuilderFactory", MessageBuilderFactory.class) returns DefaultMessageBuilderFactory.
What might be the problem causing the factory I defined as bean not to work and the message to keep coming as GenericMessage?
Spring versions:
spring-boot: 1.5.21
spring-integration: 4.3.12
Messages are immutable and there are many reasons for that, but it's out of scope of this question. What you can do is create a new Message in your handler and return it. If you want to copy most of the previous message and then modify the header you can do this:
Message resultMessage = MessageBuilder.fromMessage(sourceMessage).setHeader("myExistingHeader", "foo").build();

Spring WS remove flexible URL, Restricting WSDL URL and service URL

I'm trying to make a Spring Boot Soap WebService application, and was following the Get Started (https://spring.io/guides/gs/producing-web-service/) example to learn how to do this.
I've created what I want, but I have two URL problems with this setup and I could not find what configuration should I change to fix this :
WSDL URL basic is localhost:8080/ws/countries.wsdl but anything like localhost:8080/ws/whatever/countries.wsdl is correct
service URL for SoapUI request is localhost:8080/ws but anything like localhost:8080/ws/whatever is correct
I know that this is a feature for Spring WS, but I want a fixed URL (without 'whatever' in both cases) and could not find what to change for this
There is no straight forward way to restrict the way you want.
SOAP service is not URL based.
SOAP message body describe the endpoint.
The thing you wanted is possible following way.
Changing URL mapping in ServletRegistrationBean to restrict URL access
Existing /ws/* mapping is the reason why all the /ws/whatever url successfully responded.
Change as new ServletRegistrationBean(servlet, "/ws");
Effect will be you can not request other than /ws URL
Now the problem is, you can not get WSDL by this mapping.
Solution to get WSDL
The DefaultWsdl11Definition is actually generating WSDL from XSD on every request.
Save countries.wsdl to resource folder as static WSDL file.
Remove DefaultWsdl11Definition bean.
Create a new SimpleWsdl11Definition bean as like
#Bean(name = "countries")
public SimpleWsdl11Definition orders() {
SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
wsdl11Definition.setWsdl(new ClassPathResource("countries.wsdl"));
return wsdl11Definition;
}
Now add another static URL mapping in ServletRegistrationBean. As it will be finally look like new ServletRegistrationBean(servlet, "/ws", "/ws/countries.wsdl");
This practice is good for development phase as you can publish easily the changed definition. But it is recommended to use static-wsdl for production environment. Details ** here
Just change
return new ServletRegistrationBean(servlet, "/ws/*");
for example to
return new ServletRegistrationBean(servlet, new String[]{
"/ws/v1/countries.wsdl",
"/ws/v2/countries.wsdl"
});

Grails REST API hide "class" in respond list

I'm using Grails 2.3.2 working on a REST API using the built in Grails REST support. I'm having trouble getting rid of the "class" element in the JSON response. Based on a tutorial by Bobby Warner, I have found adding the following to the resources.groovy file:
meterRenderer(JsonRenderer, Meter) {
excludes = ['class']
}
This works fine for show, but for the index controller function, I'm responding with a list of Meters. In this, the "class" doesn't go away. What does it take to get rid of this in the list response?
Edit: To clarify, I am looking for a way to leverage the Content Negotiation feature of Grails new respond functionality without locking myself down to render as JSON implementions.
I guess if you switch to using GSON (github) instead of JSON then you need not worry about that particular exclusion.
That is driven by a config setting provided by the plugin as grails.converters.gson.domain.include.class (default is false).
nickdos' SO link had the answer. I added the following to my BootStrap.groovy:
grails.converters.JSON.registerObjectMarshaller(Meter) {
return it.properties.findAll {k,v -> k != 'class'}
}
And the respond call results in no "class" item. Oddly enough, I lost the "id" item in the process, but I'll save that for another SO question. :)

Camel mid-route jpa consumer

I faced the following problem with JPA but it's maybe more like a conceptional question about Camel.
I need a cron based Quartz consumer. But if it's triggered, I'd like to make a selection as a 1st step with JPA component.
<from uri="quartz://myQuartz?cron=myCronExpression/>
<to uri="jpa://home.myEntity?consumer.query=select o from home.myEntity o"/>
But if I call the JPA component with "to", then it's used as a Producer, and not as a Consumer. Can I use somehow the JPA component to handle this, or I have to follow the Service Activator (bean-based) logic and leave the JPA component behind?
Thanks in advance,
Gergely
This is pretty much the Content-Enrichement pattern. You can use the
<pollEnrich uri="jpa://home.myEntity?consumer.query=select o from home.myEntity o"/>
instead to use a consumer mid-route. Keep in mind that you cannot use runtime data from the route (headers or the like) but need to keep the route URI static in this case. Seems your URI is static so that should be no issue.
Very good point Petter. I had a similar issue. I wanted to create a simple route that when called will retrieve data from the database. The solutions is simple.
from("direct:test")
.pollEnrich("jpa://" + User.class.getName() + "?consumer.query=select u from test.User u&consumeDelete=false")
Also check this Camel - content enricher: enrich() vs pollEnrich().

zend soap win7/apache cant remove cache

I did everything, i think:
deleted windows/Temp
soap.wsdl_cache_enabled=0 in php.ini and restarted apache
ini_set("soap.wsdl_cache_enabled", "0"); in handleWDSL, handleSOAP and clientAction!
what else? still getting:
Message: Function ("arrays_work") is not a valid method for this service
That is the new function I added to the service. Also, if I change oldones, nothing happens (for instance, adding functionality to access db).
please...
any clues?
This was solved and in this case was related to other thing: the uri for the wdsl was pointing to an oldone... sorry..