My Runner Class
package Runner;
import org.junit.runner.RunWith;
import io.cucumber.junit.CucumberOptions;
import io.cucumber.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(features={"src/test/resources/"}, glue= {"Steps"})
public class TestRunner {
}
Related
the spring boot REST app with MySQL
I am trying to add record to DB and expect the record added and postman got it as output instead of the output "status":404,"error":"Not Found","path":"/api/employees" following is the classes
package com.controller;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.service.EmployeeService;
import com.model.Employee;
#RestController
#RequestMapping("/api")
public class EmployeeController {
private EmployeeService employeeservice;
public EmployeeController(EmployeeService employeeservice) {
super();
this.employeeservice = employeeservice;
}
//build create Employee REST API
#PostMapping("/employees")
public ResponseEntity<Employee> saveEmployee(#RequestBody Employee employee)
{
return new ResponseEntity<Employee>(employeeservice.saveEmployee(employee), HttpStatus.CREATED);
}
}
package com;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
#EnableJpaRepositories(
basePackages = {"com.model"})
#SpringBootApplication(scanBasePackages = {"service.impl"})
public class RestapimysqlApplication {
public static void main(String[] args) {
SpringApplication.run(RestapimysqlApplication.class, args);
}
}
It doesn't look like you're scanning the package that contains your REST controller (i.e. com.controller), seems like you're only scanning the service.impl package on your RestapimysqlApplication class.
You should probably add the com.controller to the list of packages being scanned by Spring here:
#EnableJpaRepositories(basePackages = {"com.repository"})
#SpringBootApplication(scanBasePackages = {"service.impl", "com"})
#EntityScan({"com.model"})
public class RestapimysqlApplication {
...
}
I'm developing a custom skill to Alexa (Amazon), and I coded the skill in lambda AWS service in JAVA 8. I'm trying to get a simple response from my ask2decide API and it's not working.
Basically I'm executing the following code:
String questiont = "casco"
String queryString =
String.format("https://www.ask2decide.com/api/prod/search.php?s=%s", questiont);
InputStreamReader inputStream = null;
BufferedReader bufferedReader = null;
StringBuilder builder = new StringBuilder();
try {
String line;
URL url = new URL(queryString);
inputStream = new InputStreamReader(url.openStream(), Charset.forName("US-ASCII"));
bufferedReader = new BufferedReader(inputStream);
while ((line = bufferedReader.readLine()) != null) {
builder.append(line);
System.out.println(line);
}
} catch (IOException e) {
// reset builder to a blank string
System.out.print("ERROR:");
System.out.println(e);
} finally {
IOUtils.closeQuietly(inputStream);
IOUtils.closeQuietly(bufferedReader);
}
The result of executing it is the following
error:"javax.net.ssl.SSLHandshakeException: Remote host closed
connection during handshake"
Note: I get a JSON standard array if I execute the URL in Chrome without any error.
Note2: The imports:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.security.*;
import javax.net.ssl.*;
import java.nio.charset.Charset;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.amazon.speech.slu.Intent;
import com.amazon.speech.slu.Slot;
import com.amazon.speech.speechlet.IntentRequest;
import com.amazon.speech.speechlet.LaunchRequest;
import com.amazon.speech.speechlet.Session;
import com.amazon.speech.speechlet.SessionEndedRequest;
import com.amazon.speech.speechlet.SessionStartedRequest;
import com.amazon.speech.speechlet.SpeechletV2;
import com.amazon.speech.speechlet.SpeechletResponse;
import com.amazon.speech.json.SpeechletRequestEnvelope;
import com.amazon.speech.ui.OutputSpeech;
import com.amazon.speech.ui.PlainTextOutputSpeech;
import com.amazon.speech.ui.SsmlOutputSpeech;
import com.amazon.speech.ui.Reprompt;
import com.amazon.speech.ui.SimpleCard;
import com.amazonaws.util.json.JSONArray;
import com.amazonaws.util.json.JSONException;
import com.amazonaws.util.json.JSONObject;
import com.amazonaws.util.json.JSONTokener;
I am trying to import my original package.
But it is said that there is no class files form Akirasda1972_001.as.
My package file is uploaded on sexydesign.club/particle/.
package{
import flash.display.Sprite;
import club.sexydesign.particle.Akirasada1972_001;
public class akirasada1972_002 extends Sprite{
private var akirasada1972_001:Akirasada1972_001;
public function akirasada1972_002():void{
akirasada1972_001=new Akirasada1972_001();
akirasada1972_001.Akirasada1972_001();
addChild(akirasada1972_001);
}
}
}
How an application which serves resources (.js; .css...) could return JSON entities if an error occurs ?
I wrote a ControllerExceptionHandler according to this blog:
package com.my.rest;
import com.my.rest.errors.ErrorMessage;
import com.my.rest.errors.ErrorMessageFactory;
import com.my.service.errors.NotFoundException;
import com.my.service.errors.ValidationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import static org.springframework.http.HttpStatus.NOT_FOUND;
#ControllerAdvice
#ResponseBody
public class GlobalControllerExceptionHandler extends ResponseEntityExceptionHandler {
#Autowired
private ErrorMessageFactory messageFactory;
#ResponseStatus(NOT_FOUND)
#ExceptionHandler({NotFoundException.class})
public ResponseEntity<Object> handleServiceException(RuntimeException e, WebRequest request) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
return handleExceptionInternal(e, messageFactory.generateMessage(e), headers, HttpStatus.NOT_FOUND, request);
}
}
If the request URL is: https://my-server/resources/a.js, but a.js is not found, this ExceptionHandler leads to a HttpMediaTypeNotAcceptableException thrown by AbstractMessageConverterMethodProcessor because ContentNegotiationManager uses a strategy based on the extension .js, and determines that ErrorMessage is not applicable to the media type application/javascript.
My question is: Is there a way to ignore the check of media type to always send JSON error responses so that the client-side error management can parse it ?
Thank you
i'm looking at some example code that is erroring out in scala 2.9.1:
import javax.swing.JFrame
import javax.swing.JMenuBar
import javax.swing.JButton
import javax.swing._
import com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel
import javax.swing.{UIManager}
object UI extends SimpleSwingApplication {
UIManager.setLookAndFeel(new NimbusLookAndFeel)
}
error: /some/path/Cls.scala:25: error: not found: type SimpleSwingApplication
turns out i had to run my code like so:
scala -classpath /usr/share/java/scala-swing.jar Cls.scala
the code base that was successful is:
import javax.swing.JFrame
import javax.swing.JMenuBar
import javax.swing.JButton
import javax.swing._
import scala.swing.SimpleSwingApplication
import scala.swing._
object UI extends SimpleSwingApplication {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
def top = new MainFrame {
title = "First Swing App"
contents = new Button {
text = "Click me"
}
}
def main() {
println("hi")
}
}