I have a requirement that I need to convert xsd file to POJO files. While using tomcat I didnot face any issue but when I am using weblogic I am getting error
Can't find resource for bundle java.util.PropertyResouceBundle,key JAXPSupportedProperty
File tmpDir = util.createTempPOJODirectory();
String xsdFilePath = convertToXSD(xmlResponse, tmpDir); // The xml response will be converted to XML file and then converted to XSD file
if (StringUtils.isNotBlank(xsdFilePath)) {
log("XSD location ::" + xsdFilePath + " and output location :: " + tmpDir);
// Setup schema compiler
SchemaCompiler sc = XJC.createSchemaCompiler();
sc.forcePackageName("");
// Setup SAX InputSource
File schemaFile = new File(xsdFilePath);
InputSource is = new InputSource(schemaFile.toURI().toString());
// is.setSystemId(schemaFile.getAbsolutePath());
// Parse & build
sc.parseSchema(is);
log("after parsing and building");
log("sc :: " + sc);
S2JJAXBModel model = null;
try {
model = sc.bind();
}
catch (Exception e1) {
log("Exception :: " + ExceptionUtils.getFullStackTrace(e1));
}
log("model :: " + model);
try {
JCodeModel jCodeModel = model.generateCode(null, null);
jCodeModel.build(tmpDir);
log("generation POJO's is success");
return "POJO are created under " + tmpDir + " successfully.";
}
catch (IOException e) {
log("unable to generate POJO's");
log("IOException occurs :: " + ExceptionUtils.getFullStackTrace(e));
}
catch (Exception e) {
log("Exception occurs :: " + ExceptionUtils.getFullStackTrace(e));
}`
For this I have used below jars :-
xsd-gen-0.2.1.jar
xom-1.2.5.jar
wiztools-commons-lib-0.4.1.jar
jaxb-xjc-2.2.11.jar
jaxb-core-2.2.11.jar
cli-7.jar
Thanks guys, I have resolved this issue by removing jaxb jars.
Related
Project setup:
<java.version>1.8</java.version>
<spring.version>4.3.9.RELEASE</spring.version>
<spring.boot.version>1.4.3.RELEASE</spring.boot.version>
We have a REST controller that has a method to upload file like this:
#PostMapping("/spreadsheet/upload")
public ResponseEntity<?> uploadSpreadsheet(#RequestBody MultipartFile file) {
if (null == file || file.isEmpty()) {
return new ResponseEntity<>("please select a file!", HttpStatus.NO_CONTENT);
} else if (blueCostService.isDuplicateSpreadsheetUploaded(file.getOriginalFilename())) {
return new ResponseEntity<>("Duplicate Spreadsheet. Please select a different file to upload",
HttpStatus.CONFLICT);
} else {
try {
saveUploadedFiles(Arrays.asList(file));
} catch (IOException e) {
e.printStackTrace();
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
return new ResponseEntity("Successfully uploaded - " + file.getOriginalFilename(), new HttpHeaders(),
HttpStatus.OK);
}
}
UPDATE:
I've tried this approach from an old example I found, but it doesn't compile cleanly, the MockMvcRequestBuilders.multipart method is not defined....
#Test
public void testUploadSpreadsheet_Empty() throws Exception {
String fileName = "EmptySpreadsheet.xls";
String content = "";
MockMultipartFile mockMultipartFile = new MockMultipartFile(
"emptyFile",
fileName,
"text/plain",
content.getBytes());
System.out.println("emptyFile content is '" + mockMultipartFile.toString() + "'.");
mockMvc.perform(MockMvcRequestBuilders.multipart("/bluecost/spreadsheet/upload")
.file("file", mockMultipartFile.getBytes())
.characterEncoding("UTF-8"))
.andExpect(status().isOk());
}
I believe MockMvcRequestBuilders.multipart() is only available since Spring 5. What you want is MockMvcRequestBuilders.fileUpload() that is available in Spring 4.
I am new to linux environment.I have a web application which is running fine in windows environment and it is developed using play framework.Now we want to move our application from windows to linux. Here issue is,while uploading files i'm getting internal server error.I have given permissions as 777 for folder.Even the controller doesn't invoke the method,how to solve it?I am unable to find where the error goes,For all help thanks in advance.
Error is :
Controller action :
#helper.form(action =routes.HoForms.uploadHoFormsByHeadOffice(),'enctype -> "multipart/form-data" ,'id -> "shiftSummaryForm")
{
}
In routes file :
POST /HeadOfficeForms/upload controllers.HoForms.uploadHoFormsByHeadOffice()
Controller method :
public static Result uploadHoFormsByHeadOffice() throws Exception {
Logger.info("#C HoForms -->> uploadHoFormsByHeadOffice() -->> ");
}
Upload method() :
public static Result uploadHoFormsByHeadOffice() throws Exception {
final String basePath = "/var/www/html/pdfs/";
Date date = new Date();
DateFormat format = new SimpleDateFormat("dd-MM-yyyy");
String startDate = format.format(date);
date = format.parse(startDate);
play.mvc.Http.MultipartFormData body = request().body()
.asMultipartFormData();
String formType = body.asFormUrlEncoded().get("formType")[0];
FilePart upFile = body.getFile("hoFormFiles");
String fileName = upFile.getFilename();
try {
File ftemp = new File(basePath + "HeadOfficeForms/" + formType
+ "");
ftemp.mkdirs();
String filePathString = "HeadOfficeForms/" + formType + "/"
+ fileName;
File f1 = new File(ftemp.getAbsolutePath() + "/" + fileName);
File file = upFile.getFile();
file.setWritable(true);
file.setReadable(true);
f1.setWritable(true);
f1.setReadable(true);
Files.copy(file.toPath(), f1.toPath(), REPLACE_EXISTING);
HoForm.create(fileName, date, formType, filePathString);
flash("success", fileName + " Has been Successfully Uploaded");
} catch (IOException e) {
e.printStackTrace();
}
return redirect(routes.HoForms.showHoFormUploadPage());
}
I am trying to connect MS SQL database using JDBC in Android Studio 1.1.0. I am refering to this site for connecting. Here is my code for connecting:
import android.annotation.SuppressLint;
import android.os.StrictMode;
import android.util.Log;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.DriverManager;
public class ConnectionClass {
String ip = "IP_Address(for eg.192.168.5.60)";
String classs = "net.sourceforge.jtds.jdbc.Driver";
String db = "Andro";
String un = "username";
String password = "pwd";
#SuppressLint("NewApi")
public Connection CONN() {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection conn = null;
String ConnURL = null;
try {
Class.forName(classs);
/* ConnURL = "jdbc:jtds:sqlserver://" + ip + "/"
+ "databaseName=" + db + ";user=" + un + ";password="
+ password + ";";*/
ConnURL= "jdbc:jtds:sqlserver://IP_Address(for eg.192.168.5.60)/databaseName=Andro;user=username;password=pwd;";
conn = DriverManager.getConnection(ConnURL);
} catch (SQLException se) {
Log.e("ERRO", se.getMessage());
} catch (ClassNotFoundException e) {
Log.e("ERRO", e.getMessage());
} catch (Exception e) {
Log.e("ERRO", e.getMessage());
}
return conn;
}
}
Calling connectionClass.CONN() function like this:
#Override
protected String doInBackground(String... params) {
if(userid.trim().equals("")|| password.trim().equals(""))
z = "Please enter User Id and Password";
else
{
try {
Connection con = connectionClass.CONN();
if (con == null) {
z = "Error in connection with SQL server";
} else {
heading.setText("u"+con.toString());
String query = "select * from Usertbl where UserId='" + userid + "' and Password='" + password + "'";
Statement stmt = con.createStatement();
heading.setText("After statement");
ResultSet rs = stmt.executeQuery(query);
// heading.setText(rs.getString(1));
z = "under else block";
if(rs.next())
{
z = "Login successfull";
isSuccess=true;
}
else
{
z = "Invalid Credentials";
isSuccess = false;
}
}
}
catch (Exception ex)
{
isSuccess = false;
z = "Exceptions";
}
}
return z;
}
I just want to connect database with android studio. The error shows like this
Please suggest any solution or any hint to perform connectivity.
The error is because you are trying to set the text value of a textview field from the Asynchronous task.
Over here : heading.setText("u"+con.toString());
Just remove this and the error might be solved.
Also note that Asynchronous task cannot set the value of the activity component like EditText,Textview or even a button field.
i had also been trying to connect ms sql database from android studio, succeeded last night using the given link
https://www.youtube.com/watch?v=HRF8NpoFteg
note that jtds-1.2.7 must be downloaded, latest versions might not work for real mobile (i was facing this problem for one week the database connected on emulator but not on real mobile).
further after including jtds-1.2.7 gradle build might give an error of instant run kindly uncheck instant run from file -> settings -> instant run -> uncheck enable instant run.
hope it hepls!!!
I get generic error occurred in GDI+ for selenium webdriver.It was working fine still yesterday,But suddenly I get this error.
public string TakeScreenshot(IWebDriver driver, string SnapFolderPath, string TCID, string KeyFunction)
{
try
{
// driver.Manage().Window.Maximize();
ITakesScreenshot ssdriver = driver as ITakesScreenshot;
Screenshot screenshot = ssdriver.GetScreenshot();
string filePath = testReport + "\\" + TCID + "_" + KeyFunction + "_" + GetDateTimeforFilePath() + ".png";
screenshot.SaveAsFile(filePath, ImageFormat.Png);
return filePath;
}
catch (Exception ex)
{
return string.Empty;
}
}
Resolved this Issue .We need to give full access permission to the folder where we want to store the image.If we don't give full permission we get this error
I use log4j for the logging.
I could see the SQLs through Log4j like below.
Here's my java source which access data base with jdbcTemplate.
public QnaDTO selectBoard(int articleID) {
String SQL =
"SELECT " +
" QA.ARTICLE_ID, " +
" QA.EMAIL, " +
" QA.TEL, " +
" QA.CATEGORY_ID, " +
" CG.CATEGORY_NAME, " +
" QA.SUBJECT, " +
" QA.CONTESTS, " +
" QA.WRITER_NAME, " +
" QA.WRITER_ID, " +
" QA.READCOUNT, " +
" QA.ANSWER, " +
" QA.FILE_NAME, " +
" QA.OPEN_FLG, " +
" QA.KTOPEN_FLG, " +
" TO_CHAR(QA.WRITE_DAY, 'YYYY.MM.DD') WRITE_DAY, " +
" QA.DISPOSAL_FLG " +
"FROM QNA QA JOIN QNA_CATEGORY_GROUP CG " +
"ON QA.CATEGORY_ID = CG.CATEGORY_ID " +
"WHERE QA.ARTICLE_ID = ? ";
QnaDTO qnaDTO = (QnaDTO) jdbcTemplate.queryForObject(
SQL,
new Object[]{articleID},
new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
QnaDTO qnaDTO = new QnaDTO();
qnaDTO.setArticleID(rs.getInt("ARTICLE_ID"));
qnaDTO.setCategoryID(rs.getInt("CATEGORY_ID"));
qnaDTO.setCategoryName(rs.getString("CATEGORY_NAME"));
qnaDTO.setEmail1(rs.getString("EMAIL"));
qnaDTO.setTel1(rs.getString("TEL"));
qnaDTO.setSubject(rs.getString("SUBJECT"));
qnaDTO.setContests(rs.getString("CONTESTS"));
qnaDTO.setName(rs.getString("WRITER_NAME"));
qnaDTO.setUserID(rs.getString("WRITER_ID"));
//
qnaDTO.setReadcount(rs.getString("READCOUNT"));
qnaDTO.setAnswer(rs.getString("ANSWER"));
qnaDTO.setFileName(rs.getString("FILE_NAME"));
qnaDTO.setOpenFlg(rs.getString("OPEN_FLG"));
qnaDTO.setKtOpenFlg(rs.getString("KTOPEN_FLG"));
//
qnaDTO.setWriteDay(rs.getString("WRITE_DAY"));
qnaDTO.setDisposalFlg(rs.getString("DISPOSAL_FLG"));
return qnaDTO;
}
}
);
return qnaDTO;
}
As you can see above.
jdbcTemplate.queryForObject(...) is the method which really send Query And Get some result.
Inside of jdbcTemplate.queryForObject, finally logger used
public Object query(final String sql, final ResultSetExtractor rse)
throws DataAccessException
{
Assert.notNull(sql, "SQL must not be null");
Assert.notNull(rse, "ResultSetExtractor must not be null");
if(logger.isDebugEnabled())
logger.debug("Executing SQL query [" + sql + "]");
class _cls1QueryStatementCallback
implements StatementCallback, SqlProvider
{
public Object doInStatement(Statement stmt)
throws SQLException
{
ResultSet rs = null;
Object obj;
try
{
rs = stmt.executeQuery(sql);
ResultSet rsToUse = rs;
if(nativeJdbcExtractor != null)
rsToUse = nativeJdbcExtractor.getNativeResultSet(rs);
obj = rse.extractData(rsToUse);
}
finally
{
JdbcUtils.closeResultSet(rs);
}
return obj;
}
public String getSql()
{
return sql;
}
_cls1QueryStatementCallback()
{
super();
}
}
return execute(new _cls1QueryStatementCallback());
}
But with above sources, I could only get the SQL with ?.
What I want is that my result doesn't have question mark ?
It means filling ? with real data.
Is there any way to do this?
thanks
Jeon, sorry, was occupied with work. :-) Anyway, I have looked into your code and replicate here using spring 2.5. I've also google and I think you want to read this and this further to understand.
From the official documentation,
Finally, all of the SQL issued by this class is logged at the 'DEBUG'
level under the category corresponding to the fully qualified class
name of the template instance (typically JdbcTemplate, but it may be
different if a custom subclass of the JdbcTemplate class is being
used).
So you need to figure out how to enable logging with debug level.
Not sure exactly how you trace, but with my trace, I end up to below. So if you enable debug level, you should be able to see the output, maybe not exactly like QA.ARTICLE_ID = 123; but you should probably get the value printed in the next line something like in that example. Anyway, I don't have the exact setup like in your environment but this I think should you give a clue.
public Object execute(PreparedStatementCreator psc, PreparedStatementCallback action)
throws DataAccessException {
Assert.notNull(psc, "PreparedStatementCreator must not be null");
Assert.notNull(action, "Callback object must not be null");
if (logger.isDebugEnabled()) {
String sql = getSql(psc);
logger.debug("Executing prepared SQL statement" + (sql != null ? " [" + sql + "]" : ""));
}