I have a maven project with an authenticator from AbstractApplicationAuthenticator, and I call a endpoint webservice
with javax.xml.wsjavax.xml.ws.Service and Dispatch
dispatch.
In maven pom I use org.apache.felix maven-bundle-plugin. But, first time I have error
javax.xml.soap.SOAPException: Provider org.apache.axis2.saaj.SAAJMetaFactoryImpl not found
I append dependency in pom:
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-saaj</artifactId>
<version>1.7.5</version>
</dependency>
And then the error is:
javax.xml.ws.spi.FactoryFinder$ConfigurationError: Provider org.apache.cxf.jaxws.spi.ProviderImpl not found
I append dependencies of cxf in </Import-Package>, but it doesnt
Works. Any suggestions?
Related
For my project I will be just using #SQSListener annotation I have added below 2 maven dependencies in my springboot pom.xm
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-aws-messaging</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
I understand that we have to use "spring-cloud-aws-messaging" maven dependency but is there any alternative for "spring-cloud-starter-aws dependency" as it adds all the dependencies which are not necessary. I just wants to have dependency related to aws SQS. Please let me know if you have any solution to this.
I have a Spring Boot demo project. I am trying to deploy them in AWS Lambda, but I get ClassNotFoundException even thought my jar that I upload contains of the necessary dependencies.
Here goes my code:
pom.xml
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container-spring</artifactId>
<version>[0.1,)</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Application Class
#SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
System.out.println("Welcome to demo project");
}
}
Controller Class
#RestController
public class DemoController {
#GetMapping(value="/getValue")
public String getId() {
return " Call from controller";
}
}
LambdaHandler Class
public class DemoLambdaHandler implements RequestStreamHandler {
public static SpringBootLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;
static {
try {
handler = SpringBootLambdaContainerHandler.getAwsProxyHandler(DemoApplication.class);
} catch (ContainerInitializationException e) {
e.printStackTrace();
throw new RuntimeException("Container not initialized", e);
}
}
#Override
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
// TODO Auto-generated method stub
handler.proxyStream(input, output, context);
}
}
Not sure what I could be missing in this. Kindly help. Below is my inspected jar
Did you find a solution to this? I have been getting the same exact error.
What I can tell so far is that unlike other languages like nodejs, the docker image for java has the command specified like CMD [ "com.example.LambdaHandler::handleRequest" ], instead the nodejs one is CMD [ "app.handler" ]. The difference here is that the nodejs one specifies what the file is e.g. app.js with function called handler.
But the java one only has the class path without the ability to specify the path to the fat JAR file even when the jar file is located in "var/task". How would lambda know the JAR file name?
I had the same issue, I fixed it marking Spring Boot as a dependency.
By default, Spring Boot plugin will pack your classes into "BOOT-INF/classes" directory, but AWS is looking for the handler class from the root directory so it can't find it.
You can check this by extracting your .jar file and seeing if your file is in:
BOOT-INF/classes/com/example/demo/handler/LambdaHandler.class
instead of:
com/example/demo/handler/LambdaHandler.class
To solve it, just mark your package as exec in your pom.xml file:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.6.1</version>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
More info here: Spring Boot as a Dependency
Try building the project with Maven and ensure you have the required maven-shade-plugin in your POM so that the JAR that is built with the dependencies when you run mvn package. If you are missing this plugin, you will create a JAR that does not contain the dependencies and you will encounter ClassNotFoundException.
To learn how to build and deploy a Lambda function by using the Lambda runtime Java API, see this AWS tutorial. It will walk you step by step through the process of building Lambda functions that work:
https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/javav2/usecases/creating_workflows_stepfunctions
This tutorial then uses the Lambda functions within Step Functions to create a workflow.
Lambda functions are created using the Lambda runtime Java API -- com.amazonaws.services.lambda.runtime.RequestHandler. Please do not use Spring BOOT APIs to create a Lambda function.
However, If you want to invoke a Lambda function from a Spring boot app and then for example display the result in a view, then you can use the Lambda Client Java API - which is software.amazon.awssdk.services.lambda.LambdaClient.
So in summary:
com.amazonaws.services.lambda.runtime.RequestHandler is used to create a Lambda function by using the Java Lambda runtime API.
software.amazon.awssdk.services.lambda.LambdaClient is the Lambda client Java API V2 that lets you interact with deployed Lambda functions. For
example, you can use this client to invoke a Lambda function from a
Java app - like a Spring boot web app. To see a working example of how to use the Lambda client API to invoke a Lambda function, see https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javav2/example_code/lambda/src/main/java/com/example/lambda/LambdaInvoke.java.
Please add these two dependencies in pomfile
1)aws-lambda-java-core
2)aws-lambda-java-events
This should fix it
I have a secret on GCP, namely greeting with the secret-value being "Hello". When in my application I have the following code.
#Value("${sm://projects/221608087928/secrets/greeting}")
private String databasePassword;
#RequestMapping(value ="/test-user")
public String getUser()
return this.databasePassword;
}
I have the value (projects/221608087928/secrets/greeting) by running the following command.
gcloud secrets describe "$secret_name"| grep name
I would assume my browser returning "Hello". However it returns "//projects/221608087928/secrets/greeting". I have the gcp-secret-manager dependency installed in my POM. How can I have the following code return the secret-value?
Solved by updating dependency from
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-secretmanager</artifactId>
<version>1.2.2.RELEASE</version>
</dependency>
to
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-secretmanager</artifactId>
<version>1.2.3.BUILD-SNAPSHOT</version>
</dependency>
I developed a spring boot application and I've put the following entries in src/main/resources/application.properties:
spring.mvc.view.prefix: /
spring.mvc.view.suffix: .jsp
server.port=5000
Now when I start it (mvn clean spring-boot:run) locally, I'm getting the output Tomcat started on port(s): 5000 (http) and the app is accessible in the browser under http://localhost:5000/welcome .
I created a Java instance in Amazon Elastic Bean Stalk, I've uploaded war, I even opened the port 5000 in the corresponding Security Group on EC2 instance:
but when I now go to http://my-aws-ebs-instance.com/welcome:5000, I'm getting the following message:
Whitelabel Error Page This application has no explicit mapping for
/error, so you are seeing this as a fallback.
Thu Dec 20 16:30:33 UTC 2018 There was an unexpected error (type=Not
Found, status=404). /welcome.jsp
Why oh why does it happen like this? What did I forget to configure?
----EDIT
as requested, here's the root java class:
package com.hellokoding.auth;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
#SpringBootApplication
public class WebApplication extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(WebApplication.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(WebApplication.class, args);
}
}
Here is also the structure of my project with highlighted welcome.jsp page:
When I unzip the generated war file, this is the file structure on my hard drive:
My pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>auth</artifactId>
<name>auth</name>
<description>my descr</description>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
and the UserController class contains:
...
#Controller
#Scope("session")
public class UserController {
#RequestMapping(value = {"/", "/welcome"}, method = RequestMethod.GET)
public String welcome(Model model) {
return "welcome";
}
...
I added some logs inside the welcome method and I see it is running correctly. Also, in log files I can see the following entry:
Mapped "{[/ || /welcome],methods=[GET]}" onto public java.lang.String com.hellokoding.auth.web.UserController.welcome(org.springframework.ui.Model)
so I have no idea why this thing does not work. After trying for 11 hours straight to make it work I'm questioning my life choices, and also I'm wondering why anyone would ever use such a stupid framework since it doesn't work ootb.
--- edit:
I've uploaded a simplified code to github https://github.com/nalogowiec/springbootProblem
Solution 1:
If you want Spring Boot With JSPs in Executable Jars
Keep in mind that we will ultimately place the JSP templates under src/main/resources/META-INF/resources/WEB-INF/jsp/
Note :
define the template prefix and suffix for our JSP files in application.properties
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
Then your can run jar file using below command :
java -jar <your jar name>
for your project you can below command
java -jar auth-1.3.5.RELEASE.jar
For More reference : https://dzone.com/articles/spring-boot-with-jsps-in-executable-jars-1
Solution 2:
JSP Limitations
When running a Spring Boot application that uses an embedded servlet container (and is packaged as an executable archive), there are some limitations in the JSP support.
With Jetty and Tomcat, it should work if you use war packaging. An executable war will work when launched with java -jar, and will also be deployable to any standard container. JSPs are not supported when using an executable jar.
Undertow does not support JSPs.
Creating a custom error.jsp page does not override the default view for error handling. Custom error pages should be used instead.
I have clone your GitHub project able to run project(if you follow below steps your problem will get solve definitely)
Step To run your project :
Step 1 : Create war package of your project
Step 2 : Run your war package using below command
java -jar <your war file name>
i.e for your project command should be like :
java -jar auth-1.3.5.RELEASE.war
Step 3 : Hit the URL http://localhost:5000/
You can see the result in browser.
More reference : https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-web-applications.html#boot-features-jsp-limitations
Nice explanation #dipak-thoke.
Just to add if anyone automating the deployment process (In my case, it was through CodeBuild And CodeDeploy), you can create Procfile and deploy the war. I have added Procfile into the root directory of the project and added it as an artifact.
Hope this helps someone looking for same usage case :)
ProcFile:
web: java -jar <your_war_file>.war
This is how my CodeBuild Buildspec looks like:
version: 0.2
phases:
build:
commands:
# - command
- ./gradlew bootWar
post_build:
commands:
# - command
- echo Build must be completed
- mv build/libs/*.war <WarFileName>.war
artifacts:
files:
# - location
- <WarFileName>.war
- Procfile
#name: $(date +%Y-%m-%d)
#discard-paths: yes
#base-directory: location
#cache:
#paths:
# - paths
If you check the Spring Boot docs, its clear that you are using the wrong directory structure.
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-spring-mvc
By default, Spring Boot serves static content from a directory called /static (or /public or /resources or /META-INF/resources) in the classpath or from the root of the ServletContext ... Do not use the src/main/webapp directory if your application is packaged as a jar. Although this directory is a common standard, it works only with war packaging, and it is silently ignored by most build tools if you generate a jar.
Since you have your app on port 5000 it is accessible on that port, not default http port 80.
Either access it with
http://my-aws-ebs-instance.com:5000/welcome
or create port forwarding rune in AWS so traffing going to port 80 will be pushed you application server's port 5000.
I am facing below error while using AWS SES Mail sending example?
"Exception in thread "main" java.lang.NoSuchMethodError: com.amazonaws.client.AwsSyncClientParams.getAdvancedConfig()Lcom/amazonaws/client/builder/AdvancedConfig;
at com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient.<init>(AmazonSimpleEmailServiceClient.java:277)
at com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient.<init>(AmazonSimpleEmailServiceClient.java:261)
at com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClientBuilder.build(AmazonSimpleEmailServiceClientBuilder.java:61)
at com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClientBuilder.build(AmazonSimpleEmailServiceClientBuilder.java:27)
at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46)
at saurabh.aws.learning.awsLearning.SendMailService.main(SendMailService.java:50)
"
Problem:
I also faced same issue.
The reason was that I was using difference artefact versions for my aws libraries: aws-java-sdk-core and aws-java-sdk-s3.
Solution (Maven):
In case you are using Maven, Amazon suggests to use BOM dependencyManagement. This way you ensure that the modules you specify use the same version of the SDK and that they're compatible with each other.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.11.522</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
And as you already declared the SDK version in the BOM, you don't need to specify the version number for each component. Like this:
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sqs</artifactId>
</dependency>
</dependencies>
Source: https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-project-maven.html#configuring-maven-individual-components
I have experienced this error myself. It is caused most likely by different versions of artifacts like: aws-java-sdk-ses and aws-java-sdk-core. Try using the same version for the two above in your pom.xml (if you are using maven). If this doesnt work, can you share your pom.xml ?
Even i had the same issue :
Exception in thread "main" java.lang.NoSuchMethodError:
com.amazonaws.client.AwsSyncClientParams.getAdvancedConfig()Lcom/amazonaws/client/builder/AdvancedConfig;
I tried configuring auto-scaling for my DynamoDB from java i faced this issue.
Solution:
We need to make sure aws sdk version match with the specific service version.
I used below dependency when i got exception,
compile group: 'com.amazonaws', name: 'aws-java-sdk-applicationautoscaling', version: '1.11.500'
compile group: 'com.amazonaws', name: 'aws-java-sdk-core', version: '1.11.123'
After changing to same version, issue got solved
compile group: 'com.amazonaws', name: 'aws-java-sdk-applicationautoscaling', version: '1.11.500'
compile group: 'com.amazonaws', name: 'aws-java-sdk-core', version: '1.11.500'