SSE stream api hangs on invoking from wso2 api manager - wso2

I have a streaming (sse) api up and running. It's realized in java and spring boot. The code is given below:
#SpringBootApplication
#RestController
#RequestMapping("sse")
public class SseApplication {
public static void main(String[] args) {
SpringApplication.run(SseApplication.class, args);
}
#GetMapping(path = "/stream-flux", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<String> streamFlux() {
return Flux.interval(Duration.ofSeconds(1))
.map(sequence -> "Flux - " + LocalTime.now().toString());
}
#GetMapping("/stream-sse")
public Flux<ServerSentEvent<String>> streamEvents() {
return Flux.interval(Duration.ofSeconds(1))
.map(sequence -> ServerSentEvent.<String> builder()
.id(String.valueOf(sequence))
.event("periodic-event")
.data("SSE - " + LocalTime.now().toString())
.build());
}
}
When it is directly checked through browser and curl, the streaming response is as expected.
I published it on wso2 apim by publisher portal following the official documentation. Then I tested that api through wso2 apim gateway. It does not returning anything just like as it hangs

Related

CXF Code First SOAP Web Service Endpoint Protocol

I am implementing a Code first cxf web service. How does cxf decide the soap:address part of generated wsdl ? Is it using the hostname from the deployed machine ?
Also, can I change the endpoint protocol from http to https programmatically or by-configuration on the deployed application ?
You can use Spring for this.
you must create an impl for the interface service.
#WebService(endpointInterface = "com.services.MyAwesomeService")
public class MyAwesomeServiceImpl implements MyAwesomeService {
#Override
public String sayHi(String text) {
return "Hello " + text;
}
}
And config vía Spring.
#Configuration
public class ServiceConfig {
#Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus() {
return new SpringBus();
}
#Bean(name = "myAwesomeService")
public MyAwesomeServiceImpl myAwesomeService() {
return new MyAwesomeServiceImpl();
}
#Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(springBus(), myAwesomeService());
endpoint.publish("/MyAwesomeService");
return endpoint;
}
}
After doing this. You will have your service published in the path /MyAwesomeService.
To configure the HTTPS protocol, I recommend you configure it in the application container (Tomcat) or dedicated front (Apache, F5, etc.)

AWS Load Balancer with HTTPS redirections for Server-side event (eventSource)

guys,
I am building a website with JAVA Spring on AWS Elastic beanstalk with Load Balancer. In short, I have a page which receives Server-side Event (SSE) from server using eventsource on client-side and SseEmitter on my Java Spring back-end.
I want my website to work with HTTPS so I followed official suggestion to set the NGINX configuration:
https://aws.amazon.com/premiumsupport/knowledge-center/redirect-http-https-elb/?nc1=f_ls
It works well...when I connect to my website with HTTP, it automatically redirect to HTTPS.
However, my server-side event stops working.
I tried solutions from another post:
EventSource / Server-Sent Events through Nginx
But it didn't help.
On my server side, I also add httpHeaders following other suggestions.
Server-side:
public static final class CustomSseEmitter extends SseEmitter {
static final MediaType UTF8_TEXT_EVENTSTREAM = new MediaType("text", "event-stream", Charset.forName("UTF-8"));
#Override
protected void extendResponse(ServerHttpResponse outputMessage) {
HttpHeaders headers = outputMessage.getHeaders();
headers.set("X-Accel-Buffering", "no");
headers.set("Cache-Control", "no-cache");
headers.set("Connection", "keep-alive");
headers.set("Content-Type", "text/event-stream");
if (headers.getContentType() == null) {
headers.setContentType(UTF8_TEXT_EVENTSTREAM);
}
}
}
Client-side:
var registerSSE = function (companyId, retryCount) {
source = new EventSource("/middle/registerSSE/" + companyId);
source.onopen = function (e) {
console.log("Build SSE successful");
};
source.onmessage = function (e) {
console.log("receive SSE");
};
source.onerror = function (e) {
console.error("SSE broken [" + e.data + "], retry " + (
++retryCount) + " times!");
}
}
Sorry I am kinda a newbie in this context, how can I combine both required features?
Any suggestions would be appreciated.
Thanks.

Workday SOAP client Unsupported endpoint address

I am trying to connect to workday HR Web Service. But I am getting:
WebServiceException : Unsupported endpoint address: Human_Resources.
public static void main(String[] args){
HumanResourcesService hrservice=new HumanResourcesService();
HumanResourcesPort hrport=hrservice.getHumanResources();
//further code
}
WebEndpoint Snippet from the HumanResourcesService class:
#WebEndpoint(name = "Human_Resources")
public HumanResourcesPort getHumanResources() {
return super.getPort(new QName("urn:com.workday/bsvc/Human_Resources", "Human_Resources"),
HumanResourcesPort.class);
}
Any help is appreciated.
When defining Workday API endpoints, you need to include the version number at the end of the urn.
For example you have:
urn:com.workday/bsvc/Human_Resources
and it should be (if you use v28)
urn:com.workday/bsvc/Human_Resources/v28.0

how to stop this javax.xml.ws.Endpoint service

i have like this below code in order to start to publish wsdl
package my.mimos.stp.MelodyWS.webservice;
import javax.xml.ws.Endpoint;
public class Server {
public static void main(String[] args) {
Endpoint.publish("http://localhost:8081/Melody/MelodyService", new MelodyWS());
System.out.println("Melody service is ready");
}
}
what should i do if i want to stop that service? i have a changes in MelodyWS and would like to republish it.
You have to keep a reference on the Endpoint object and call stop() method on it:
Endpoint ep = Endpoint.create(new MelodyWS());
ep.publish("http://localhost:8081/Melody/MelodyService");
..
ep.stop();

ServiceStack web services security

Hi I am new to working with Servicestack and have downloaded their very comprehensive bootstrapapi example and am working with it, but am still having some issues. The issue is with security, what is happening is I am getting 405 errors when trying to access the protected services. Using the authenticate service it appears that I am authenticating correctly. Please help and explain. Here is the code:
public class Hello
{
public string Name { get; set; }
}
public class AuthHello
{
public string Name { get; set; }
}
public class RoleHello
{
public string Name { get; set; }
}
public class HelloResponse
{
public string Result { get; set; }
}
The Services:
public class HelloService : ServiceBase<Hello>
{
//Get's called by all HTTP Verbs (GET,POST,PUT,DELETE,etc) and endpoints JSON,XMl,JSV,etc
protected override object Run(Hello request)
{
return new HelloResponse { Result = "Hello, Olle är en ÖL ål " + request.Name };
}
}
[Authenticate()]
public class AuthHelloService : RestServiceBase<AuthHello>
{
public object Execute(Hello request)
{
return new HelloResponse { Result = "Hello, " + request.Name };
}
}
[RequiredRole("Test")]
public class RoleHelloService : RestServiceBase<RoleHello>
{
public object Execute(Hello request)
{
return new HelloResponse { Result = "Hello, " + request.Name };
}
}
Here is the AppHost:
public class HelloAppHost : AppHostBase
{
//Tell Service Stack the name of your application and where to find your web services
public HelloAppHost() : base("Hello Web Services", typeof(HelloService).Assembly) { }
public override void Configure(Container container)
{
//Register all Authentication methods you want to enable for this web app.
Plugins.Add(new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] {new CustomCredentialsAuthProvider(), //HTML Form post of UserName/Password credentials
}));
container.Register<ICacheClient>(new MemoryCacheClient() { FlushOnDispose = false });
//register user-defined REST-ful urls
Routes
.Add<Hello>("/hello")
.Add<Hello>("/hello/{Name}")
.Add<AuthHello>("/AuthHello")
.Add<RoleHello>("/RoleHello");
}
}
UPDATE
Everything works as expect if you replace : RestServiceBase with : ISevice so now the question is why.
Check the wiki documentation first
I would first go through the documentation in ServiceStack's Authentication Wiki to get a better idea about how ServiceStack's Authentication works. There's a lot of documentation in the wiki, so if you're unsure of something you should refer to that first. It's a community wiki so feel free to expand whats there if you think it can help others.
Refer to the implementation in the source code if behavior is not clear
If you're unsure of what something does you should refer to the RequiredRole source code as the master authority as how it works. RequiredRole is just a Request Filter Attribute which gets run before every service that has the attribute.
The RequiredRole attribute just calls your session.HasRole() method as seen here:
public bool HasAllRoles(IAuthSession session)
{
return this.RequiredRoles
.All(requiredRole => session != null
&& session.HasRole(requiredRole));
}
Because it just calls your session you can override the implementation of session.HasRole() if you have a custom session.
Registering and Implementing a CustomUserSession
The Social BootstrapApi project does implement its own CustomSession that it registers here but does not override the HasRole() implementation so it uses the built-in implementation in the base AuthUserSession.HasRole() which simply looks like the Roles collection to see if the user has the specified role in their Session POCO:
public virtual bool HasRole(string role)
{
return this.Roles != null && this.Roles.Contains(role);
}
Session properties populated by AuthUserRepository
The Roles property (as well as most other properties on a users Session) is populated by the AuthUserRepository that you have specified e.g. if you're using the OrmLiteAuthRepository like SocialBootstrapApi does here than the Roles attribute is persisted in the Roles column in the UserAuth RDBMS table. Depending on the AuthUserRepository you use the UserAuth / UserOAuthProvider POCOs get stored as RDBMS tables in OrmLite or as text blobs in Redis, etc.
Manage roles and permissions with AssignRoles / UnAssignRoles services
So for a user to have the required role (and authorization to pass), it should have this Role added to its UserAuth db row entry. ServiceStack's AuthFeature includes 2 services for managing users permissions and roles:
/assignroles
/unassignroles
How to initially give someone the Admin Role
These services does require a user with the Admin Role to be already authenticated.
You can do this by manually changing a specific users UserAuth.Role column to include the value "Admin". The Social Bootstrap API project instead does this by handling the OnAuthenticated() event on its CustomUserSession that simply checks to see if the authenticated username is declared in the Web.Config and if it is, calls the AssignRoles service giving that authenticated user the Admin Role:
if (AppHost.Config.AdminUserNames.Contains(session.UserAuthName)
&& !session.HasRole(RoleNames.Admin))
{
var assignRoles = authService.ResolveService<AssignRolesService>();
assignRoles.Execute(new AssignRoles {
UserName = session.UserAuthName,
Roles = { RoleNames.Admin }
});
}