List of usage examples for javax.servlet ServletRequest getServerPort
public int getServerPort();
From source file:org.everit.jetty.server.ecm.tests.EchoRemoteInfoServlet.java
@Override public void service(final ServletRequest req, final ServletResponse res) throws ServletException, IOException { PrintWriter writer = res.getWriter(); JSONObject jsonObject = new JSONObject(); jsonObject.put("remoteAddr", req.getRemoteAddr()); jsonObject.put("remoteHost", req.getRemoteHost()); jsonObject.put("remotePort", req.getRemotePort()); jsonObject.put("serverName", req.getServerName()); jsonObject.put("serverPort", req.getServerPort()); jsonObject.put("protocol", req.getProtocol()); jsonObject.put("secure", req.isSecure()); writer.write(jsonObject.toString()); }
From source file:com.castlemock.web.mock.rest.web.mvc.controller.resource.RestResourceController.java
/** * Retrieves a specific REST resource with a project id, application and resource id * @param restProjectId The id of the project that the REST resource belongs to * @param restApplicationId The id of the application that the REST resource belongs to * @param restResourceId The id of the REST resource that should be retrieve * @param request The incoming servlet request. Used to extract the address used to invoke the REST methods * @return REST resource that matches the provided resource id */// www.j a v a 2 s. co m @PreAuthorize("hasAuthority('READER') or hasAuthority('MODIFIER') or hasAuthority('ADMIN')") @RequestMapping(value = "/{restProjectId}/application/{restApplicationId}/resource/{restResourceId}", method = RequestMethod.GET) public ModelAndView defaultPage(@PathVariable final String restProjectId, @PathVariable final String restApplicationId, @PathVariable final String restResourceId, final ServletRequest request) { final ReadRestResourceOutput output = serviceProcessor .process(new ReadRestResourceInput(restProjectId, restApplicationId, restResourceId)); final RestResourceDto restResource = output.getRestResource(); final String protocol = getProtocol(request); final String invokeAddress = getRestInvokeAddress(protocol, request.getServerPort(), restProjectId, restApplicationId, restResource.getUri()); restResource.setInvokeAddress(invokeAddress); final ModelAndView model = createPartialModelAndView(PAGE); model.addObject(REST_PROJECT_ID, restProjectId); model.addObject(REST_APPLICATION_ID, restApplicationId); model.addObject(REST_RESOURCE, restResource); model.addObject(REST_METHOD_STATUSES, getRestMethodStatuses()); model.addObject(REST_METHOD_MODIFIER_COMMAND, new RestMethodModifierCommand()); return model; }
From source file:pt.webdetails.cdv.api.CdvApi.java
private String getRoot(ServletRequest wrapper) { return wrapper.getScheme() + "://" + wrapper.getServerName() + ":" + wrapper.getServerPort(); }
From source file:pt.webdetails.cfr.CfrContentGenerator.java
private String getRoot() { ServletRequest wrapper = getRequest(); String root = wrapper.getScheme() + "://" + wrapper.getServerName() + ":" + wrapper.getServerPort(); return root;// w w w. j ava 2s .c om }
From source file:org.jboss.dashboard.ui.components.URLMarkupGenerator.java
public String getContextHost(ServletRequest request) { StringBuffer sb = new StringBuffer(); String context = ((HttpServletRequest) request).getContextPath(); String protocol = request.getScheme(); while (context.startsWith("/")) context = context.substring(1);/* w w w.j a v a2s .c o m*/ sb.append(protocol.toLowerCase()).append("://").append(request.getServerName()); if (request.getServerPort() != 80) { sb.append(":").append(request.getServerPort()); } return sb.toString(); }
From source file:pt.webdetails.cfr.CfrContentGenerator.java
@Exposed(accessLevel = AccessLevel.PUBLIC) public void home(OutputStream out) throws IOException { IParameterProvider requestParams = getRequestParameters(); // IParameterProvider pathParams = getPathParameters(); ServletRequest wrapper = getRequest(); String root = wrapper.getScheme() + "://" + wrapper.getServerName() + ":" + wrapper.getServerPort(); Map<String, Object> params = new HashMap<String, Object>(); params.put("solution", "system"); params.put("path", "cfr/presentation/"); params.put("file", "cfr.wcdf"); params.put("absolute", "false"); params.put("inferScheme", "false"); params.put("root", root); // add request parameters PluginUtils.copyParametersFromProvider(params, WrapperUtils.wrapParamProvider(requestParams)); if (requestParams.hasParameter("mode") && requestParams.getStringParameter("mode", "Render").equals("edit")) { // Send this to CDE redirectToCdeEditor(out, params); return;/*from ww w . jav a2s. co m*/ } InterPluginCall pluginCall = new InterPluginCall(InterPluginCall.CDE, "Render", params); pluginCall.setResponse(getResponse()); pluginCall.setRequest(getRequest()); pluginCall.setOutputStream(out); pluginCall.run(); }
From source file:org.parancoe.web.tag.MarkPositionTag.java
@Override protected final int doStartTagInternal() throws JspException, IOException { final HttpSession session = pageContext.getSession(); ServletRequest request = pageContext.getRequest(); final RequestContext requestContext = this.getRequestContext(); final String uri = requestContext.getRequestUri(); String contextPath = requestContext.getContextPath(); final String queryString = requestContext.getQueryString(); String url = ""; if (uri.startsWith(contextPath)) { url = uri.substring(contextPath.length()); } else {// w ww . java 2 s . c o m url = uri; } if (!StringUtils.isBlank(queryString)) { url = url + "?" + queryString; } if (useFullUri) { String port = ""; if (request.getServerPort() != 80) { port = ":" + request.getServerPort(); } url = request.getScheme() + "://" + request.getServerName() + port + requestContext.getContextPath() + url; } MarkPositionHelper.markPosition(session, pathId, url); return SKIP_BODY; }
From source file:org.jboss.dashboard.ui.components.URLMarkupGenerator.java
/** * Get the base href for current request * @param request/* w w w .j a va2 s .com*/ * @return a String with the form http://host[:port]/[context/] * @throws IOException */ public String getBaseHref(ServletRequest request) throws IOException { StringBuffer sb = new StringBuffer(); String context = ((HttpServletRequest) request).getContextPath(); String protocol = request.getScheme(); while (context.startsWith("/")) { context = context.substring(1); } sb.append(protocol.toLowerCase()).append("://").append(request.getServerName()); if (request.getServerPort() != 80) { sb.append(":").append(request.getServerPort()); } sb.append("/"); if (!StringUtils.isEmpty(context)) { sb.append(context).append("/"); } return sb.toString(); }
From source file:com.castlemock.web.mock.soap.web.mvc.controller.operation.SoapOperationController.java
/** * The method provides functionality to retrieve a specific operation * @param soapProjectId The id of the project that the operation belongs to * @param soapPortId The id of the port that the operation belongs to * @param soapOperationId The id of the operation that will be retrieved * @param request The request is used to retrieve with port was used to communicate with the project * @return A view that displays the retrieved operation *///from w w w. j a va 2 s . c o m @PreAuthorize("hasAuthority('READER') or hasAuthority('MODIFIER') or hasAuthority('ADMIN')") @RequestMapping(value = "/{soapProjectId}/port/{soapPortId}/operation/{soapOperationId}", method = RequestMethod.GET) public ModelAndView defaultPage(@PathVariable final String soapProjectId, @PathVariable final String soapPortId, @PathVariable final String soapOperationId, final ServletRequest request) { final ReadSoapPortOutput readSoapPortOutput = serviceProcessor .process(new ReadSoapPortInput(soapProjectId, soapPortId)); final SoapPortDto soapPort = readSoapPortOutput.getSoapPort(); final ReadSoapOperationOutput readSoapOperationOutput = serviceProcessor .process(new ReadSoapOperationInput(soapProjectId, soapPortId, soapOperationId)); final SoapOperationDto soapOperation = readSoapOperationOutput.getSoapOperation(); final ReadSoapEventsByOperationIdOutput readSoapEventsByOperationIdOutput = serviceProcessor .process(new ReadSoapEventsByOperationIdInput(soapOperationId)); final String protocol = getProtocol(request); final String invokeAddress = getSoapInvokeAddress(protocol, request.getServerPort(), soapProjectId, soapPort.getUri()); soapOperation.setInvokeAddress(invokeAddress); final ModelAndView model = createPartialModelAndView(PAGE); model.addObject(SOAP_OPERATION, soapOperation); model.addObject(SOAP_PROJECT_ID, soapProjectId); model.addObject(SOAP_PORT_ID, soapPortId); model.addObject(SOAP_MOCK_RESPONSE_STATUSES, SoapMockResponseStatus.values()); model.addObject(SOAP_EVENTS, readSoapEventsByOperationIdOutput.getSoapEvents()); model.addObject(SOAP_MOCK_RESPONSE_MODIFIER_COMMAND, new SoapMockResponseModifierCommand()); return model; }
From source file:com.castlemock.web.mock.rest.web.mvc.controller.method.RestMethodController.java
/** * Retrieves a specific method with a method id * @param restProjectId The id of the project responsible for the REST method * @param restApplicationId The id of the application responsible for the REST method * @param restResourceId The id of the resource responsible for the REST method * @param restMethodId The id of the method that should be retrieved * @param request The incoming servlet request. Used to extract the address used to invoke the REST methods * @return REST Method that matches the provided project id *//*from ww w . jav a 2 s . co m*/ @PreAuthorize("hasAuthority('READER') or hasAuthority('MODIFIER') or hasAuthority('ADMIN')") @RequestMapping(value = "/{restProjectId}/application/{restApplicationId}/resource/{restResourceId}/method/{restMethodId}", method = RequestMethod.GET) public ModelAndView defaultPage(@PathVariable final String restProjectId, @PathVariable final String restApplicationId, @PathVariable final String restResourceId, @PathVariable final String restMethodId, final ServletRequest request) { final ReadRestResourceOutput readRestResourceOutput = serviceProcessor .process(new ReadRestResourceInput(restProjectId, restApplicationId, restResourceId)); final ReadRestMethodOutput restMethodOutput = serviceProcessor .process(new ReadRestMethodInput(restProjectId, restApplicationId, restResourceId, restMethodId)); final RestResourceDto restResource = readRestResourceOutput.getRestResource(); final RestMethodDto restMethod = restMethodOutput.getRestMethod(); final ReadRestEventWithMethodIdOutput readRestEventWithMethodIdOutput = serviceProcessor .process(new ReadRestEventWithMethodIdInput(restMethodId)); final String protocol = getProtocol(request); final String invokeAddress = getRestInvokeAddress(protocol, request.getServerPort(), restProjectId, restApplicationId, restResource.getUri()); restMethod.setInvokeAddress(invokeAddress); final ModelAndView model = createPartialModelAndView(PAGE); model.addObject(REST_PROJECT_ID, restProjectId); model.addObject(REST_APPLICATION_ID, restApplicationId); model.addObject(REST_RESOURCE_ID, restResourceId); model.addObject(REST_METHOD, restMethod); model.addObject(REST_MOCK_RESPONSE_STATUSES, RestMockResponseStatus.values()); model.addObject(REST_EVENTS, readRestEventWithMethodIdOutput.getRestEvents()); model.addObject(REST_MOCK_RESPONSE_MODIFIER_COMMAND, new RestMockResponseModifierCommand()); return model; }