Deploy a swagger generated RESTFUL API in websphere 8.5 - spring-mvc

I have created a REST Spring-MVC webservice using swagger plugin for maven. Here is the plugin definition and goals in my pom:
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.1.5</version>
<executions>
<execution>
<id>generate-spring-mvc</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.build.sourceDirectory}/../resources/api.yaml</inputSpec>
<language>spring-mvc</language>
<modelPackage>com.myproject.ws.gen.model</modelPackage>
<apiPackage>com.myProject.ws.gen.api</apiPackage>
<templateDirectory>${project.build.sourceDirectory}/../templates/JavaSpringMVC</templateDirectory>
<configOptions>
<sourceFolder>src/main/java</sourceFolder>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</configOptions>
</configuration>
</execution>
<execution>
<id>generate-yaml-dist</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.build.sourceDirectory}/../resources/api.yaml</inputSpec>
<language>swagger</language>
<output>${project.build.directory}/site/api</output>
<addCompileSourceRoot>false</addCompileSourceRoot>
</configuration>
</execution>
</executions>
</plugin>
The plugin takes then the api.yaml file, wich contains the definition of the API and generates the java code with spring annotations, additionally, I am using CORS filter to manage the requests.
When I deploy the war in a Websphere Liberty profile server, all runs ok, but when I try to do the same in a full WebSphere 8.5, I always get "File not found" massage from server.
I have checked that the application is installed correctly and the generated .class files of the REST API are packaged in the .war and also that the request is processed by the CORS Filter, but for some reason it still does not work.
Can anybody help me?

It's possible the difference is in the CORS support, or misconfigured CORS support.
In WebSphere Liberty the support is configured in the server.xml using the cors tag.
In WebSphere Traditional 8.5 you may need some JAR file additions as described here along with the relevant app configuration.

If you're using a standard JEE servlet filter then it should work on both Liberty and WAS traditional. It doesn't seem like you're using Liberty's native CORS configuration, so I am assuming a regular servlet filter.
Have you tried accessing your endpoint from a client that doesn't trigger CORS (ie: java client), to ensure that the application is indeed running and accessible in your WAS traditional environment? A manual CORS filter should always work, without special configuration besides actually registering the filter with your app.

Related

How to enable Connection:Keep-Alive for aps.net core 2.1

I have an asp.net core 2.1 website running on a windows server as an azure web app. I was asked to enable "keep-alive" so that when a client asks for "Connection:Keep-Alive" the connection is NOT closed. I cant find any documentation on how to do this (nor if this is even possible).
The reason for getting a persistent connection (if this is the correct term) is to reduce the overhead from the SSL negotiation.
I did find this: Azure Website Connection Keep-Alive stack-overflow question. The provided answer doesn't help. There is no web.config file in asp.net core web apps. i didn't find anything else regarding Keep-Alive in asp.net core.
Actually, there will still be a web.config file for IIS in web app. After you publish your .NET Core web app, you can use Azure Kudu tools from portal to checks files, and you will find the web.config generated by system.
So, you can manually add a web.config file in your project:
And then choose web configuration file
Then, you can add your configurations:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpProtocol allowKeepAlive="true" />
</system.webServer>
</configuration>
Finally, deploy your project, and configurations will be updated in kudu:

invoking wso2 admin services using wsdl2java

I have a web application from which i have to invoke a WSO2 Admin service..
I am following this https://docs.wso2.com/display/IS570/Calling+Admin+Services
When I used wsdl2java , I got a zip file...When i opened it , it has just a pom.xml..
How can i use this? My web app is using Maven itself..But no clue how to use this pom.xml and invoke admin service? How to generate stub out of this pom.xml?
Once you build it with maven client stubs will be generated. See [1] as a sample. Any way client stubs are already available in nexus for released products.
EX: If I want to use client stubs for ChallengeQuestionManagementAdminService I can do it by adding maven dependency
<dependency>
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>org.wso2.carbon.identity.recovery.stub</artifactId>
<version>xxx</version>
</dependency>
[1] https://github.com/wso2-extensions/identity-governance/tree/master/service-stubs/identity/org.wso2.carbon.identity.recovery.stub

Publish pacts to a pact broker using maven plugin

I was able to generate a pact file and then verify it using the maven plugin. Now, I am trying to publish the pacts using a pact broker.
What I have done so far is based on the below link-
https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-provider-maven#publishing-pact-files-to-a-pact-broker-version-320
<plugin>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-provider-maven_2.11</artifactId>
<version>3.5.5</version>
<configuration>
<pactDirectory>target/pacts</pactDirectory> <!-- Defaults to ${project.build.directory}/pacts -->
<pactBrokerUrl>http://<localIP>:80</pactBrokerUrl>
<projectVersion>1.0.100</projectVersion> <!-- Defaults to ${project.version} -->
<trimSnapshot>true</trimSnapshot> <!-- Defaults to false -->
</configuration>
</plugin>
The question I have here is how do I generate the pactBrokerUrl? Does this involve using the dockerized image of the pact broker as stated here? https://github.com/DiUS/pact_broker-docker Or can I just use the Pact Broker Maven plugin by warmuuh?
you need to install the pact broker in a container as explained in the link in your question. the URL is the IP where the broker is installed. Also you need to use the maven plugin to callout your broker url.
PACT Broker required to publish PACT file generated by consumer, I have answered the PACT Broker config info for other question, https://stackoverflow.com/a/62300089/3056361

Unable to connect openshift mysql using spring boot

I have created application in openshit (tomcat7 type) using spring boot. Below is my connection properties
# Remote Datasource Configuration
spring.datasource.url=jdbc:mysql://127.3.175.2:3306/sivam
spring.datasource.username=xxx
spring.datasource.password=yyy
When I tried to deploy my application, Its not connecting to the DB. Unfortunately I am unable to the logs now due to proxy settings.
The same code is working fine in my system with local database credentials.
# Local Datasource Configuration
spring.datasource.url=jdbc:mysql://localhost:3306/sivam
spring.datasource.username=xxx
spring.datasource.password =yyy
Also I have checked remote db credentials using normal JDBC connections (Class.forName() etc) and its deployed correctly & fetching the records from openshift mysql db. So my difficulty is only on spring boot, Do I need to make any specific changes for this?
Finally I found the issue and fixed it.
Actually issue is spring boot's latest version using tomcat version compiled with Java 7, so we need to do few workarounds to make it work.
<properties>
<tomcat.version>7.0.59</tomcat.version>
</properties>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>javax.transaction</groupId>
<artifactId>javax.transaction-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
<version>1.0.0.Final</version>
</dependency>
My application is deployed into openshift PaaS server and working as expected.

CXF (and interceptors) and 2.5 webapps

I've a very basic question. When and How will CXF kick in if my webapp is 2.5 or higher. The weblogic 10.3 that I'm running picks up the WS annotation defined in my web-app.
Until now I had web-app version 2.3. When I upgraded it to 2.5 in webapp XML, I noticed my interceptors are not getting kicked in because now weblogic is able to handle the annotation and CXF is out of picture (based upon stacktrace analysis).
Is my observation correct, or am I totally wrong? I just changed from:
<DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
to
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
I didnt want to mess with WL as we have more than one app running on the WL.So the simple solution was to use the handlers. See here: handlers_introduction.
You are right, changing Servlet version to 2.5 triggers autodiscovery of classes annotated with #WebService annotation.
To prevent this you have to tweak classloading policy. On Apache CXF site there is a good description: Apache CXF - WebLogic
According to this website you have two options:
"Put the geronimo-ws-metadata_2.0_spec-1.1.1.jar in the $Weblogic_Home/jdk_../jre/lib/endorsed folder." - this will affect whole server and might break other web services running on WebLogic
"Pack war in an ear, deploy the ear with weblogic-application.xml" - this way you change classloading policy for single EAR application, not for whole server.
I prefer to use solution based on weblogic-application.xml, as it is more portable.
However it didn't work for me immediately, I had to add additional library to EAR/WAR - geronimo-ws-metadata_2.0_spec-1.1.1.jar.
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-ws-metadata_2.0_spec</artifactId>
<version>1.1.1</version>
</dependency>
If you don't have yet EAR archive you have to create one. Assuming you are using maven:
mvn archetype:generate -DarchetypeGroupId=org.codehaus.mojo.archetypes -DarchetypeArtifactId=ear-jee5
And add your WAR project to dependencies.

Resources