I am new to Apache CXF , so please help .
I dont know why the client is not getting called .
client = (BayerService) factory.create();
I did this way
public class RunBayer implements CallbackHandler
{
RunBayer()
{
init();
}
private static void init()
{
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
WSS4JOutInterceptor out = new WSS4JOutInterceptor();
out.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.TIMESTAMP + " " + WSHandlerConstants.SIGNATURE);
out.setProperty(WSHandlerConstants.USER, "svi_ws");
out.setProperty(WSHandlerConstants.PASSWORD_TYPE, "PasswordDigest");
factory.getOutInterceptors().add(out);
factory.setServiceClass(BayerService.class);
factory.setAddress(host);
client = (BayerService) factory.create();
}
}
And I have a BayerService interface which is in this format
public interface BayerService
{
public OurServiceResponse OurView(#WebParam(name = "request") ServiceRequest request);
}
I have another class named Bayer.java which actually implements this Interafce
public class Bayer implements BayerService
{
public OurServiceResponse OurView(ServiceRequest request)
{
// code
}
}
Could anybody please tell me why the control is not coming inside when i call this way ??
Thank you very much .
I didn't see the code like below in your RunBayer class.
client.OurView(request);
Related
I have created a project using abpframwork. When running swagger, swagger receives the function in the application layer is a api. I don't want that. Can you guys tell me how to remove it in swagger
Code in Application Layer
public class UserService : AdminSSOAppService, ITransientDependency, IValidationEnabled, IUserService
{
IUserRepository _userRepository;
private readonly ILogger<UserService> _log;
public UserService(IUserRepository userRepository,
ILogger<UserService> log
)
{
_userRepository = userRepository;
_log = log;
}
public async Task<List<UserDto>> GetList()
{
var list = await _userRepository.GetListAsync();
return ObjectMapper.Map<List<User>, List<UserDto>>(list);
}
public async Task<UserDto> GetUserById(int Id)
{
var user = await _userRepository.GetAsync(c=>c.Id == Id);
return ObjectMapper.Map<User, UserDto>(user);
}
}
Code in HttpApi Layer
[Area(AdminSSORemoteServiceConsts.ModuleName)]
[RemoteService(Name = AdminSSORemoteServiceConsts.RemoteServiceName)]
[Route("api/user/user-profile")]
public class UserController : ControllerBase, IUserService
{
private readonly IUserService _userAppService;
public UserController(IUserService userAppService)
{
_userAppService = userAppService;
}
[HttpGet]
[Route("get-list-httpapi")]
public Task<List<UserDto>> GetList()
{
return _userAppService.GetList();
}
[HttpGet]
[Route("get-by-id-httpapi")]
public Task<UserDto> GetUserById(int Id)
{
return _userAppService.GetUserById(Id);
}
}
I can suggest a workaround as to enable only the APIs you need to appear on swagger (though the ones that don't appear anymore will still be available for consumption).
I would suggest you add a configuration part in your *.Http.Api project module inside your ConfigureSwaggerServices, like so:
context.Services.AddSwaggerGen(options =>
{
options.DocInclusionPredicate(
(_, apiDesc) =>
apiDesc
.CustomAttributes()
.OfType<IncludeInSwaggerDocAttribute>()
.Any());
});
And for the attribute, it would be very simple, like so:
[AttributeUsage(AttributeTargets.Class)]
public class IncludeInSwaggerDocAttribute : Attribute
{
}
This will let you achieve what you want, however I still recommend reading the doc carefully to be able to implement DDD.
I've been working with Hystrix but now I want to change one project from Hystrix to Resilience4J but I don't not how!
My code is as follow:
#FeignClient(name = "customer-service", fallback = CustomerHystrixFallbackFactory.class)
public interface CustomerClient {
#GetMapping(value = "/customers/{id}")
public ResponseEntity<Customer> getCustomer(#PathVariable("id") long id);
}
And my CustomerHystrixFallbackFactory as follow:
#Component
public class CustomerHystrixFallbackFactory implements CustomerClient{
#Override
public ResponseEntity<Customer> getCustomer(long id) {
Customer customer = Customer.builder()
.firstName("none")
.lastName("none")
.email("none")
.photoUrl("none").build();
return ResponseEntity.ok(customer);
}
}
The thing is when customer-service is down, it returns none, but not a 500 Error message.
So, how can I convert what I have to apply Resilience4J?
Thanks in advance!
I'm using Spring AOP for intercept annoted methods by #MyAnnotation. The intercepting is ok. but, unfortunately, i'm not arrive to have my annotation instance.
My Annotation :
#Retention(RetentionPolicy.RUNTIME)
#Target(ElementType.METHOD)
public #interface MyAnnotation {
String[] description();
}
My Configuration Aspect
#Aspect
public class OAuthAspect {
#Pointcut(value = "execution(public * *(..))")
public void anyPublicMethod() {
}
#Pointcut(value = "#annotation(annotation)", argNames = "annotation")
public void anyAnnotationMethod(MyAnnotation annotation) {
}
#Around(value = "anyPublicMethod() && anyAnnotationMethod(annotation)")
public Object authorization(ProceedingJoinPoint pjp, MyAnnotation annotation) throws Throwable {
//annotation is null
}
}
Example pointcut :
#Service
public class ContextService {
#MyAnnotation(description = {"de1", "des2"})
public String getAll() {
}
}
I don't understand why I can't retrieve the instance of the annotation.
if someone have an idea?
pc : edited
For me the class ContextService does not even compile because of a typo in your annotation: String[] descrition(); (note the missing "p") should really be String[] description();, then it compiles and I can also print the annotation instance.
Dear Camel/Akka/Netty Masters!
I've created UntypedConsumerActor which consumes tcp connection:
public class TcpEndpoint extends UntypedConsumerActor {
private static final Logger log = LoggerFactory.getLogger(TcpEndpoint.class);
public static Props props = Props.create(TcpEndpoint.class);
#Override
public String getEndpointUri() {
return "netty4:tcp://localhost:8000?decoders=#fdDecoder,#fdHandler";
}
#Override
public void onReceive(Object message) throws Throwable {
log.error("onReceived");
}
}
In case to configure decoders for netty component, I've created ContextProvider:
public class FDCamelContext implements ContextProvider {
public DefaultCamelContext getContext(ExtendedActorSystem system) {
JndiRegistry registry = new JndiRegistry();
registry.bind("fdDecoder", new FDDecoder());
registry.bind("fdHandler", new FDHandler());
DefaultCamelContext context = new DefaultCamelContext(registry);
return context;
}
}
Now, when I send message there is no call on onReceive method. Why? When I set DefaultContextProvider and configure netty to consumes textlines everything works as expected.
Ok, I found problem. Maybe it helps someone:
It is necesarry to fire channelRead event:
ctx.fireChannelRead(msg);
I want to define a SuggestBox, which behaves like the search bar in Google Maps: When you begin to type, real addresses, starting with the typed letters, appear.
I think, that I need to use the Geocoder.getLocations(String address, LocationCallback callback) method, but I have no idea how to connect this with the oracle, which is needed by the suggest box to produce its suggestions.
Can you please give me ideas how do I connect the getLocations Method with the SuggestOracle?
I solved this by implementing a subclass of SuggestBox, which has it's own SuggestOracle. The AddressOracle deals as a Wrapper for the Google Maps Service, for which the class Geocoderin the Google Maps API for GWT offers abstractions.
So here is my solution:
First we implement the Widget for a SuggestBox with Google Maps suggestions
public class GoogleMapsSuggestBox extends SuggestBox {
public GoogleMapsSuggestBox() {
super(new AddressOracle());
}
}
Then we implement the SuggestOracle, which wraps the Geocoder async method abstractions:
class AddressOracle extends SuggestOracle {
// this instance is needed, to call the getLocations-Service
private final Geocoder geocoder;
public AddressOracle() {
geocoder = new Geocoder();
}
#Override
public void requestSuggestions(final Request request,
final Callback callback) {
// this is the string, the user has typed so far
String addressQuery = request.getQuery();
// look up for suggestions, only if at least 2 letters have been typed
if (addressQuery.length() > 2) {
geocoder.getLocations(addressQuery, new LocationCallback() {
#Override
public void onFailure(int statusCode) {
// do nothing
}
#Override
public void onSuccess(JsArray<Placemark> places) {
// create an oracle response from the places, found by the
// getLocations-Service
Collection<Suggestion> result = new LinkedList<Suggestion>();
for (int i = 0; i < places.length(); i++) {
String address = places.get(i).getAddress();
AddressSuggestion newSuggestion = new AddressSuggestion(
address);
result.add(newSuggestion);
}
Response response = new Response(result);
callback.onSuggestionsReady(request, response);
}
});
} else {
Response response = new Response(
Collections.<Suggestion> emptyList());
callback.onSuggestionsReady(request, response);
}
}
}
And this is a special class for the oracle suggestions, which just represent a String with the delivered address.
class AddressSuggestion implements SuggestOracle.Suggestion, Serializable {
private static final long serialVersionUID = 1L;
String address;
public AddressSuggestion(String address) {
this.address = address;
}
#Override
public String getDisplayString() {
return this.address;
}
#Override
public String getReplacementString() {
return this.address;
}
}
Now you can bind the new widget into your web page by writing the following line in the onModuleLoad()-method of your EntryPoint-class:
RootPanel.get("hm-map").add(new GoogleMapsSuggestBox());