I use jetty-maven-plugin to run my web application:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.12.v20130726</version>
<configuration>
<webApp>
<contextPath>/test</contextPath>
</webApp>
</configuration>
</plugin>
Next, I use nginx to proxify requests:
server {
server_name q.ru;
listen 80;
location / {
proxy_http_version 1.1;
proxy_pass http://127.0.0.1:8080/test;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Now, I open my browser, and send request to http://q.ru (localhost in my /etc/hosts).
I get infinite redirection.
Here is HTTP dialog dump- request from nginx to jetty, and jetty response:
GET /test HTTP/1.1
Host: 127.0.0.1:8080
Connection: close
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
HTTP/1.1 302 Found
Location: http://127.0.0.1:8080/test/
Connection: close
Server: Jetty(8.1.12.v20130726)
Host and path are exactly specified in request. So why does jetty send 302 redirect ?
I'm pretty sure this stackoverflow question might help you, I've been searching for similar thing.
Hope that helps.
Cheers
Related
I am trying to implement CORS where the client and server are in the same URL using CORS Filter.
Below is the code I have implemented
CORS Filter
package com.core.web.spring.cors;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CORSFilter implements Filter{
#Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) res;
HttpServletRequest request = (HttpServletRequest) req;
((HttpServletResponse) res).addHeader("Access-Control-Allow-Origin", "http://192.168.0.103:1111");
((HttpServletResponse) res).addHeader("Access-Control-Allow-Methods",
"GET, POST");
((HttpServletResponse) res).addHeader("Access-Control-Max-Age", "3600");
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
response.setStatus(HttpServletResponse.SC_OK);
} else {
chain.doFilter(req, res);
}
}
}
web.xml
<filter>
<filter-name>cors</filter-name>
<filter-class>com.core.web.spring.cors.CORSFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>cors</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
I have set the Access-Control-Allow-Origin as http://192.168.0.103:1111. I am changing the origin to http://192.168.0.108:1111 from the postman tool. But instead of blocking the request, it is executing it. I am getting a successful response.
Below is the request header and response header
Request Header
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8
Connection: keep-alive
Content-Length: 1296
Content-Type: text/html; charset=UTF-8`enter code here`
Host: 192.168.0.103:1111
Origin: http://192.168.0.108:1111
Referer: http://192.168.0.103:1111/SampleTest/index.html
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36
X-Requested-With: XMLHttpRequest
Response Header
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST
Access-Control-Allow-Origin: http://192.168.0.103:1111
Access-Control-Max-Age: 3600
Connection: keep-alive
Content-Length: 1210
Date: Sat, 03 Jul 2021 06:11:55 GMT
Server: WildFly/11
Strict-Transport-Security: max-age=7776000; includeSubdomains
X-Content-Type-Options: nosniff
X-FRAME-OPTIONS: SAMEORIGIN
X-Powered-By: Undertow/1
Can anyone help me with this?
Postman doesn't care about SOP (Same-Origin Policy), it's a dev tool, not a browser.
CORS (Cross-Origin Resource Sharing) and SOP (Same-Origin Policy) are server-side configurations that clients decide to enforce or not.
Related to clients
Most Browsers do enforce it to prevent issues related to CSRF attacks.
Most Development tools don't care about it. Postman being dev tool will not give much importance to CORS header, you will need something else to test.
There are chrome extensions that can help you test CORS on your browser.
I am developing a web application and get this error but can't make sense of it (I've looked at similar questions but the answers there don't seem to apply to my problem)
Can anyone make sense of this?
Please help me.
[WARN] Exception while dispatching incoming RPC call
java.lang.ClassCastException: java.lang.NoClassDefFoundError cannot be cast to java.lang.Exception
at net.sf.gilead.gwt.PersistentRemoteService.processCall(PersistentRemoteService.java:177)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:373)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:755)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:686)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1494)
at org.realityforge.gwt.cache_filter.GWTGzipFilter.doFilter(GWTGzipFilter.java:57)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482)
at ... (more eclipse.jetty...)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:748)
[ERROR] 500 - POST /webproj/login (127.0.0.1) 57 bytes
Request headers
Host: (...)
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: text/x-gwt-rpc; charset=utf-8
(leaving some stuff out)
Connection: keep-alive
Response headers
Content-Type: text/plain
Recently I got a requirement from one of our customer. They provided a WSDL to call their service. They are doing IP whitelisting for authentication. I gave my server public IP and it got whitelisted. First, I tested that service through SOAP UI tool and it got worked without any issues. Then I integrated through JAVA code and it got failed. I am getting an exception like
Unable to sendViaPost to url[https://apps.greystar.com/gsWebService/gsExtract.asmx]
org.apache.axis2.AxisFault: Transport error: 401 Error: Unauthorized
at org.apache.axis2.transport.http.impl.httpclient3.HTTPSenderImpl.handleResponse(HTTPSenderImpl.java:343) ~[axis2-transport-http-1.7.1.jar:1.7.1]
at org.apache.axis2.transport.http.impl.httpclient3.HTTPSenderImpl.sendViaPost(HTTPSenderImpl.java:213) ~[axis2-transport-http-1.7.1.jar:1.7.1]
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:121) [axis2-transport-http-1.7.1.jar:1.7.1]
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:403) [axis2-transport-http-1.7.1.jar:1.7.1]
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:234) [axis2-transport-http-1.7.1.jar:1.7.1]
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:431) [axis2-kernel-1.7.1.jar:1.7.1]
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:399) [axis2-kernel-1.7.1.jar:1.7.1]
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:225) [axis2-kernel-1.7.1.jar:1.7.1]
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:150) [axis2-kernel-1.7.1.jar:1.7.1]
at com.reputation.r4e.integrator.greystar.ExtractDataStub.greystarExtract(ExtractDataStub.java:300) [classes/:na]
at com.reputation.r4e.integrator.recordreader.GreystarLocationImportRecordReader.getGreystarExtractResponse(GreystarLocationImportRecordReader.java:198) [classes/:na]
at com.reputation.r4e.integrator.recordreader.GreystarLocationImportRecordReader.process(GreystarLocationImportRecordReader.java:97) [classes/:na]
at com.reputation.r4e.integrator.impl.DefaultPipeline.flow(DefaultPipeline.java:33) [classes/:na]
at com.reputation.r4e.integrator.impl.DefaultPipeline.process(DefaultPipeline.java:52) [classes/:na]
at com.reputation.r4e.integrator.importer.NullImporter.process(NullImporter.java:38) [classes/:na]
at com.reputation.r4e.integrator.impl.DefaultPipeline.flow(DefaultPipeline.java:33) [classes/:na]
at com.reputation.r4e.integrator.impl.DefaultPipeline.process(DefaultPipeline.java:52) [classes/:na]
at com.reputation.r4e.integrator.IntegrationRunner$IntegrationRunnable.run(IntegrationRunner.java:87) [classes/:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_45]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_45]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45]
It's saying 401 unauthorised error. How it got worked through SOAP UI and why its not working through a JAVA client.?
I monitor http traffic through TCPMon and except headers all are same. So I added the headers which got from the SOAP UI tool to my JAVA Client but still no luck. I am getting the same 401 unauthorised error.
Here are the soap request of both SOAP UI and through JAVA Client.
SOAP UI Request:
POST https://apps.greystar.com/gsWebService/gsExtract.asmx HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/soap+xml;charset=UTF-8;action="https://apps.greystar.com/greystarExtract"
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
Content-Length: 692
Host: apps.greystar.com
Connection: Keep-Alive
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:apps="https://apps.greystar.com/">
<soap:Header/>
<soap:Body>
<apps:greystarExtract>
<apps:axmlVendorCode>VENDOR_CODE</apps:axmlVendorCode>
<apps:axmlToken>PASSWORD</apps:axmlToken>
<apps:axmlExtractType>PROPERTY_LIST</apps:axmlExtractType>
<apps:axmlFormat>XML</apps:axmlFormat>
<apps:axmlParameters></apps:axmlParameters>
</apps:greystarExtract>
</soap:Body>
</soap:Envelope>
JAVA CLIENT Request:
POST /gsWebService/gsExtract.asmx HTTP/1.1
Content-Type: application/soap+xml; charset=UTF-8; action="https://apps.greystar.com/greystarExtract
Accept-Encoding: gzip,deflate
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36[\r][\n]
Connection: Keep-Alive
Host: apps.greystar.com
Transfer-Encoding: chunked
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header />
<soapenv:Body>
<ns1:greystarExtract xmlns:ns1="https://apps.greystar.com/">
<ns1:axmlVendorCode>VENDOR_CODE</ns1:axmlVendorCode>
<ns1:axmlToken>PASSWORD</ns1:axmlToken>
<ns1:axmlExtractType>PROPERTY_LIST</ns1:axmlExtractType>
<ns1:axmlFormat>JSON</ns1:axmlFormat>
<ns1:axmlParameters></ns1:axmlParameters>
</ns1:greystarExtract>
</soapenv:Body>
</soapenv:Envelope>
Note: I added JAVA Client headers by looking at the SOAP UI headers. The actual JAVA client headers are below
POST /gsWebService/gsExtract.asmx HTTP/1.1
Content-Type: application/soap+xml; charset=UTF-8;
action="https://apps.greystar.com/greystarExtract
User-Agent: Axis2
Host: apps.greystar.com
Transfer-Encoding: chunked
What could be the reason for failing this through JAVA client.? Can any one please answer my question because I stuck over here.
Thanks in advance,
Amar.T
I tried other third party libraries and its working as expected. I tried CXF and SOAP UI JAVA API and its working as expected. I don't know why its not working with APACHE AXIS2.
If anyone finds the answer why its not working with AXIS2 please post the answer.
Thanks & Regards,
Amar.T
I deployed my gwt project on localhost with gwt-plugin on eclipse. Everything works fine. But when I try to launch application outside (from tomcat) it doesn't work normally. I put war content into webaaps folder. The client side of gwt works well but there is a problem with connection to server side.
Probable error from logs:
127.0.0.1 - - [07/Mar/2014:17:31:36 +0400] "GET /BugGitGwt/ HTTP/1.1" 200 2954
127.0.0.1 - - [07/Mar/2014:17:31:36 +0400] "GET /BugGitGwt/buggitgwt/buggitgwt.nocache.js HTTP/1.1" 200 6004
127.0.0.1 - - [07/Mar/2014:17:31:36 +0400] "GET /BugGitGwt/loading4.gif HTTP/1.1" 200 2164
127.0.0.1 - - [07/Mar/2014:17:31:36 +0400] "GET /BugGitGwt/BugGitGwt.css HTTP/1.1" 200 708
127.0.0.1 - - [07/Mar/2014:17:31:36 +0400] "GET /BugGitGwt/buggitgwt/gwt/clean/clean.css HTTP/1.1" 200 29325
127.0.0.1 - - [07/Mar/2014:17:31:36 +0400] "GET /BugGitGwt/buggitgwt/0B29E478EEA6D0F7C8617BCA1D490240.cache.html HTTP/1.1" 200 161530
127.0.0.1 - - [07/Mar/2014:17:31:36 +0400] "POST /BugGitGwt/buggitgwt/greet HTTP/1.1" 500 2820
127.0.0.1 - - [07/Mar/2014:17:31:36 +0400] "POST /BugGitGwt/buggitgwt/greet HTTP/1.1" 500 2820
127.0.0.1 - - [07/Mar/2014:17:31:36 +0400] "POST /BugGitGwt/buggitgwt/greet HTTP/1.1" 500 2820
127.0.0.1 - - [07/Mar/2014:17:31:36 +0400] "GET /BugGitGwt/buggitgwt/gwt/clean/images/hborder.png HTTP/1.1" 200 1995
127.0.0.1 - - [07/Mar/2014:17:31:36 +0400] "GET /BugGitGwt/buggitgwt/gwt/clean/images/circles.png HTTP/1.1" 200 1492
127.0.0.1 - - [07/Mar/2014:17:31:36 +0400] "GET /BugGitGwt/buggitgwt/gwt/clean/images/vborder.png HTTP/1.1" 200 298
or this:
INFO: The APR based Apache Tomcat Native library which allows optimal performance in
production environments was not found on the
java.library.path: C:\Program Files (x86)\Java\jdk1.6.0_45\bin;
C:\Windows\Sun\Java\bin;
C:\Windows\system32;
C:\Windows;C:\Program Files (x86)\Intel\iCLS Client\;
C:\Program Files\Intel\iCLS Client\;
C:\Program Files (x86)\AMD APP\bin\x86_64;
C:\Program Files (x86)\AMD APP\bin\x86;C:\Windows\system32;
C:\Windows;C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;
C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;
C:\Program Files (x86)\Java\jdk1.6.0_45\bin;
C:\apache-maven-3.1.1\bin;
C:\Program Files (x86)\MySQL\MySQL Utilities 1.3.6\;
C:\apache-ant-1.9.3\bin;
C:\Program Files (x86)\Java\jdk1.6.0_45\bin;
C:\Program Files (x86)\Git\bin;
C:\Program Files (x86)\Git\cmd;;.
or this:
INFO: JSR 356 WebSocket (Java WebSocket 1.0) support is not available
when running on Java 6. To suppress this message, run Tomcat on Java 7,
remove the WebSocket JARs from $CATALINA_HOME/lib or add
the WebSocketJARs to thetomcat.util.scan.DefaultJarScanner.jarsToSkip property in
$CATALINA_BASE/conf/catalina.properties. Note that the deprecated Tomcat 7
WebSocket API will be available.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee">
<!-- Servlets -->
<servlet>
<servlet-name>greetServlet</servlet-name>
<servlet-class>ru.sersem.buggitgwt.server.DataProviderServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>greetServlet</servlet-name>
<url-pattern>/buggitgwt/greet</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>BugGitGwt.html</welcome-file>
</welcome-file-list>
</web-app>
Service:
#RemoteServiceRelativePath("greet")
public interface DataProviderService extends RemoteService {
List<List<String>> getDatabaseData(String call);
}
Step to follow to run GWT project from external server.
Open command window
Navigate to war folder that contains following things:
war
|
|__GWTTestProject.html
|__GWTTestProject.css
|__gwttestproject folder
| |
| |__compiled js files and html files generated by GWT compilation
|
|__WEB-INF folder
|
|__classes
|__deploy
|__lib
|__web.xml
Execute following command using Command prompt to create a war file
jar -cf gwtproject.war *
Copy gwtproject.war under tomcat webapps
start the server
Please check it again in following files:
web.xml:
<servlet>
<servlet-name>greetServlet</servlet-name>
<servlet-class>com.gwt.test.server.GreetingServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>greetServlet</servlet-name>
<url-pattern>/gwtproject/greet</url-pattern>
</servlet-mapping>
GreetingService:
#RemoteServiceRelativePath("greet")
public interface GreetingService extends RemoteService {
Long greetServer(String name) throws IllegalArgumentException;
}
Okay. There was a thing. We use Java 6 in our enterprise but GWT supports Java 7. So it works under java 7 in eclipse but in system environment it was down.
I am using Netty (via the Ning async HTTP library) to retrieve documents via HTTP. This produces a huge amount of debug output the console, as listed below for a single document request.
Anyone know how to turn this off? I really don't need to see this output.
I'm calling from Scala, if that makes any difference.
15:07:14.273 [run-main] DEBUG c.n.h.c.p.n.NettyAsyncHttpProvider -
Non cached request
DefaultHttpRequest(chunked: false)
GET /api/search.json?q=foo HTTP/1.1
Host: www.documentcloud.org
Connection: keep-alive
Accept: */*
User-Agent: NING/1.0
using Channel
[id: 0x2839ca40]
15:07:14.930 [New I/O client worker #1-1] DEBUG c.n.h.c.p.n.NettyAsyncHttpProvider -
Request DefaultHttpRequest(chunked: false)
GET /api/search.json?q=foo HTTP/1.1
Host: www.documentcloud.org
Connection: keep-alive
Accept: */*
User-Agent: NING/1.0
Response DefaultHttpResponse(chunked: true)
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 10477
Connection: keep-alive
Vary: Accept-Encoding
Status: 200
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.13
ETag: "4f8f766d639dd84d014dfee3abb45de2"
X-Runtime: 611
Cache-Control: private, max-age=0, must-revalidate
Server: nginx/1.2.1 + Phusion Passenger 3.0.13 (mod_rails/mod_rack)
15:07:14.941 [New I/O client worker #1-1] DEBUG c.n.h.c.p.netty.NettyConnectionsPool - Adding uri: http://www.documentcloud.org:80 for channel [id: 0x2839ca40, /10.5.165.61:56133 => www.documentcloud.org/75.101.159.206:80]
15:07:16.921 [New I/O client worker #1-1] DEBUG c.n.h.c.p.n.NettyAsyncHttpProvider - Channel Closed: [id: 0x2839ca40, /10.5.165.61:56133 :> www.documentcloud.org/75.101.159.206:80] with attachment com.ning.http.client.providers.netty.NettyAsyncHttpProvider$DiscardEvent#63182c3d
15:08:13.924 [Timer-0] DEBUG c.n.h.c.p.netty.NettyConnectionsPool - Entry count for : http://www.documentcloud.org:80 : 0
judging by the abbreviated package names seems to me slf4j/logback is being used for logging here.
in that case just try including a logback.xml configuration file in your classpath. something along the lines of
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
<logger name="com.ning.http.client" level="WARN"/>
</configuration>
the above xml would cause anything under com.ning.http.client (and downwards) to omit only warnings and worse to the output, which will be streamed to system.out. anything else will ommit INFO+
you can find more information on configuring logback here: http://logback.qos.ch/manual/configuration.html
Late posting for an old question I know but I recently had to turn off annoying repetitive INFO level logging coming from netty:
[main] INFO com.ning.http.client.providers.netty.NettyAsyncHttpProvider - Number of application's worked threads is 16
In my case I needed to disable it programmatically. Looking into slf4j org.slf4j.impl.SimpleLogger (the logger facade called by netty) I discovered an easy way to control the default slf4j log level for all SimpleLogger instances in your own startup code:
System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "warn");
or for just the logger instance I was interested in:
System.setProperty(SimpleLogger.LOG_KEY_PREFIX + "com.ning.http.client", "warn");
The value can be any of "trace", "debug", "info", "warn", or "error" with the default being "info".