updating Beans marked as RefreshScope - refresh

Here is my scenario:
My micro service gets notified about some changes of its configuration from the central conf server. It can be partial update, or a full.
I use #RefreshScope mark on relevant beans. The question is how to update marked beans, I mean reload them.
Just to clarify: From Spring Cloud I use only RefreshScope.
Any ideas?

Add dependency org.springframework.boot:spring-boot-starter-actuator in your project.
Refreshing configuration via call refresh endpoint.
For example, you configure your management endpoint like below. curl -X POST http://localhost:8001/manage/refresh will trigger refreshing changed configuration.
management:
context-path: /manage
port: 8001
security.enabled: false

If you have different components that are affected by changes, then it's good to keep your configurations on repository and then you can add a publish-subscribe model for refreshing context in which all the affected components are to subscribe to an event that is published by your repository as a result of configurations change.
And for refreshing context we have two options:
Hit refresh endpoint of your app by a post request.
Get RefreshEndpoint bean by autowiring it, then apply refreshEndpoint.refresh(). This will refresh context at runtime.
In both solutions mark the beans of interest by #RefreshScope.

Related

Web service fails with org.apache.axis2.AxisFault: The system cannot infer the transport information from the [my URL] URL

We have a strange situation. It's a web service (svc1) that calls another web service (svc2) on a different box, both in websphere. Works in every previous environment.
But recently they built out another staging environment as largely a clone of a working one. The service is failing with this message everytime svc1 attempts to call svc2.
Caused by: org.apache.axis2.AxisFault: The system cannot infer the transport information from the [svc2's URL] URL.
at org.apache.axis2.description.ClientUtils.inferOutTransport(ClientUtils.java:81)
at org.apache.axis2.client.OperationClient.prepareMessageContext(OperationClient.java:304)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:180)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at org.apache.axis2.jaxws.core.controller.impl.AxisInvocationController.execute(AxisInvocationController.java:578)
at org.apache.axis2.jaxws.core.controller.impl.AxisInvocationController.doInvoke(AxisInvocationController.java:127)
at org.apache.axis2.jaxws.core.controller.impl.InvocationControllerImpl.invoke(InvocationControllerImpl.java:93)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invokeSEIMethod(JAXWSProxyHandler.java:419)
... 45 more
The URL is correct. We can point the not-working apps at a database supporting a working set of apps and it works, but when we point the working apps from that other environment at the not-working environment's DB, it stops working.
This seems to indict the DB, yet the error has nothing to do with the DB. Svc1's only DB call BEFORE the call to svc2 happens well before the service call and works fine according to logs. The logs indicate svc2 never gets the request. So how can database be the problem?
I know this isn't alot to go on, but does anyone even have suggestions on where to look to narrow this down? I can't believe the DB is the problem based on the code and when it's failing...yet the DB swapping test seems to imply it is.
I might be pointing out the obvious, but the error message is telling you one of two things: either svc1 isn't configured correctly to invoke svc2, or svc2 isn't up and running.
For clarity, if I label the working environment: enviornmentA and the not-working environment: environmentB.
Based on what you said, you were able to use environmentB.svc1 to invoke environmentA.svc2? If that is true, than environmentB.svc1 is configured correctly and working. Which leaves svc2. You said svc2 doesn't receive the request, which means its up at least. Well, like you'd mention this isn't much to go on but I'd make sure you configured svc2 correctly, since it is up. Configuring a Web Service can be complicated, but one of the things that can be configured is making a Web Service available to client invocation. So you might want to check out this link for information on how to configure it:
https://www.ibm.com/support/knowledgecenter/SSAW57_9.0.0/com.ibm.websphere.nd.multiplatform.doc/ae/twbs_publishwsdl.html.
There are a bunch of similar articles on configuring your Web Service that might help you to solve what's missing, so I would verify that the configuration for enviornmentB.svc2 matches enviornmentA.svc2 since you know that one is working.

How to find out if an app is currently stopped with CloudFoundry in Swisscom Cloud? Header X-Cf-Routererror reliable?

We would like to add a maintenance page to our front-end which should appear when the back-end is currently unavailable (e.g. stopped or deploying). When the application is not running, the following message is displayed together with a 404 status code:
404 Not Found: Requested route ('name.scapp.io') does not exist.
Additionally, there is header present, when the application is stopped (and only then):
X-Cf-Routererror: unknown_route
Is this header reliably added if the application is not running? If this is the case, I can use this flag to display a maintenance page.
By the way: Wouldn't it make more sense to provide a 5xx status code if the application is not started/crashed, i.e. differ between stopped applications and wrong request routes? Catching a 503 error would be much easier, as it does not interfere with our business logic (404 is used inside the application).
Another option is to use a wildcard route.
https://docs.cloudfoundry.org/devguide/deploy-apps/routes-domains.html#create-an-http-route-with-wildcard-hostname
An application mapped to a wildcard route acts as a fallback app for route requests if the requested route does not exist.
Thus you can map a wildcard route to a static app that displays a maintenance page. Then if your app mapped to a specific route is down or unavailable the maintenance page will get displayed instead of the 404.
In regards to your question...
By the way: Wouldn't it make more sense to provide a 5xx status code if the application is not started/crashed, i.e. differ between stopped applications and wrong request routes? Catching a 503 error would be much easier, as it does not interfere with our business logic (404 is used inside the application).
The GoRouter maintains a list of routes for mapping incoming requests to applications. If your application is down then there is no route in the routing table, that's why you end up with a 404. If you think about it from the perspective of the GoRouter, it makes sense. There's no route, so it returns a 404 Not Found. For a 503 to make sense, the GoRouter would have to know about the app and know it's down or not responding.
I suppose you might be able to achieve that behavior if you used a wildcard route above, but instead of displaying a maintenance page just have it return an HTTP 503.
Hope that helps!
The 404 Error you see is generated by CloudFoundrys routing tier and is maintained upstream.
Generally if you don't want to get such error messages you can use blue-green deployments. Here is a detailed description of it in the CF docs: https://docs.cloudfoundry.org/devguide/deploy-apps/blue-green.html
An other option is to add a routing service that implements this functionality for you. Have a look at the CF docs for this: https://docs.cloudfoundry.org/services/route-services.html

Sitecore Mixed Content error for workflow

We have added a sample workflow for our current site. For some of the environments we have a https connection. When we tried to use the workflow for https we got the error:
Mixed Content: The page at 'https://site/sitecore/shell/default.aspx?sc_lang=en' was loaded over HTTPS, but requested an insecure resource 'http://site//sitecore/shell/default.aspx?xmlcontrol=Workbox&mo=preview&reload=1&{190B1C84-F1BE-47ED-AA41-F42193D9C8FC}=0&{46DA5376-10DC-4B66-B464-AFDAA29DE84F}=0&{FCA998C5-0CC3-4F91-94D8-0A4E6CAECE88}=0'. This request has been blocked; the content must be served over HTTPS.
I am using Sitecore 8.1 Update 2.
You can see there 3 ids for:
190B1C84-F1BE-47ED-AA41-F42193D9C8FC Draft state Id for sample workflow
46DA5376-10DC-4B66-B464-AFDAA29DE84F Awaiting aproval state Id for sample
workflow
FCA998C5-0CC3-4F91-94D8-0A4E6CAECE88 Approved state Id for sample workflow
The problem seems to be on workflow reload
Is there a setting in sitecore workflows that I can set for the workflow to use https urls?

Sitecore API issue

I am currently getting 404 error for “API/sitecore/{controller}/{action}” calls in delivery server (after Hardening) but the same was working fine on authoring environment in sitecore. Please help
It sounds like routing configuration is different for these server. There are 2 typical places, where this configuration is done:
Check and compare your configuration of initialize pipelines on both
servers: I guess on CD is absent configuration that is respond for
this route "API/sitecore/{controller}/{action}".
Compare your Global.asax files on both servers.
The other reason could be in some additional configurations on CD server, e.g.: URL rewrite, HTTP redirect.
#Vikram Devasenapathy Please register your controller route in route config.
Are you using forms with ajax postback?
This issues was fixed by registering the routes in global asas file.

Consuming a webservice with jsessionid in URL

I`m working on a SAP project, where i have to call a non-sap service with jsessionid in binding url. I already generated a proxy class out of the wsdl and defined a logical port with my URL. In my case it should be dynamic like: {host}/service/foo/binding;jsessionid={xxx} but its static like: {host}/service/foo/binding
How can i achieve that session handling?
EDIT: The problem here is, its not only for authentification its also for load balancing. The jsessionid MUST be submitted via URL rewriting. Any ideas?
You should be able to configure this with the soamanager transaction:
Go to the service configuration screen and select your consumer proxy
Edit the existing, or create a new logical port
Go to the transport settings tab and change the URL access path
Once saved, you can find the logical port as a destination in transaction SM59. It's one of the generated ones in the external HTTP connections tree.
Providing a value for the parameter will probably require a modification of the SAP software though. The system uses the cl_http_client=>create_by_destination method to obtain a client object to perform the http call, so maybe you can implement some custom code there.