Hybris can't install occ addon - sap-commerce-cloud

I've followed the official documentation in order to create my own occaddon webservice layer : https://help.sap.com/viewer/e5d7cec9064f453b84235dc582b886da/1905/en-US/8b96a80f8669101482d4f3c1e27b4eb6.html and created the "dummy" controller :
package org.training.trainingoccaddon.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
#Controller
#RequestMapping(value = "/{baseSiteId}/newResource")
public class ExtendedCustomersController {
#RequestMapping(method = RequestMethod.GET)
#ResponseBody
public String getNewResource() {
return "newSampleResource";
}
}
However, when I try to access to
https://localhost:9002/rest/v2/{baseSiteId}/newResource
It redirects me to hac.
I've created my new occ addon
added to localextensions.xml
Performed ant addoninstall -Daddonnames="occaddon" -DaddonStorefront.ycommercewebservices="ycommercewebservices"
Rebuit the application with ant clean all && hybrisserver debug
But It doesn't work. Am I missing something?
Also, how can I setup swagger?

I am assuming you are using SAP Commerce 1905, also that you not have added any custom 'ycommercewebservices' extension.
Missing ycommercewebservices extension
Since you are redirected to the HAC your 'ycommercewebservices' extension is not loaded correctly. Normally it should throw an error from the 'ycommercewebservices' extension itself instead of redirecting to the HAC.
The extension should be at least present in the 'localextension.xml'.
You can verify loaded extensions in the HAC
e.g. https://localhost:9002/platform/extensions
The next thing you could check if your addon was added as dependency in the 'ycommercewebservices' extension by checking the 'extensioninfo.xml' in its directory. Also double check if a 'project.properties' file was generated in your custom occaddon extension. If something is wrong here you should review your 'ant addoninstall' command.
Swagger Setup
Swagger works out of the box and you can decorate your classes with the annotations as documented on here https://github.com/swagger-api/swagger-core/wiki/Annotations-1.5.X.
You can visit the swagger ui on the ycommercewebservices extension
e.g. https://localhost:9002/rest/v2/swagger-ui.html

Related

setting micronaut configuration location

I have an existing groovy micronaut app I'm trying to change where it loads its config from. I don't understand what code to write so I can set the location of the micronaut configuration. I know you can use micronaut.config.files system variable or MICRONAUT_CONFIG_FILES environment variable, but this is a terrible idea because micronaut is built into grails and therefore every grails app you have running in tomcat will pick up the same config and crash.
Nor do I know where in the code to set the config file. There's an Application class with a run() method, but I don't know if this is only called during development, or whether it gets called when deploying in Tomcat. When setting the config in a Grails app, there is an Application class extending EnvironmentAware, and you can override setEnvironment, and load external configs there, but there is no hint of that for micronaut apps.
The micronaut doco says it can load a configuration from "application.{extension}", but it doesn't say what "application" is, or what directory it expects that in, or whether you can change the directory. Is "application" the value of micronaut.application.name in one's application.yml? I couldn't seem to get it to load based on that.
Then the documentation talks about loading from a PropertySource, which is fine and all, but doesn't tell you where you can put that code to load from a PropertySource. There is mention you can pass the PropertySource to ApplicationContext.run(xx), but in this app I inherited, there is no mention of ApplicationContext, and the micronaut documentation isn't very clear what I'm supposed to do with ApplicationContext. This app I've inherited has an Application class with a main() calling Micronaut.run() which apparently returns an ApplicationContext, but it's not clear if main() is called when running in Tomcat, or whether I should be calling run() on that, when it works as is, and I'm just trying to change where it loads its config.
The question is, how do I get my micronaut app to load its config from
where I tell it to, and not from micronaut.config.file system variable
location.
I don't think we have a specific feature in the framework that allows you to tell the framework to ignore micronaut.config.files. If you would like such a feature you can request it at https://github.com/micronaut-projects/micronaut-core/issues. If that is of interest I suggest you open it up for discussion at https://github.com/micronaut-projects/micronaut-core/discussions first.
You can load external config files, from a path not set as micronaut.config.files, in the main method of the Application class before running the application. Take a look at below class which accepts a config folder location as a system property demo.config.path(can be something else) and loads yaml config files from that folder:
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import io.micronaut.context.env.PropertySource;
import io.micronaut.context.env.yaml.YamlPropertySourceLoader;
import io.micronaut.core.io.ResourceLoader;
import io.micronaut.core.io.file.DefaultFileSystemResourceLoader;
import io.micronaut.runtime.Micronaut;
public class Application {
private static final String PROP_CONFIG_LOCATION = "demo.config.path";
public static void main(String[] args) throws IOException {
if (System.getProperty(PROP_CONFIG_LOCATION) != null) {
List<PropertySource> propertySources = new ArrayList<>();
YamlPropertySourceLoader propertySourceLoader = new YamlPropertySourceLoader();
ResourceLoader resourceLoader = new DefaultFileSystemResourceLoader();
Files.newDirectoryStream(Paths.get(System.getProperty(PROP_CONFIG_LOCATION))).forEach(file -> {
String fileName = file.toString();
String fileNameWithoutExtension = fileName.substring(0, fileName.lastIndexOf('.'));
propertySourceLoader.load(fileNameWithoutExtension, resourceLoader).ifPresent(propertySources::add);
});
Micronaut.build(args)
.classes(Application.class)
.propertySources(propertySources.toArray(new PropertySource[1]))
.start();
} else {
Micronaut.run(Application.class, args);
}
}
}
As is, this code works for yaml config files(with snakeyaml in classpath). With minor changes, it can be made to work for properties files and to read config location from environment variable instead of system property. Full sample application present in github

Import org.openntf cannot be resolved

I have a Notes V11.0.1 designer client and configured a widget that imports the latest OpenNTF Domino API (downloaded from OpenNTF website) through an update site.
The plug-in is loaded in the designer
I created a new application and added the library to XSP Properties.
But when I create a simple Java class and want to import org.openntf.domino.*, I get an error:
package test;
import org.openntf.domino.*;
public class Test {
public static void test() {
Session session = null;
}
}
Error: the import org.openntf cannot be resolved.
Building the app does not solve the problem.
In the MANIFESST.MF I get the following error
Any idea why this goes wrong?
It's most likely that the default Target Platform in 9.0.1FP10 and newer (11.0.1 included) is broken: https://frostillic.us/blog/posts/2018/10/19/058650e080e352178525832b00519d2c

jhiTranslate doesn't work on html template- it shows Unknown attribute 'jhiTranslate'

I created a module(component, html tmeplate) by myself in a jhipster project. And I imported the new module into 'app.module.ts'. when I use the translation tag 'jhiTranslate' on the html template, it shows Unknown attribute
'jhiTranslate'
enter image description here
Any suggestion what I should do to enable 'jhiTranslate' in a customized module?
Thanks.
Please post your module code and add some informations about your project :
- version
- front framework (seems to be angular)
what happen when you deploy and run the app ? have you some errors in the browser console ?
I suppose you didn't import your shared-module into your new one like this :
imports: [
MyAppSharedModule,
...
],
The Jhipster translation directive is store into the NgJhipsterModule.
the NgJhipsterModule is import into the shared-lib.module which is import into shared.module. Import this last could fix your problem.

Why am I getting "A route named 'swagger_docs' is already in the route collection" after I publish my API App?

After publishing my API App I'm getting the yellow error screen of ASP.NET. The error message says "A route named 'swagger_docs' is already in the route collection".
How can I fix this?
This is not related to API Apps per se but more around Web API. What triggers the error is pretty simple:
You publish the API App which is based on Web API.
You discard your project and start working on a new API App based on Web API
You want to publish the new API App instead of the old API App you created at step 1.
You select the API App during "Publish.." and you get the publishing profile of the existing API App we deployed at step 1.
You deploy using Web Deploy and the publishing profile, the new API App on top of the old one.
That will trigger the issue I've explained before. That happens because there are two routes being registered by Swashbuckle when you try to start the app. One of the old one and one of the new one. That's because the old files are still present at the destination.
To solve this, during Web Deploy, click on the Settings tab and then expand the "File Publish Options". There is a checkbox there, called "Remove additional files from destination". This will fix the issue as it will only leave the files you deploy at the destination and not the old ones as well.
Hope it helps.
What if it happens when trying to debug the app locally ?
This happened for me, and the reason was, I renamed my assembly name. So the bin folder had two dlls for the same project with different names which caused this error. Once I deleted the old named dll all is well. Hope this helps.
This happens because You probally are configuring you route in your WebApiConfig class and SwaggerConfig class, as explained below:
WebApiConfig file:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
SwaggerConfig.Register();
}
}
SwaggerConfig file:
using Swashbuckle.Application;
[assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")]
namespace NEOH.Api
{
public class SwaggerConfig
{
public static void Register()
{
What you should do is remove the assembly call on SwaggerConfig file.
It should work.
My Solution & Cause:
I had the same problem when I renamed NamesSpaces,Refactored,etc.
After reading what everyone else did here's what I tried:
Cleaned the Solution in Visual Studio
Cleaned the Bin folder manually
Checked the nameSpace in the Project Properties (copied it just in case) >> Build tab >> Scrolldown to Output and ensure the XML documentation file is correct. You will need this name later.
Opened up: SwaggerConfig.cs >> fixed the name space in here (copy,paste) c.SingleApiVersion("vX","NameSpace")
Scrolled down until I found: GetXmlCommentsPath() copied and pasted the correct name space in the .xml file path.
Ran, smoke tested, finished this post.
My issue was that I was referencing another project that had the Swashbuckle extension.
Here is how I kept both projects without changing the anything in project that was referenced:
Remove the routes created by the project referenced under SwaggerConfig.cs > Register right before GlobalConfiguration.Configuration.EnableSwagger(...).EnableSwaggerUi(...);:
// Clears the previous routes as this solution references another Swagger ASP.NET project which adds the swagger routes.
// Trying to add the Swagger routes more than once will prevent the application from starting
GlobalConfiguration.Configuration.Routes.Clear();
Then, the application will be able to start, but you will see the operations/functions that are in both projects. To remove the operations from the project being referenced...
Create the following class
using Swashbuckle.Swagger;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http.Description;
namespace yournamespace.Models
{
/// <summary>
/// This class allows to manage the Swagger document filters.
/// </summary>
public class SwaggerCustomOperationsFilter : IDocumentFilter
{
/// <summary>
/// Applies the Swagger operation filter to exclude the Swagger operations/functions
/// that are inherited by the other Swagger projects referenced.
/// </summary>
///
/// <param name="p_swaggerDoc">Swagger document</param>
/// <param name="p_schemaRegistry">Swagger schema registry</param>
/// <param name="p_apiExplorer">Api description collection</param>
public void Apply(SwaggerDocument p_swaggerDoc, SchemaRegistry p_schemaRegistry, IApiExplorer p_apiExplorer)
{
IEnumerable<ApiDescription> externalApiDescriptions = p_apiExplorer.ApiDescriptions
.Where(d => d.ActionDescriptor.ControllerDescriptor.ControllerType.Module.Name != GetType().Module.Name);
IEnumerable<int> externalApiDescriptionIndexes = externalApiDescriptions
.Select(d => p_apiExplorer.ApiDescriptions.IndexOf(d))
.OrderByDescending(i => i);
IEnumerable<string> externalPaths = externalApiDescriptions.Select(d => $"/{d.RelativePathSansQueryString()}");
foreach (string path in externalPaths)
{
p_swaggerDoc.paths.Remove(path);
}
foreach (int apiDescriptionIndex in externalApiDescriptionIndexes)
{
p_apiExplorer.ApiDescriptions.RemoveAt(apiDescriptionIndex);
}
}
}
}
And add the following in SwaggerConfig.cs > Register > GlobalConfiguration.Configuration.EnableSwagger(...)
c.DocumentFilter<SwaggerCustomOperationsFilter>();
Alternative cause of this problem:
Seems like a lot of people have this issue resolved by deleting their "bin" and "obj" folders as per the other answers.
However the cause of the issue might be that you are configuring your Swagger Config in a referenced project, as per this comment: https://github.com/domaindrivendev/Swashbuckle/issues/364#issuecomment-226013593
I received this error when one project with Swagger referenced another
project with Swagger. Removing the reference fixed the problem.
This caused me to split some core functionality out into a Third project that both of my API's could reference, rather than them referencing each other.

Problems using an installclass in a web setup for a web site

I am trying to create a web setup for my web site, and I want to use an installer class to do some custom stuff. I am using VS 2010, and the web site and installer is .NET 3.5.
I have added reference to the installer class project output in the Install section under Custom Actions:
I have also set /targetdir="[TARGETDIR]/" on the CustomActionData for this action.
The InstallScript project is a standard class library (dll).
There is a public class that inherits from Installer class. It overrides the Install method as I have seen been done in several online examples:
using System.Collections;
using System.Windows.Forms;
namespace InstallScript
{
public class MyWebInstaller : System.Configuration.Install.Installer
{
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
var targetDir = Context.Parameters["targetdir"];
if(targetDir==null) targetDir = "No TARGETDIR!";
MessageBox.Show("TARGETDIR:\t" + targetDir);
}
}
}
I would think there should be shown a message box here som time during the install, but it seems like it is never called. No error is shown either. The setup just runs through as if this code was never called.
Anyone have idea of what is wrong?
OK, I found out what was missing.
You need to specify the class with the class attribute RunInstaller(true) for the setup to pick up and actually run the code.
So the class needs to be declared like this:
[System.ComponentModel.RunInstaller(true)]
public class MyWebInstaller : System.Configuration.Install.Installer
{
...

Resources