clean up
This commit is contained in:
parent
39af154b5d
commit
f461fc1fbb
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -67,25 +67,6 @@ public class MessageDrivenEJBBean implements MessageDrivenBean, MessageListener
|
|||||||
log("onMessage called");
|
log("onMessage called");
|
||||||
String msgPayload = tm.getText();
|
String msgPayload = tm.getText();
|
||||||
msgPayload.replace("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>","");
|
msgPayload.replace("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>","");
|
||||||
// sendHttpPost(text);
|
|
||||||
// Document jmsMessage = convertStringToXml(text);
|
|
||||||
// Node root = jmsMessage.getDocumentElement();
|
|
||||||
// int logID = getLogNextSeq();
|
|
||||||
// if (root != null){
|
|
||||||
// NodeList nodeList = ((Element) root).getElementsByTagName("soa:LogRequest");
|
|
||||||
// for (int i = 0; i < nodeList.getLength(); i++) {
|
|
||||||
// Node nodeXml = nodeList.item(i);
|
|
||||||
// if (nodeXml.getNodeType() == Node.ELEMENT_NODE) {
|
|
||||||
// Element element = (Element) nodeXml;
|
|
||||||
// System.out.println("[myMessageDrivenBean] element: " + element.toString() );
|
|
||||||
// } else {
|
|
||||||
// System.out.println("[myMessageDrivenBean] node: " + nodeXml.toString() );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String postPayload ="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:soa=\"http://soa-kemenkeu.org\"><soapenv:Header/><soapenv:Body>";
|
String postPayload ="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:soa=\"http://soa-kemenkeu.org\"><soapenv:Header/><soapenv:Body>";
|
||||||
String cleanPayload = msgPayload.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"", "");
|
String cleanPayload = msgPayload.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"", "");
|
||||||
String cleanPayload2 = cleanPayload.replace("?>", "");
|
String cleanPayload2 = cleanPayload.replace("?>", "");
|
||||||
@ -93,101 +74,20 @@ public class MessageDrivenEJBBean implements MessageDrivenBean, MessageListener
|
|||||||
postPayload += " </soapenv:Body></soapenv:Envelope>";
|
postPayload += " </soapenv:Body></soapenv:Envelope>";
|
||||||
|
|
||||||
|
|
||||||
System.out.println("[myMessageDrivenBean] Received message: " + msgPayload );
|
|
||||||
System.out.println("[myMessageDrivenBean] postPayload message: " + postPayload );
|
|
||||||
sendHttpPost(postPayload);
|
sendHttpPost(postPayload);
|
||||||
|
|
||||||
|
|
||||||
} catch(JMSException ex) {
|
} catch(JMSException ex) {
|
||||||
System.out.println("Caught JMSException: " + ex );
|
System.out.println("[logJmsMessageDrivenBean] Caught JMSException: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// private static String convertXmlToString(Document doc) {
|
|
||||||
// DOMSource domSource = new DOMSource(doc);
|
|
||||||
// StringWriter writer = new StringWriter();
|
|
||||||
// StreamResult result = new StreamResult(writer);
|
|
||||||
// TransformerFactory tf = TransformerFactory.newInstance();
|
|
||||||
// Transformer transformer = null;
|
|
||||||
// try {
|
|
||||||
// transformer = tf.newTransformer();
|
|
||||||
// transformer.transform(domSource, result);
|
|
||||||
// } catch (TransformerException e) {
|
|
||||||
// throw new RuntimeException(e);
|
|
||||||
// }
|
|
||||||
// return writer.toString();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private static Document convertStringToXml(String xmlString) {
|
|
||||||
//
|
|
||||||
// DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
|
||||||
//
|
|
||||||
// try {
|
|
||||||
//
|
|
||||||
// // optional, but recommended
|
|
||||||
// // process XML securely, avoid attacks like XML External Entities (XXE)
|
|
||||||
// dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
|
||||||
//
|
|
||||||
// DocumentBuilder builder = dbf.newDocumentBuilder();
|
|
||||||
//
|
|
||||||
// Document doc = builder.parse(new InputSource(new StringReader(xmlString)));
|
|
||||||
//
|
|
||||||
// return doc;
|
|
||||||
//
|
|
||||||
// } catch (ParserConfigurationException | IOException | SAXException e) {
|
|
||||||
// throw new RuntimeException(e);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private int getLogNextSeq(){
|
|
||||||
// int logId = 0;
|
|
||||||
// String dbUrl = ConfigUtil.getProperty("db.url");
|
|
||||||
// String dbUsername = ConfigUtil.getProperty("db.username");
|
|
||||||
// String dbPassword = ConfigUtil.getProperty("db.password");
|
|
||||||
// ResultSet rs = null;
|
|
||||||
// try (Connection connection = DriverManager.getConnection(dbUrl, dbUsername, dbPassword)) {
|
|
||||||
// String sql = "SELECT PKLOGIDSEQ.nextval FROM dual";
|
|
||||||
// PreparedStatement preparedStatement = connection.prepareStatement(sql);
|
|
||||||
// rs = preparedStatement.executeQuery();
|
|
||||||
//
|
|
||||||
// if (rs.next()) {
|
|
||||||
// logId = rs.getInt(1);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// e.printStackTrace();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return logId;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private void storeMessageInDatabase(String messageContent) {
|
|
||||||
// String dbUrl = ConfigUtil.getProperty("db.url");
|
|
||||||
// String dbUsername = ConfigUtil.getProperty("db.username");
|
|
||||||
// String dbPassword = ConfigUtil.getProperty("db.password");
|
|
||||||
//
|
|
||||||
// try (Connection connection = DriverManager.getConnection(dbUrl, dbUsername, dbPassword)) {
|
|
||||||
// String sql = "INSERT INTO jms_messages (message_content) VALUES (?)";
|
|
||||||
// try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
|
||||||
// preparedStatement.setString(1, messageContent);
|
|
||||||
// preparedStatement.executeUpdate();
|
|
||||||
// System.out.println("Message stored in the database successfully.");
|
|
||||||
// }
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// e.printStackTrace();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
private void sendHttpPost(String messageContent) {
|
private void sendHttpPost(String messageContent) {
|
||||||
try {
|
try {
|
||||||
String apiUrl = ConfigUtil.getProperty("api.url");
|
String apiUrl = ConfigUtil.getProperty("api.url");
|
||||||
URL url = new URL(apiUrl);
|
URL url = new URL(apiUrl);
|
||||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
|
|
||||||
// URL url = new URL("http://localhost:17080/soa-infra/services/default/SoaLoggerProject/LogOsbInsertService");
|
|
||||||
// HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
|
||||||
conn.setRequestMethod("POST");
|
conn.setRequestMethod("POST");
|
||||||
conn.setRequestProperty("Content-Type", "text/xml");
|
conn.setRequestProperty("Content-Type", "text/xml");
|
||||||
conn.setRequestProperty("SOAPAction","\"execute\"");
|
conn.setRequestProperty("SOAPAction","\"execute\"");
|
||||||
@ -197,17 +97,14 @@ public class MessageDrivenEJBBean implements MessageDrivenBean, MessageListener
|
|||||||
String body = messageContent;
|
String body = messageContent;
|
||||||
OutputStream out = conn.getOutputStream();
|
OutputStream out = conn.getOutputStream();
|
||||||
OutputStreamWriter wout = new OutputStreamWriter(out, "UTF-8");
|
OutputStreamWriter wout = new OutputStreamWriter(out, "UTF-8");
|
||||||
// System.out.println("Writing message: " + body + " to outputstream.");
|
|
||||||
wout.write(body);
|
wout.write(body);
|
||||||
wout.flush();
|
wout.flush();
|
||||||
out.close();
|
out.close();
|
||||||
|
|
||||||
// OutputStream output = new BufferedOutputStream(conn.getOutputStream());
|
|
||||||
// output.write(body.getBytes());
|
|
||||||
// output.flush();
|
|
||||||
|
|
||||||
int responseCode = conn.getResponseCode();
|
int responseCode = conn.getResponseCode();
|
||||||
// System.out.println("POST Response Code :: " + responseCode);
|
System.out.println("[logJmsMessageDrivenBean] POST Response Code :: " + responseCode);
|
||||||
|
|
||||||
if (responseCode == HttpURLConnection.HTTP_OK) { // success
|
if (responseCode == HttpURLConnection.HTTP_OK) { // success
|
||||||
try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
|
try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
|
||||||
@ -216,14 +113,14 @@ public class MessageDrivenEJBBean implements MessageDrivenBean, MessageListener
|
|||||||
while ((inputLine = in.readLine()) != null) {
|
while ((inputLine = in.readLine()) != null) {
|
||||||
response.append(inputLine);
|
response.append(inputLine);
|
||||||
}
|
}
|
||||||
System.out.println("Response :: " + response.toString());
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
System.out.println("POST request failed");
|
System.out.println("[logJmsMessageDrivenBean] POST request failed");
|
||||||
}
|
}
|
||||||
conn.disconnect();
|
conn.disconnect();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
System.out.println("[logJmsMessageDrivenBean] sendHttpPost Exception : " + e.getMessage());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user