Results 1 to 8 of 8
Thread: javastring problem
- 07-02-2010, 07:08 PM #1
Member
- Join Date
- Jul 2010
- Posts
- 5
- Rep Power
- 0
javastring problem
I'm getting string as
String url = request.getRequestURL().toString();
and url String could be either one of following three
e.g 1) http://www.abctest.com
2) http://wwwcte.abctest.com
3) http://mydev.abctest.com
I'm need split the url as
String[] urlpref = url.split(".");
String test = urlpref[0];
to get the first part of url before "."
and compare it with "www"
if(test.indexof("www")>-1)
{ go to page url start with www}
else
{go to page url start other then www}
but it is giving error
I'm very new to java can any one help me to get the first part of the string before "."
and help me compare that part with "WWW"
thanks,
- 07-02-2010, 08:16 PM #2
Please copy and paste the full text of the error message here.it is giving error
try debugging your code by printing out the values in the array so you can see what is happening.
- 07-02-2010, 09:11 PM #3
Member
- Join Date
- Jul 2010
- Posts
- 5
- Rep Power
- 0
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="com.actuate.reportcast.utils.*" %>
<%@ page import="com.actuate.activeportal.beans.*" %>
<%@ page import="com.actuate.activeportal.idapiadapter.*" %>
<%@ page import="com.actuate.schemas.*" %>
<%@ page import="com.actuate.activeportal.utils.*" %>
<%@ page import="org.apache.axis.client.*" %>
<%@ page import="org.apache.axis.Message" %>
<%@ page import="org.apache.axis.MessageContext" %>
<%@ page import="org.apache.axis.attachments.AttachmentPart " %>
<%@ page import="java.io.*" %>
<%@ page import="java.net.*" %>
<%@ page import="javax.xml.parsers.*" %>
<%@ page import="org.w3c.dom.*" %>
<%@ page import="org.apache.xerces.parsers.DOMParser " %>
<%@ page import="javax.xml.transform.*" %>
<%@ page import="javax.xml.transform.stream.*" %>
<%@ page import = "org.apache.xpath.*" %>
<%@page import="com.wachovia.beans.*"%>
<%@ page import="java.util.*" %>
<%@page import="java.sql.*"%>
<%@page import="oracle.jdbc.driver.*"%>
<%@page import="oracle.sql.*"%>
<%@page import="javax.servlet.ServletContext.*"%>
<%@page import="javax.servlet.ServletRequest.*"%>
<%@page import="javax.servlet.http.HttpServletRequest.*"%>
<%@page import="com.actuate.reportcast.exceptions.Authenti cationException.*"%>
<%@ taglib uri="/common" prefix="common" %>
<%@ page import="com.actuate.reportcast.utils.StaticFuncs" %>
<%-- GATHER AUTHENTICATION CREDENTIALS AT THE TOP OF ALL LEVEL 0 PAGES --%>
<%@ include file="/iportal/activePortal/authenticate.jsp" %>
<% if (sAuthID == null) return; %>
<%-- TAG LIBRARIES ------------------------------------------------------- --%>
<%@ taglib uri="/struts-bean" prefix="bean" %>
<%@ taglib uri="/struts-html" prefix="html" %>
<%@ taglib uri="/struts-logic" prefix="logic" %>
<%@ taglib uri="/i18n" prefix="i18n" %>
<%@ taglib uri="/viewer" prefix="viewer" %>
<%@ taglib uri="/common" prefix="common" %>
<%-- DECLARE ANY RESOURCE BUNDLES USED IN THIS PAGE --%>
<i18n:bundle baseName="com.actuate.reportcast.resources.rc.View er" id="bdlViewer" locale="<%= lLocale %>"/>
<%
String XMLfile = null;
String XSLfile = null;
String AuthType = null;
String objectId = paramBean.getParameter("id");
//out.println(objectId);
String connectionHandle = paramBean.getParameter("connectionhandle");
//out.println(connectionHandle);
String serverURL = sServerURL;
//out.println(serverURL);
String volume = sVolume;
//out.println(volume);
//out.println(sAuthID);
//String ServerName = request.getServerName();
int ServerPort = request.getServerPort();
out.println("uri=" + ServerPort);
//out.println("SP=" + ServerName);
%>
<%
// Get the person_id from the header
String person_id = request.getHeader("proxy-remote-user");
// Get the info for web.xml
ServletContext context = getServletContext();
String HOST_NAME = context.getInitParameter("HOST_NAME");
String PORT = context.getInitParameter("PORT");
String SERVICE_NAME = context.getInitParameter("SERVICE_NAME");
String USER = context.getInitParameter("USER");
String PASSWORD = context.getInitParameter("PASSWORD");
String ENVIRONMENT_URL = context.getInitParameter("ENVIRONMENT_URL");
String ENVIRONMENT_URL_EXTERNAL = context.getInitParameter("ENVIRONMENT_URL_EXTERNAL ");
try {
IdapiProxyPool thePool = IdapiProxyPool.getInstance();
//IdapiProxy prox = thePool.getProxyObject(serverURL);
//Changed to make it work in ver-8.0
IdapiProxy prox = (IdapiProxy) thePool.getProxyObject(serverURL);
ActuateAPIEx actuateAPI = prox.getActuateAPI();
ActuateSoapPort wsdlProxy = actuateAPI.getActuateSoapPort(new java.net.URL(serverURL));
actuateAPI.setTargetVolume(volume);
actuateAPI.setAuthId(sAuthID);
// Get XML Content
com.actuate.schemas.GetContent getContentmsg = new com.actuate.schemas.GetContent();
com.actuate.schemas.ObjectIdentifier obj = new com.actuate.schemas.ObjectIdentifier();
obj.setId(objectId); //make sure to check in viewnavigation that is the same id
com.actuate.schemas.ViewParameter type = new com.actuate.schemas.ViewParameter();
type.setFormat("XMLData");
type.setUserAgent("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Q312461; .NET CLR 1.0.3705)");
com.actuate.schemas.ComponentType comp = new com.actuate.schemas.ComponentType();
comp.setId("0");
getContentmsg.setObject(obj);
getContentmsg.setViewParameter(type);
getContentmsg.setComponent(comp);
getContentmsg.setDownloadEmbedded(new Boolean(false));
//connectionHandle is Soap Header for GetContent request (required for transient reports)
actuateAPI.setConnectionHandle(connectionHandle);
com.actuate.schemas.GetContentResponse getContentresp = wsdlProxy.getContent(getContentmsg);
Call call = actuateAPI.getCall();
MessageContext messageContext = call.getMessageContext();
Message message = messageContext.getResponseMessage();
// show the first attachment
Iterator iterator = message.getAttachments();
if (iterator.hasNext()) {
AttachmentPart attachmentPart = (AttachmentPart) iterator.next();
XMLfile = attachmentPart.getDataHandler().getName();
attachmentPart.getDataHandler().getOutputStream();
String attachmentttype = attachmentPart.getContentType();
//out.print("file is located at: " + XMLfile);
//out.print(attachmentPart.getDataHandler().getConte nt());
}
else //no attachments were received
{
out.println("Error while receiving the report attachment");
}
ServletContext sc = getServletConfig().getServletContext();
String path = sc.getRealPath("/");
out.println(path);
//Stream the XML and XSL and produce output
StreamSource xml = new StreamSource(XMLfile);
StreamSource xsl = new StreamSource(path + "/wfa/jsp/MailMerge.xsl");
java.io.File resultFile = java.io.File.createTempFile("Streams", ".xml");
Result result = new StreamResult(resultFile);
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(xsl);
transformer.transform(xml,result);
out.print("file is located at: " + resultFile);
out.print("The file length is " + resultFile.length());
//Open the test file and get the bytes
byte[] reportBytes = new byte[(int)resultFile.length()];
FileInputStream fr = new FileInputStream(resultFile);
while(fr.read(reportBytes) != -1)
{
fr.read(reportBytes);
}
String userId = "123456";
//BEGIN DATABASE INSERT CODE
Connection conn = null;
java.sql.Statement stmt = null;
java.sql.ResultSet rs = null;
Timestamp ts = new Timestamp(System.currentTimeMillis());
Calendar dt = Calendar.getInstance();
String requestId = Integer.toString(dt.get(Calendar.YEAR)) + Integer.toString(dt.get(Calendar.MONTH)) + Integer.toString(dt.get(Calendar.DAY_OF_MONTH)) + Integer.toString(dt.get(Calendar.HOUR_OF_DAY)) + Integer.toString(dt.get(Calendar.MINUTE)) + Integer.toString(dt.get(Calendar.SECOND)) + Integer.toString(dt.get(Calendar.MILLISECOND)) + userId;
long fileLength = reportBytes.length;
String connectionString = "jdbc:oracle:thin:@(DESCRIPTION=" +
"(ADDRESS_LIST=" +
"(ADDRESS=(PROTOCOL=TCP)" +
"(HOST=" + HOST_NAME + ")" +
"(PORT=" + PORT + ")" +
")" +
")" +
"(CONNECT_DATA=" +
"(SERVICE_NAME=" + SERVICE_NAME + ")" +
"(SERVER=DEDICATED)" +
")" +
")";
String insertSql = "INSERT INTO AC_REPORT_XML (REQUEST_ID, XML_TXT, XML_BYTE_CNT, REQUEST_DTM,USER_ID) VALUES ('" + requestId + "', EMPTY_BLOB(), " + fileLength + ", { ts '" + ts + "'}, '"+ person_id +"')";
String updateSql = "SELECT xml_txt FROM ac_report_xml WHERE request_id='" + requestId + "' FOR UPDATE";
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
conn = DriverManager.getConnection(connectionString, USER ,PASSWORD);
conn.setAutoCommit(false);
stmt = conn.createStatement();
stmt.execute(insertSql);
// Select the BLOB
rs = stmt.executeQuery(updateSql);
if (rs.next()) {
BLOB blob = ((OracleResultSet)rs).getBLOB(1);
// Create an OutputStram object to write the BLOB as a stream
OutputStream ostream = blob.getBinaryOutputStream();
ostream.write(reportBytes);
//Close the inputstream and outputstream
ostream.close();
}
conn.commit();
}
catch (Exception ex){
out.println(ex);
ex.printStackTrace();
requestId = null;
}
finally{
try{
if(rs != null) rs.close();
if(stmt != null) stmt.close();
if(conn != null) conn.close();
}
catch (Exception e){
e.printStackTrace();
}
}
//END DATABASE INSERT CODE
//check if the request is secure
if (!request.isSecure())
{
AuthType = "http://";
}
else {
AuthType = "https://";
}
if (requestId != null && requestId != "")
{
//Read the Request URL
//Added by -Jay Talasila May 2010
//Redirect to External URL functionality is added - New Variable ENVIRONMENT_URL_EXTERNAL is created in Web.xml
//This variable is specific to evnironment
String url = request.getRequestURL().toString();
//String delimiter = ".";
alert (url);
//String[] urlprefx = url.split(".");
//String test = urlprefx[0];
//String abc = urlprefx[0];
//if(test.indexOf("www")>-1)
if(url.indexOf("//www.")>-1)
{
response.sendRedirect(AuthType + ENVIRONMENT_URL_EXTERNAL + "/mailmerge/TemplateList.aspx?requestId=" + requestId);
}
else
{
// Changed it as part of upgrade to 9SP3 as the APS is unable to process the prior URLs.
// response.sendRedirect(AuthType + ENVIRONMENT_NAME_EXTERNAL + "/mailmerge/TemplateList.aspx?requestId=" + requestId);
response.sendRedirect(AuthType + ENVIRONMENT_URL + "/mailmerge/TemplateList.aspx?requestId=" + requestId);
//response.sendRedirect("https://mydev.advisor-connection.com/mailmerge/TemplateList.aspx?requestId=" + requestId);
// out.println(AuthType + ENVIRONMENT_URL + "/mailmerge/TemplateList.aspx?requestId=" + requestId);
}
}
} // end of big try
catch (Exception e) {
String sErrorMsg = e.getMessage();
sErrorMsg = sErrorMsg.replace('\n', ' ');
sErrorMsg = sErrorMsg.replace('"', ' ');
sErrorMsg = sErrorMsg.replace('=', '-');
String sURLError = StaticFuncs.jsEncode(request.getContextPath()) + "/wfa/jsp/displayerror.jsp?errorcode=MailMerge&errormsg=" + sErrorMsg;
response.sendRedirect(sURLError);
}
File file = new File(XMLfile);
try {
// Create file if it does not exist
boolean success = file.createNewFile();
if (success) {
// File did not exist and was created
} else {
// File already exists
}
} catch (IOException e) {
}
file.delete();
%>
- 07-02-2010, 09:12 PM #4
Member
- Join Date
- Jul 2010
- Posts
- 5
- Rep Power
- 0
I have copy entire jsp file please look at actual code
String url = request.getRequestURL().toString();
String delimiter = ".";
String[] urlprefx = url.split(".");
String test = urlprefx[0];
if(test.indexOf("www")>-1)
I need your advise
- 07-02-2010, 09:32 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
Split uses a regular expression to split on; the single dot "." means "any character" i regular expression lingo; you have to escape it as in "\\."; it's all in the API documentation which you probably haven't read because no one does; you're no exception to the rule ...
kind regards,
Jos
- 07-02-2010, 09:44 PM #6
Member
- Join Date
- Jul 2010
- Posts
- 5
- Rep Power
- 0
Thanks jos you save my day
I appriciated your help
- 07-02-2010, 10:52 PM #7
Member
- Join Date
- Jul 2010
- Posts
- 5
- Rep Power
- 0
Hi jos please help me where I can find API documentation
thanks
- 07-03-2010, 08:08 AM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
A few seconds of googling would've helped you faster: API Documentation.
kind regards,
Jos


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks